1
1
package fr .free .nrw .commons ;
2
2
3
+ import android .app .AlertDialog ;
3
4
import android .content .Context ;
4
5
import android .content .Intent ;
5
6
import android .os .Bundle ;
6
7
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 ;
15
10
import fr .free .nrw .commons .quiz .QuizActivity ;
16
11
import fr .free .nrw .commons .theme .BaseActivity ;
17
12
import fr .free .nrw .commons .utils .ConfigUtils ;
18
- import android .app .AlertDialog ;
19
- import android .widget .Button ;
20
13
21
14
public class WelcomeActivity extends BaseActivity {
22
15
23
- @ BindView (R .id .welcomePager )
24
- ViewPager pager ;
25
- @ BindView (R .id .welcomePagerIndicator )
26
- CirclePageIndicator indicator ;
16
+ private ActivityWelcomeBinding binding ;
17
+ private PopupForCopyrightBinding copyrightBinding ;
27
18
28
- private WelcomePagerAdapter adapter = new WelcomePagerAdapter ();
19
+ private final WelcomePagerAdapter adapter = new WelcomePagerAdapter ();
29
20
private boolean isQuiz ;
30
21
private AlertDialog .Builder dialogBuilder ;
31
22
private AlertDialog dialog ;
32
- Button okButton ;
33
23
34
24
/**
35
25
* Initialises exiting fields and dependencies
36
26
*
37
27
* @param savedInstanceState WelcomeActivity bundled data
38
28
*/
39
29
@ Override
40
- public void onCreate (Bundle savedInstanceState ) {
30
+ public void onCreate (final Bundle savedInstanceState ) {
41
31
super .onCreate (savedInstanceState );
42
- setContentView (R .layout .activity_welcome );
32
+ binding = ActivityWelcomeBinding .inflate (getLayoutInflater ());
33
+ final View view = binding .getRoot ();
34
+ setContentView (view );
43
35
44
36
if (getIntent () != null ) {
45
- Bundle bundle = getIntent ().getExtras ();
37
+ final Bundle bundle = getIntent ().getExtras ();
46
38
if (bundle != null ) {
47
39
isQuiz = bundle .getBoolean ("isQuiz" );
48
40
}
@@ -52,22 +44,23 @@ public void onCreate(Bundle savedInstanceState) {
52
44
53
45
// Enable skip button if beta flavor
54
46
if (ConfigUtils .isBetaFlavour ()) {
55
- findViewById ( R . id . finishTutorialButton ) .setVisibility (View .VISIBLE );
47
+ binding . finishTutorialButton .setVisibility (View .VISIBLE );
56
48
57
49
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 ();
59
52
dialogBuilder .setView (contactPopupView );
60
53
dialog = dialogBuilder .create ();
61
54
dialog .show ();
62
55
63
- okButton = dialog .findViewById (R .id .button_ok );
64
- okButton .setOnClickListener (view -> dialog .dismiss ());
56
+ copyrightBinding .buttonOk .setOnClickListener (v -> dialog .dismiss ());
65
57
}
66
58
67
- ButterKnife .bind (this );
59
+ binding .welcomePager .setAdapter (adapter );
60
+ binding .welcomePagerIndicator .setViewPager (binding .welcomePager );
61
+
62
+ binding .finishTutorialButton .setOnClickListener (v -> finishTutorial ());
68
63
69
- pager .setAdapter (adapter );
70
- indicator .setViewPager (pager );
71
64
}
72
65
73
66
/**
@@ -76,7 +69,7 @@ public void onCreate(Bundle savedInstanceState) {
76
69
@ Override
77
70
public void onDestroy () {
78
71
if (isQuiz ) {
79
- Intent i = new Intent (WelcomeActivity . this , QuizActivity .class );
72
+ final Intent i = new Intent (this , QuizActivity .class );
80
73
startActivity (i );
81
74
}
82
75
super .onDestroy ();
@@ -87,8 +80,8 @@ public void onDestroy() {
87
80
*
88
81
* @param context Activity context
89
82
*/
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 );
92
85
context .startActivity (welcomeIntent );
93
86
}
94
87
@@ -97,8 +90,8 @@ public static void startYourself(Context context) {
97
90
*/
98
91
@ Override
99
92
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 );
102
95
} else {
103
96
if (defaultKvStore .getBoolean ("firstrun" , true )) {
104
97
finishAffinity ();
@@ -108,7 +101,6 @@ public void onBackPressed() {
108
101
}
109
102
}
110
103
111
- @ OnClick (R .id .finishTutorialButton )
112
104
public void finishTutorial () {
113
105
defaultKvStore .putBoolean ("firstrun" , false );
114
106
finish ();
0 commit comments