diff --git a/OSJ Forum/AndroidManifest.xml b/OSJ Forum/AndroidManifest.xml index 46a8042..bf58801 100644 --- a/OSJ Forum/AndroidManifest.xml +++ b/OSJ Forum/AndroidManifest.xml @@ -1,5 +1,5 @@ @@ -20,6 +20,17 @@ + + + + + diff --git a/OSJ Forum/res/layout/forum_item.xml b/OSJ Forum/res/layout/forum_item.xml new file mode 100644 index 0000000..6612461 --- /dev/null +++ b/OSJ Forum/res/layout/forum_item.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/OSJ Forum/res/values/strings.xml b/OSJ Forum/res/values/strings.xml index 4bde249..0bd7fde 100644 --- a/OSJ Forum/res/values/strings.xml +++ b/OSJ Forum/res/values/strings.xml @@ -3,6 +3,8 @@ OSJ Forum Topic Detail Topics + Forum Detail + Forumss http://rickbarrette.org/forum/mobiquo/mobiquo.php \ No newline at end of file diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/ForumListFragment.java b/OSJ Forum/src/com/RickBarrette/osj/forum/ForumListFragment.java index 98d5dd7..fdac936 100644 --- a/OSJ Forum/src/com/RickBarrette/osj/forum/ForumListFragment.java +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/ForumListFragment.java @@ -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(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 diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/content/ForumAdapter.java b/OSJ Forum/src/com/RickBarrette/osj/forum/content/ForumAdapter.java new file mode 100644 index 0000000..8c6950a --- /dev/null +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/content/ForumAdapter.java @@ -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; + } + +} diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/content/ForumContent.java b/OSJ Forum/src/com/RickBarrette/osj/forum/content/ForumContent.java new file mode 100644 index 0000000..ad17d5c --- /dev/null +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/content/ForumContent.java @@ -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 ITEMS = new ArrayList(); + public static Map ITEM_MAP = new HashMap(); + + 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)); + } + } + } +} \ No newline at end of file