commit
6bca40dd71
|
@ -32,8 +32,11 @@
|
||||||
{"class":"GuComics", "name":"Gu Comics", "pref":"gucomicsPref"},
|
{"class":"GuComics", "name":"Gu Comics", "pref":"gucomicsPref"},
|
||||||
{"class":"GunnerkriggCourt", "name":"Gunnerkrigg Court", "pref":"gunnerkriggcourtPref"},
|
{"class":"GunnerkriggCourt", "name":"Gunnerkrigg Court", "pref":"gunnerkriggcourtPref"},
|
||||||
{"class":"JoeAndMonkey", "name":"Joe And Monkey", "pref":"joeandmonkeyPref"},
|
{"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":"LeastICouldDo", "name":"Least I Could Do", "pref":"leasticoulddoPref"},
|
||||||
{"class":"LookingForGroup", "name":"Looking For Group", "pref":"lookingforgroupPref"},
|
{"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":"Misfile", "name":"Misfile", "pref":"misfilePref"},
|
||||||
{"class":"MotherGooseandGrimm", "name":"Mother Goose & Grimm", "pref":"mothergooseandgrimmPref"},
|
{"class":"MotherGooseandGrimm", "name":"Mother Goose & Grimm", "pref":"mothergooseandgrimmPref"},
|
||||||
{"class":"OOTS", "name":"Order of the Stick", "pref":"ootsPref"},
|
{"class":"OOTS", "name":"Order of the Stick", "pref":"ootsPref"},
|
||||||
|
@ -62,7 +65,6 @@
|
||||||
{"class":"Wondermark", "name":"Wondermark", "pref":"wondermarkPref"},
|
{"class":"Wondermark", "name":"Wondermark", "pref":"wondermarkPref"},
|
||||||
{"class":"Wulffmorgenthaler", "name":"Wulffmorgenthaler", "pref":"wulffmorgenthalerPref"},
|
{"class":"Wulffmorgenthaler", "name":"Wulffmorgenthaler", "pref":"wulffmorgenthalerPref"},
|
||||||
{"class":"Xkcd", "name":"Xkcd", "pref":"xkcdPref"},
|
{"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":"Yafgc", "name":"Yet Another Fantasy Gamer Comic", "pref":"yafgcPref"},
|
||||||
{"class":"Zap", "name":"Zap!", "pref":"zapPref"},
|
{"class":"Zap", "name":"Zap!", "pref":"zapPref"},
|
||||||
{"class":"Channelate", "name":"Channelate", "pref":"channelatePref"},
|
{"class":"Channelate", "name":"Channelate", "pref":"channelatePref"},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="backgroundCacheEnabledPref"
|
android:key="backgroundCacheEnabledPref"
|
||||||
android:title="Enable Caching"
|
android:title="Enable Caching"
|
||||||
|
@ -44,6 +45,11 @@
|
||||||
android:entries="@array/sync_type"
|
android:entries="@array/sync_type"
|
||||||
android:entryValues="@array/sync_type_values"
|
android:entryValues="@array/sync_type_values"
|
||||||
android:dependency="backgroundCacheEnabledPref" />
|
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
|
<ListPreference
|
||||||
android:title="Sort (My Comics)"
|
android:title="Sort (My Comics)"
|
||||||
android:summary="Sort Order in My Comics Page"
|
android:summary="Sort Order in My Comics Page"
|
||||||
|
|
|
@ -25,7 +25,6 @@ import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actual class for background caching
|
* Actual class for background caching
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +69,6 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
/** progress message */
|
/** progress message */
|
||||||
private String mStr;
|
private String mStr;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -87,12 +85,12 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
* Waits for connectivity to come up
|
* Waits for connectivity to come up
|
||||||
*/
|
*/
|
||||||
private void _waitForConnectivity() {
|
private void _waitForConnectivity() {
|
||||||
if(!_isOnWifi(mCtx) && !_isOnMobileData(mCtx)) {
|
if (!_isOnWifi(mCtx) && !_isOnMobileData(mCtx)) {
|
||||||
Log.d(TAG, "Sleeping for "+SLEEP_DURATION+" ms hoping that the network will turn on...");
|
Log.d(TAG, "Sleeping for " + SLEEP_DURATION
|
||||||
|
+ " ms hoping that the network will turn on...");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(SLEEP_DURATION);
|
Thread.sleep(SLEEP_DURATION);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Sleeping is over...");
|
Log.d(TAG, "Sleeping is over...");
|
||||||
|
@ -104,25 +102,25 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
*/
|
*/
|
||||||
synchronized private void _mutexCall() {
|
synchronized private void _mutexCall() {
|
||||||
mCtx = getApplicationContext();
|
mCtx = getApplicationContext();
|
||||||
Log.d(TAG, "starting the service for caching comic strips in background ...");
|
Log.d(TAG,
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mCtx);
|
"starting the service for caching comic strips in background ...");
|
||||||
if(!sp.getBoolean("backgroundCacheEnabledPref", false)) {
|
SharedPreferences sp = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(mCtx);
|
||||||
|
if (!sp.getBoolean("backgroundCacheEnabledPref", false)) {
|
||||||
Log.d(TAG, "Background caching not enabled. Returing back...");
|
Log.d(TAG, "Background caching not enabled. Returing back...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_waitForConnectivity();
|
_waitForConnectivity();
|
||||||
if(_isOnWifi(mCtx)) {
|
if (_isOnWifi(mCtx)) {
|
||||||
_cacheStrips(sp);
|
_cacheStrips(sp);
|
||||||
}
|
} else if (_isOnMobileData(mCtx)) {
|
||||||
else if(_isOnMobileData(mCtx)) {
|
if (sp.getBoolean("mobileDataCacheEnabledPref", false)) {
|
||||||
if(sp.getBoolean("mobileDataCacheEnabledPref", false)) {
|
|
||||||
_cacheStrips(sp);
|
_cacheStrips(sp);
|
||||||
|
} else {
|
||||||
|
Log.d(TAG,
|
||||||
|
"You're on mobile-data, but caching is disabled on this network. So, returning back...");
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
Log.d(TAG, "You're on mobile-data, but caching is disabled on this network. So, returning back...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Log.d(TAG, "No wifi + no mobile-data. So, returing back...");
|
Log.d(TAG, "No wifi + no mobile-data. So, returing back...");
|
||||||
}
|
}
|
||||||
Log.d(TAG, "background comic cache service ended ...");
|
Log.d(TAG, "background comic cache service ended ...");
|
||||||
|
@ -130,91 +128,112 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for cancelling this progress
|
* Callback for cancelling this progress
|
||||||
* @param v view generating this callback
|
*
|
||||||
|
* @param v
|
||||||
|
* view generating this callback
|
||||||
*/
|
*/
|
||||||
public void onCancelClick(View v) {
|
public void onCancelClick(View v) {
|
||||||
final Resources res = mCtx.getResources();
|
final Resources res = mCtx.getResources();
|
||||||
AlertDialog.Builder alertbox = new AlertDialog.Builder(mCtx);
|
AlertDialog.Builder alertbox = new AlertDialog.Builder(mCtx);
|
||||||
alertbox.setMessage(res.getString(R.string.my_comic_restore_confirmation));
|
alertbox.setMessage(res
|
||||||
alertbox.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
.getString(R.string.my_comic_restore_confirmation));
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
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
|
* Caching the strips
|
||||||
* @param sp shared preferences
|
*
|
||||||
|
* @param sp
|
||||||
|
* shared preferences
|
||||||
*/
|
*/
|
||||||
private void _cacheStrips(SharedPreferences sp) {
|
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"));
|
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...");
|
Log.d(TAG, "Setting up the progress bar for notifying sync updates...");
|
||||||
try {
|
try {
|
||||||
mList = new ComicClassList(mCtx.getAssets());
|
mList = new ComicClassList(mCtx.getAssets());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mMgr = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
|
mMgr = (NotificationManager) mCtx
|
||||||
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
mTotal = mList.numSelected() * mNumStrips;
|
mTotal = mList.numSelected() * mNumStrips;
|
||||||
if(mSyncType == SYNC_BOTH) {
|
if (mSyncType == SYNC_BOTH) {
|
||||||
mTotal *= 2;
|
mTotal *= 2;
|
||||||
}
|
}
|
||||||
mChecked = 0;
|
mChecked = 0;
|
||||||
mStr = mCtx.getResources().getString(R.string.bg_cache_progress_msg);
|
mStr = mCtx.getResources().getString(R.string.bg_cache_progress_msg);
|
||||||
mNotify = new Notification(R.drawable.icon, "ComicReader", System.currentTimeMillis());
|
if (sp.getBoolean("notificationPref", true)) {
|
||||||
Intent in = new Intent(mCtx, ActivityComicReader.class);
|
mNotify = new Notification(R.drawable.icon, "ComicReader",
|
||||||
mNotify.contentIntent = PendingIntent.getActivity(mCtx, 0, in, 0);
|
System.currentTimeMillis());
|
||||||
mNotify.contentView = new RemoteViews(mCtx.getPackageName(), R.layout.bg_cache_progress);
|
Intent in = new Intent(mCtx, ActivityComicReader.class);
|
||||||
mNotify.flags = Notification.FLAG_ONGOING_EVENT;
|
mNotify.contentIntent = PendingIntent.getActivity(mCtx, 0, in, 0);
|
||||||
_updateProgress();
|
mNotify.contentView = new RemoteViews(mCtx.getPackageName(),
|
||||||
|
R.layout.bg_cache_progress);
|
||||||
|
mNotify.flags = Notification.FLAG_ONGOING_EVENT;
|
||||||
|
_updateProgress();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
mNumDnlds = 0;
|
mNumDnlds = 0;
|
||||||
mList.sortClasses(mSortType);
|
mList.sortClasses(mSortType);
|
||||||
int num = mList.length();
|
int num = mList.length();
|
||||||
for(int i=0;i<num;++i) {
|
for (int i = 0; i < num; ++i) {
|
||||||
ComicClass clz = mList.getComicClassFromIndex(i);
|
ComicClass clz = mList.getComicClassFromIndex(i);
|
||||||
if(!clz.mSel) {
|
if (!clz.mSel) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Working on comic = "+clz.mName);
|
Log.d(TAG, "Working on comic = " + clz.mName);
|
||||||
Comic com = mList.getComicFromIndex(i);
|
Comic com = mList.getComicFromIndex(i);
|
||||||
com.setComicName(clz.mName);
|
com.setComicName(clz.mName);
|
||||||
com.readProperties();
|
com.readProperties();
|
||||||
com.setLaunchType(Comic.TYPE_CACHING);
|
com.setLaunchType(Comic.TYPE_CACHING);
|
||||||
boolean status = _syncAcomic(com, mNumStrips, mSyncType);
|
boolean status = _syncAcomic(com, mNumStrips, mSyncType);
|
||||||
com.writeProperties();
|
com.writeProperties();
|
||||||
Log.d(TAG, "Finished working on comic = "+clz.mName+" status="+status);
|
Log.d(TAG, "Finished working on comic = " + clz.mName
|
||||||
Log.d(TAG, "Number of downloads so far="+mNumDnlds);
|
+ " status=" + status);
|
||||||
|
Log.d(TAG, "Number of downloads so far=" + mNumDnlds);
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
mMgr.cancel(PROGRESS_NOTIFY_ID);
|
||||||
if(mNumDnlds <= 0) {
|
if (mNumDnlds <= 0) {
|
||||||
Log.d(TAG, "No new strips to be read. So, not setting up a notification...");
|
Log.d(TAG,
|
||||||
|
"No new strips to be read. So, not setting up a notification...");
|
||||||
_commitLastSyncTime();
|
_commitLastSyncTime();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Intent i = new Intent(mCtx, ActivityComicReader.class);
|
Intent i = new Intent(mCtx, ActivityComicReader.class);
|
||||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
PendingIntent pi = PendingIntent.getActivity(mCtx, 0, i, 0);
|
PendingIntent pi = PendingIntent.getActivity(mCtx, 0, i, 0);
|
||||||
mNotify = new Notification(R.drawable.icon, "ComicReader", System.currentTimeMillis());
|
// TODO: location of notifies.
|
||||||
mNotify.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
|
|
||||||
mNotify.setLatestEventInfo(mCtx, "Comic Reader", "Total of "+mNumDnlds+" newly downloaded strips", pi);
|
if (sp.getBoolean("notificationPref", true)) {
|
||||||
Log.d(TAG, "Notifying the manager of this new notification...");
|
mNotify = new Notification(R.drawable.icon, "ComicReader",
|
||||||
mMgr.notify(NOTIFY_ID, mNotify);
|
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();
|
_commitLastSyncTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,35 +242,45 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
*/
|
*/
|
||||||
private void _commitLastSyncTime() {
|
private void _commitLastSyncTime() {
|
||||||
long lastSync = System.currentTimeMillis();
|
long lastSync = System.currentTimeMillis();
|
||||||
Log.d(TAG, "last sync time = "+lastSync);
|
Log.d(TAG, "last sync time = " + lastSync);
|
||||||
SharedPreferences.Editor ed = PreferenceManager.getDefaultSharedPreferences(mCtx).edit();
|
SharedPreferences.Editor ed = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(mCtx).edit();
|
||||||
ed.putLong(ActivitySettingsPage.LAST_SYNC_PREF, lastSync);
|
ed.putLong(ActivitySettingsPage.LAST_SYNC_PREF, lastSync);
|
||||||
Calendar now = Calendar.getInstance();
|
Calendar now = Calendar.getInstance();
|
||||||
int mon = now.get(Calendar.MONTH) + 1;
|
int mon = now.get(Calendar.MONTH) + 1;
|
||||||
String str = "'" + now.get(Calendar.YEAR) + "/" + mon + "/" + now.get(Calendar.DAY_OF_MONTH);
|
String str = "'" + now.get(Calendar.YEAR) + "/" + mon + "/"
|
||||||
str += " " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "'";
|
+ 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.putString(ActivitySettingsPage.LAST_SYNC_STRING_PREF, str);
|
||||||
ed.commit();
|
ed.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to check whether we are on WIFI or not
|
* Helper function to check whether we are on WIFI or not
|
||||||
* @param ctxt application context
|
*
|
||||||
|
* @param ctxt
|
||||||
|
* application context
|
||||||
* @return true if we are
|
* @return true if we are
|
||||||
*/
|
*/
|
||||||
private boolean _isOnWifi(Context ctxt) {
|
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);
|
NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
return wifi.isConnected();
|
return wifi.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to check whether we are on Mobile-data or not
|
* 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
|
* @return true if we are
|
||||||
*/
|
*/
|
||||||
private boolean _isOnMobileData(Context ctxt) {
|
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);
|
NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||||
return mobile.isConnected();
|
return mobile.isConnected();
|
||||||
}
|
}
|
||||||
|
@ -270,13 +299,17 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs for a comic
|
* Syncs for a comic
|
||||||
* @param com comic
|
*
|
||||||
* @param numStrips number of strips to be synced
|
* @param com
|
||||||
* @param sType sync type
|
* comic
|
||||||
|
* @param numStrips
|
||||||
|
* number of strips to be synced
|
||||||
|
* @param sType
|
||||||
|
* sync type
|
||||||
* @return true if the sync succeeded
|
* @return true if the sync succeeded
|
||||||
*/
|
*/
|
||||||
private boolean _syncAcomic(Comic com, int numStrips, int sType) {
|
private boolean _syncAcomic(Comic com, int numStrips, int sType) {
|
||||||
switch(sType) {
|
switch (sType) {
|
||||||
case SYNC_FROM_LATEST:
|
case SYNC_FROM_LATEST:
|
||||||
return _syncFromLatest(com, numStrips);
|
return _syncFromLatest(com, numStrips);
|
||||||
case SYNC_FROM_PREV_SESSION:
|
case SYNC_FROM_PREV_SESSION:
|
||||||
|
@ -284,23 +317,26 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
case SYNC_BOTH:
|
case SYNC_BOTH:
|
||||||
return _syncBoth(com, numStrips);
|
return _syncBoth(com, numStrips);
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "Bad sync type passed! ("+sType+")");
|
Log.e(TAG, "Bad sync type passed! (" + sType + ")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs for a comic from latest strip onwards
|
* 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
|
* @return true if the sync succeeded
|
||||||
*/
|
*/
|
||||||
private boolean _syncFromLatest(Comic com, int numStrips) {
|
private boolean _syncFromLatest(Comic com, int numStrips) {
|
||||||
if(!_getStrip(com, Comic.NAV_LATEST_FORCE)) {
|
if (!_getStrip(com, Comic.NAV_LATEST_FORCE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean status = true;
|
boolean status = true;
|
||||||
for(int i=1;i<numStrips;++i) {
|
for (int i = 1; i < numStrips; ++i) {
|
||||||
status = status && _getStrip(com, Comic.NAV_PREVIOUS);
|
status = status && _getStrip(com, Comic.NAV_PREVIOUS);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
|
@ -308,50 +344,64 @@ public class BackgroundCacheIntentService extends FullyAwakeIntentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs for a comic from previous session strip onwards
|
* 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
|
* @return true if the sync succeeded
|
||||||
*/
|
*/
|
||||||
private boolean _syncFromPrevSession(Comic com, int numStrips) {
|
private boolean _syncFromPrevSession(Comic com, int numStrips) {
|
||||||
if(!_getStrip(com, Comic.NAV_PREV_SESSION)) {
|
if (!_getStrip(com, Comic.NAV_PREV_SESSION)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean status = true;
|
boolean status = true;
|
||||||
for(int i=1;i<numStrips;++i) {
|
for (int i = 1; i < numStrips; ++i) {
|
||||||
status = status && _getStrip(com, Comic.NAV_NEXT);
|
status = status && _getStrip(com, Comic.NAV_NEXT);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs for a comic from both latest strip onwards and previous session strip onwards
|
* Syncs for a comic from both latest strip onwards and previous session
|
||||||
* @param com comic
|
* strip onwards
|
||||||
* @param numStrips number of strips to be synced in each direction
|
*
|
||||||
|
* @param com
|
||||||
|
* comic
|
||||||
|
* @param numStrips
|
||||||
|
* number of strips to be synced in each direction
|
||||||
* @return true if the sync succeeded
|
* @return true if the sync succeeded
|
||||||
*/
|
*/
|
||||||
private boolean _syncBoth(Comic com, int numStrips) {
|
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
|
* 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
|
* @return true if download is successful
|
||||||
*/
|
*/
|
||||||
private boolean _getStrip(Comic com, int type) {
|
private boolean _getStrip(Comic com, int type) {
|
||||||
try {
|
try {
|
||||||
Strip s = com.navigateStrip(type);
|
Strip s = com.navigateStrip(type);
|
||||||
if(s.downloadImage(com)) {
|
if (s.downloadImage(com)) {
|
||||||
mNumDnlds++;
|
mNumDnlds++;
|
||||||
}
|
}
|
||||||
_updateProgress();
|
SharedPreferences sp = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(mCtx);
|
||||||
|
if (sp.getBoolean("notificationPref", true)) {
|
||||||
|
_updateProgress();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
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 str;
|
||||||
String final_str = null;
|
String final_str = null;
|
||||||
String final_title = null;
|
String final_title = null;
|
||||||
String final_title1 = null;
|
|
||||||
String final_itext = null;
|
String final_itext = null;
|
||||||
while ((str = reader.readLine()) != null) {
|
while ((str = reader.readLine()) != null) {
|
||||||
int index1 = str.indexOf("<img align=\"middle\" src=\"strips/");
|
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