Skip to content

Update FirebaseListAdapter to use Context instead of Activity #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.firebase.ui.database;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
Expand All @@ -27,21 +29,21 @@
public abstract class FirebaseListAdapter<T> extends BaseAdapter implements FirebaseAdapter<T> {
private static final String TAG = "FirebaseListAdapter";

protected final Activity mActivity;
protected final Context mContext;
protected final ObservableSnapshotArray<T> mSnapshots;
protected final int mLayout;

/**
* @param activity The {@link Activity} containing the {@link ListView}
* @param modelLayout This is the layout used to represent a single list item. You will be
* responsible for populating an instance of the corresponding view with the
* data from an instance of modelClass.
* @param context The {@link Activity} containing the {@link ListView}
* @param snapshots The data used to populate the adapter
* @param modelLayout This is the layout used to represent a single list item. You will be
* responsible for populating an instance of the corresponding view with the
* data from an instance of modelClass.
*/
public FirebaseListAdapter(Activity activity,
public FirebaseListAdapter(Context context,
ObservableSnapshotArray<T> snapshots,
@LayoutRes int modelLayout) {
mActivity = activity;
mContext = context;
mSnapshots = snapshots;
mLayout = modelLayout;

Expand All @@ -54,23 +56,23 @@ public FirebaseListAdapter(Activity activity,
* @param query The Firebase location to watch for data changes. Can also be a slice of a
* location, using some combination of {@code limit()}, {@code startAt()}, and
* {@code endAt()}. <b>Note, this can also be a {@link DatabaseReference}.</b>
* @see #FirebaseListAdapter(Activity, ObservableSnapshotArray, int)
* @see #FirebaseListAdapter(Context, ObservableSnapshotArray, int)
*/
public FirebaseListAdapter(Activity activity,
public FirebaseListAdapter(Context context,
SnapshotParser<T> parser,
@LayoutRes int modelLayout,
Query query) {
this(activity, new FirebaseArray<>(query, parser), modelLayout);
this(context, new FirebaseArray<>(query, parser), modelLayout);
}

/**
* @see #FirebaseListAdapter(Activity, SnapshotParser, int, Query)
* @see #FirebaseListAdapter(Context, SnapshotParser, int, Query)
*/
public FirebaseListAdapter(Activity activity,
public FirebaseListAdapter(Context context,
Class<T> modelClass,
@LayoutRes int modelLayout,
Query query) {
this(activity, new ClassSnapshotParser<>(modelClass), modelLayout, query);
this(context, new ClassSnapshotParser<>(modelClass), modelLayout, query);
}

@Override
Expand Down Expand Up @@ -126,7 +128,7 @@ public long getItemId(int i) {
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
if (view == null) {
view = mActivity.getLayoutInflater().inflate(mLayout, viewGroup, false);
view = LayoutInflater.from(mContext).inflate(mLayout, viewGroup, false);
}

T model = getItem(position);
Expand Down