Skip to content

Commit 6d2c1ae

Browse files
WillieCubedsamtstern
authored andcommitted
Update FirebaseListAdapter to use Context in constructor and layout inflation (#774)
1 parent 7330b45 commit 6d2c1ae

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.firebase.ui.database;
22

33
import android.app.Activity;
4+
import android.content.Context;
45
import android.support.annotation.LayoutRes;
56
import android.util.Log;
7+
import android.view.LayoutInflater;
68
import android.view.View;
79
import android.view.ViewGroup;
810
import android.widget.BaseAdapter;
@@ -27,21 +29,21 @@
2729
public abstract class FirebaseListAdapter<T> extends BaseAdapter implements FirebaseAdapter<T> {
2830
private static final String TAG = "FirebaseListAdapter";
2931

30-
protected final Activity mActivity;
32+
protected final Context mContext;
3133
protected final ObservableSnapshotArray<T> mSnapshots;
3234
protected final int mLayout;
3335

3436
/**
35-
* @param activity The {@link Activity} containing the {@link ListView}
36-
* @param modelLayout This is the layout used to represent a single list item. You will be
37-
* responsible for populating an instance of the corresponding view with the
38-
* data from an instance of modelClass.
37+
* @param context The {@link Activity} containing the {@link ListView}
3938
* @param snapshots The data used to populate the adapter
39+
* @param modelLayout This is the layout used to represent a single list item. You will be
40+
* responsible for populating an instance of the corresponding view with the
41+
* data from an instance of modelClass.
4042
*/
41-
public FirebaseListAdapter(Activity activity,
43+
public FirebaseListAdapter(Context context,
4244
ObservableSnapshotArray<T> snapshots,
4345
@LayoutRes int modelLayout) {
44-
mActivity = activity;
46+
mContext = context;
4547
mSnapshots = snapshots;
4648
mLayout = modelLayout;
4749

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

6668
/**
67-
* @see #FirebaseListAdapter(Activity, SnapshotParser, int, Query)
69+
* @see #FirebaseListAdapter(Context, SnapshotParser, int, Query)
6870
*/
69-
public FirebaseListAdapter(Activity activity,
71+
public FirebaseListAdapter(Context context,
7072
Class<T> modelClass,
7173
@LayoutRes int modelLayout,
7274
Query query) {
73-
this(activity, new ClassSnapshotParser<>(modelClass), modelLayout, query);
75+
this(context, new ClassSnapshotParser<>(modelClass), modelLayout, query);
7476
}
7577

7678
@Override
@@ -126,7 +128,7 @@ public long getItemId(int i) {
126128
@Override
127129
public View getView(int position, View view, ViewGroup viewGroup) {
128130
if (view == null) {
129-
view = mActivity.getLayoutInflater().inflate(mLayout, viewGroup, false);
131+
view = LayoutInflater.from(mContext).inflate(mLayout, viewGroup, false);
130132
}
131133

132134
T model = getItem(position);

0 commit comments

Comments
 (0)