Skip to content

Commit 5d827e4

Browse files
madhurgupta10neslihanturan
authored andcommitted
Moved hardcoded URLs to a constant file Fixed commons-app#2850 (commons-app#2851)
* Moved hardcoded URLs to build.grade Fixed commons-app#2850 * Moved Urls to a constant file * Fixed Typo
1 parent a4ac27d commit 5d827e4

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

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

+20-13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class AboutActivity extends NavigationBaseActivity {
3232
@BindView(R.id.about_version) TextView versionText;
3333
@BindView(R.id.about_license) HtmlTextView aboutLicenseText;
3434
@BindView(R.id.about_faq) TextView faqText;
35+
@BindView(R.id.about_improve) HtmlTextView improve;
3536

3637
/**
3738
* This method helps in the creation About screen
@@ -45,18 +46,25 @@ public void onCreate(Bundle savedInstanceState) {
4546
setContentView(R.layout.activity_about);
4647

4748
ButterKnife.bind(this);
49+
4850
String aboutText = getString(R.string.about_license);
4951
aboutLicenseText.setHtmlText(aboutText);
52+
53+
@SuppressLint("StringFormatMatches")
54+
String improveText = String.format(getString(R.string.about_improve), Urls.NEW_ISSUE_URL);
55+
improve.setHtmlText(improveText);
56+
5057
SpannableString content = new SpannableString(getString(R.string.about_faq));
5158
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
5259
faqText.setText(content);
60+
5361
versionText.setText(ConfigUtils.getVersionNameWithSha(getApplicationContext()));
62+
5463
TextView rate_us = findViewById(R.id.about_rate_us);
5564
TextView privacy_policy = findViewById(R.id.about_privacy_policy);
5665
TextView translate = findViewById(R.id.about_translate);
5766
TextView credits = findViewById(R.id.about_credits);
5867
TextView faq = findViewById(R.id.about_faq);
59-
6068
rate_us.setText(StringUtil.fromHtml(getString(R.string.about_rate_us)));
6169
privacy_policy.setText(StringUtil.fromHtml(getString(R.string.about_privacy_policy)));
6270
translate.setText(StringUtil.fromHtml(getString(R.string.about_translate)));
@@ -70,22 +78,22 @@ public void onCreate(Bundle savedInstanceState) {
7078
public void launchFacebook(View view) {
7179
Intent intent;
7280
try {
73-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + "1921335171459985"));
74-
intent.setPackage("com.facebook.katana");
81+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Urls.FACEBOOK_APP_URL));
82+
intent.setPackage(Urls.FACEBOOK_PACKAGE_NAME);
7583
startActivity(intent);
7684
} catch (Exception e) {
77-
Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985"));
85+
Utils.handleWebUrl(this, Uri.parse(Urls.FACEBOOK_WEB_URL));
7886
}
7987
}
8088

8189
@OnClick(R.id.github_launch_icon)
8290
public void launchGithub(View view) {
83-
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
91+
Utils.handleWebUrl(this, Uri.parse(Urls.GITHUB_REPO_URL));
8492
}
8593

8694
@OnClick(R.id.website_launch_icon)
8795
public void launchWebsite(View view) {
88-
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
96+
Utils.handleWebUrl(this, Uri.parse(Urls.WEBSITE_URL));
8997
}
9098

9199
@OnClick(R.id.about_rate_us)
@@ -95,18 +103,18 @@ public void launchRatings(View view){
95103

96104
@OnClick(R.id.about_credits)
97105
public void launchCredits(View view) {
98-
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
106+
Utils.handleWebUrl(this, Uri.parse(Urls.CREDITS_URL));
99107
}
100108

101109
@OnClick(R.id.about_privacy_policy)
102110
public void launchPrivacyPolicy(View view) {
103-
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
111+
Utils.handleWebUrl(this, Uri.parse(BuildConfig.PRIVACY_POLICY_URL));
104112
}
105113

106114

107115
@OnClick(R.id.about_faq)
108116
public void launchFrequentlyAskedQuesions(View view) {
109-
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Frequently-Asked-Questions\\"));
117+
Utils.handleWebUrl(this, Uri.parse(Urls.FAQ_URL));
110118
}
111119

112120
@Override
@@ -120,12 +128,12 @@ public boolean onCreateOptionsMenu(Menu menu) {
120128
public boolean onOptionsItemSelected(MenuItem item) {
121129
switch (item.getItemId()) {
122130
case R.id.share_app_icon:
123-
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";
131+
String shareText = String.format(getString(R.string.share_text), Urls.PLAY_STORE_URL);
124132
Intent sendIntent = new Intent();
125133
sendIntent.setAction(Intent.ACTION_SEND);
126134
sendIntent.putExtra(Intent.EXTRA_TEXT, shareText);
127135
sendIntent.setType("text/plain");
128-
startActivity(Intent.createChooser(sendIntent, "Share app via..."));
136+
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_via)));
129137
return true;
130138
default:
131139
return super.onOptionsItemSelected(item);
@@ -148,8 +156,7 @@ public void launchTranslate(View view) {
148156
.setMessage(R.string.about_translate_message)
149157
.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> {
150158
String langCode = CommonsApplication.getInstance().getLanguageLookUpTable().getCodes().get(spinner.getSelectedItemPosition());
151-
Utils.handleWebUrl(AboutActivity.this,Uri.parse("https://translatewiki.net/w/i.php?title=Special:Translate&language="
152-
+ langCode + "&group=commons-android-strings&filter=%21translated&action=translate ?"));
159+
Utils.handleWebUrl(AboutActivity.this, Uri.parse(Urls.TRANSLATE_WIKI_URL + langCode));
153160
});
154161
builder.setNegativeButton(R.string.about_translate_cancel, (dialog, which) -> finish());
155162
builder.create().show();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fr.free.nrw.commons;
2+
3+
class Urls {
4+
static final String NEW_ISSUE_URL = "https://github.com/commons-app/apps-android-commons/issues";
5+
static final String GITHUB_REPO_URL = "https://github.com/commons-app/apps-android-commons";
6+
static final String WEBSITE_URL = "https://commons-app.github.io";
7+
static final String CREDITS_URL = "https://github.com/commons-app/apps-android-commons/blob/master/CREDITS";
8+
static final String FAQ_URL = "https://github.com/commons-app/apps-android-commons/wiki/Frequently-Asked-Questions";
9+
static final String PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=fr.free.nrw.commons";
10+
static final String TRANSLATE_WIKI_URL = "https://translatewiki.net/w/i.php?title=Special:Translate&group=commons-android-strings&filter=%21translated&action=translate&language=";
11+
static final String FACEBOOK_WEB_URL = "https://www.facebook.com/1921335171459985";
12+
static final String FACEBOOK_APP_URL = "fb://page/1921335171459985";
13+
static final String FACEBOOK_PACKAGE_NAME = "com.facebook.katana";
14+
}

app/src/main/res/layout/activity_about.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@
6969
android:layout_width="wrap_content"
7070
android:layout_height="wrap_content"
7171
android:layout_marginTop="@dimen/small_gap"
72-
android:gravity="center"
73-
android:text="@string/about_improve" />
72+
android:gravity="center" />
7473

7574

7675
<LinearLayout

app/src/main/res/values/strings.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<string name="menu_about">About</string>
9292
<string name="about_license">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. </string>
9393
<string name="trademarked_name" translatable="false">Wikimedia Commons</string>
94-
<string name="about_improve">Create a new &lt;a href=\"https://github.com/commons-app/apps-android-commons/issues\"&gt;GitHub issue&lt;/a&gt; for bug reports and suggestions.</string>
94+
<string name="about_improve">Create a new &lt;a href=\"%1$s\"&gt;GitHub issue&lt;/a&gt; for bug reports and suggestions.</string>
9595
<string name="about_privacy_policy"><![CDATA[<u>Privacy policy</u>]]></string>
9696
<string name="about_credits"><![CDATA[<u>Credits</u>]]></string>
9797
<string name="title_activity_about">About</string>
@@ -537,5 +537,7 @@ Upload your first media by tapping on the add button.</string>
537537
<string name="welcome_dont_upload_content_description">Examples of images not to upload</string>
538538
<string name="skip_image">SKIP THIS IMAGE</string>
539539
<string name="download_failed_we_cannot_download_the_file_without_storage_permission">Download Failed!!. We cannot download the file without external storage permission.</string>
540+
<string name="share_text">Upload photos to Wikimedia Commons on your phone Download the Commons app: %1$s</string>
541+
<string name="share_via">Share app via...</string>
540542
<string name="image_info">Image Info</string>
541543
</resources>

0 commit comments

Comments
 (0)