Started working on updating the UI after a database sync
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<manifest package="org.RickBarrette.osj.forum"
|
<manifest package="org.RickBarrette.osj.forum"
|
||||||
android:versionCode="328"
|
android:versionCode="344"
|
||||||
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
|
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
|||||||
@@ -20,11 +20,9 @@
|
|||||||
package org.RickBarrette.osj.forum;
|
package org.RickBarrette.osj.forum;
|
||||||
|
|
||||||
import org.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
import org.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
import org.RickBarrette.osj.forum.database.ForumDatabase;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -48,14 +46,6 @@ public class ForumListActivity extends FragmentActivity implements OnItemSelecte
|
|||||||
|
|
||||||
setContentView(R.layout.activity_forum_list);
|
setContentView(R.layout.activity_forum_list);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Looper.prepare();
|
|
||||||
new ForumDatabase(ForumListActivity.this).saveForums(true);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
if (findViewById(R.id.forum_detail_container) != null) {
|
if (findViewById(R.id.forum_detail_container) != null) {
|
||||||
mTwoPane = true;
|
mTwoPane = true;
|
||||||
((ForumListFragment) getSupportFragmentManager().findFragmentById(R.id.forum_list)).setActivateOnItemClick(true);
|
((ForumListFragment) getSupportFragmentManager().findFragmentById(R.id.forum_list)).setActivateOnItemClick(true);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ package org.RickBarrette.osj.forum;
|
|||||||
import org.RickBarrette.osj.forum.content.ForumAdapter;
|
import org.RickBarrette.osj.forum.content.ForumAdapter;
|
||||||
import org.RickBarrette.osj.forum.content.ForumContent;
|
import org.RickBarrette.osj.forum.content.ForumContent;
|
||||||
import org.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
import org.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
|
import org.RickBarrette.osj.forum.database.DatabaseListener;
|
||||||
|
import org.RickBarrette.osj.forum.database.ForumDatabase;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -36,11 +38,12 @@ import android.widget.ListView;
|
|||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumListFragment extends ListFragment {
|
public class ForumListFragment extends ListFragment implements DatabaseListener {
|
||||||
|
|
||||||
|
private ForumDatabase mDb;
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
|
private static final String TAG = "ForumListFragment";
|
||||||
private OnItemSelectedListener mCallbacks = sForumCallbacks;
|
private OnItemSelectedListener mCallbacks = sForumCallbacks;
|
||||||
|
|
||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||||
|
|
||||||
private static OnItemSelectedListener sForumCallbacks = new OnItemSelectedListener() {
|
private static OnItemSelectedListener sForumCallbacks = new OnItemSelectedListener() {
|
||||||
@@ -64,23 +67,19 @@ public class ForumListFragment extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Log.v(TAG, "onCreate()");
|
||||||
|
|
||||||
if (ForumContent.ITEMS.size() == 0) {
|
mDb = new ForumDatabase(this.getActivity(), this);
|
||||||
// new Thread(new Runnable() {
|
|
||||||
// @Override
|
new Thread(new Runnable() {
|
||||||
// public void run() {
|
@Override
|
||||||
ForumContent.getForum(getActivity());
|
public void run() {
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
mDb.saveForums(true);
|
||||||
@Override
|
}
|
||||||
public void run() {
|
}).start();
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
|
||||||
}
|
if (ForumContent.ITEMS.size() != 0)
|
||||||
});
|
|
||||||
// }
|
|
||||||
// }).start();
|
|
||||||
} else
|
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,4 +120,45 @@ public class ForumListFragment extends ListFragment {
|
|||||||
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()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ import java.util.Map;
|
|||||||
import org.RickBarrette.osj.forum.Log;
|
import org.RickBarrette.osj.forum.Log;
|
||||||
import org.RickBarrette.osj.forum.database.ForumDatabase;
|
import org.RickBarrette.osj.forum.database.ForumDatabase;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to maintain an instance of a forum's content data
|
* This class is used to maintain an instance of a forum's content data
|
||||||
*
|
*
|
||||||
@@ -102,11 +100,10 @@ public class ForumContent {
|
|||||||
* @param context
|
* @param context
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void getForum(final Context context) {
|
public static void getForum(final ForumDatabase db) {
|
||||||
ITEMS.clear();
|
ITEMS.clear();
|
||||||
ITEM_MAP.clear();
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
final ForumDatabase db = new ForumDatabase(context);
|
|
||||||
final List<String> list = db.getForums();
|
final List<String> list = db.getForums();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|||||||
@@ -37,4 +37,6 @@ public interface DatabaseListener {
|
|||||||
|
|
||||||
public void onRestoreComplete();
|
public void onRestoreComplete();
|
||||||
|
|
||||||
|
public void onSyncComplete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -539,6 +539,8 @@ public class ForumDatabase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(mListener != null)
|
||||||
|
mListener.onSyncComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -549,6 +551,19 @@ public class ForumDatabase {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads and save threads into the database
|
||||||
|
*
|
||||||
|
* @param client
|
||||||
|
* @param forumId
|
||||||
|
* @param topicId
|
||||||
|
* @param isRecursive
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private void saveThreads(final XMLRPCClient client, final Object forumId, final Object topicId, final boolean isRecursive) {
|
||||||
Object[] result = null;
|
Object[] result = null;
|
||||||
try {
|
try {
|
||||||
result = (Object[]) ((HashMap<?, ?>) client.call("get_thread", topicId, 0, 0)).get("posts");
|
result = (Object[]) ((HashMap<?, ?>) client.call("get_thread", topicId, 0, 0)).get("posts");
|
||||||
@@ -562,6 +577,8 @@ public class ForumDatabase {
|
|||||||
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)
|
||||||
|
mListener.onSyncComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -585,9 +602,11 @@ public class ForumDatabase {
|
|||||||
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"));
|
saveThreads(client, forumId, contentHash.get("topic_id"), isRecursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isRecursive && mListener != null)
|
||||||
|
mListener.onSyncComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user