@@ -68,20 +68,44 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.v(TAG, "onCreate()");
|
Log.v(TAG, "onCreate()");
|
||||||
|
|
||||||
mDb = new ForumDatabase(this.getActivity(), this);
|
mDb = new ForumDatabase(getActivity(), this);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mDb.saveForums(true);
|
mDb.saveForums(true);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
if (ForumContent.ITEMS.size() != 0)
|
if (ForumContent.ITEMS.size() != 0)
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDatabaseCreate() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDatabaseUpgrade() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDatabaseUpgradeComplete() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeletionComplete() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
@@ -94,6 +118,12 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
mCallbacks.onItemSelected(this, ForumContent.ITEMS.get(position).id);
|
mCallbacks.onItemSelected(this, ForumContent.ITEMS.get(position).id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRestoreComplete() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(final Bundle outState) {
|
public void onSaveInstanceState(final Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
@@ -101,6 +131,17 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
|
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSyncComplete() {
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ForumContent.getForum(mDb);
|
||||||
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(final View view, final Bundle savedInstanceState) {
|
public void onViewCreated(final View view, final Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
@@ -120,45 +161,4 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
public void setActivateOnItemClick(final boolean activateOnItemClick) {
|
public void setActivateOnItemClick(final boolean activateOnItemClick) {
|
||||||
getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
|
getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDatabaseCreate() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDatabaseUpgrade() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDatabaseUpgradeComplete() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDeletionComplete() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRestoreComplete() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSyncComplete() {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ForumContent.getForum(mDb);
|
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public interface DatabaseListener {
|
|||||||
public void onDeletionComplete();
|
public void onDeletionComplete();
|
||||||
|
|
||||||
public void onRestoreComplete();
|
public void onRestoreComplete();
|
||||||
|
|
||||||
public void onSyncComplete();
|
public void onSyncComplete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -85,8 +85,8 @@ public class ForumDatabase {
|
|||||||
* These tables will be used for storing forum, topic, and post id's
|
* These tables will be used for storing forum, topic, and post id's
|
||||||
*/
|
*/
|
||||||
db.execSQL("CREATE TABLE " + TABLE_FORUMS + "( id TEXT PRIMARY KEY)");
|
db.execSQL("CREATE TABLE " + TABLE_FORUMS + "( id TEXT PRIMARY KEY)");
|
||||||
db.execSQL("CREATE TABLE " + TABLE_TOPICS + "( id TEXT PRIMARY KEY, " + KEY_FORUM_ID + " TEXT, "+ KEY_TIME_STAMP + " DATE)");
|
db.execSQL("CREATE TABLE " + TABLE_TOPICS + "( id TEXT PRIMARY KEY, " + KEY_FORUM_ID + " TEXT, " + KEY_TIME_STAMP + " DATE)");
|
||||||
db.execSQL("CREATE TABLE " + TABLE_THREADS + "( id TEXT PRIMARY KEY, " + KEY_FORUM_ID + " TEXT, " + KEY_TOPIC_ID + " TEXT, "+ KEY_TIME_STAMP + " DATE)");
|
db.execSQL("CREATE TABLE " + TABLE_THREADS + "( id TEXT PRIMARY KEY, " + KEY_FORUM_ID + " TEXT, " + KEY_TOPIC_ID + " TEXT, " + KEY_TIME_STAMP + " DATE)");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These tables will be used for storing forum, topic, and post
|
* These tables will be used for storing forum, topic, and post
|
||||||
@@ -432,13 +432,14 @@ public class ForumDatabase {
|
|||||||
/**
|
/**
|
||||||
* Retrieves a list of thread ids
|
* Retrieves a list of thread ids
|
||||||
*
|
*
|
||||||
* @param id of topic
|
* @param id
|
||||||
|
* of topic
|
||||||
* @return
|
* @return
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public List<String> getThreads(String id) {
|
public List<String> getThreads(final String id) {
|
||||||
final ArrayList<String> list = new ArrayList<String>();
|
final ArrayList<String> list = new ArrayList<String>();
|
||||||
final Cursor c = mDb.query(TABLE_THREADS, new String[] { KEY_ID }, KEY_TOPIC_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, KEY_TIME_STAMP);
|
final Cursor c = mDb.query(TABLE_THREADS, new String[] { KEY_ID }, KEY_TOPIC_ID + " = " + DatabaseUtils.sqlEscapeString(id), null, null, null, KEY_TIME_STAMP);
|
||||||
if (c.moveToFirst())
|
if (c.moveToFirst())
|
||||||
do
|
do
|
||||||
list.add(c.getString(0));
|
list.add(c.getString(0));
|
||||||
@@ -461,13 +462,15 @@ public class ForumDatabase {
|
|||||||
/**
|
/**
|
||||||
* Retrieves a list of topic ids
|
* Retrieves a list of topic ids
|
||||||
*
|
*
|
||||||
* @param id of forum
|
* @param id
|
||||||
|
* of forum
|
||||||
* @return
|
* @return
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public List<String> getTopics(String id) {
|
public List<String> getTopics(final String id) {
|
||||||
final ArrayList<String> list = new ArrayList<String>();
|
final ArrayList<String> list = new ArrayList<String>();
|
||||||
final Cursor c = mDb.query(TABLE_TOPICS, new String[] { KEY_ID }, KEY_FORUM_ID +" = "+ DatabaseUtils.sqlEscapeString(id) , null, null, null, KEY_TIME_STAMP + " DESC");
|
final Cursor c = mDb.query(TABLE_TOPICS, new String[] { KEY_ID }, KEY_FORUM_ID + " = " + DatabaseUtils.sqlEscapeString(id), null, null, null, KEY_TIME_STAMP
|
||||||
|
+ " DESC");
|
||||||
if (c.moveToFirst())
|
if (c.moveToFirst())
|
||||||
do
|
do
|
||||||
list.add(c.getString(0));
|
list.add(c.getString(0));
|
||||||
@@ -539,7 +542,7 @@ public class ForumDatabase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mListener != null)
|
if (mListener != null)
|
||||||
mListener.onSyncComplete();
|
mListener.onSyncComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +556,7 @@ public class ForumDatabase {
|
|||||||
public void saveThreads(final XMLRPCClient client, final Object forumId, final Object topicId) {
|
public void saveThreads(final XMLRPCClient client, final Object forumId, final Object topicId) {
|
||||||
saveThreads(client, forumId, topicId, false);
|
saveThreads(client, forumId, topicId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads and save threads into the database
|
* Downloads and save threads into the database
|
||||||
*
|
*
|
||||||
@@ -574,10 +577,11 @@ public class ForumDatabase {
|
|||||||
if (result != null)
|
if (result != null)
|
||||||
for (final Object element : result) {
|
for (final Object element : result) {
|
||||||
final HashMap<?, ?> contentHash = (HashMap<?, ?>) element;
|
final HashMap<?, ?> contentHash = (HashMap<?, ?>) element;
|
||||||
upsertThreadTable((String) forumId, (String) topicId, (String) contentHash.get("post_id"), (Date) contentHash.get("post_time"), convertHashMapToContentValues(contentHash));
|
upsertThreadTable((String) forumId, (String) topicId, (String) contentHash.get("post_id"), (Date) contentHash.get("post_time"),
|
||||||
|
convertHashMapToContentValues(contentHash));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isRecursive && mListener != null)
|
if (!isRecursive && mListener != null)
|
||||||
mListener.onSyncComplete();
|
mListener.onSyncComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,12 +604,13 @@ public class ForumDatabase {
|
|||||||
if (result != null)
|
if (result != null)
|
||||||
for (final Object element : result) {
|
for (final Object element : result) {
|
||||||
final HashMap<?, ?> contentHash = (HashMap<?, ?>) element;
|
final HashMap<?, ?> contentHash = (HashMap<?, ?>) element;
|
||||||
upsertTopicTable((String) forumId, (String) contentHash.get("topic_id"), (Date) contentHash.get("last_reply_time"), convertHashMapToContentValues(contentHash));
|
upsertTopicTable((String) forumId, (String) contentHash.get("topic_id"), (Date) contentHash.get("last_reply_time"),
|
||||||
|
convertHashMapToContentValues(contentHash));
|
||||||
if (isRecursive)
|
if (isRecursive)
|
||||||
saveThreads(client, forumId, contentHash.get("topic_id"), isRecursive);
|
saveThreads(client, forumId, contentHash.get("topic_id"), isRecursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isRecursive && mListener != null)
|
if (!isRecursive && mListener != null)
|
||||||
mListener.onSyncComplete();
|
mListener.onSyncComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,7 +646,7 @@ public class ForumDatabase {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void upsertTable(final String table, final String where, final ContentValues item) {
|
private void upsertTable(final String table, final String where, final ContentValues item) {
|
||||||
Log.v(TAG, "upserting: " + item.getAsString(KEY) + " : "+ item.getAsString(KEY_VALUE));
|
Log.v(TAG, "upserting: " + item.getAsString(KEY) + " : " + item.getAsString(KEY_VALUE));
|
||||||
if (!(mDb.update(table, item, where, null) > 0))
|
if (!(mDb.update(table, item, where, null) > 0))
|
||||||
mDb.insert(table, null, item);
|
mDb.insert(table, null, item);
|
||||||
}
|
}
|
||||||
@@ -656,7 +661,8 @@ public class ForumDatabase {
|
|||||||
* @throws NullPointerException
|
* @throws NullPointerException
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void upsertThreadTable(final String forumId, final String topicId, final String postId, final Date time, final List<ContentValues> values) throws NullPointerException {
|
private void upsertThreadTable(final String forumId, final String topicId, final String postId, final Date time, final List<ContentValues> values)
|
||||||
|
throws NullPointerException {
|
||||||
if (values == null)
|
if (values == null)
|
||||||
throw new NullPointerException("values was null");
|
throw new NullPointerException("values was null");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user