Cleaned up topic content data model
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<manifest package="com.RickBarrette.osj.forum"
|
<manifest package="com.RickBarrette.osj.forum"
|
||||||
android:versionCode="60"
|
android:versionCode="116"
|
||||||
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
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".TopicListActivity" />
|
android:value=".TopicListActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name="com.TwentyCodes.android.exception.ExceptionReportActivity" android:launchMode="singleInstance" android:noHistory="true" android:excludeFromRecents="true"></activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
<QuickContactBadge
|
<QuickContactBadge
|
||||||
android:id="@+id/quickContactBadge1"
|
android:id="@+id/quickContactBadge1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentTop="true" />
|
android:layout_centerVertical="true"
|
||||||
|
android:src="@drawable/ic_launcher" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView1"
|
android:id="@+id/textView1"
|
||||||
@@ -34,10 +35,20 @@
|
|||||||
android:id="@+id/textView3"
|
android:id="@+id/textView3"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignBottom="@+id/quickContactBadge1"
|
android:layout_below="@+id/textView2"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_toRightOf="@+id/quickContactBadge1"
|
android:layout_toRightOf="@+id/quickContactBadge1"
|
||||||
android:text="@string/user"
|
android:text="@string/user"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView4"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/textView2"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:text="@string/new_posts"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name">OSJ Forum</string>
|
<string name="app_name">OSJ Forum</string>
|
||||||
<string name="title_topic_detail">Topic Detail</string>
|
<string name="title_topic_detail">Topic Detail</string>
|
||||||
<string name="title_topic_list">Topics</string>
|
<string name="title_topic_list">Topics</string>
|
||||||
@@ -11,5 +10,7 @@
|
|||||||
<string name="post">Post</string>
|
<string name="post">Post</string>
|
||||||
<string name="user">User</string>
|
<string name="user">User</string>
|
||||||
<string name="latest_post">Lastest Post</string>
|
<string name="latest_post">Lastest Post</string>
|
||||||
|
<string name="new_posts">New Posts</string>
|
||||||
|
<string name="username">test</string>
|
||||||
|
<string name="password">Test1</string>
|
||||||
</resources>
|
</resources>
|
||||||
41
OSJ Forum/src/com/RickBarrette/osj/forum/Constraints.java
Normal file
41
OSJ Forum/src/com/RickBarrette/osj/forum/Constraints.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* Constraints.java
|
||||||
|
* @date Sep 13, 2012
|
||||||
|
* @author ricky barrette
|
||||||
|
*
|
||||||
|
* Copyright 2012 Richard Barrette
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License
|
||||||
|
*/
|
||||||
|
package com.RickBarrette.osj.forum;
|
||||||
|
|
||||||
|
import org.xmlrpc.android.XMLRPCClient;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class will be used to house the constraints of this application
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public class Constraints {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an XML RPC Client
|
||||||
|
* @param Context
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static XMLRPCClient getClient(Context context) {
|
||||||
|
return new XMLRPCClient(context.getString(R.string.server), context.getString(R.string.username), context.getString(R.string.password));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.RickBarrette.osj.forum;
|
package com.RickBarrette.osj.forum;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -28,7 +29,9 @@ import android.widget.ListView;
|
|||||||
|
|
||||||
import com.RickBarrette.osj.forum.content.ForumContent;
|
import com.RickBarrette.osj.forum.content.ForumContent;
|
||||||
import com.RickBarrette.osj.forum.content.ForumContent.ForumItem;
|
import com.RickBarrette.osj.forum.content.ForumContent.ForumItem;
|
||||||
|
import com.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
import com.RickBarrette.osj.forum.content.TopicAdapter;
|
import com.RickBarrette.osj.forum.content.TopicAdapter;
|
||||||
|
import com.RickBarrette.osj.forum.content.TopicContent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This fragment will be used to display information about the forum
|
* This fragment will be used to display information about the forum
|
||||||
@@ -41,31 +44,55 @@ public class ForumDetailFragment extends ListFragment {
|
|||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
|
|
||||||
ForumItem mItem;
|
ForumItem mItem;
|
||||||
|
private OnItemSelectedListener mCallbacks;
|
||||||
|
|
||||||
public ForumDetailFragment() {
|
public ForumDetailFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onAttach(Activity activity) {
|
||||||
|
super.onAttach(activity);
|
||||||
|
if (!(activity instanceof OnItemSelectedListener))
|
||||||
|
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||||
|
|
||||||
|
mCallbacks = (OnItemSelectedListener) activity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments().containsKey(ARG_ITEM_ID))
|
if (getArguments().containsKey(ARG_ITEM_ID))
|
||||||
mItem = ForumContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
mItem = ForumContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
||||||
|
|
||||||
|
|
||||||
new Thread( new Runnable(){
|
new Thread( new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
final Object[] result = mItem.getTopics(getActivity());
|
TopicContent.getTopics((String) mItem.content.get("forum_id"), getActivity());
|
||||||
getActivity().runOnUiThread(new Runnable(){
|
getActivity().runOnUiThread(new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
setListAdapter(new TopicAdapter(getActivity(), result));
|
setListAdapter(new TopicAdapter(getActivity()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView, android.view.View, int, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
|
super.onListItemClick(l, v, position, id);
|
||||||
|
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position).id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(final Bundle outState) {
|
public void onSaveInstanceState(final Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ package com.RickBarrette.osj.forum;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
|
import com.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumListActivity extends FragmentActivity implements ForumListFragment.Callbacks {
|
public class ForumListActivity extends FragmentActivity implements OnItemSelectedListener {
|
||||||
|
|
||||||
private boolean mTwoPane;
|
private boolean mTwoPane;
|
||||||
|
|
||||||
@@ -47,7 +49,7 @@ public class ForumListActivity extends FragmentActivity implements ForumListFrag
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(final String id) {
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
if (mTwoPane) {
|
if (mTwoPane) {
|
||||||
final Bundle arguments = new Bundle();
|
final Bundle arguments = new Bundle();
|
||||||
arguments.putString(ForumDetailFragment.ARG_ITEM_ID, id);
|
arguments.putString(ForumDetailFragment.ARG_ITEM_ID, id);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package com.RickBarrette.osj.forum;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
@@ -29,6 +30,7 @@ import android.widget.ListView;
|
|||||||
|
|
||||||
import com.RickBarrette.osj.forum.content.ForumAdapter;
|
import com.RickBarrette.osj.forum.content.ForumAdapter;
|
||||||
import com.RickBarrette.osj.forum.content.ForumContent;
|
import com.RickBarrette.osj.forum.content.ForumContent;
|
||||||
|
import com.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -36,19 +38,14 @@ import com.RickBarrette.osj.forum.content.ForumContent;
|
|||||||
*/
|
*/
|
||||||
public class ForumListFragment extends ListFragment {
|
public class ForumListFragment extends ListFragment {
|
||||||
|
|
||||||
public interface Callbacks {
|
|
||||||
|
|
||||||
public void onItemSelected(String id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
private Callbacks mCallbacks = sForumCallbacks;
|
private OnItemSelectedListener mCallbacks = sForumCallbacks;
|
||||||
|
|
||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||||
|
|
||||||
private static Callbacks sForumCallbacks = new Callbacks() {
|
private static OnItemSelectedListener sForumCallbacks = new OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(final String id) {
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,10 +55,10 @@ public class ForumListFragment extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(final Activity activity) {
|
public void onAttach(final Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
if (!(activity instanceof Callbacks))
|
if (!(activity instanceof OnItemSelectedListener))
|
||||||
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||||
|
|
||||||
mCallbacks = (Callbacks) activity;
|
mCallbacks = (OnItemSelectedListener) activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -95,7 +92,7 @@ public class ForumListFragment extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onListItemClick(final ListView listView, final View view, final int position, final long id) {
|
public void onListItemClick(final ListView listView, final View view, final int position, final long id) {
|
||||||
super.onListItemClick(listView, view, position, id);
|
super.onListItemClick(listView, view, position, id);
|
||||||
mCallbacks.onItemSelected(ForumContent.ITEMS.get(position).id);
|
mCallbacks.onItemSelected(this, ForumContent.ITEMS.get(position).id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,11 +21,13 @@ package com.RickBarrette.osj.forum;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
|
import com.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||||
|
|
||||||
public class TopicListActivity extends FragmentActivity implements TopicListFragment.Callbacks {
|
public class TopicListActivity extends FragmentActivity implements OnItemSelectedListener {
|
||||||
|
|
||||||
private boolean mTwoPane;
|
private boolean mTwoPane;
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ public class TopicListActivity extends FragmentActivity implements TopicListFrag
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(final String id) {
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
if (mTwoPane) {
|
if (mTwoPane) {
|
||||||
final Bundle arguments = new Bundle();
|
final Bundle arguments = new Bundle();
|
||||||
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id);
|
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package com.RickBarrette.osj.forum;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
@@ -28,23 +29,19 @@ import android.widget.AdapterView;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
import com.RickBarrette.osj.forum.dummy.DummyContent;
|
import com.RickBarrette.osj.forum.dummy.DummyContent;
|
||||||
|
|
||||||
public class TopicListFragment extends ListFragment {
|
public class TopicListFragment extends ListFragment {
|
||||||
|
|
||||||
public interface Callbacks {
|
|
||||||
|
|
||||||
public void onItemSelected(String id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
private Callbacks mCallbacks = sDummyCallbacks;
|
private OnItemSelectedListener mCallbacks = sDummyCallbacks;
|
||||||
|
|
||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||||
|
|
||||||
private static Callbacks sDummyCallbacks = new Callbacks() {
|
private static OnItemSelectedListener sDummyCallbacks = new OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(final String id) {
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,10 +51,11 @@ public class TopicListFragment extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(final Activity activity) {
|
public void onAttach(final Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
if (!(activity instanceof Callbacks))
|
if (!(activity instanceof OnItemSelectedListener))
|
||||||
|
|
||||||
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||||
|
|
||||||
mCallbacks = (Callbacks) activity;
|
mCallbacks = (OnItemSelectedListener) activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,7 +73,7 @@ public class TopicListFragment extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onListItemClick(final ListView listView, final View view, final int position, final long id) {
|
public void onListItemClick(final ListView listView, final View view, final int position, final long id) {
|
||||||
super.onListItemClick(listView, view, position, id);
|
super.onListItemClick(listView, view, position, id);
|
||||||
mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id);
|
mCallbacks.onItemSelected(this, DummyContent.ITEMS.get(position).id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import android.util.Log;
|
|||||||
import com.RickBarrette.osj.forum.R;
|
import com.RickBarrette.osj.forum.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This
|
* This class is used to maintian the forum's content data
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumContent {
|
public class ForumContent {
|
||||||
@@ -62,14 +62,6 @@ public class ForumContent {
|
|||||||
Log.d(TAG, key.toString());
|
Log.d(TAG, key.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of this forum object
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return (String) content.get("forum_name");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This gets all the categories and sub-forums
|
* This gets all the categories and sub-forums
|
||||||
* @return array of HashMap
|
* @return array of HashMap
|
||||||
@@ -80,24 +72,17 @@ public class ForumContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This gets all the topics for the current forum item
|
* Returns the name of this forum object
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
*/
|
||||||
public Object[] getTopics(final Context context){
|
@Override
|
||||||
final XMLRPCClient client = new XMLRPCClient((context.getString(R.string.server)));
|
public String toString() {
|
||||||
try {
|
return (String) content.get("forum_name");
|
||||||
return (Object[]) ((HashMap<?,?>) client.call("get_topic", this.content.get("forum_id"), 0, 0)).get("topics");
|
|
||||||
} catch (XMLRPCException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ForumItem> ITEMS = new ArrayList<ForumItem>();
|
}
|
||||||
public static Map<String, ForumItem> ITEM_MAP = new HashMap<String, ForumItem>();
|
|
||||||
|
public static final List<ForumItem> ITEMS = new ArrayList<ForumItem>();
|
||||||
|
public static final Map<String, ForumItem> ITEM_MAP = new HashMap<String, ForumItem>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new Forum Item to the list
|
* Adds a new Forum Item to the list
|
||||||
@@ -115,6 +100,9 @@ public class ForumContent {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void getForum(Context context){
|
public static void getForum(Context context){
|
||||||
|
ITEMS.clear();
|
||||||
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
final XMLRPCClient client = new XMLRPCClient((context.getString(R.string.server)));
|
final XMLRPCClient client = new XMLRPCClient((context.getString(R.string.server)));
|
||||||
|
|
||||||
Object[] result = null;
|
Object[] result = null;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* OnItemSelectedListener.java
|
||||||
|
* @date Sep 13, 2012
|
||||||
|
* @author ricky barrette
|
||||||
|
*
|
||||||
|
* Copyright 2012 Richard Barrette
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License
|
||||||
|
*/
|
||||||
|
package com.RickBarrette.osj.forum.content;
|
||||||
|
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a simple on item selcted callback for list fragments
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public interface OnItemSelectedListener {
|
||||||
|
/**
|
||||||
|
* Called when a list item from a list fragment is selected
|
||||||
|
* @param listFragment
|
||||||
|
* @param id of selected item
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void onItemSelected(final Fragment listFragment, final String id);
|
||||||
|
}
|
||||||
@@ -42,21 +42,20 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
TextView title;
|
TextView title;
|
||||||
TextView lastestPost;
|
TextView lastestPost;
|
||||||
TextView user;
|
TextView user;
|
||||||
|
TextView newPosts;
|
||||||
QuickContactBadge badage;
|
QuickContactBadge badage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG = "TopicAdapter";
|
private static final String TAG = "TopicAdapter";
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private Object[] mTopics;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public TopicAdapter(final Context context, final Object[] topics) {
|
public TopicAdapter(final Context context) {
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
mTopics = topics;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,10 +64,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
if(mTopics != null)
|
return TopicContent.ITEMS.size();
|
||||||
return mTopics.length;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,7 +73,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HashMap<?,?> getItem(int position) {
|
public HashMap<?,?> getItem(int position) {
|
||||||
return (HashMap<?,?>) mTopics[position];
|
return (HashMap<?,?>) TopicContent.ITEMS.get(position).content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,6 +110,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
holder.title = (TextView) convertView.findViewById(R.id.textView1);
|
holder.title = (TextView) convertView.findViewById(R.id.textView1);
|
||||||
holder.lastestPost = (TextView) convertView.findViewById(R.id.textView2);
|
holder.lastestPost = (TextView) convertView.findViewById(R.id.textView2);
|
||||||
holder.user = (TextView) convertView.findViewById(R.id.textView3);
|
holder.user = (TextView) convertView.findViewById(R.id.textView3);
|
||||||
|
holder.newPosts = (TextView) convertView.findViewById(R.id.textView4);
|
||||||
holder.badage = (QuickContactBadge) convertView.findViewById(R.id.quickContactBadge1);
|
holder.badage = (QuickContactBadge) convertView.findViewById(R.id.quickContactBadge1);
|
||||||
|
|
||||||
convertView.setTag(holder);
|
convertView.setTag(holder);
|
||||||
@@ -131,6 +128,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
holder.title.setText(new String((byte[]) getItem(position).get("topic_title")));
|
holder.title.setText(new String((byte[]) getItem(position).get("topic_title")));
|
||||||
holder.user.setText(new String((byte[]) getItem(position).get("topic_author_name")));
|
holder.user.setText(new String((byte[]) getItem(position).get("topic_author_name")));
|
||||||
holder.lastestPost.setText(new String((byte[]) getItem(position).get("short_content")));
|
holder.lastestPost.setText(new String((byte[]) getItem(position).get("short_content")));
|
||||||
|
holder.newPosts.setVisibility(((Boolean) getItem(position).get("new_post") ? View.VISIBLE : View.GONE));
|
||||||
|
|
||||||
for(Object key: getItem(position).keySet())
|
for(Object key: getItem(position).keySet())
|
||||||
Log.d(TAG, key.toString());
|
Log.d(TAG, key.toString());
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/**
|
||||||
|
* TopicContent.java
|
||||||
|
* @date Sep 13, 2012
|
||||||
|
* @author ricky barrette
|
||||||
|
*
|
||||||
|
* Copyright 2012 Richard Barrette
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License
|
||||||
|
*/
|
||||||
|
package com.RickBarrette.osj.forum.content;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.xmlrpc.android.XMLRPCClient;
|
||||||
|
import org.xmlrpc.android.XMLRPCException;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.RickBarrette.osj.forum.Constraints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used to maintain a topic's content data
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public class TopicContent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Forum Object
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static class TopicItem {
|
||||||
|
private static final String TAG = "TopicItem";
|
||||||
|
public String id;
|
||||||
|
public HashMap<?, ?> content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Topic Item
|
||||||
|
* @param id
|
||||||
|
* @param content
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public TopicItem(final String id, final HashMap<?, ?> content) {
|
||||||
|
this.id = id;
|
||||||
|
this.content = content;
|
||||||
|
|
||||||
|
for(Object key: content.keySet())
|
||||||
|
Log.d(TAG, key.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final List<TopicItem> ITEMS = new ArrayList<TopicItem>();
|
||||||
|
public static final Map<String, TopicItem> ITEM_MAP = new HashMap<String, TopicItem>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new Forum Item to the list
|
||||||
|
* @param item
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private static void addItem(final TopicItem item) {
|
||||||
|
ITEMS.add(item);
|
||||||
|
ITEM_MAP.put(item.id, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This gets all the topics for the current forum item
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static void getTopics(String forumId, final Context context){
|
||||||
|
final XMLRPCClient client = Constraints.getClient(context);
|
||||||
|
|
||||||
|
ITEMS.clear();
|
||||||
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
|
Object[] result = null;
|
||||||
|
try {
|
||||||
|
result = (Object[]) ((HashMap<?,?>) client.call("get_topic", forumId, 0, 0)).get("topics");
|
||||||
|
} catch (XMLRPCException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result!= null){
|
||||||
|
for(int i = 0; i < result.length; i++){
|
||||||
|
HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
||||||
|
addItem(new TopicItem(Integer.valueOf(i).toString(), contentHash));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user