Commit 01c833ec authored by Adrien Dorsaz's avatar Adrien Dorsaz

Add Javadoc, comments and add ID to exception as asked by Eclipse.

parent 040cc3df
......@@ -16,6 +16,11 @@ import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;
/**
* ArticleDetailActivity display all needed informations from one Article in one
* Activity. It can update read state, starred state and can call WebBrowser to
* show article in his context.
* */
public class ArticleDetailActivity extends Activity implements OnClickListener {
private Article mArticle = null;
......
......@@ -29,6 +29,10 @@ import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
/**
* ArticleListActivity tasks is to get all articles from server (taking account
* of user preference, to get all, only unread or only starred articles).
* */
public class ArticleListActivity extends ListActivity {
private ArticleAdapter mArticleAdapter = null;
......@@ -72,6 +76,10 @@ public class ArticleListActivity extends ListActivity {
}
}
/**
* DisplayDialogListener is only used if user asked to prompt it which
* articles he want to see.
* */
private class DisplayDialogListener implements
DialogInterface.OnClickListener {
......@@ -86,6 +94,10 @@ public class ArticleListActivity extends ListActivity {
}
}
/**
* onPause() have to save data to be able to avoid reload always data from
* server.
* */
@Override
public void onPause() {
super.onPause();
......@@ -138,12 +150,24 @@ public class ArticleListActivity extends ListActivity {
return false;
}
/**
* updateArticleList should be used by AsyncTask (especially
* loungeDroid.server.ArticleListGetter) to update data on this activity.
*
* @param articleList
* List of articles to display in the activity (will replace all
* already displayed articles)
* */
public void updateArticleList(List<Article> articleList) {
mArticleAdapter = new ArticleAdapter(getApplicationContext(),
R.layout.articlelist_item, R.id.articleItemTitle, articleList);
updateArticleAdapter();
}
/**
* updateArticleAdapter updates really the displayed articles with his
* latest ArticleAdapter field version.
* */
private void updateArticleAdapter() {
ListView listView = getListView();
listView.setScrollingCacheEnabled(false);
......@@ -158,6 +182,10 @@ public class ArticleListActivity extends ListActivity {
setListAdapter(mArticleAdapter);
}
/**
* fetchNews() is an async task that will get news depending on user
* preferences.
* */
private void fetchNews() {
ArticleListGetter getter = new ArticleListGetter(this);
getter.execute(mDisplayChoice);
......@@ -190,6 +218,15 @@ public class ArticleListActivity extends ListActivity {
}
/**
* disableMenuItem will disable the item with depending on his id and in
* which menu is it.
*
* @param menu
* Menu where to disable some menu item.
* @param id
* Id of the menuItem to disable.
* */
private void disableMenuItem(Menu menu, int id) {
MenuItem menuItem = menu.findItem(id);
menuItem.setVisible(false);
......@@ -201,6 +238,10 @@ public class ArticleListActivity extends ListActivity {
menuItem.setEnabled(true);
}
/**
* saveData will save already downloaded data to avoid too many http request
* (especially on resume).
* */
private void saveData() {
Intent intent = null;
......@@ -230,6 +271,13 @@ public class ArticleListActivity extends ListActivity {
}
}
/**
* restoreAndUpdateData restores data saved in some Intent and update a
* modified article (which is also in Intent with special key).
*
* This function is used when resume from ArticleDetailActivity because this
* activity is able to update article states (read state and starred state).
* */
private void restoreAndUpdateData() {
// Restore data
Intent intent = getIntent();
......@@ -280,6 +328,9 @@ public class ArticleListActivity extends ListActivity {
updateArticleAdapter();
}
/**
* ArticleAdapter is the specific ArrayAdapter for this ArticleListActivity.
* */
private class ArticleAdapter extends ArrayAdapter<Article> {
private Context mContext;
private List<Article> mArticles;
......
......@@ -10,6 +10,11 @@ import android.preference.PreferenceActivity;
import android.util.Log;
import android.widget.Toast;
/**
* SettingsActivity prompt user to get his preferences. It's also the first
* activity to be launched to be able to verify that settings are good (need a
* server url).
* */
public class SettingsActivity extends PreferenceActivity {
/* Preference constants */
......
......@@ -3,6 +3,12 @@ package ch.adorsaz.loungeDroid.article;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Article is the type which implements all data received from the server for
* one article.
*
* This implements Parcelable to be able to pass it in android Intents.
* */
public class Article implements Parcelable {
private Integer mId;
private Integer mDay;
......
package ch.adorsaz.loungeDroid.article;
/**
* This enum give all possible filter to display articles depending on their
* state.
* */
public enum ToDisplay {
ALWAYS_PROMPT, ALL, UNREAD, STARRED
}
package ch.adorsaz.loungeDroid.exception;
/**
* GetArticleListException is sent when you can't correctly get and read
* articles from server.
* */
public class GetArticleListException extends Exception {
/**
* Auto-generated ID by Eclpipse.
*/
private static final long serialVersionUID = 8449004512651295034L;
@Override
public String getMessage() {
return "Unable to get article list.\n"+super.getMessage();
return "Unable to get article list.\n" + super.getMessage();
}
}
package ch.adorsaz.loungeDroid.exception;
/**
* ParseArticleException is sent when it's impossible to parse correctly an
* Article in a response.
* */
public class ParseArticleException extends Exception {
/**
* Auto-generated ID by Eclpipse.
*/
private static final long serialVersionUID = -1916018652604709645L;
@Override
public String getMessage() {
return "Unable parse correctly messages.\n"+super.getMessage();
return "Unable parse correctly messages.\n" + super.getMessage();
}
}
package ch.adorsaz.loungeDroid.exception;
/**
* ReadStateUpdateException is sent when application is unable to update the
* read state of one article.
* */
public class ReadStateUpdateException extends Exception {
/**
* Auto-generated ID by Eclpipse.
*/
private static final long serialVersionUID = 859540452885060466L;
@Override
public String getMessage() {
return "Unable to update the read state of an article.\n"+super.getMessage();
return "Unable to update the read state of an article.\n"
+ super.getMessage();
}
}
package ch.adorsaz.loungeDroid.exception;
/**
* StartredSateUpdateException is sent when application is unable to update the
* starred state of one article.
* */
public class StarredStateUpdateException extends Exception {
/**
* Auto-generated ID by Eclpipse.
*/
private static final long serialVersionUID = -7137335428363481542L;
@Override
public String getMessage() {
return "Unable to update the starred state of an article.\n"+super.getMessage();
......
......@@ -21,12 +21,16 @@ import android.text.Html;
import android.util.Log;
import android.widget.Toast;
/**
* ArticleListGetter is an async task which will get all articles on server,
* store it using own Article type and update ArticleListActivity data.
* */
public class ArticleListGetter extends
AsyncTask<ToDisplay, Object, List<Article>> {
private SessionManager mSessionManager = null;
private ArticleListActivity mActivity = null;
/* Some urls needed to get feeds */
/* Some urls needed to get specific articles */
private final static String ARTICLELIST_PAGE_RSSLOUNGE = "/item/list";
private final static String DISPLAY_ALL_PARAMS = "unread=0&starred=0";
private final static String DISPLAY_UNREAD_PARAMS = "unread=1&starred=0";
......
......@@ -12,6 +12,10 @@ import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
/**
* ArticleStarredStateUpdate is an async task to update read state of one
* article and update ArticleDetailActivity.
* */
public class ArticleReadStateUpdater extends
AsyncTask<Article, Object, Article> {
private SessionManager mSessionManager = null;
......
......@@ -12,6 +12,10 @@ import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
/**
* ArticleStarredStateUpdate is an async task to update starred state of one
* article and update ArticleDetailActivity.
* */
public class ArticleStarredStateUpdater extends
AsyncTask<Article, Object, Article> {
private SessionManager mSessionManager = null;
......
......@@ -25,6 +25,10 @@ import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.widget.Toast;
/**
* SessionManager is the class which manage connection with server, check if
* always logged and execute a request.
* */
public class SessionManager {
private static String mLogin = null;
private static String mPassword = null;
......@@ -57,6 +61,15 @@ public class SessionManager {
return mSessionManager;
}
protected JSONObject serverRequest(String pageUrl, String httpParameters)
throws ConnectException {
if (mSessionCookie == null || mSessionCookie.length() == 0) {
loginLounge();
}
return doRequest(pageUrl, httpParameters);
}
private void loginLounge() throws ConnectException {
try {
String urlParameters = LOGIN_GET_RSSLOUNGE + "="
......@@ -207,13 +220,4 @@ public class SessionManager {
Intent intent = new Intent(mApplicationContext, SettingsActivity.class);
mApplicationContext.startActivity(intent);
}
protected JSONObject serverRequest(String pageUrl, String httpParameters)
throws ConnectException {
if (mSessionCookie == null || mSessionCookie.length() == 0) {
loginLounge();
}
return doRequest(pageUrl, httpParameters);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment