Skip to content

Commit de1a314

Browse files
committed
Don't pass Activity into WelcomePagerAdapter.
1 parent dea43c0 commit de1a314

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public void onCreate(Bundle savedInstanceState) {
2828
}
2929

3030
private void setUpAdapter() {
31-
WelcomePagerAdapter adapter = new WelcomePagerAdapter(this);
32-
pager.setAdapter(adapter);
31+
pager.setAdapter(new WelcomePagerAdapter());
3332
indicator.setViewPager(pager);
3433
}
3534
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.free.nrw.commons;
22

33
import android.app.Activity;
4-
import android.content.Context;
54
import android.support.v4.view.PagerAdapter;
65
import android.view.LayoutInflater;
76
import android.view.View;
@@ -11,9 +10,6 @@
1110
import butterknife.OnClick;
1211

1312
public class WelcomePagerAdapter extends PagerAdapter {
14-
15-
private Context context;
16-
1713
private static final int PAGE_FINAL = 4;
1814

1915
static final int[] PAGE_LAYOUTS = new int[]{
@@ -24,10 +20,6 @@ public class WelcomePagerAdapter extends PagerAdapter {
2420
R.layout.welcome_final
2521
};
2622

27-
public WelcomePagerAdapter(Context context) {
28-
this.context = context;
29-
}
30-
3123
@Override
3224
public int getCount() {
3325
return PAGE_LAYOUTS.length;
@@ -40,11 +32,11 @@ public boolean isViewFromObject(View view, Object object) {
4032

4133
@Override
4234
public Object instantiateItem(ViewGroup container, int position) {
43-
LayoutInflater inflater = LayoutInflater.from(context);
35+
LayoutInflater inflater = LayoutInflater.from(container.getContext());
4436
ViewGroup layout = (ViewGroup) inflater.inflate(PAGE_LAYOUTS[position], container, false);
4537

4638
if (position == PAGE_FINAL) {
47-
ViewHolder holder = new ViewHolder(layout, context);
39+
ViewHolder holder = new ViewHolder(layout);
4840
layout.setTag(holder);
4941
}
5042
container.addView(layout);
@@ -57,16 +49,13 @@ public void destroyItem(ViewGroup container, int position, Object obj) {
5749
}
5850

5951
public static class ViewHolder {
60-
private Context context;
61-
62-
public ViewHolder(View view, Context context) {
52+
public ViewHolder(View view) {
6353
ButterKnife.bind(this, view);
64-
this.context = context;
6554
}
6655

6756
@OnClick(R.id.welcomeYesButton)
68-
void onClicked() {
69-
((Activity) context).finish();
57+
void onClicked(View view) {
58+
((Activity) view.getContext()).finish();
7059
}
7160
}
7261
}

0 commit comments

Comments
 (0)