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"
|
<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">
|
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
|||||||
@@ -126,9 +126,9 @@ public class ThreadAdapter 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).get("post_title")));
|
holder.title.setText((String) getItem(position).get("post_title"));
|
||||||
holder.user.setText(new String((byte[]) getItem(position).get("post_author_name")));
|
holder.user.setText((String) getItem(position).get("post_author_name"));
|
||||||
holder.post.setText(new String((byte[]) getItem(position).get("post_content")));
|
holder.post.setText((String) getItem(position).get("post_content"));
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -87,23 +86,15 @@ public class ThreadContent {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void getThread(final String topicId, final int startNumber, final int lastNumber, final Context context) {
|
public static void getThread(final String topicId, final int startNumber, final int lastNumber, final Context context) {
|
||||||
final XMLRPCClient client = XMLRPCClient.getClient(context);
|
|
||||||
|
|
||||||
ITEMS.clear();
|
ITEMS.clear();
|
||||||
ITEM_MAP.clear();
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
Object[] result = null;
|
final ForumDatabase db = new ForumDatabase(context);
|
||||||
try {
|
List<String> list = db.getThreads();
|
||||||
result = (Object[]) ((HashMap<?, ?>) client.call("get_thread", topicId, startNumber, lastNumber)).get("posts");
|
|
||||||
} catch (final XMLRPCException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != null)
|
int index = 0;
|
||||||
for (int i = 0; i < result.length; i++) {
|
for(String item : list)
|
||||||
final HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
addItem(new ThreadItem(Integer.valueOf(index++).toString(), db.getThread(item)));
|
||||||
addItem(new ThreadItem(Integer.valueOf(i).toString(), contentHash));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +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.RickBarrette.osj.forum.content.ForumContent.ForumItem;
|
|
||||||
import org.RickBarrette.osj.forum.database.ForumDatabase;
|
import org.RickBarrette.osj.forum.database.ForumDatabase;
|
||||||
import org.xmlrpc.android.XMLRPCClient;
|
|
||||||
import org.xmlrpc.android.XMLRPCException;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|||||||
@@ -391,6 +391,21 @@ public class ForumDatabase {
|
|||||||
return list;
|
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
|
* Retrieves a forum from the database
|
||||||
* @param id
|
* @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));
|
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
|
* Converts a cursor with key-value pairs into a hash map
|
||||||
* @param c
|
* @param c
|
||||||
|
|||||||
Reference in New Issue
Block a user