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"
android:versionCode="287"
android:versionCode="297"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-sdk

View File

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

View File

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

View File

@@ -25,8 +25,7 @@ import java.util.List;
import java.util.Map;
import org.RickBarrette.osj.forum.Log;
import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;
import org.RickBarrette.osj.forum.database.ForumDatabase;
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
* @author ricky barrette
@@ -107,19 +106,11 @@ public class ForumContent {
ITEMS.clear();
ITEM_MAP.clear();
final XMLRPCClient client = XMLRPCClient.getClient(context);
final ForumDatabase db = new ForumDatabase(context);
List<String> list = db.getForums();
Object[] result = null;
try {
result = (Object[]) client.call("get_forum", true);
} 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));
}
int index = 0;
for(String item : list)
addItem(new ForumItem(Integer.valueOf(index++).toString(), db.getForum(item)));
}
}

View File

@@ -361,8 +361,35 @@ public class ForumDatabase {
}).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;
}
/**