12
12
import android .widget .ArrayAdapter ;
13
13
import android .widget .LinearLayout ;
14
14
import android .widget .Spinner ;
15
- import android .widget .TextView ;
16
-
17
15
import androidx .annotation .NonNull ;
18
- import androidx . appcompat . widget . Toolbar ;
16
+ import fr . free . nrw . commons . databinding . ActivityAboutBinding ;
19
17
import fr .free .nrw .commons .theme .BaseActivity ;
18
+ import fr .free .nrw .commons .utils .ConfigUtils ;
20
19
import java .util .Collections ;
21
20
import java .util .List ;
22
21
23
- import butterknife .BindView ;
24
- import butterknife .ButterKnife ;
25
- import butterknife .OnClick ;
26
- import fr .free .nrw .commons .ui .widget .HtmlTextView ;
27
- import fr .free .nrw .commons .utils .ConfigUtils ;
28
-
29
22
/**
30
23
* Represents about screen of this app
31
24
*/
32
25
public class AboutActivity extends BaseActivity {
33
- @ BindView (R .id .about_version ) TextView versionText ;
34
- @ BindView (R .id .about_license ) HtmlTextView aboutLicenseText ;
35
- @ BindView (R .id .about_faq ) TextView faqText ;
36
- @ BindView (R .id .about_improve ) HtmlTextView improve ;
37
- @ BindView (R .id .about_rate_us ) TextView rateUsText ;
38
- @ BindView (R .id .about_privacy_policy ) TextView privacyPolicyText ;
39
- @ BindView (R .id .about_translate ) TextView translateText ;
40
- @ BindView (R .id .about_credits ) TextView creditsText ;
41
- @ BindView (R .id .toolbar ) Toolbar toolbar ;
26
+
27
+ /*
28
+ This View Binding class is auto-generated for each xml file. The format is usually the name
29
+ of the file with PascalCasing (The underscore characters will be ignored).
30
+ More information is available at https://developer.android.com/topic/libraries/view-binding
31
+ */
32
+ private ActivityAboutBinding binding ;
33
+
42
34
/**
43
35
* This method helps in the creation About screen
44
36
*
@@ -48,25 +40,45 @@ public class AboutActivity extends BaseActivity {
48
40
@ SuppressLint ("StringFormatInvalid" )
49
41
public void onCreate (Bundle savedInstanceState ) {
50
42
super .onCreate (savedInstanceState );
51
- setContentView (R .layout .activity_about );
52
43
53
- ButterKnife .bind (this );
54
- setSupportActionBar (toolbar );
44
+ /*
45
+ Instead of just setting the view with the xml file. We need to use View Binding class.
46
+ */
47
+ binding = ActivityAboutBinding .inflate (getLayoutInflater ());
48
+ final View view = binding .getRoot ();
49
+ setContentView (view );
50
+
51
+ setSupportActionBar (binding .toolbarBinding .toolbar );
55
52
getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
56
- String aboutText = getString (R .string .about_license );
57
- aboutLicenseText .setHtmlText (aboutText );
53
+ final String aboutText = getString (R .string .about_license );
54
+ /*
55
+ We can then access all the views by just using the id names like this.
56
+ camelCasing is used with underscore characters being ignored.
57
+ */
58
+ binding .aboutLicense .setHtmlText (aboutText );
58
59
59
60
@ SuppressLint ("StringFormatMatches" )
60
61
String improveText = String .format (getString (R .string .about_improve ), Urls .NEW_ISSUE_URL );
61
- improve .setHtmlText (improveText );
62
-
63
- versionText .setText (ConfigUtils .getVersionNameWithSha (getApplicationContext ()));
64
-
65
- Utils .setUnderlinedText (faqText , R .string .about_faq , getApplicationContext ());
66
- Utils .setUnderlinedText (rateUsText , R .string .about_rate_us , getApplicationContext ());
67
- Utils .setUnderlinedText (privacyPolicyText , R .string .about_privacy_policy , getApplicationContext ());
68
- Utils .setUnderlinedText (translateText , R .string .about_translate , getApplicationContext ());
69
- Utils .setUnderlinedText (creditsText , R .string .about_credits , getApplicationContext ());
62
+ binding .aboutImprove .setHtmlText (improveText );
63
+ binding .aboutVersion .setText (ConfigUtils .getVersionNameWithSha (getApplicationContext ()));
64
+
65
+ Utils .setUnderlinedText (binding .aboutFaq , R .string .about_faq , getApplicationContext ());
66
+ Utils .setUnderlinedText (binding .aboutRateUs , R .string .about_rate_us , getApplicationContext ());
67
+ Utils .setUnderlinedText (binding .aboutPrivacyPolicy , R .string .about_privacy_policy , getApplicationContext ());
68
+ Utils .setUnderlinedText (binding .aboutTranslate , R .string .about_translate , getApplicationContext ());
69
+ Utils .setUnderlinedText (binding .aboutCredits , R .string .about_credits , getApplicationContext ());
70
+
71
+ /*
72
+ To set listeners, we can create a separate method and use lambda syntax.
73
+ */
74
+ binding .facebookLaunchIcon .setOnClickListener (this ::launchFacebook );
75
+ binding .githubLaunchIcon .setOnClickListener (this ::launchGithub );
76
+ binding .websiteLaunchIcon .setOnClickListener (this ::launchWebsite );
77
+ binding .aboutRateUs .setOnClickListener (this ::launchRatings );
78
+ binding .aboutCredits .setOnClickListener (this ::launchCredits );
79
+ binding .aboutPrivacyPolicy .setOnClickListener (this ::launchPrivacyPolicy );
80
+ binding .aboutFaq .setOnClickListener (this ::launchFrequentlyAskedQuesions );
81
+ binding .aboutTranslate .setOnClickListener (this ::launchTranslate );
70
82
}
71
83
72
84
@ Override
@@ -75,7 +87,6 @@ public boolean onSupportNavigateUp() {
75
87
return true ;
76
88
}
77
89
78
- @ OnClick (R .id .facebook_launch_icon )
79
90
public void launchFacebook (View view ) {
80
91
Intent intent ;
81
92
try {
@@ -87,33 +98,26 @@ public void launchFacebook(View view) {
87
98
}
88
99
}
89
100
90
- @ OnClick (R .id .github_launch_icon )
91
101
public void launchGithub (View view ) {
92
102
Utils .handleWebUrl (this , Uri .parse (Urls .GITHUB_REPO_URL ));
93
103
}
94
104
95
- @ OnClick (R .id .website_launch_icon )
96
105
public void launchWebsite (View view ) {
97
106
Utils .handleWebUrl (this , Uri .parse (Urls .WEBSITE_URL ));
98
107
}
99
108
100
- @ OnClick (R .id .about_rate_us )
101
109
public void launchRatings (View view ){
102
110
Utils .rateApp (this );
103
111
}
104
112
105
- @ OnClick (R .id .about_credits )
106
113
public void launchCredits (View view ) {
107
114
Utils .handleWebUrl (this , Uri .parse (Urls .CREDITS_URL ));
108
115
}
109
116
110
- @ OnClick (R .id .about_privacy_policy )
111
117
public void launchPrivacyPolicy (View view ) {
112
118
Utils .handleWebUrl (this , Uri .parse (BuildConfig .PRIVACY_POLICY_URL ));
113
119
}
114
120
115
-
116
- @ OnClick (R .id .about_faq )
117
121
public void launchFrequentlyAskedQuesions (View view ) {
118
122
Utils .handleWebUrl (this , Uri .parse (Urls .FAQ_URL ));
119
123
}
@@ -141,7 +145,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
141
145
}
142
146
}
143
147
144
- @ OnClick (R .id .about_translate )
145
148
public void launchTranslate (View view ) {
146
149
@ NonNull List <String > sortedLocalizedNamesRef = CommonsApplication .getInstance ().getLanguageLookUpTable ().getCanonicalNames ();
147
150
Collections .sort (sortedLocalizedNamesRef );
0 commit comments