I can now display forums from the database

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-10-06 11:02:20 -04:00
parent b732dbe28d
commit 106a4626f6
5 changed files with 47 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
<manifest package="org.RickBarrette.osj.forum" <manifest package="org.RickBarrette.osj.forum"
android:versionCode="287" android:versionCode="297"
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

View File

@@ -65,10 +65,10 @@ public class ForumListFragment extends ListFragment {
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (ForumContent.ITEMS.size() == 0) if (ForumContent.ITEMS.size() == 0){
new Thread(new Runnable() { // new Thread(new Runnable() {
@Override // @Override
public void run() { // public void run() {
ForumContent.getForum(getActivity()); ForumContent.getForum(getActivity());
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
@Override @Override
@@ -76,8 +76,9 @@ public class ForumListFragment extends ListFragment {
setListAdapter(new ForumAdapter(getActivity())); setListAdapter(new ForumAdapter(getActivity()));
} }
}); });
} // }
}).start(); // }).start();
}
else else
setListAdapter(new ForumAdapter(getActivity())); setListAdapter(new ForumAdapter(getActivity()));

View File

@@ -120,8 +120,8 @@ public class ForumAdapter extends BaseAdapter {
* always call setChecked() after calling setOnCheckedChangedListener. * always call setChecked() after calling setOnCheckedChangedListener.
* This will prevent the list from changing the values on you. * This will prevent the list from changing the values on you.
*/ */
holder.title.setText(new String((byte[]) getItem(position).content.get("forum_name"))); holder.title.setText((String) getItem(position).content.get("forum_name"));
holder.description.setText(new String((byte[]) getItem(position).content.get("description"))); holder.description.setText((String) getItem(position).content.get("description"));
return convertView; return convertView;
} }

View File

@@ -25,8 +25,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.RickBarrette.osj.forum.Log; import org.RickBarrette.osj.forum.Log;
import org.xmlrpc.android.XMLRPCClient; import org.RickBarrette.osj.forum.database.ForumDatabase;
import org.xmlrpc.android.XMLRPCException;
import android.content.Context; import android.content.Context;
@@ -98,7 +97,7 @@ public class ForumContent {
} }
/** /**
* Downloads the forum from the Internet * Retrives the forum from the Database
* *
* @param context * @param context
* @author ricky barrette * @author ricky barrette
@@ -107,19 +106,11 @@ public class ForumContent {
ITEMS.clear(); ITEMS.clear();
ITEM_MAP.clear(); ITEM_MAP.clear();
final XMLRPCClient client = XMLRPCClient.getClient(context); final ForumDatabase db = new ForumDatabase(context);
List<String> list = db.getForums();
Object[] result = null; int index = 0;
try { for(String item : list)
result = (Object[]) client.call("get_forum", true); addItem(new ForumItem(Integer.valueOf(index++).toString(), db.getForum(item)));
} catch (final XMLRPCException e) {
e.printStackTrace();
}
if (result != null)
for (int i = 0; i < result.length; i++) {
final HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
addItem(new ForumItem(Integer.valueOf(i).toString(), contentHash));
}
} }
} }

View File

@@ -361,8 +361,35 @@ public class ForumDatabase {
}).start(); }).start();
} }
public Cursor getForums(){ /**
return mDb.query(TABLE_FORUMS, new String[] { KEY_ID}, null, null, null, null, null); * Retrieves a list of forum ids
* @return
* @author ricky barrette
*/
public List<String> getForums(){
ArrayList<String> list = new ArrayList<String>();
Cursor c = mDb.query(TABLE_FORUMS, new String[] { KEY_ID }, null, null, null, null, null);
if(c.moveToFirst())
do{
list.add(c.getString(0));
} while(c.moveToNext());
return list;
}
/**
* Retrieves a forum from the database
* @param id
* @return
* @author ricky barrette
*/
public HashMap<String, String> getForum(String id){
HashMap<String, String> h = new HashMap<String, String>();
Cursor c = mDb.query(TABLE_FORUM_INFO, new String[] { KEY, KEY_VALUE }, KEY_FORUM_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null);
if(c.moveToFirst())
do{
h.put(c.getString(0), c.getString(1));
} while(c.moveToNext());
return h;
} }
/** /**