diff --git a/OSJ Forum/AndroidManifest.xml b/OSJ Forum/AndroidManifest.xml index 9e549e5..52608d1 100644 --- a/OSJ Forum/AndroidManifest.xml +++ b/OSJ Forum/AndroidManifest.xml @@ -1,5 +1,5 @@ list = db.getTopics(); - Object[] result = null; - try { - result = (Object[]) ((HashMap) client.call("get_topic", forumId, 0, 0)).get("topics"); - } 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)); - } + int index = 0; + for(String item : list) + addItem(new TopicItem(Integer.valueOf(index++).toString(), db.getTopic(item))); } } diff --git a/OSJ Forum/src/org/RickBarrette/osj/forum/database/ForumDatabase.java b/OSJ Forum/src/org/RickBarrette/osj/forum/database/ForumDatabase.java index 82015cb..560301f 100644 --- a/OSJ Forum/src/org/RickBarrette/osj/forum/database/ForumDatabase.java +++ b/OSJ Forum/src/org/RickBarrette/osj/forum/database/ForumDatabase.java @@ -376,6 +376,21 @@ public class ForumDatabase { return list; } + /** + * Retrieves a list of topic ids + * @return + * @author ricky barrette + */ + public List getTopics(){ + ArrayList list = new ArrayList(); + 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 * @param id @@ -383,11 +398,30 @@ public class ForumDatabase { * @author ricky barrette */ public HashMap 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 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 cursorToHashMap(Cursor c){ HashMap h = new HashMap(); - 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)); + h.put(c.getString(c.getColumnIndex(KEY)), c.getString(c.getColumnIndex(KEY_VALUE))); } while(c.moveToNext()); return h; } @@ -593,4 +627,4 @@ public class ForumDatabase { KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY)) + " AND " + KEY_TOPIC_ID + " = " + DatabaseUtils.sqlEscapeString(topicId), item); } } -} +} \ No newline at end of file