Implemented Android-PullToRefresh
Project home: https://github.com/chrisbanes/Android-PullToRefresh Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
1
Android-PullToRefresh
Submodule
1
Android-PullToRefresh
Submodule
Submodule Android-PullToRefresh added at a38ed2fc7f
@@ -1,5 +1,5 @@
|
|||||||
<manifest package="org.RickBarrette.osj.forum"
|
<manifest package="org.RickBarrette.osj.forum"
|
||||||
android:versionCode="364"
|
android:versionCode="1230"
|
||||||
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
|
||||||
|
|||||||
@@ -37,7 +37,8 @@
|
|||||||
<strong>OJS Forum</strong> uses the following open source libraries licensed under the <a href="#apachelicense">Apache Software License 2.0</a>.
|
<strong>OJS Forum</strong> uses the following open source libraries licensed under the <a href="#apachelicense">Apache Software License 2.0</a>.
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li> <a href="http://code.google.com/p/android-xmlrpc/">android-xmlrpc</a> - Very thin xmlrpc client library for Android platform
|
<li> <a href="http://code.google.com/p/android-xmlrpc/">android-xmlrpc</a> - Very thin xmlrpc client library for Android platform</li>
|
||||||
|
<li> <a href="https://github.com/chrisbanes/Android-PullToRefresh"/>Android-PullToRefresh</a> - A project to provide a reusable Pull to Refresh widget for Android.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
|
|||||||
@@ -13,3 +13,4 @@
|
|||||||
# Project target.
|
# Project target.
|
||||||
target=android-16
|
target=android-16
|
||||||
android.library.reference.1=../../exception_handler_library/ExceptionHandlerLib
|
android.library.reference.1=../../exception_handler_library/ExceptionHandlerLib
|
||||||
|
android.library.reference.2=../../Android-PullToRefresh/library
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.handmark.pulltorefresh.extras.listfragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.ListFragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
|
||||||
|
import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sample implementation of how to the PullToRefreshListView with
|
||||||
|
* ListFragment. This implementation simply replaces the ListView that
|
||||||
|
* ListFragment creates with a new PullToRefreshListView. This means that
|
||||||
|
* ListFragment still works 100% (e.g. <code>setListShown(...)</code>).
|
||||||
|
*
|
||||||
|
* The new PullToRefreshListView is created in the method
|
||||||
|
* <code>onCreatePullToRefreshListView()</code>. If you wish to customise the
|
||||||
|
* PullToRefreshListView then override this method and return your customised
|
||||||
|
* instance.
|
||||||
|
*
|
||||||
|
* @author Chris Banes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class PullToRefreshListFragment extends ListFragment implements OnRefreshListener<ListView> {
|
||||||
|
|
||||||
|
private PullToRefreshListView mPullToRefreshListView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link PullToRefreshListView} attached to this ListFragment.
|
||||||
|
*/
|
||||||
|
public final PullToRefreshListView getPullToRefreshListView() {
|
||||||
|
return mPullToRefreshListView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
getPullToRefreshListView().setOnRefreshListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link PullToRefreshListView} which will replace the ListView
|
||||||
|
* created from ListFragment. You should override this method if you wish to
|
||||||
|
* customise the {@link PullToRefreshListView} from the default.
|
||||||
|
*
|
||||||
|
* @param inflater
|
||||||
|
* - LayoutInflater which can be used to inflate from XML.
|
||||||
|
* @param savedInstanceState
|
||||||
|
* - Bundle passed through from
|
||||||
|
* {@link ListFragment#onCreateView(LayoutInflater, ViewGroup, Bundle)
|
||||||
|
* onCreateView(...)}
|
||||||
|
* @return The {@link PullToRefreshListView} which will replace the
|
||||||
|
* ListView.
|
||||||
|
*/
|
||||||
|
protected PullToRefreshListView onCreatePullToRefreshListView(final LayoutInflater inflater, final Bundle savedInstanceState) {
|
||||||
|
return new PullToRefreshListView(getActivity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||||
|
final View layout = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
|
||||||
|
final ListView lv = (ListView) layout.findViewById(android.R.id.list);
|
||||||
|
final ViewGroup parent = (ViewGroup) lv.getParent();
|
||||||
|
|
||||||
|
// Iterate through parent's children until we find the ListView, we need
|
||||||
|
// to do it this way as we need to find out the child index
|
||||||
|
for (int i = 0, z = parent.getChildCount(); i < z; i++) {
|
||||||
|
final View child = parent.getChildAt(i);
|
||||||
|
|
||||||
|
if (child == lv) {
|
||||||
|
// Remove the ListView first
|
||||||
|
parent.removeViewAt(i);
|
||||||
|
|
||||||
|
// Now create ListView, and add it in it's place...
|
||||||
|
mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState);
|
||||||
|
parent.addView(mPullToRefreshListView, i, lv.getLayoutParams());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -30,22 +30,25 @@ import org.xmlrpc.android.XMLRPCClient;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ListFragment;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment;
|
||||||
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This fragment will be used to display information about the forum
|
* This fragment will be used to display information about the forum
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumDetailFragment extends ListFragment implements DatabaseListener {
|
public class ForumDetailFragment extends PullToRefreshListFragment implements DatabaseListener {
|
||||||
|
|
||||||
public static final String ARG_ITEM_ID = "item_id";
|
public static final String ARG_ITEM_ID = "item_id";
|
||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
|
private static final String TAG = "ForumDetailFragment";
|
||||||
|
|
||||||
ForumItem mItem;
|
ForumItem mItem;
|
||||||
private OnItemSelectedListener mCallbacks;
|
private OnItemSelectedListener mCallbacks;
|
||||||
@@ -59,18 +62,15 @@ public class ForumDetailFragment extends ListFragment implements DatabaseListene
|
|||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
mDb = new ForumDatabase(getActivity(), this);
|
mDb = new ForumDatabase(getActivity(), this);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
refreshList();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mDb.saveTopics(XMLRPCClient.getClient(getActivity()), mItem.content.get("forum_id"), false);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
if (TopicContent.ITEMS.size() == 0) {
|
if (TopicContent.ITEMS.size() == 0)
|
||||||
TopicContent.getTopics((String) mItem.content.get("forum_id"), mDb);
|
new Thread(new Runnable() {
|
||||||
if (TopicContent.ITEMS.size() != 0)
|
@Override
|
||||||
setListAdapter(new TopicAdapter(getActivity()));
|
public void run() {
|
||||||
}
|
mDb.saveTopics(XMLRPCClient.getClient(getActivity()), mItem.content.get("forum_id"), false);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,7 +125,18 @@ public class ForumDetailFragment extends ListFragment implements DatabaseListene
|
|||||||
@Override
|
@Override
|
||||||
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
|
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position).id);
|
Log.v(TAG, "onListItemClick");
|
||||||
|
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position - 1).id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefresh(final PullToRefreshBase<ListView> refreshView) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mDb.saveTopics(XMLRPCClient.getClient(getActivity()), mItem.content.get("forum_id"), false);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,6 +174,7 @@ public class ForumDetailFragment extends ListFragment implements DatabaseListene
|
|||||||
public void run() {
|
public void run() {
|
||||||
TopicContent.getTopics((String) mItem.content.get("forum_id"), mDb);
|
TopicContent.getTopics((String) mItem.content.get("forum_id"), mDb);
|
||||||
setListAdapter(new TopicAdapter(getActivity()));
|
setListAdapter(new TopicAdapter(getActivity()));
|
||||||
|
getPullToRefreshListView().onRefreshComplete();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,21 +28,24 @@ import org.RickBarrette.osj.forum.database.ForumDatabase;
|
|||||||
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.Fragment;
|
||||||
import android.support.v4.app.ListFragment;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment;
|
||||||
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This fragment will be used to display a list of forums to the user
|
* This fragment will be used to display a list of forums to the user
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumListFragment extends ListFragment implements DatabaseListener {
|
public class ForumListFragment extends PullToRefreshListFragment implements DatabaseListener {
|
||||||
|
|
||||||
private ForumDatabase mDb;
|
private ForumDatabase mDb;
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
|
private static final String TAG = "ForumListFragment";
|
||||||
private OnItemSelectedListener mCallbacks = sForumCallbacks;
|
private OnItemSelectedListener mCallbacks = sForumCallbacks;
|
||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||||
|
|
||||||
@@ -61,18 +64,15 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
mDb = new ForumDatabase(getActivity(), this);
|
mDb = new ForumDatabase(getActivity(), this);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
refreshList();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mDb.saveForums(false);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
if (ForumContent.ITEMS.size() == 0) {
|
if (ForumContent.ITEMS.size() == 0)
|
||||||
ForumContent.getForum(mDb);
|
new Thread(new Runnable() {
|
||||||
if (ForumContent.ITEMS.size() != 0)
|
@Override
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
public void run() {
|
||||||
}
|
mDb.saveForums(false);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -116,7 +116,18 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
@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(this, ForumContent.ITEMS.get(position).id);
|
Log.v(TAG, "onListItemClick");
|
||||||
|
mCallbacks.onItemSelected(this, ForumContent.ITEMS.get(position - 1).id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefresh(final PullToRefreshBase<ListView> refreshView) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mDb.saveForums(false);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -154,6 +165,7 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
public void run() {
|
public void run() {
|
||||||
ForumContent.getForum(mDb);
|
ForumContent.getForum(mDb);
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
|
getPullToRefreshListView().onRefreshComplete();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -170,4 +182,4 @@ public class ForumListFragment extends ListFragment implements DatabaseListener
|
|||||||
public void setActivateOnItemClick(final boolean activateOnItemClick) {
|
public void setActivateOnItemClick(final boolean activateOnItemClick) {
|
||||||
getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
|
getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,17 +30,20 @@ import org.xmlrpc.android.XMLRPCClient;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ListFragment;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
public class TopicDetailFragment extends ListFragment implements DatabaseListener {
|
import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment;
|
||||||
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
||||||
|
|
||||||
|
public class TopicDetailFragment extends PullToRefreshListFragment implements DatabaseListener {
|
||||||
|
|
||||||
public static final String ARG_ITEM_ID = "item_id";
|
public static final String ARG_ITEM_ID = "item_id";
|
||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
|
private static final String TAG = "TopicDetailFragment";
|
||||||
|
|
||||||
TopicItem mItem;
|
TopicItem mItem;
|
||||||
private OnItemSelectedListener mCallbacks;
|
private OnItemSelectedListener mCallbacks;
|
||||||
@@ -54,18 +57,15 @@ public class TopicDetailFragment extends ListFragment implements DatabaseListene
|
|||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
mDb = new ForumDatabase(getActivity(), this);
|
mDb = new ForumDatabase(getActivity(), this);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
refreshList();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mDb.saveThreads(XMLRPCClient.getClient(getActivity()), mItem.content.get("forum_id"), mItem.content.get("topic_id"));
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
if (ThreadContent.ITEMS.size() == 0) {
|
if (ThreadContent.ITEMS.size() == 0)
|
||||||
ThreadContent.getThread((String) mItem.content.get("topic_id"), mDb);
|
new Thread(new Runnable() {
|
||||||
if (ThreadContent.ITEMS.size() != 0)
|
@Override
|
||||||
setListAdapter(new ThreadAdapter(getActivity()));
|
public void run() {
|
||||||
}
|
mDb.saveThreads(XMLRPCClient.getClient(getActivity()), mItem.content.get("forum_id"), mItem.content.get("topic_id"));
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,7 +123,18 @@ public class TopicDetailFragment extends ListFragment implements DatabaseListene
|
|||||||
@Override
|
@Override
|
||||||
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
|
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position).id);
|
Log.v(TAG, "onListItemClick");
|
||||||
|
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position - 1).id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefresh(final PullToRefreshBase<ListView> refreshView) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mDb.saveThreads(XMLRPCClient.getClient(getActivity()), mItem.content.get("forum_id"), mItem.content.get("topic_id"));
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -161,6 +172,7 @@ public class TopicDetailFragment extends ListFragment implements DatabaseListene
|
|||||||
public void run() {
|
public void run() {
|
||||||
ThreadContent.getThread((String) mItem.content.get("topic_id"), mDb);
|
ThreadContent.getThread((String) mItem.content.get("topic_id"), mDb);
|
||||||
setListAdapter(new ThreadAdapter(getActivity()));
|
setListAdapter(new ThreadAdapter(getActivity()));
|
||||||
|
getPullToRefreshListView().onRefreshComplete();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user