Bug 1299224 - Pre: remove unnecessary LoaderManager reference from StreamAdapter r=sebastian

I think originally I wanted to fiddle the Loaders from the Adapter, but we don't do that
so this code is unused/unnecessary. We should also make sure we only ever create one adapter,
which we can do by initalising it in the constructor.

MozReview-Commit-ID: MCNBXll1ZX

--HG--
extra : histedit_source : 379bcb165906ab3d79d1676617b19589e3add652%2C4a2d8c786192614a798820a641c2368cffb307ac
This commit is contained in:
Andrzej Hunt 2016-09-01 14:40:40 -07:00
parent 45e2be7962
commit b635c55c15
4 changed files with 12 additions and 23 deletions

View File

@ -7,7 +7,6 @@
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
@ -17,15 +16,11 @@ import android.widget.FrameLayout;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.home.HomeBanner;
import org.mozilla.gecko.home.HomeFragment;
import org.mozilla.gecko.home.HomeScreen;
import org.mozilla.gecko.home.SimpleCursorLoader;
import org.mozilla.gecko.home.activitystream.topsites.TopSitesPagerAdapter;
public class ActivityStream extends FrameLayout {
private StreamRecyclerAdapter adapter;
private final StreamRecyclerAdapter adapter;
private static final int LOADER_ID_HIGHLIGHTS = 0;
private static final int LOADER_ID_TOPSITES = 1;
@ -34,20 +29,19 @@ public class ActivityStream extends FrameLayout {
super(context, attrs);
inflate(context, R.layout.as_content, this);
}
public void load(LoaderManager lm) {
// Signal to load data from storage as needed, compare with HomePager
adapter = new StreamRecyclerAdapter();
RecyclerView rv = (RecyclerView) findViewById(R.id.activity_stream_main_recyclerview);
// TODO: we need to retrieve BrowserApp and pass it in as onUrlOpenListener. That will
// be simpler once we're a HomeFragment, but isn't so simple while we're still a View.
adapter = new StreamRecyclerAdapter(lm, null);
rv.setAdapter(adapter);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setHasFixedSize(true);
}
public void load(LoaderManager lm) {
CursorLoaderCallbacks callbacks = new CursorLoaderCallbacks();
lm.initLoader(LOADER_ID_HIGHLIGHTS, null, callbacks);
lm.initLoader(LOADER_ID_TOPSITES, null, callbacks);
}
@ -55,7 +49,6 @@ public class ActivityStream extends FrameLayout {
public void unload() {
adapter.swapHighlightsCursor(null);
adapter.swapTopSitesCursor(null);
// Signal to clear data that has been loaded, compare with HomePager
}
/**

View File

@ -22,11 +22,9 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamItem> {
private Cursor highlightsCursor;
private Cursor topSitesCursor;
private final WeakReference<LoaderManager> loaderManagerWeakReference;
private final HomePager.OnUrlOpenListener onUrlOpenListener;
StreamRecyclerAdapter(LoaderManager lm, HomePager.OnUrlOpenListener onUrlOpenListener) {
loaderManagerWeakReference = new WeakReference<>(lm);
StreamRecyclerAdapter(HomePager.OnUrlOpenListener onUrlOpenListener) {
this.onUrlOpenListener = onUrlOpenListener;
}

View File

@ -3,10 +3,4 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FAFAFA">
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_stream_main_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</org.mozilla.gecko.home.activitystream.ActivityStreamHomeScreen>
android:background="#FAFAFA"/>

View File

@ -2,4 +2,8 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/white">
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_stream_main_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</merge>