I can now display topics 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="297"
|
android:versionCode="302"
|
||||||
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
|
||||||
|
|||||||
@@ -127,10 +127,10 @@ public class TopicAdapter 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("topic_title")));
|
holder.title.setText((String) getItem(position).get("topic_title"));
|
||||||
holder.user.setText(new String((byte[]) getItem(position).get("topic_author_name")));
|
holder.user.setText((String) getItem(position).get("topic_author_name"));
|
||||||
holder.lastestPost.setText(new String((byte[]) getItem(position).get("short_content")));
|
holder.lastestPost.setText((String) getItem(position).get("short_content"));
|
||||||
holder.newPosts.setVisibility((Boolean) getItem(position).get("new_post") ? View.VISIBLE : View.GONE);
|
holder.newPosts.setVisibility((Boolean.parseBoolean((String) getItem(position).get("new_post")) ? View.VISIBLE : View.GONE));
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ 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.xmlrpc.android.XMLRPCClient;
|
import org.xmlrpc.android.XMLRPCClient;
|
||||||
import org.xmlrpc.android.XMLRPCException;
|
import org.xmlrpc.android.XMLRPCException;
|
||||||
|
|
||||||
@@ -85,22 +87,14 @@ public class TopicContent {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void getTopics(final String forumId, final Context context) {
|
public static void getTopics(final String forumId, final Context context) {
|
||||||
final XMLRPCClient client = XMLRPCClient.getClient(context);
|
|
||||||
|
|
||||||
ITEMS.clear();
|
ITEMS.clear();
|
||||||
ITEM_MAP.clear();
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
|
final ForumDatabase db = new ForumDatabase(context);
|
||||||
|
List<String> list = db.getTopics();
|
||||||
|
|
||||||
Object[] result = null;
|
int index = 0;
|
||||||
try {
|
for(String item : list)
|
||||||
result = (Object[]) ((HashMap<?, ?>) client.call("get_topic", forumId, 0, 0)).get("topics");
|
addItem(new TopicItem(Integer.valueOf(index++).toString(), db.getTopic(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 TopicItem(Integer.valueOf(i).toString(), contentHash));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,6 +376,21 @@ public class ForumDatabase {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of topic ids
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public List<String> getTopics(){
|
||||||
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
|
Cursor c = mDb.query(TABLE_TOPICS, 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
|
||||||
@@ -383,11 +398,30 @@ public class ForumDatabase {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public HashMap<String, String> getForum(String id){
|
public HashMap<String, String> getForum(String id){
|
||||||
|
return cursorToHashMap(mDb.query(TABLE_FORUM_INFO, new String[] { KEY, KEY_VALUE }, KEY_FORUM_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a topic from the database
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public HashMap<String, String> getTopic(String id) {
|
||||||
|
return cursorToHashMap(mDb.query(TABLE_TOPIC_INFO, new String[] { KEY, KEY_VALUE }, KEY_TOPIC_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a cursor with key-value pairs into a hash map
|
||||||
|
* @param c
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private HashMap<String, String> cursorToHashMap(Cursor c){
|
||||||
HashMap<String, String> h = new HashMap<String, String>();
|
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())
|
if(c.moveToFirst())
|
||||||
do{
|
do{
|
||||||
h.put(c.getString(0), c.getString(1));
|
h.put(c.getString(c.getColumnIndex(KEY)), c.getString(c.getColumnIndex(KEY_VALUE)));
|
||||||
} while(c.moveToNext());
|
} while(c.moveToNext());
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
@@ -593,4 +627,4 @@ public class ForumDatabase {
|
|||||||
KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY)) + " AND " + KEY_TOPIC_ID + " = " + DatabaseUtils.sqlEscapeString(topicId), item);
|
KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY)) + " AND " + KEY_TOPIC_ID + " = " + DatabaseUtils.sqlEscapeString(topicId), item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user