Started work on downloading and displaying forums.
As of this commit, I can officially download and display forums to the user Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<manifest package="com.RickBarrette.osj.forum"
|
||||
android:versionCode="2"
|
||||
android:versionCode="23"
|
||||
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
|
||||
|
||||
<uses-sdk
|
||||
@@ -12,7 +12,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name=".TopicListActivity"
|
||||
android:name=".ForumListActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@@ -20,6 +20,17 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ForumDetailActivity"
|
||||
android:label="@string/title_forum_detail" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ForumListActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".TopicListActivity"
|
||||
android:label="@string/app_name" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".TopicDetailActivity"
|
||||
android:label="@string/title_topic_detail" >
|
||||
|
||||
14
OSJ Forum/res/layout/forum_item.xml
Normal file
14
OSJ Forum/res/layout/forum_item.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -3,6 +3,8 @@
|
||||
<string name="app_name">OSJ Forum</string>
|
||||
<string name="title_topic_detail">Topic Detail</string>
|
||||
<string name="title_topic_list">Topics</string>
|
||||
<string name="title_forum_detail">Forum Detail</string>
|
||||
<string name="title_forum_list">Forumss</string>
|
||||
<string name="server">http://rickbarrette.org/forum/mobiquo/mobiquo.php</string>
|
||||
|
||||
</resources>
|
||||
@@ -19,16 +19,16 @@
|
||||
*/
|
||||
package com.RickBarrette.osj.forum;
|
||||
|
||||
import android.R;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.RickBarrette.osj.forum.content.ForumAdapter;
|
||||
import com.RickBarrette.osj.forum.content.ForumContent;
|
||||
import com.RickBarrette.osj.forum.dummy.DummyContent;
|
||||
|
||||
public class ForumListFragment extends ListFragment {
|
||||
@@ -39,11 +39,11 @@ public class ForumListFragment extends ListFragment {
|
||||
}
|
||||
|
||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||
private Callbacks mCallbacks = sDummyCallbacks;
|
||||
private Callbacks mCallbacks = sForumCallbacks;
|
||||
|
||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||
|
||||
private static Callbacks sDummyCallbacks = new Callbacks() {
|
||||
private static Callbacks sForumCallbacks = new Callbacks() {
|
||||
@Override
|
||||
public void onItemSelected(final String id) {
|
||||
}
|
||||
@@ -64,13 +64,26 @@ public class ForumListFragment extends ListFragment {
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(), R.layout.simple_list_item_activated_1, R.id.text1, DummyContent.ITEMS));
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ForumContent.getForum(getActivity());
|
||||
getActivity().runOnUiThread(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
setListAdapter(new ForumAdapter(getActivity()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mCallbacks = sDummyCallbacks;
|
||||
mCallbacks = sForumCallbacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* ForumAdapter.java
|
||||
* @date Aug 30, 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.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.RickBarrette.osj.forum.R;
|
||||
import com.RickBarrette.osj.forum.content.ForumContent.ForumItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class ForumAdapter extends BaseAdapter {
|
||||
|
||||
class ViewHolder {
|
||||
TextView title;
|
||||
TextView description;
|
||||
CheckBox checkbox;
|
||||
}
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public ForumAdapter(final Context context) {
|
||||
mInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.widget.Adapter#getCount()
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
return ForumContent.ITEMS.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.widget.Adapter#getItem(int)
|
||||
*/
|
||||
@Override
|
||||
public ForumItem getItem(int position) {
|
||||
return ForumContent.ITEMS.get(position);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.widget.Adapter#getItemId(int)
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
// A ViewHolder keeps references to children views to avoid unnecessary
|
||||
// calls to findViewById() on each row.
|
||||
ViewHolder holder;
|
||||
|
||||
// When convertView is not null, we can reuse it directly, there is no
|
||||
// need
|
||||
// to reinflate it. We only inflate a new View when the convertView
|
||||
// supplied
|
||||
// by ListView is null.
|
||||
if (convertView == null) {
|
||||
convertView = mInflater.inflate(R.layout.forum_item, null);
|
||||
|
||||
// Creates a ViewHolder and store references to the two children
|
||||
// views
|
||||
// we want to bind data to.
|
||||
holder = new ViewHolder();
|
||||
holder.title = (TextView) convertView.findViewById(R.id.textView1);
|
||||
|
||||
convertView.setTag(holder);
|
||||
} else
|
||||
// Get the ViewHolder back to get fast access to the TextView
|
||||
// and the ImageView.
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
|
||||
|
||||
/*
|
||||
* Bind the data efficiently with the holder. Remember that you should
|
||||
* always call setChecked() after calling setOnCheckedChangedListener.
|
||||
* This will prevent the list from changing the values on you.
|
||||
*/
|
||||
holder.title.setText(new String((byte[]) getItem(position).content.get("forum_name")));
|
||||
return convertView;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* ForumContent.java
|
||||
* @date Aug 30, 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 com.RickBarrette.osj.forum.R;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class ForumContent {
|
||||
|
||||
public static class ForumItem {
|
||||
|
||||
public String id;
|
||||
public HashMap<?, ?> content;
|
||||
|
||||
public ForumItem(final String id, final HashMap<?, ?> content) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (String) content.get("forum_name");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ForumItem> ITEMS = new ArrayList<ForumItem>();
|
||||
public static Map<String, ForumItem> ITEM_MAP = new HashMap<String, ForumItem>();
|
||||
|
||||
private static void addItem(final ForumItem item) {
|
||||
ITEMS.add(item);
|
||||
ITEM_MAP.put(item.id, item);
|
||||
}
|
||||
|
||||
public static void getForum(Context context){
|
||||
final XMLRPCClient client = new XMLRPCClient((context.getString(R.string.server)));
|
||||
|
||||
Object[] result = null;
|
||||
try {
|
||||
result = (Object[]) client.call("get_forum", true);
|
||||
} catch (XMLRPCException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(result!= null){
|
||||
for(int i = 0; i < result.length; i++){
|
||||
HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
||||
addItem(new ForumItem(new Integer(i).toString(), contentHash));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user