Skip to content

Commit 10b025c

Browse files
authored
4664: Moved WelcomeActivity to ViewBinding (#5063)
* 4664: Moved WelcomeActivity to ViewBinding * 4664: Removed non-null test on member variables
1 parent 1a39c9f commit 10b025c

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

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

+24-32
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,40 @@
11
package fr.free.nrw.commons;
22

3+
import android.app.AlertDialog;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.os.Bundle;
67
import android.view.View;
7-
8-
import androidx.viewpager.widget.ViewPager;
9-
10-
import com.viewpagerindicator.CirclePageIndicator;
11-
12-
import butterknife.BindView;
13-
import butterknife.ButterKnife;
14-
import butterknife.OnClick;
8+
import fr.free.nrw.commons.databinding.ActivityWelcomeBinding;
9+
import fr.free.nrw.commons.databinding.PopupForCopyrightBinding;
1510
import fr.free.nrw.commons.quiz.QuizActivity;
1611
import fr.free.nrw.commons.theme.BaseActivity;
1712
import fr.free.nrw.commons.utils.ConfigUtils;
18-
import android.app.AlertDialog;
19-
import android.widget.Button;
2013

2114
public class WelcomeActivity extends BaseActivity {
2215

23-
@BindView(R.id.welcomePager)
24-
ViewPager pager;
25-
@BindView(R.id.welcomePagerIndicator)
26-
CirclePageIndicator indicator;
16+
private ActivityWelcomeBinding binding;
17+
private PopupForCopyrightBinding copyrightBinding;
2718

28-
private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
19+
private final WelcomePagerAdapter adapter = new WelcomePagerAdapter();
2920
private boolean isQuiz;
3021
private AlertDialog.Builder dialogBuilder;
3122
private AlertDialog dialog;
32-
Button okButton;
3323

3424
/**
3525
* Initialises exiting fields and dependencies
3626
*
3727
* @param savedInstanceState WelcomeActivity bundled data
3828
*/
3929
@Override
40-
public void onCreate(Bundle savedInstanceState) {
30+
public void onCreate(final Bundle savedInstanceState) {
4131
super.onCreate(savedInstanceState);
42-
setContentView(R.layout.activity_welcome);
32+
binding = ActivityWelcomeBinding.inflate(getLayoutInflater());
33+
final View view = binding.getRoot();
34+
setContentView(view);
4335

4436
if (getIntent() != null) {
45-
Bundle bundle = getIntent().getExtras();
37+
final Bundle bundle = getIntent().getExtras();
4638
if (bundle != null) {
4739
isQuiz = bundle.getBoolean("isQuiz");
4840
}
@@ -52,22 +44,23 @@ public void onCreate(Bundle savedInstanceState) {
5244

5345
// Enable skip button if beta flavor
5446
if (ConfigUtils.isBetaFlavour()) {
55-
findViewById(R.id.finishTutorialButton).setVisibility(View.VISIBLE);
47+
binding.finishTutorialButton.setVisibility(View.VISIBLE);
5648

5749
dialogBuilder = new AlertDialog.Builder(this);
58-
final View contactPopupView = getLayoutInflater().inflate(R.layout.popup_for_copyright,null);
50+
copyrightBinding = PopupForCopyrightBinding.inflate(getLayoutInflater());
51+
final View contactPopupView = copyrightBinding.getRoot();
5952
dialogBuilder.setView(contactPopupView);
6053
dialog = dialogBuilder.create();
6154
dialog.show();
6255

63-
okButton = dialog.findViewById(R.id.button_ok);
64-
okButton.setOnClickListener(view -> dialog.dismiss());
56+
copyrightBinding.buttonOk.setOnClickListener(v -> dialog.dismiss());
6557
}
6658

67-
ButterKnife.bind(this);
59+
binding.welcomePager.setAdapter(adapter);
60+
binding.welcomePagerIndicator.setViewPager(binding.welcomePager);
61+
62+
binding.finishTutorialButton.setOnClickListener(v -> finishTutorial());
6863

69-
pager.setAdapter(adapter);
70-
indicator.setViewPager(pager);
7164
}
7265

7366
/**
@@ -76,7 +69,7 @@ public void onCreate(Bundle savedInstanceState) {
7669
@Override
7770
public void onDestroy() {
7871
if (isQuiz) {
79-
Intent i = new Intent(WelcomeActivity.this, QuizActivity.class);
72+
final Intent i = new Intent(this, QuizActivity.class);
8073
startActivity(i);
8174
}
8275
super.onDestroy();
@@ -87,8 +80,8 @@ public void onDestroy() {
8780
*
8881
* @param context Activity context
8982
*/
90-
public static void startYourself(Context context) {
91-
Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
83+
public static void startYourself(final Context context) {
84+
final Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
9285
context.startActivity(welcomeIntent);
9386
}
9487

@@ -97,8 +90,8 @@ public static void startYourself(Context context) {
9790
*/
9891
@Override
9992
public void onBackPressed() {
100-
if (pager.getCurrentItem() != 0) {
101-
pager.setCurrentItem(pager.getCurrentItem() - 1, true);
93+
if (binding.welcomePager.getCurrentItem() != 0) {
94+
binding.welcomePager.setCurrentItem(binding.welcomePager.getCurrentItem() - 1, true);
10295
} else {
10396
if (defaultKvStore.getBoolean("firstrun", true)) {
10497
finishAffinity();
@@ -108,7 +101,6 @@ public void onBackPressed() {
108101
}
109102
}
110103

111-
@OnClick(R.id.finishTutorialButton)
112104
public void finishTutorial() {
113105
defaultKvStore.putBoolean("firstrun", false);
114106
finish();

app/src/test/kotlin/fr/free/nrw/commons/WelcomeActivityUnitTest.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ class WelcomeActivityUnitTest {
3939
}
4040

4141
/**
42-
* Checks if the activity is not null and member variables are not null
42+
* Checks if the activity is not null
4343
*/
4444
@Test
4545
@Throws(Exception::class)
4646
fun checkActivityNotNull() {
4747
assertNotNull(activity)
48-
assertNotNull(activity.pager)
49-
assertNotNull(activity.indicator)
5048
}
5149

5250
/**

0 commit comments

Comments
 (0)