@@ -69,7 +69,7 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.v(TAG, "onCreate()");
|
||||
|
||||
mDb = new ForumDatabase(this.getActivity(), this);
|
||||
mDb = new ForumDatabase(getActivity(), this);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
@@ -82,45 +82,6 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
||||
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
|
||||
public void onDatabaseCreate() {
|
||||
// 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
|
||||
public void onRestoreComplete() {
|
||||
// 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
|
||||
public void onSyncComplete() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,11 +432,12 @@ public class ForumDatabase {
|
||||
/**
|
||||
* Retrieves a list of thread ids
|
||||
*
|
||||
* @param id of topic
|
||||
* @param id
|
||||
* of topic
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public List<String> getThreads(String id) {
|
||||
public List<String> getThreads(final String id) {
|
||||
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);
|
||||
if (c.moveToFirst())
|
||||
@@ -461,13 +462,15 @@ public class ForumDatabase {
|
||||
/**
|
||||
* Retrieves a list of topic ids
|
||||
*
|
||||
* @param id of forum
|
||||
* @param id
|
||||
* of forum
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public List<String> getTopics(String id) {
|
||||
public List<String> getTopics(final String id) {
|
||||
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())
|
||||
do
|
||||
list.add(c.getString(0));
|
||||
@@ -574,7 +577,8 @@ public class ForumDatabase {
|
||||
if (result != null)
|
||||
for (final Object element : result) {
|
||||
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)
|
||||
@@ -600,7 +604,8 @@ public class ForumDatabase {
|
||||
if (result != null)
|
||||
for (final Object element : result) {
|
||||
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)
|
||||
saveThreads(client, forumId, contentHash.get("topic_id"), isRecursive);
|
||||
}
|
||||
@@ -656,7 +661,8 @@ public class ForumDatabase {
|
||||
* @throws NullPointerException
|
||||
* @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)
|
||||
throw new NullPointerException("values was null");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user