Added RandomIndexedComic + added a welcome message seeking help from fellow programmers

This commit is contained in:
applications4android 2012-12-16 23:58:34 +05:30
parent f328f499c0
commit b9145fc27b
3 changed files with 185 additions and 1 deletions

View File

@ -57,6 +57,12 @@
<string name="help_msg">If you are facing any issues, look at out FAQs at: http://applications4android.blogspot.in/2012/02/version-2020-faqs.html\n\nFor info on how to use this app, refer to the \'Help\' page in Menu.\n\nCheck \'About Page\' in Menu to know what\'s new in this version.</string>
<string name="faq_url">http://applications4android.blogspot.in/2012/02/version-2020-faqs.html</string>
<string name="last_update_title">ComicReader needs volunteer programmers!</string>
<string name="last_update_volunteer_subj">I would love to help ComicReader!</string>
<string name="last_update_volunteer_body">I am a programmer and I would love to contribute to the ComicReader code-base to keep it alive! Please send me the details to ramp-up on the topic.</string>
<string name="last_update_msg">ComicReader has come a long way with your continued support. But unfortunately, we are not having enough time to support all your requests and keep ComicReader running! Thus we have the source-code for this app opensourced on github at https://github.com/applications4android/ComicReader! So, we are requesting all programmers out there to contribute to the codebase and help us keep ComicReader alive!</string>
<string name="github_link">https://github.com/applications4android/ComicReader</string>
<string name="comic_bound_fetch_msg">Fetching the comic bound....</string>
</resources>

View File

@ -50,8 +50,10 @@ public class ActivityComicReader extends ComicActivity {
private static final String ITEM_POSITION_PREF = "myComicsListViewPosPref";
/** pref-key for welcome message */
private static final String WELCOME_KEY = "welcomeMsg_1";
/** perf-key for first run */
/** pref-key for first run */
private static final String FIRST_RUN = "firstRun_1";
/** pref-key for last update! */
private static final String LAST_UPDATE_NOTICE = "lastUpdateNotice";
/** list of comics */
protected static int[] mComicItems;
@ -362,6 +364,7 @@ public class ActivityComicReader extends ComicActivity {
*/
protected void initListView() {
_showWelcomeMessage();
_lastUpdateNotice();
if((mComicItems == null) || (mComicItems.length == 0)) {
setContentView(R.layout.comic_reader_empty_list);
return;
@ -401,6 +404,49 @@ public class ActivityComicReader extends ComicActivity {
e.commit();
}
/**
* Showing that we are not going to support this app for long! Need all your help in keeping ComicReader alive!
*/
private void _lastUpdateNotice() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
final SharedPreferences.Editor e = sp.edit();
ActivitySettingsPage.launchRepeatedCaching(this, true);
if(!sp.getBoolean(LAST_UPDATE_NOTICE, true)) {
return;
}
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setTitle(getResources().getString(R.string.last_update_title));
alertbox.setMessage(getResources().getString(R.string.last_update_msg));
alertbox.setPositiveButton("I'm ready to help!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
e.putBoolean(LAST_UPDATE_NOTICE, false);
e.commit();
Resources res = ActivityComicReader.this.getResources();
String[] email = new String[] { res.getString(R.string.dev_email) };
String subj = res.getString(R.string.last_update_volunteer_subj);
String body = res.getString(R.string.last_update_volunteer_body);
ActivityComicReader.this.startActivity(IntentGen.emailChooserIntent(email, subj, body, false, "Send Report..."));
}
});
alertbox.setNeutralButton("Go to github", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
e.putBoolean(LAST_UPDATE_NOTICE, false);
e.commit();
String url = ActivityComicReader.this.getString(R.string.github_link);
ActivityComicReader.this.startActivity(IntentGen.linkViewIntent(url));
}
});
alertbox.setNegativeButton("Not interested", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
e.putBoolean(LAST_UPDATE_NOTICE, false);
e.commit();
}
});
alertbox.show();
}
/**
* Display a welcome message for the first time users!
*/

View File

@ -0,0 +1,132 @@
package com.blogspot.applications4android.comicreader.comictypes;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.client.ClientProtocolException;
import com.blogspot.applications4android.comicreader.core.Downloader;
/**
* Base class for all those comics which are indexed, but not in order
*/
public abstract class RandomIndexedComic extends IndexedComic {
/** next strip's id */
protected int mNextId = -1;
/** previous strip's id */
protected int mPrevId = -1;
/** list of urls to be not cached */
private String[] DONT_CACHE = null;
/**
* Function to return the random url
* @return random url
*/
protected abstract String getRandUrl();
/**
* Evaluate the next strip's index from the current strip's url
* @param br reader for the current strip's url connection
* @param url current strip's url
* @return next strip's index
*/
protected abstract int getNextStripId(BufferedReader br, String url);
/**
* Evaluate the previous strip's index from the current strip's url
* @param br reader for the current strip's url connection
* @param url current strip's url
* @return previous strip's index
*/
protected abstract int getPreviousStripId(BufferedReader br, String url);
/**
* Given a line containing the previous strip's url, return the id
* @param line line of interest
* @param def default value to be returned
* @return prev Id
*/
protected abstract int parseForPrevId(String line, int def);
/**
* Given a line containing the next strip's url, return the id
* @param line line of interest
* @param def default value to be returned
* @return next Id
*/
protected abstract int parseForNextId(String line, int def);
/**
* Helper function to set the next id
* @param id next id
*/
protected void setNextId(int id) {
mNextId = id;
}
/**
* Helper function to set the previous id
* @param id prev id
*/
protected void setPreviousId(int id) {
mPrevId = id;
}
@Override
protected String getNextStripUrl() {
int id = mNextId;
if(id < getFirstId()) {
String url = getCurrentStrip().uid();
try {
BufferedReader reader = Downloader.openConnection(new URI(url));
id = getNextStripId(reader, url);
reader.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return getStripUrlFromId(id);
}
@Override
protected String getPreviousStripUrl() {
int id = mPrevId;
if(id < getFirstId()) {
String url = getCurrentStrip().uid();
try {
BufferedReader reader = Downloader.openConnection(new URI(url));
id = getPreviousStripId(reader, url);
reader.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return getStripUrlFromId(id);
}
@Override
protected String[] urlsNotForCaching() {
if(DONT_CACHE != null) {
return DONT_CACHE;
}
DONT_CACHE = new String[] { getRandUrl() };
return DONT_CACHE;
}
@Override
protected String getRandomStripUrl() {
return getRandUrl();
}
}