Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Stop list from jumping back to the top on reload

Uses setList() instead of setAdapter() - it's not a method available on
ListAdapter, so we have to ensure we have a ViewHoldingListAdapter.

This is a redo of commit 73689dc - which was broken because it left the
'Content' and 'Referrers' fragments blank. This was because a private
reference to the ListAdapter was being held in the ListLoadingFragment-
a bad idea because list fragments can actually have their ListAdapters
replaced when on coming back on screen, leaving the LLF holding an old
ref. Now, instead of holding our own ref to the ViewHoldingListAdapter,
we call getListAdapter() and cast it, ensuring we have the correct
ListAdapter.




fix the jump fix
  • Loading branch information...
commit 3c1525fc6a1493c032055c4f2ddf4461e32e1d36 1 parent 01eb01a
@rtyley rtyley authored
View
3  app/src/main/java/com/github/mobile/gauges/ui/ContentListFragment.java
@@ -34,6 +34,7 @@
import com.github.mobile.gauges.core.PageContent;
import com.google.inject.Inject;
import com.madgag.android.listviews.ReflectiveHolderFactory;
+import com.madgag.android.listviews.ViewHoldingListAdapter;
import com.madgag.android.listviews.ViewInflator;
import java.io.IOException;
@@ -90,7 +91,7 @@ public void onDestroyView() {
}
@Override
- protected ListAdapter adapterFor(List<PageContent> items) {
+ protected ViewHoldingListAdapter<PageContent> adapterFor(List<PageContent> items) {
return new AlternatingColorListAdapter<PageContent>(getResources(), items, ViewInflator.viewInflatorFor(
getActivity(), layout.content_list_item),
ReflectiveHolderFactory.reflectiveFactoryFor(ContentViewHolder.class));
View
3  app/src/main/java/com/github/mobile/gauges/ui/GaugeListFragment.java
@@ -31,6 +31,7 @@
import com.github.mobile.gauges.R.drawable;
import com.github.mobile.gauges.R.id;
import com.github.mobile.gauges.R.layout;
+import com.github.mobile.gauges.core.DatedViewSummary;
import com.github.mobile.gauges.core.Gauge;
import com.google.inject.Inject;
import com.madgag.android.listviews.ReflectiveHolderFactory;
@@ -81,7 +82,7 @@ public void onListItemClick(ListView list, View view, int position, long id) {
}
@Override
- protected ListAdapter adapterFor(List<Gauge> items) {
+ protected ViewHoldingListAdapter<Gauge> adapterFor(List<Gauge> items) {
return new ViewHoldingListAdapter<Gauge>(items, ViewInflator.viewInflatorFor(getActivity(),
layout.gauge_list_item), ReflectiveHolderFactory.reflectiveFactoryFor(GaugeViewHolder.class,
getActivity().getResources()));
View
25 app/src/main/java/com/github/mobile/gauges/ui/ListLoadingFragment.java
@@ -22,20 +22,19 @@
import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
-import android.widget.ListAdapter;
import android.widget.Toast;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
import com.github.mobile.gauges.R.anim;
import com.github.mobile.gauges.R.id;
import com.github.mobile.gauges.R.layout;
import com.github.mobile.gauges.R.menu;
+import com.madgag.android.listviews.ViewHoldingListAdapter;
import java.util.List;
@@ -101,7 +100,7 @@ public void refresh() {
}
public void onLoadFinished(Loader<List<E>> loader, List<E> items) {
- setListAdapter(adapterFor(items));
+ setList(items);
if (isResumed())
setListShown(true);
@@ -115,12 +114,24 @@ public void onLoadFinished(Loader<List<E>> loader, List<E> items) {
}
/**
+ * Allows you to update the list's items without using setListAdapter(), which makes the list jump back to the top.
+ */
+ private void setList(List<E> items) {
+ ViewHoldingListAdapter<E> listAdapter = (ViewHoldingListAdapter<E>) getListAdapter();
+ if (listAdapter == null) {
+ setListAdapter(adapterFor(items));
+ } else {
+ listAdapter.setList(items);
+ }
+ }
+
+ /**
* Create adapter for list of items
*
* @param items
* @return list adapter
*/
- protected abstract ListAdapter adapterFor(List<E> items);
+ protected abstract ViewHoldingListAdapter<E> adapterFor(List<E> items);
@Override
public void onLoaderReset(Loader<List<E>> listLoader) {
View
8 app/src/main/java/com/github/mobile/gauges/ui/ReferrerListFragment.java
@@ -18,6 +18,8 @@
import static android.content.Intent.ACTION_VIEW;
import static com.github.mobile.gauges.IntentConstants.GAUGE_ID;
+import static com.madgag.android.listviews.ReflectiveHolderFactory.reflectiveFactoryFor;
+import static com.madgag.android.listviews.ViewInflator.viewInflatorFor;
import android.accounts.AccountsException;
import android.content.Intent;
import android.net.Uri;
@@ -89,10 +91,10 @@ public void onDestroyView() {
};
}
- protected ListAdapter adapterFor(List<Referrer> items) {
- return new AlternatingColorListAdapter<Referrer>(getResources(), items, ViewInflator.viewInflatorFor(
+ protected ViewHoldingListAdapter<Referrer> adapterFor(List<Referrer> items) {
+ return new AlternatingColorListAdapter<Referrer>(getResources(), items, viewInflatorFor(
getActivity(), layout.referrer_list_item),
- ReflectiveHolderFactory.reflectiveFactoryFor(ReferrerViewHolder.class));
+ reflectiveFactoryFor(ReferrerViewHolder.class));
}
public void onListItemClick(ListView l, View v, int position, long id) {
View
3  app/src/main/java/com/github/mobile/gauges/ui/TrafficListFragment.java
@@ -39,6 +39,7 @@
import com.github.mobile.gauges.core.Gauge;
import com.google.inject.Inject;
import com.madgag.android.listviews.ReflectiveHolderFactory;
+import com.madgag.android.listviews.ViewHoldingListAdapter;
import com.madgag.android.listviews.ViewInflator;
import java.io.IOException;
@@ -158,7 +159,7 @@ private BarGraphDrawable barGraphDrawableFor(List<DatedViewSummary> graphDays) {
}
@Override
- protected ListAdapter adapterFor(List<DatedViewSummary> items) {
+ protected ViewHoldingListAdapter<DatedViewSummary> adapterFor(List<DatedViewSummary> items) {
return new AlternatingColorListAdapter<DatedViewSummary>(getResources(), items, ViewInflator.viewInflatorFor(
getActivity(), layout.traffic_list_item),
ReflectiveHolderFactory.reflectiveFactoryFor(TrafficViewHolder.class));
Please sign in to comment.
Something went wrong with that request. Please try again.