@@ -69,7 +69,7 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
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
|
||||||
@@ -82,45 +82,6 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
setListAdapter(new ForumAdapter(getActivity()));
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetach() {
|
|
||||||
super.onDetach();
|
|
||||||
mCallbacks = sForumCallbacks;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onListItemClick(final ListView listView, final View view, final int position, final long id) {
|
|
||||||
super.onListItemClick(listView, view, position, id);
|
|
||||||
mCallbacks.onItemSelected(this, ForumContent.ITEMS.get(position).id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(final Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
if (mActivatedPosition != AdapterView.INVALID_POSITION)
|
|
||||||
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(final View view, final Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION))
|
|
||||||
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActivatedPosition(final int position) {
|
|
||||||
if (position == AdapterView.INVALID_POSITION)
|
|
||||||
getListView().setItemChecked(mActivatedPosition, false);
|
|
||||||
else
|
|
||||||
getListView().setItemChecked(position, true);
|
|
||||||
|
|
||||||
mActivatedPosition = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActivateOnItemClick(final boolean activateOnItemClick) {
|
|
||||||
getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDatabaseCreate() {
|
public void onDatabaseCreate() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
@@ -145,12 +106,31 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
mCallbacks = sForumCallbacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListItemClick(final ListView listView, final View view, final int position, final long id) {
|
||||||
|
super.onListItemClick(listView, view, position, id);
|
||||||
|
mCallbacks.onItemSelected(this, ForumContent.ITEMS.get(position).id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRestoreComplete() {
|
public void onRestoreComplete() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(final Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
if (mActivatedPosition != AdapterView.INVALID_POSITION)
|
||||||
|
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSyncComplete() {
|
public void onSyncComplete() {
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@@ -161,4 +141,24 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(final View view, final Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION))
|
||||||
|
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivatedPosition(final int position) {
|
||||||
|
if (position == AdapterView.INVALID_POSITION)
|
||||||
|
getListView().setItemChecked(mActivatedPosition, false);
|
||||||
|
else
|
||||||
|
getListView().setItemChecked(position, true);
|
||||||
|
|
||||||
|
mActivatedPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivateOnItemClick(final boolean activateOnItemClick) {
|
||||||
|
getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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