1212import android .widget .ArrayAdapter ;
1313import android .widget .LinearLayout ;
1414import android .widget .Spinner ;
15- import android .widget .TextView ;
16-
1715import androidx .annotation .NonNull ;
18- import androidx . appcompat . widget . Toolbar ;
16+ import fr . free . nrw . commons . databinding . ActivityAboutBinding ;
1917import fr .free .nrw .commons .theme .BaseActivity ;
18+ import fr .free .nrw .commons .utils .ConfigUtils ;
2019import java .util .Collections ;
2120import java .util .List ;
2221
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-
2922/**
3023 * Represents about screen of this app
3124 */
3225public 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+
4234 /**
4335 * This method helps in the creation About screen
4436 *
@@ -48,25 +40,45 @@ public class AboutActivity extends BaseActivity {
4840 @ SuppressLint ("StringFormatInvalid" )
4941 public void onCreate (Bundle savedInstanceState ) {
5042 super .onCreate (savedInstanceState );
51- setContentView (R .layout .activity_about );
5243
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 );
5552 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 );
5859
5960 @ SuppressLint ("StringFormatMatches" )
6061 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 );
7082 }
7183
7284 @ Override
@@ -75,7 +87,6 @@ public boolean onSupportNavigateUp() {
7587 return true ;
7688 }
7789
78- @ OnClick (R .id .facebook_launch_icon )
7990 public void launchFacebook (View view ) {
8091 Intent intent ;
8192 try {
@@ -87,33 +98,26 @@ public void launchFacebook(View view) {
8798 }
8899 }
89100
90- @ OnClick (R .id .github_launch_icon )
91101 public void launchGithub (View view ) {
92102 Utils .handleWebUrl (this , Uri .parse (Urls .GITHUB_REPO_URL ));
93103 }
94104
95- @ OnClick (R .id .website_launch_icon )
96105 public void launchWebsite (View view ) {
97106 Utils .handleWebUrl (this , Uri .parse (Urls .WEBSITE_URL ));
98107 }
99108
100- @ OnClick (R .id .about_rate_us )
101109 public void launchRatings (View view ){
102110 Utils .rateApp (this );
103111 }
104112
105- @ OnClick (R .id .about_credits )
106113 public void launchCredits (View view ) {
107114 Utils .handleWebUrl (this , Uri .parse (Urls .CREDITS_URL ));
108115 }
109116
110- @ OnClick (R .id .about_privacy_policy )
111117 public void launchPrivacyPolicy (View view ) {
112118 Utils .handleWebUrl (this , Uri .parse (BuildConfig .PRIVACY_POLICY_URL ));
113119 }
114120
115-
116- @ OnClick (R .id .about_faq )
117121 public void launchFrequentlyAskedQuesions (View view ) {
118122 Utils .handleWebUrl (this , Uri .parse (Urls .FAQ_URL ));
119123 }
@@ -141,7 +145,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
141145 }
142146 }
143147
144- @ OnClick (R .id .about_translate )
145148 public void launchTranslate (View view ) {
146149 @ NonNull List <String > sortedLocalizedNamesRef = CommonsApplication .getInstance ().getLanguageLookUpTable ().getCanonicalNames ();
147150 Collections .sort (sortedLocalizedNamesRef );
0 commit comments