I can now display threads 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="302"
|
||||
android:versionCode="305"
|
||||
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
|
||||
|
||||
<uses-sdk
|
||||
|
||||
@@ -126,9 +126,9 @@ public class ThreadAdapter 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).get("post_title")));
|
||||
holder.user.setText(new String((byte[]) getItem(position).get("post_author_name")));
|
||||
holder.post.setText(new String((byte[]) getItem(position).get("post_content")));
|
||||
holder.title.setText((String) getItem(position).get("post_title"));
|
||||
holder.user.setText((String) getItem(position).get("post_author_name"));
|
||||
holder.post.setText((String) getItem(position).get("post_content"));
|
||||
|
||||
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;
|
||||
|
||||
@@ -87,23 +86,15 @@ public class ThreadContent {
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static void getThread(final String topicId, final int startNumber, final int lastNumber, final Context context) {
|
||||
final XMLRPCClient client = XMLRPCClient.getClient(context);
|
||||
|
||||
ITEMS.clear();
|
||||
ITEM_MAP.clear();
|
||||
|
||||
final ForumDatabase db = new ForumDatabase(context);
|
||||
List<String> list = db.getThreads();
|
||||
|
||||
Object[] result = null;
|
||||
try {
|
||||
result = (Object[]) ((HashMap<?, ?>) client.call("get_thread", topicId, startNumber, lastNumber)).get("posts");
|
||||
} 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 ThreadItem(Integer.valueOf(i).toString(), contentHash));
|
||||
}
|
||||
int index = 0;
|
||||
for(String item : list)
|
||||
addItem(new ThreadItem(Integer.valueOf(index++).toString(), db.getThread(item)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.RickBarrette.osj.forum.Log;
|
||||
import org.RickBarrette.osj.forum.content.ForumContent.ForumItem;
|
||||
import org.RickBarrette.osj.forum.database.ForumDatabase;
|
||||
import org.xmlrpc.android.XMLRPCClient;
|
||||
import org.xmlrpc.android.XMLRPCException;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
@@ -391,6 +391,21 @@ public class ForumDatabase {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of thread ids
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public List<String> getThreads(){
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
Cursor c = mDb.query(TABLE_THREADS, 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
|
||||
@@ -411,6 +426,16 @@ public class ForumDatabase {
|
||||
return cursorToHashMap(mDb.query(TABLE_TOPIC_INFO, new String[] { KEY, KEY_VALUE }, KEY_TOPIC_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a post from the threads table of the database
|
||||
* @param id
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public HashMap<String, String> getThread(String id) {
|
||||
return cursorToHashMap(mDb.query(TABLE_THREAD_INFO, new String[] { KEY, KEY_VALUE }, KEY_POST_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a cursor with key-value pairs into a hash map
|
||||
* @param c
|
||||
|
||||
Reference in New Issue
Block a user