I can now display forums from the database
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()));
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user