@@ -48,8 +48,9 @@ public class ForumListActivity extends FragmentActivity implements OnItemSelecte
|
|||||||
|
|
||||||
setContentView(R.layout.activity_forum_list);
|
setContentView(R.layout.activity_forum_list);
|
||||||
|
|
||||||
new Thread(new Runnable(){
|
new Thread(new Runnable() {
|
||||||
public void run(){
|
@Override
|
||||||
|
public void run() {
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
new ForumDatabase(ForumListActivity.this).saveForums(true);
|
new ForumDatabase(ForumListActivity.this).saveForums(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ public class ForumListFragment extends ListFragment {
|
|||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (ForumContent.ITEMS.size() == 0){
|
if (ForumContent.ITEMS.size() == 0) {
|
||||||
// new Thread(new Runnable() {
|
// new Thread(new Runnable() {
|
||||||
// @Override
|
// @Override
|
||||||
// public void run() {
|
// public void run() {
|
||||||
ForumContent.getForum(getActivity());
|
ForumContent.getForum(getActivity());
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -76,10 +76,9 @@ public class ForumListFragment extends ListFragment {
|
|||||||
setListAdapter(new ForumAdapter(getActivity()));
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// }
|
// }
|
||||||
// }).start();
|
// }).start();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,10 +107,10 @@ public class ForumContent {
|
|||||||
ITEM_MAP.clear();
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
final ForumDatabase db = new ForumDatabase(context);
|
final ForumDatabase db = new ForumDatabase(context);
|
||||||
List<String> list = db.getForums();
|
final List<String> list = db.getForums();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for(String item : list)
|
for (final String item : list)
|
||||||
addItem(new ForumItem(Integer.valueOf(index++).toString(), db.getForum(item)));
|
addItem(new ForumItem(Integer.valueOf(index++).toString(), db.getForum(item)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,10 +90,10 @@ public class ThreadContent {
|
|||||||
ITEM_MAP.clear();
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
final ForumDatabase db = new ForumDatabase(context);
|
final ForumDatabase db = new ForumDatabase(context);
|
||||||
List<String> list = db.getThreads();
|
final List<String> list = db.getThreads();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for(String item : list)
|
for (final String item : list)
|
||||||
addItem(new ThreadItem(Integer.valueOf(index++).toString(), db.getThread(item)));
|
addItem(new ThreadItem(Integer.valueOf(index++).toString(), db.getThread(item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
holder.title.setText((String) getItem(position).get("topic_title"));
|
holder.title.setText((String) getItem(position).get("topic_title"));
|
||||||
holder.user.setText((String) getItem(position).get("topic_author_name"));
|
holder.user.setText((String) getItem(position).get("topic_author_name"));
|
||||||
holder.lastestPost.setText((String) getItem(position).get("short_content"));
|
holder.lastestPost.setText((String) getItem(position).get("short_content"));
|
||||||
holder.newPosts.setVisibility((Boolean.parseBoolean((String) 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,10 +88,10 @@ public class TopicContent {
|
|||||||
ITEM_MAP.clear();
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
final ForumDatabase db = new ForumDatabase(context);
|
final ForumDatabase db = new ForumDatabase(context);
|
||||||
List<String> list = db.getTopics();
|
final List<String> list = db.getTopics();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for(String item : list)
|
for (final String item : list)
|
||||||
addItem(new TopicItem(Integer.valueOf(index++).toString(), db.getTopic(item)));
|
addItem(new TopicItem(Integer.valueOf(index++).toString(), db.getTopic(item)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
package org.RickBarrette.osj.forum.database;
|
package org.RickBarrette.osj.forum.database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface will be used to listen to see when the database events are complete
|
* This interface will be used to listen to see when the database events are
|
||||||
|
* complete
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -32,8 +33,8 @@ public interface DatabaseListener {
|
|||||||
|
|
||||||
public void onDatabaseUpgradeComplete();
|
public void onDatabaseUpgradeComplete();
|
||||||
|
|
||||||
public void onRestoreComplete();
|
|
||||||
|
|
||||||
public void onDeletionComplete();
|
public void onDeletionComplete();
|
||||||
|
|
||||||
|
public void onRestoreComplete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -83,14 +83,15 @@ public class ForumDatabase {
|
|||||||
* These tables will be used for storing forum, topic, and post id's
|
* These tables will be used for storing forum, topic, and post id's
|
||||||
*/
|
*/
|
||||||
db.execSQL("CREATE TABLE " + TABLE_FORUMS + "( id TEXT PRIMARY KEY)");
|
db.execSQL("CREATE TABLE " + TABLE_FORUMS + "( id TEXT PRIMARY KEY)");
|
||||||
db.execSQL("CREATE TABLE " + TABLE_TOPICS + "( id TEXT PRIMARY KEY, "+ KEY_FORUM_ID +" TEXT)");
|
db.execSQL("CREATE TABLE " + TABLE_TOPICS + "( id TEXT PRIMARY KEY, " + KEY_FORUM_ID + " TEXT)");
|
||||||
db.execSQL("CREATE TABLE " + TABLE_THREADS + "( id TEXT PRIMARY KEY, "+ KEY_FORUM_ID + " TEXT, "+ KEY_TOPIC_ID + " TEXT)");
|
db.execSQL("CREATE TABLE " + TABLE_THREADS + "( id TEXT PRIMARY KEY, " + KEY_FORUM_ID + " TEXT, " + KEY_TOPIC_ID + " TEXT)");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These tables will be used for storing forum, topic, and post information.
|
* These tables will be used for storing forum, topic, and post
|
||||||
|
* information.
|
||||||
*/
|
*/
|
||||||
db.execSQL("CREATE TABLE " + TABLE_FORUM_INFO + "( id INTEGER PRIMARY KEY, " + KEY_FORUM_ID + " TEXT, " + KEY + " TEXT, " + KEY_VALUE + " TEXT)");
|
db.execSQL("CREATE TABLE " + TABLE_FORUM_INFO + "( id INTEGER PRIMARY KEY, " + KEY_FORUM_ID + " TEXT, " + KEY + " TEXT, " + KEY_VALUE + " TEXT)");
|
||||||
db.execSQL("CREATE TABLE " + TABLE_TOPIC_INFO + "( id INTEGER PRIMARY KEY, " + KEY_TOPIC_ID + " TEXT, " + KEY + " TEXT, " + KEY_VALUE+ " TEXT)");
|
db.execSQL("CREATE TABLE " + TABLE_TOPIC_INFO + "( id INTEGER PRIMARY KEY, " + KEY_TOPIC_ID + " TEXT, " + KEY + " TEXT, " + KEY_VALUE + " TEXT)");
|
||||||
db.execSQL("CREATE TABLE " + TABLE_THREAD_INFO + "( id INTEGER PRIMARY KEY, " + KEY_POST_ID + " TEXT, " + KEY + " TEXT, " + KEY_VALUE + " TEXT)");
|
db.execSQL("CREATE TABLE " + TABLE_THREAD_INFO + "( id INTEGER PRIMARY KEY, " + KEY_POST_ID + " TEXT, " + KEY + " TEXT, " + KEY_VALUE + " TEXT)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,6 +338,22 @@ public class ForumDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a cursor with key-value pairs into a hash map
|
||||||
|
*
|
||||||
|
* @param c
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private HashMap<String, String> cursorToHashMap(final Cursor c) {
|
||||||
|
final HashMap<String, String> h = new HashMap<String, String>();
|
||||||
|
if (c.moveToFirst())
|
||||||
|
do
|
||||||
|
h.put(c.getString(c.getColumnIndex(KEY)), c.getString(c.getColumnIndex(KEY_VALUE)));
|
||||||
|
while (c.moveToNext());
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes a note by its row id
|
* deletes a note by its row id
|
||||||
*
|
*
|
||||||
@@ -361,94 +378,88 @@ public class ForumDatabase {
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 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 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
|
||||||
* @return
|
* @return
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public HashMap<String, String> getForum(String id){
|
public HashMap<String, String> getForum(final String id) {
|
||||||
return cursorToHashMap(mDb.query(TABLE_FORUM_INFO, new String[] { KEY, KEY_VALUE }, KEY_FORUM_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null));
|
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
|
* Retrieves a list of forum ids
|
||||||
* @param id
|
*
|
||||||
* @return
|
* @return
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public HashMap<String, String> getTopic(String id) {
|
public List<String> getForums() {
|
||||||
return cursorToHashMap(mDb.query(TABLE_TOPIC_INFO, new String[] { KEY, KEY_VALUE }, KEY_TOPIC_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null));
|
final ArrayList<String> list = new ArrayList<String>();
|
||||||
|
final 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 post from the threads table of the database
|
* Retrieves a post from the threads table of the database
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public HashMap<String, String> getThread(String id) {
|
public HashMap<String, String> getThread(final String id) {
|
||||||
return cursorToHashMap(mDb.query(TABLE_THREAD_INFO, new String[] { KEY, KEY_VALUE }, KEY_POST_ID +" = "+ DatabaseUtils.sqlEscapeString(id), null, null, null, null));
|
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
|
* Retrieves a list of thread ids
|
||||||
* @param c
|
*
|
||||||
* @return
|
* @return
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private HashMap<String, String> cursorToHashMap(Cursor c){
|
public List<String> getThreads() {
|
||||||
HashMap<String, String> h = new HashMap<String, String>();
|
final ArrayList<String> list = new ArrayList<String>();
|
||||||
if(c.moveToFirst())
|
final Cursor c = mDb.query(TABLE_THREADS, new String[] { KEY_ID }, null, null, null, null, null);
|
||||||
do{
|
if (c.moveToFirst())
|
||||||
h.put(c.getString(c.getColumnIndex(KEY)), c.getString(c.getColumnIndex(KEY_VALUE)));
|
do
|
||||||
} while(c.moveToNext());
|
list.add(c.getString(0));
|
||||||
return h;
|
while (c.moveToNext());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a topic from the database
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public HashMap<String, String> getTopic(final String id) {
|
||||||
|
return cursorToHashMap(mDb.query(TABLE_TOPIC_INFO, new String[] { KEY, KEY_VALUE }, KEY_TOPIC_ID + " = " + DatabaseUtils.sqlEscapeString(id), null, null, null,
|
||||||
|
null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of topic ids
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public List<String> getTopics() {
|
||||||
|
final ArrayList<String> list = new ArrayList<String>();
|
||||||
|
final 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -504,7 +515,7 @@ public class ForumDatabase {
|
|||||||
/*
|
/*
|
||||||
* save the forums
|
* save the forums
|
||||||
*/
|
*/
|
||||||
if (result != null){
|
if (result != null) {
|
||||||
String id = null;
|
String id = null;
|
||||||
for (final Object element : result) {
|
for (final Object element : result) {
|
||||||
final HashMap<?, ?> contentHash = (HashMap<?, ?>) element;
|
final HashMap<?, ?> contentHash = (HashMap<?, ?>) element;
|
||||||
@@ -578,13 +589,14 @@ public class ForumDatabase {
|
|||||||
if (values == null)
|
if (values == null)
|
||||||
throw new NullPointerException("values was null");
|
throw new NullPointerException("values was null");
|
||||||
|
|
||||||
ContentValues id = new ContentValues();
|
final ContentValues id = new ContentValues();
|
||||||
id.put(KEY_ID, forumId);
|
id.put(KEY_ID, forumId);
|
||||||
upsertTable(TABLE_FORUMS, KEY_ID +" = "+ DatabaseUtils.sqlEscapeString(forumId), id);
|
upsertTable(TABLE_FORUMS, KEY_ID + " = " + DatabaseUtils.sqlEscapeString(forumId), id);
|
||||||
|
|
||||||
for (final ContentValues item : values) {
|
for (final ContentValues item : values) {
|
||||||
item.put(KEY_FORUM_ID, forumId);
|
item.put(KEY_FORUM_ID, forumId);
|
||||||
upsertTable(TABLE_FORUM_INFO, KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY) + " AND " + KEY_FORUM_ID + " = " + DatabaseUtils.sqlEscapeString(forumId)), item);
|
upsertTable(TABLE_FORUM_INFO,
|
||||||
|
KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY) + " AND " + KEY_FORUM_ID + " = " + DatabaseUtils.sqlEscapeString(forumId)), item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,15 +628,16 @@ public class ForumDatabase {
|
|||||||
if (values == null)
|
if (values == null)
|
||||||
throw new NullPointerException("values was null");
|
throw new NullPointerException("values was null");
|
||||||
|
|
||||||
ContentValues id = new ContentValues();
|
final ContentValues id = new ContentValues();
|
||||||
id.put(KEY_ID, postId);
|
id.put(KEY_ID, postId);
|
||||||
id.put(KEY_FORUM_ID, forumId);
|
id.put(KEY_FORUM_ID, forumId);
|
||||||
id.put(KEY_TOPIC_ID, topicId);
|
id.put(KEY_TOPIC_ID, topicId);
|
||||||
upsertTable(TABLE_THREADS, KEY_ID +" = "+ DatabaseUtils.sqlEscapeString(postId), id);
|
upsertTable(TABLE_THREADS, KEY_ID + " = " + DatabaseUtils.sqlEscapeString(postId), id);
|
||||||
|
|
||||||
for (final ContentValues item : values) {
|
for (final ContentValues item : values) {
|
||||||
item.put(KEY_POST_ID, postId);
|
item.put(KEY_POST_ID, postId);
|
||||||
upsertTable( TABLE_THREAD_INFO, KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY)) + " AND " + KEY_POST_ID + " = " + DatabaseUtils.sqlEscapeString(postId), item);
|
upsertTable(TABLE_THREAD_INFO,
|
||||||
|
KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY)) + " AND " + KEY_POST_ID + " = " + DatabaseUtils.sqlEscapeString(postId), item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,10 +654,10 @@ public class ForumDatabase {
|
|||||||
if (values == null)
|
if (values == null)
|
||||||
throw new NullPointerException("values was null");
|
throw new NullPointerException("values was null");
|
||||||
|
|
||||||
ContentValues id = new ContentValues();
|
final ContentValues id = new ContentValues();
|
||||||
id.put(KEY_ID, topicId);
|
id.put(KEY_ID, topicId);
|
||||||
id.put(KEY_FORUM_ID, forumId);
|
id.put(KEY_FORUM_ID, forumId);
|
||||||
upsertTable(TABLE_TOPICS, KEY_ID +" = "+ DatabaseUtils.sqlEscapeString(topicId), id);
|
upsertTable(TABLE_TOPICS, KEY_ID + " = " + DatabaseUtils.sqlEscapeString(topicId), id);
|
||||||
|
|
||||||
for (final ContentValues item : values) {
|
for (final ContentValues item : values) {
|
||||||
item.put(KEY_TOPIC_ID, topicId);
|
item.put(KEY_TOPIC_ID, topicId);
|
||||||
|
|||||||
Reference in New Issue
Block a user