From 5d827e44ae0e925a002fe59151710f9f3bcfb5cb Mon Sep 17 00:00:00 2001 From: Madhur Gupta <30932899+madhurgupta10@users.noreply.github.com> Date: Fri, 10 May 2019 17:39:32 +0530 Subject: [PATCH] Moved hardcoded URLs to a constant file Fixed #2850 (#2851) * Moved hardcoded URLs to build.grade Fixed #2850 * Moved Urls to a constant file * Fixed Typo --- .../fr/free/nrw/commons/AboutActivity.java | 33 +++++++++++-------- .../main/java/fr/free/nrw/commons/Urls.java | 14 ++++++++ app/src/main/res/layout/activity_about.xml | 3 +- app/src/main/res/values/strings.xml | 4 ++- 4 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/fr/free/nrw/commons/Urls.java diff --git a/app/src/main/java/fr/free/nrw/commons/AboutActivity.java b/app/src/main/java/fr/free/nrw/commons/AboutActivity.java index 6699bf2b3..91c634a2d 100644 --- a/app/src/main/java/fr/free/nrw/commons/AboutActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/AboutActivity.java @@ -32,6 +32,7 @@ public class AboutActivity extends NavigationBaseActivity { @BindView(R.id.about_version) TextView versionText; @BindView(R.id.about_license) HtmlTextView aboutLicenseText; @BindView(R.id.about_faq) TextView faqText; + @BindView(R.id.about_improve) HtmlTextView improve; /** * This method helps in the creation About screen @@ -45,18 +46,25 @@ public class AboutActivity extends NavigationBaseActivity { setContentView(R.layout.activity_about); ButterKnife.bind(this); + String aboutText = getString(R.string.about_license); aboutLicenseText.setHtmlText(aboutText); + + @SuppressLint("StringFormatMatches") + String improveText = String.format(getString(R.string.about_improve), Urls.NEW_ISSUE_URL); + improve.setHtmlText(improveText); + SpannableString content = new SpannableString(getString(R.string.about_faq)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); faqText.setText(content); + versionText.setText(ConfigUtils.getVersionNameWithSha(getApplicationContext())); + TextView rate_us = findViewById(R.id.about_rate_us); TextView privacy_policy = findViewById(R.id.about_privacy_policy); TextView translate = findViewById(R.id.about_translate); TextView credits = findViewById(R.id.about_credits); TextView faq = findViewById(R.id.about_faq); - rate_us.setText(StringUtil.fromHtml(getString(R.string.about_rate_us))); privacy_policy.setText(StringUtil.fromHtml(getString(R.string.about_privacy_policy))); translate.setText(StringUtil.fromHtml(getString(R.string.about_translate))); @@ -70,22 +78,22 @@ public class AboutActivity extends NavigationBaseActivity { public void launchFacebook(View view) { Intent intent; try { - intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + "1921335171459985")); - intent.setPackage("com.facebook.katana"); + intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Urls.FACEBOOK_APP_URL)); + intent.setPackage(Urls.FACEBOOK_PACKAGE_NAME); startActivity(intent); } catch (Exception e) { - Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985")); + Utils.handleWebUrl(this, Uri.parse(Urls.FACEBOOK_WEB_URL)); } } @OnClick(R.id.github_launch_icon) public void launchGithub(View view) { - Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons\\")); + Utils.handleWebUrl(this, Uri.parse(Urls.GITHUB_REPO_URL)); } @OnClick(R.id.website_launch_icon) public void launchWebsite(View view) { - Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\")); + Utils.handleWebUrl(this, Uri.parse(Urls.WEBSITE_URL)); } @OnClick(R.id.about_rate_us) @@ -95,18 +103,18 @@ public class AboutActivity extends NavigationBaseActivity { @OnClick(R.id.about_credits) public void launchCredits(View view) { - Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\")); + Utils.handleWebUrl(this, Uri.parse(Urls.CREDITS_URL)); } @OnClick(R.id.about_privacy_policy) public void launchPrivacyPolicy(View view) { - Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\")); + Utils.handleWebUrl(this, Uri.parse(BuildConfig.PRIVACY_POLICY_URL)); } @OnClick(R.id.about_faq) public void launchFrequentlyAskedQuesions(View view) { - Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Frequently-Asked-Questions\\")); + Utils.handleWebUrl(this, Uri.parse(Urls.FAQ_URL)); } @Override @@ -120,12 +128,12 @@ public class AboutActivity extends NavigationBaseActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.share_app_icon: - String shareText = "Upload photos to Wikimedia Commons on your phone\nDownload the Commons app: http://play.google.com/store/apps/details?id=fr.free.nrw.commons"; + String shareText = String.format(getString(R.string.share_text), Urls.PLAY_STORE_URL); Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, shareText); sendIntent.setType("text/plain"); - startActivity(Intent.createChooser(sendIntent, "Share app via...")); + startActivity(Intent.createChooser(sendIntent, getString(R.string.share_via))); return true; default: return super.onOptionsItemSelected(item); @@ -148,8 +156,7 @@ public class AboutActivity extends NavigationBaseActivity { .setMessage(R.string.about_translate_message) .setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> { String langCode = CommonsApplication.getInstance().getLanguageLookUpTable().getCodes().get(spinner.getSelectedItemPosition()); - Utils.handleWebUrl(AboutActivity.this,Uri.parse("https://translatewiki.net/w/i.php?title=Special:Translate&language=" - + langCode + "&group=commons-android-strings&filter=%21translated&action=translate ?")); + Utils.handleWebUrl(AboutActivity.this, Uri.parse(Urls.TRANSLATE_WIKI_URL + langCode)); }); builder.setNegativeButton(R.string.about_translate_cancel, (dialog, which) -> finish()); builder.create().show(); diff --git a/app/src/main/java/fr/free/nrw/commons/Urls.java b/app/src/main/java/fr/free/nrw/commons/Urls.java new file mode 100644 index 000000000..ec398777b --- /dev/null +++ b/app/src/main/java/fr/free/nrw/commons/Urls.java @@ -0,0 +1,14 @@ +package fr.free.nrw.commons; + +class Urls { + static final String NEW_ISSUE_URL = "https://github.com/commons-app/apps-android-commons/issues"; + static final String GITHUB_REPO_URL = "https://github.com/commons-app/apps-android-commons"; + static final String WEBSITE_URL = "https://commons-app.github.io"; + static final String CREDITS_URL = "https://github.com/commons-app/apps-android-commons/blob/master/CREDITS"; + static final String FAQ_URL = "https://github.com/commons-app/apps-android-commons/wiki/Frequently-Asked-Questions"; + static final String PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=fr.free.nrw.commons"; + static final String TRANSLATE_WIKI_URL = "https://translatewiki.net/w/i.php?title=Special:Translate&group=commons-android-strings&filter=%21translated&action=translate&language="; + static final String FACEBOOK_WEB_URL = "https://www.facebook.com/1921335171459985"; + static final String FACEBOOK_APP_URL = "fb://page/1921335171459985"; + static final String FACEBOOK_PACKAGE_NAME = "com.facebook.katana"; +} diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index f990ace7c..389aec575 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -69,8 +69,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/small_gap" - android:gravity="center" - android:text="@string/about_improve" /> + android:gravity="center" /> About The Wikimedia Commons app is an open-source app created and maintained by grantees and volunteers of the Wikimedia community. The Wikimedia Foundation is not involved in the creation, development, or maintenance of the app. Wikimedia Commons - Create a new <a href=\"https://github.com/commons-app/apps-android-commons/issues\">GitHub issue</a> for bug reports and suggestions. + Create a new <a href=\"%1$s\">GitHub issue</a> for bug reports and suggestions. Privacy policy]]> Credits]]> About @@ -537,5 +537,7 @@ Upload your first media by tapping on the add button. Examples of images not to upload SKIP THIS IMAGE Download Failed!!. We cannot download the file without external storage permission. + Upload photos to Wikimedia Commons on your phone Download the Commons app: %1$s + Share app via... Image Info