mirror of
https://github.com/moparisthebest/ComicReader
synced 2024-11-15 13:45:07 -05:00
commit
6bca40dd71
@ -32,8 +32,11 @@
|
||||
{"class":"GuComics", "name":"Gu Comics", "pref":"gucomicsPref"},
|
||||
{"class":"GunnerkriggCourt", "name":"Gunnerkrigg Court", "pref":"gunnerkriggcourtPref"},
|
||||
{"class":"JoeAndMonkey", "name":"Joe And Monkey", "pref":"joeandmonkeyPref"},
|
||||
{"class":"KevinAndKell", "name":"Kevin And Kell", "pref":"kevinandkellPref", "new":"1"},
|
||||
{"class":"LeastICouldDo", "name":"Least I Could Do", "pref":"leasticoulddoPref"},
|
||||
{"class":"LookingForGroup", "name":"Looking For Group", "pref":"lookingforgroupPref"},
|
||||
{"class":"MegaTokyo", "name":"MegaTokyo", "pref":"megatokyoPref", "new":"1"},
|
||||
{"class":"MenageA3", "name":"Menage a 3", "pref":"menagea3Pref", "new":"1"},
|
||||
{"class":"Misfile", "name":"Misfile", "pref":"misfilePref"},
|
||||
{"class":"MotherGooseandGrimm", "name":"Mother Goose & Grimm", "pref":"mothergooseandgrimmPref"},
|
||||
{"class":"OOTS", "name":"Order of the Stick", "pref":"ootsPref"},
|
||||
@ -62,7 +65,6 @@
|
||||
{"class":"Wondermark", "name":"Wondermark", "pref":"wondermarkPref"},
|
||||
{"class":"Wulffmorgenthaler", "name":"Wulffmorgenthaler", "pref":"wulffmorgenthalerPref"},
|
||||
{"class":"Xkcd", "name":"Xkcd", "pref":"xkcdPref"},
|
||||
{"class":"MegaTokyo", "name":"MegaTokyo", "pref":"megatokyoPref", "new":"1"},
|
||||
{"class":"Yafgc", "name":"Yet Another Fantasy Gamer Comic", "pref":"yafgcPref"},
|
||||
{"class":"Zap", "name":"Zap!", "pref":"zapPref"},
|
||||
{"class":"Channelate", "name":"Channelate", "pref":"channelatePref"},
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="backgroundCacheEnabledPref"
|
||||
android:title="Enable Caching"
|
||||
@ -44,6 +45,11 @@
|
||||
android:entries="@array/sync_type"
|
||||
android:entryValues="@array/sync_type_values"
|
||||
android:dependency="backgroundCacheEnabledPref" />
|
||||
<CheckBoxPreference
|
||||
android:key="notificationPref"
|
||||
android:title="Display Notifications"
|
||||
android:summary="Display notifications to appear in the notification bar"
|
||||
android:defaultValue="true" />
|
||||
<ListPreference
|
||||
android:title="Sort (My Comics)"
|
||||
android:summary="Sort Order in My Comics Page"
|
||||
|
@ -25,7 +25,6 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
|
||||
/**
|
||||
* Actual class for background caching
|
||||
*/
|
||||
@ -70,7 +69,6 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
/** progress message */
|
||||
private String mStr;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@ -87,12 +85,12 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
* Waits for connectivity to come up
|
||||
*/
|
||||
private void _waitForConnectivity() {
|
||||
if(!_isOnWifi(mCtx) && !_isOnMobileData(mCtx)) {
|
||||
Log.d(TAG, "Sleeping for "+SLEEP_DURATION+" ms hoping that the network will turn on...");
|
||||
if (!_isOnWifi(mCtx) && !_isOnMobileData(mCtx)) {
|
||||
Log.d(TAG, "Sleeping for " + SLEEP_DURATION
|
||||
+ " ms hoping that the network will turn on...");
|
||||
try {
|
||||
Thread.sleep(SLEEP_DURATION);
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.d(TAG, "Sleeping is over...");
|
||||
@ -104,25 +102,25 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
*/
|
||||
synchronized private void _mutexCall() {
|
||||
mCtx = getApplicationContext();
|
||||
Log.d(TAG, "starting the service for caching comic strips in background ...");
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mCtx);
|
||||
if(!sp.getBoolean("backgroundCacheEnabledPref", false)) {
|
||||
Log.d(TAG,
|
||||
"starting the service for caching comic strips in background ...");
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences(mCtx);
|
||||
if (!sp.getBoolean("backgroundCacheEnabledPref", false)) {
|
||||
Log.d(TAG, "Background caching not enabled. Returing back...");
|
||||
return;
|
||||
}
|
||||
_waitForConnectivity();
|
||||
if(_isOnWifi(mCtx)) {
|
||||
if (_isOnWifi(mCtx)) {
|
||||
_cacheStrips(sp);
|
||||
}
|
||||
else if(_isOnMobileData(mCtx)) {
|
||||
if(sp.getBoolean("mobileDataCacheEnabledPref", false)) {
|
||||
} else if (_isOnMobileData(mCtx)) {
|
||||
if (sp.getBoolean("mobileDataCacheEnabledPref", false)) {
|
||||
_cacheStrips(sp);
|
||||
} else {
|
||||
Log.d(TAG,
|
||||
"You're on mobile-data, but caching is disabled on this network. So, returning back...");
|
||||
}
|
||||
else {
|
||||
Log.d(TAG, "You're on mobile-data, but caching is disabled on this network. So, returning back...");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Log.d(TAG, "No wifi + no mobile-data. So, returing back...");
|
||||
}
|
||||
Log.d(TAG, "background comic cache service ended ...");
|
||||
@ -130,91 +128,112 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
|
||||
/**
|
||||
* Callback for cancelling this progress
|
||||
* @param v view generating this callback
|
||||
*
|
||||
* @param v
|
||||
* view generating this callback
|
||||
*/
|
||||
public void onCancelClick(View v) {
|
||||
final Resources res = mCtx.getResources();
|
||||
AlertDialog.Builder alertbox = new AlertDialog.Builder(mCtx);
|
||||
alertbox.setMessage(res.getString(R.string.my_comic_restore_confirmation));
|
||||
alertbox.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertbox.setMessage(res
|
||||
.getString(R.string.my_comic_restore_confirmation));
|
||||
alertbox.setNegativeButton("Cancel",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
});
|
||||
alertbox.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
stopSelf();
|
||||
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
||||
}
|
||||
});
|
||||
alertbox.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
stopSelf();
|
||||
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Caching the strips
|
||||
* @param sp shared preferences
|
||||
*
|
||||
* @param sp
|
||||
* shared preferences
|
||||
*/
|
||||
private void _cacheStrips(SharedPreferences sp) {
|
||||
mSortType = Integer.parseInt(sp.getString("mySortPref", Integer.toString(ComicClassList.SORT_ALPHABETICAL)));
|
||||
mSortType = Integer.parseInt(sp.getString("mySortPref",
|
||||
Integer.toString(ComicClassList.SORT_ALPHABETICAL)));
|
||||
mNumStrips = Integer.parseInt(sp.getString("numStripsCachePref", "5"));
|
||||
mSyncType = Integer.parseInt(sp.getString("syncTypePref", Integer.toString(SYNC_FROM_LATEST)));
|
||||
mSyncType = Integer.parseInt(sp.getString("syncTypePref",
|
||||
Integer.toString(SYNC_FROM_LATEST)));
|
||||
Log.d(TAG, "Setting up the progress bar for notifying sync updates...");
|
||||
try {
|
||||
mList = new ComicClassList(mCtx.getAssets());
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
mMgr = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mMgr = (NotificationManager) mCtx
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mTotal = mList.numSelected() * mNumStrips;
|
||||
if(mSyncType == SYNC_BOTH) {
|
||||
if (mSyncType == SYNC_BOTH) {
|
||||
mTotal *= 2;
|
||||
}
|
||||
mChecked = 0;
|
||||
mStr = mCtx.getResources().getString(R.string.bg_cache_progress_msg);
|
||||
mNotify = new Notification(R.drawable.icon, "ComicReader", System.currentTimeMillis());
|
||||
Intent in = new Intent(mCtx, ActivityComicReader.class);
|
||||
mNotify.contentIntent = PendingIntent.getActivity(mCtx, 0, in, 0);
|
||||
mNotify.contentView = new RemoteViews(mCtx.getPackageName(), R.layout.bg_cache_progress);
|
||||
mNotify.flags = Notification.FLAG_ONGOING_EVENT;
|
||||
_updateProgress();
|
||||
if (sp.getBoolean("notificationPref", true)) {
|
||||
mNotify = new Notification(R.drawable.icon, "ComicReader",
|
||||
System.currentTimeMillis());
|
||||
Intent in = new Intent(mCtx, ActivityComicReader.class);
|
||||
mNotify.contentIntent = PendingIntent.getActivity(mCtx, 0, in, 0);
|
||||
mNotify.contentView = new RemoteViews(mCtx.getPackageName(),
|
||||
R.layout.bg_cache_progress);
|
||||
mNotify.flags = Notification.FLAG_ONGOING_EVENT;
|
||||
_updateProgress();
|
||||
}
|
||||
try {
|
||||
mNumDnlds = 0;
|
||||
mList.sortClasses(mSortType);
|
||||
int num = mList.length();
|
||||
for(int i=0;i<num;++i) {
|
||||
for (int i = 0; i < num; ++i) {
|
||||
ComicClass clz = mList.getComicClassFromIndex(i);
|
||||
if(!clz.mSel) {
|
||||
if (!clz.mSel) {
|
||||
continue;
|
||||
}
|
||||
Log.d(TAG, "Working on comic = "+clz.mName);
|
||||
Log.d(TAG, "Working on comic = " + clz.mName);
|
||||
Comic com = mList.getComicFromIndex(i);
|
||||
com.setComicName(clz.mName);
|
||||
com.readProperties();
|
||||
com.setLaunchType(Comic.TYPE_CACHING);
|
||||
boolean status = _syncAcomic(com, mNumStrips, mSyncType);
|
||||
com.writeProperties();
|
||||
Log.d(TAG, "Finished working on comic = "+clz.mName+" status="+status);
|
||||
Log.d(TAG, "Number of downloads so far="+mNumDnlds);
|
||||
Log.d(TAG, "Finished working on comic = " + clz.mName
|
||||
+ " status=" + status);
|
||||
Log.d(TAG, "Number of downloads so far=" + mNumDnlds);
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
||||
e.printStackTrace();
|
||||
}
|
||||
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
||||
if(mNumDnlds <= 0) {
|
||||
Log.d(TAG, "No new strips to be read. So, not setting up a notification...");
|
||||
if (mNumDnlds <= 0) {
|
||||
Log.d(TAG,
|
||||
"No new strips to be read. So, not setting up a notification...");
|
||||
_commitLastSyncTime();
|
||||
return;
|
||||
}
|
||||
Intent i = new Intent(mCtx, ActivityComicReader.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
PendingIntent pi = PendingIntent.getActivity(mCtx, 0, i, 0);
|
||||
mNotify = new Notification(R.drawable.icon, "ComicReader", System.currentTimeMillis());
|
||||
mNotify.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
|
||||
mNotify.setLatestEventInfo(mCtx, "Comic Reader", "Total of "+mNumDnlds+" newly downloaded strips", pi);
|
||||
Log.d(TAG, "Notifying the manager of this new notification...");
|
||||
mMgr.notify(NOTIFY_ID, mNotify);
|
||||
// TODO: location of notifies.
|
||||
|
||||
if (sp.getBoolean("notificationPref", true)) {
|
||||
mNotify = new Notification(R.drawable.icon, "ComicReader",
|
||||
System.currentTimeMillis());
|
||||
mNotify.flags = Notification.FLAG_AUTO_CANCEL
|
||||
| Notification.FLAG_SHOW_LIGHTS;
|
||||
mNotify.setLatestEventInfo(mCtx, "Comic Reader", "Total of "
|
||||
+ mNumDnlds + " newly downloaded strips", pi);
|
||||
Log.d(TAG, "Notifying the manager of this new notification...");
|
||||
mMgr.notify(NOTIFY_ID, mNotify);
|
||||
}
|
||||
|
||||
_commitLastSyncTime();
|
||||
}
|
||||
|
||||
@ -223,35 +242,45 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
*/
|
||||
private void _commitLastSyncTime() {
|
||||
long lastSync = System.currentTimeMillis();
|
||||
Log.d(TAG, "last sync time = "+lastSync);
|
||||
SharedPreferences.Editor ed = PreferenceManager.getDefaultSharedPreferences(mCtx).edit();
|
||||
Log.d(TAG, "last sync time = " + lastSync);
|
||||
SharedPreferences.Editor ed = PreferenceManager
|
||||
.getDefaultSharedPreferences(mCtx).edit();
|
||||
ed.putLong(ActivitySettingsPage.LAST_SYNC_PREF, lastSync);
|
||||
Calendar now = Calendar.getInstance();
|
||||
int mon = now.get(Calendar.MONTH) + 1;
|
||||
String str = "'" + now.get(Calendar.YEAR) + "/" + mon + "/" + now.get(Calendar.DAY_OF_MONTH);
|
||||
str += " " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "'";
|
||||
String str = "'" + now.get(Calendar.YEAR) + "/" + mon + "/"
|
||||
+ now.get(Calendar.DAY_OF_MONTH);
|
||||
str += " " + now.get(Calendar.HOUR_OF_DAY) + ":"
|
||||
+ now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)
|
||||
+ "'";
|
||||
ed.putString(ActivitySettingsPage.LAST_SYNC_STRING_PREF, str);
|
||||
ed.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to check whether we are on WIFI or not
|
||||
* @param ctxt application context
|
||||
*
|
||||
* @param ctxt
|
||||
* application context
|
||||
* @return true if we are
|
||||
*/
|
||||
private boolean _isOnWifi(Context ctxt) {
|
||||
ConnectivityManager cm = (ConnectivityManager) ctxt.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
ConnectivityManager cm = (ConnectivityManager) ctxt
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
return wifi.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to check whether we are on Mobile-data or not
|
||||
* @param ctxt application context
|
||||
*
|
||||
* @param ctxt
|
||||
* application context
|
||||
* @return true if we are
|
||||
*/
|
||||
private boolean _isOnMobileData(Context ctxt) {
|
||||
ConnectivityManager cm = (ConnectivityManager) ctxt.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
ConnectivityManager cm = (ConnectivityManager) ctxt
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
return mobile.isConnected();
|
||||
}
|
||||
@ -270,13 +299,17 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
|
||||
/**
|
||||
* Syncs for a comic
|
||||
* @param com comic
|
||||
* @param numStrips number of strips to be synced
|
||||
* @param sType sync type
|
||||
*
|
||||
* @param com
|
||||
* comic
|
||||
* @param numStrips
|
||||
* number of strips to be synced
|
||||
* @param sType
|
||||
* sync type
|
||||
* @return true if the sync succeeded
|
||||
*/
|
||||
private boolean _syncAcomic(Comic com, int numStrips, int sType) {
|
||||
switch(sType) {
|
||||
switch (sType) {
|
||||
case SYNC_FROM_LATEST:
|
||||
return _syncFromLatest(com, numStrips);
|
||||
case SYNC_FROM_PREV_SESSION:
|
||||
@ -284,23 +317,26 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
case SYNC_BOTH:
|
||||
return _syncBoth(com, numStrips);
|
||||
default:
|
||||
Log.e(TAG, "Bad sync type passed! ("+sType+")");
|
||||
Log.e(TAG, "Bad sync type passed! (" + sType + ")");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs for a comic from latest strip onwards
|
||||
* @param com comic
|
||||
* @param numStrips number of strips to be synced
|
||||
*
|
||||
* @param com
|
||||
* comic
|
||||
* @param numStrips
|
||||
* number of strips to be synced
|
||||
* @return true if the sync succeeded
|
||||
*/
|
||||
private boolean _syncFromLatest(Comic com, int numStrips) {
|
||||
if(!_getStrip(com, Comic.NAV_LATEST_FORCE)) {
|
||||
if (!_getStrip(com, Comic.NAV_LATEST_FORCE)) {
|
||||
return false;
|
||||
}
|
||||
boolean status = true;
|
||||
for(int i=1;i<numStrips;++i) {
|
||||
for (int i = 1; i < numStrips; ++i) {
|
||||
status = status && _getStrip(com, Comic.NAV_PREVIOUS);
|
||||
}
|
||||
return status;
|
||||
@ -308,50 +344,64 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||
|
||||
/**
|
||||
* Syncs for a comic from previous session strip onwards
|
||||
* @param com comic
|
||||
* @param numStrips number of strips to be synced
|
||||
*
|
||||
* @param com
|
||||
* comic
|
||||
* @param numStrips
|
||||
* number of strips to be synced
|
||||
* @return true if the sync succeeded
|
||||
*/
|
||||
private boolean _syncFromPrevSession(Comic com, int numStrips) {
|
||||
if(!_getStrip(com, Comic.NAV_PREV_SESSION)) {
|
||||
if (!_getStrip(com, Comic.NAV_PREV_SESSION)) {
|
||||
return false;
|
||||
}
|
||||
boolean status = true;
|
||||
for(int i=1;i<numStrips;++i) {
|
||||
for (int i = 1; i < numStrips; ++i) {
|
||||
status = status && _getStrip(com, Comic.NAV_NEXT);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs for a comic from both latest strip onwards and previous session strip onwards
|
||||
* @param com comic
|
||||
* @param numStrips number of strips to be synced in each direction
|
||||
* Syncs for a comic from both latest strip onwards and previous session
|
||||
* strip onwards
|
||||
*
|
||||
* @param com
|
||||
* comic
|
||||
* @param numStrips
|
||||
* number of strips to be synced in each direction
|
||||
* @return true if the sync succeeded
|
||||
*/
|
||||
private boolean _syncBoth(Comic com, int numStrips) {
|
||||
return (_syncFromLatest(com, numStrips) && _syncFromPrevSession(com, numStrips));
|
||||
return (_syncFromLatest(com, numStrips) && _syncFromPrevSession(com,
|
||||
numStrips));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to download the strip
|
||||
* @param com comic
|
||||
* @param type strip type
|
||||
*
|
||||
* @param com
|
||||
* comic
|
||||
* @param type
|
||||
* strip type
|
||||
* @return true if download is successful
|
||||
*/
|
||||
private boolean _getStrip(Comic com, int type) {
|
||||
try {
|
||||
Strip s = com.navigateStrip(type);
|
||||
if(s.downloadImage(com)) {
|
||||
if (s.downloadImage(com)) {
|
||||
mNumDnlds++;
|
||||
}
|
||||
_updateProgress();
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences(mCtx);
|
||||
if (sp.getBoolean("notificationPref", true)) {
|
||||
_updateProgress();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,79 @@
|
||||
package com.blogspot.applications4android.comicreader.comics;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.blogspot.applications4android.comicreader.comictypes.DailyComic;
|
||||
import com.blogspot.applications4android.comicreader.core.Strip;
|
||||
|
||||
public class KevinAndKell extends DailyComic {
|
||||
|
||||
@Override
|
||||
public String getComicWebPageUrl() {
|
||||
return "http://www.kevinandkell.com/";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Calendar getFirstCalendar() {
|
||||
Calendar first = Calendar.getInstance();
|
||||
first.set(1995, 8, 3); // 1995,Sept,3
|
||||
return first;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Calendar getLatestCalendar() {
|
||||
return Calendar.getInstance(m_zone);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Calendar getTimeFromUrl(String url) {
|
||||
String str = url.replace("http://www.kevinandkell.com/", "");
|
||||
String[] time = str.split("/");
|
||||
int year = Integer.parseInt(time[0]);
|
||||
int month = Integer.parseInt(time[1].substring(2,4))- 1;
|
||||
int day = Integer.parseInt(time[1].substring(4,6));
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.set(year, month, day);
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlFromTime(Calendar cal) {
|
||||
String surl = String.format("http://www.kevinandkell.com/%4d/kk%02d%02d.html",
|
||||
cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH));
|
||||
|
||||
return surl;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean htmlNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String parse(String url, BufferedReader reader, Strip strip) throws IOException {
|
||||
|
||||
//Get URL
|
||||
Calendar cal = getTimeFromUrl(url);
|
||||
String surl = String.format("http://www.kevinandkell.com/%4d/strips/kk%4d%02d%02d.gif",
|
||||
cal.get(Calendar.YEAR), cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH));
|
||||
//Get Title
|
||||
String str;
|
||||
String final_title = null;
|
||||
while((str = reader.readLine()) != null) {
|
||||
int index1 = str.indexOf("\"caption\"");
|
||||
if (index1 != -1) {
|
||||
final_title = str;
|
||||
}
|
||||
}
|
||||
final_title = final_title.replaceAll(".*.>"","");
|
||||
final_title = final_title.replaceAll("".*","");
|
||||
strip.setTitle("Kevin and Kell: " + final_title);
|
||||
strip.setText("-NA-");
|
||||
return surl;
|
||||
}
|
||||
|
||||
}
|
@ -63,7 +63,6 @@ public class MegaTokyo extends IndexedComic {
|
||||
String str;
|
||||
String final_str = null;
|
||||
String final_title = null;
|
||||
String final_title1 = null;
|
||||
String final_itext = null;
|
||||
while ((str = reader.readLine()) != null) {
|
||||
int index1 = str.indexOf("<img align=\"middle\" src=\"strips/");
|
||||
|
@ -0,0 +1,163 @@
|
||||
package com.blogspot.applications4android.comicreader.comics;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.blogspot.applications4android.comicreader.comictypes.ArchivedComic;
|
||||
import com.blogspot.applications4android.comicreader.core.Bound;
|
||||
import com.blogspot.applications4android.comicreader.core.Downloader;
|
||||
import com.blogspot.applications4android.comicreader.core.Strip;
|
||||
|
||||
//This comic does not have numbers to work with each URL is the title of the comic.
|
||||
//So we will use the archive to get the comics is order.
|
||||
public class MenageA3 extends ArchivedComic {
|
||||
@Override
|
||||
public String getComicWebPageUrl() {
|
||||
return "http://www.ma3comic.com/strips-ma3/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getAllComicUrls(BufferedReader reader)
|
||||
throws IOException {
|
||||
ArrayList<String> m_com = new ArrayList<String>();
|
||||
String str, str_temp;
|
||||
String search = "http://www.ma3comic.com/strips-ma3";
|
||||
int i;
|
||||
while ((str = reader.readLine()) != null) {
|
||||
i = str.indexOf(search);
|
||||
if (i != -1) {
|
||||
//remove the html surrounding the URL
|
||||
if (!str.contains("ARCHIVE")) {
|
||||
str_temp = str;
|
||||
str_temp = str_temp.replaceAll(".*?href=\"", "");
|
||||
str_temp = str_temp.replaceAll("\".*$", "");
|
||||
m_com.add(str_temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] m_com_urls = new String[m_com.size()];
|
||||
m_com.toArray(m_com_urls);
|
||||
return m_com_urls;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fetchAllComicUrls() {
|
||||
if (mComicUrls == null) {
|
||||
try {
|
||||
ArrayList<String> all_vols = new ArrayList<String>();
|
||||
// Archive has volumes that update no according to calendar
|
||||
// So find number of archives first.
|
||||
ArrayList<String> vol_urls = getVolURL();
|
||||
|
||||
for (String currentVol : vol_urls) {
|
||||
URI u = null;
|
||||
try {
|
||||
u = new URI(currentVol);
|
||||
} catch (Exception e) {
|
||||
} // This should never occur!!
|
||||
BufferedReader reader = Downloader.openConnection(u);
|
||||
String[] urls = getAllComicUrls(reader);
|
||||
for (int i = 0; i <= urls.length - 1; i++) {
|
||||
all_vols.add(urls[i]);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
mComicUrls = new String[all_vols.size()];
|
||||
all_vols.toArray(mComicUrls);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
mBound = new Bound(0, (long) (mComicUrls.length - 1));
|
||||
}
|
||||
|
||||
//Finds the urls for volumes. This number can be updated.
|
||||
private ArrayList<String> getVolURL() {
|
||||
String str;
|
||||
String search = "http://www.menagea3.net/archive/volume";
|
||||
String mArchiveStr = "http://www.ma3comic.com/archive";
|
||||
//We use an arraylist because the website does not do a great job on its design.
|
||||
//They have duplicate urls and I use contains to check that there are no duplicates
|
||||
ArrayList<String> vol_urls = new ArrayList<String>();
|
||||
Pattern p = Pattern.compile(search + "\\d");
|
||||
|
||||
try {
|
||||
URI u = null;
|
||||
try {
|
||||
u = new URI(mArchiveStr);
|
||||
} catch (Exception e) {
|
||||
} // This should never occur!!
|
||||
|
||||
BufferedReader reader = Downloader.openConnection(u);
|
||||
int i;
|
||||
while ((str = reader.readLine()) != null) {
|
||||
i = str.indexOf(search);
|
||||
if (i != -1) {
|
||||
//Find the patter of the volume and add to the Arraylist
|
||||
Matcher m = p.matcher(str);
|
||||
while (m.find()) {
|
||||
if (!vol_urls.contains(m.group())) {
|
||||
vol_urls.add(m.group());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return vol_urls;
|
||||
}
|
||||
|
||||
return vol_urls;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLatestStripUrl() {
|
||||
fetchAllComicUrls();
|
||||
return getStripUrlFromId(mComicUrls.length - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArchiveUrl() {
|
||||
return "http://www.ma3comic.com/archive/volume";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean htmlNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String parse(String url, BufferedReader reader, Strip strip)
|
||||
throws IOException {
|
||||
String str;
|
||||
String final_str = null;
|
||||
String final_title = null;
|
||||
while ((str = reader.readLine()) != null) {
|
||||
// This gets the location of the image
|
||||
int index1 = str.indexOf("comics/mat");
|
||||
if (index1 != -1) {
|
||||
final_str = str;
|
||||
}
|
||||
// This gets the title of the commic
|
||||
int index2 = str.indexOf("<title>Ménage");
|
||||
if (index2 != -1) {
|
||||
final_title = str;
|
||||
}
|
||||
}
|
||||
// Pattern matching to remove unwanted characters.
|
||||
final_str = final_str.replaceAll(".*img src=\"", "");
|
||||
final_str = final_str.replaceAll("\".*", "");
|
||||
final_title = final_title.replaceAll(".*.::", "");
|
||||
final_title = final_title.replaceAll("</title>.*", "");
|
||||
strip.setTitle("Ménage à 3 :" + final_title);
|
||||
return final_str;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user