Skip to content

Commit 6e9ea26

Browse files
committed
2 parents 81147aa + 4c3513b commit 6e9ea26

File tree

7 files changed

+91
-16
lines changed

7 files changed

+91
-16
lines changed
Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package fr.free.nrw.commons;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Intent;
45
import android.net.Uri;
56
import android.os.Bundle;
7+
import android.util.Log;
68
import android.support.customtabs.CustomTabsIntent;
79
import android.support.v4.content.ContextCompat;
810
import android.view.View;
911
import android.widget.TextView;
12+
import android.widget.Toast;
1013

1114
import butterknife.BindView;
1215
import butterknife.ButterKnife;
1316
import butterknife.OnClick;
1417
import fr.free.nrw.commons.theme.NavigationBaseActivity;
1518
import fr.free.nrw.commons.ui.widget.HtmlTextView;
1619

20+
import static android.widget.Toast.LENGTH_SHORT;
21+
1722
/**
1823
* Represents about screen of this app
1924
*/
@@ -27,12 +32,12 @@ public class AboutActivity extends NavigationBaseActivity {
2732
* @param savedInstanceState Data bundle
2833
*/
2934
@Override
35+
@SuppressLint("StringFormatInvalid")
3036
public void onCreate(Bundle savedInstanceState) {
3137
super.onCreate(savedInstanceState);
3238
setContentView(R.layout.activity_about);
3339

3440
ButterKnife.bind(this);
35-
3641
String aboutText = getString(R.string.about_license);
3742
aboutLicenseText.setHtmlText(aboutText);
3843

@@ -42,35 +47,66 @@ public void onCreate(Bundle savedInstanceState) {
4247

4348
@OnClick(R.id.facebook_launch_icon)
4449
public void launchFacebook(View view) {
45-
4650
Intent intent;
4751
try {
4852
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + "1921335171459985"));
4953
intent.setPackage("com.facebook.katana");
5054
startActivity(intent);
5155
} catch (Exception e) {
52-
Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985"));
56+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + "1921335171459985\\"));
57+
if(intent.resolveActivity(this.getPackageManager()) != null){
58+
Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985"));
59+
} else {
60+
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
61+
toast.show();
62+
}
5363
}
5464
}
5565

5666
@OnClick(R.id.github_launch_icon)
5767
public void launchGithub(View view) {
58-
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
68+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
69+
//check if web browser available
70+
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
71+
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
72+
} else {
73+
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
74+
toast.show();
75+
}
5976
}
6077

6178
@OnClick(R.id.website_launch_icon)
6279
public void launchWebsite(View view) {
63-
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
80+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://commons-app.github.io/\\"));
81+
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
82+
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
83+
} else {
84+
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
85+
toast.show();
86+
}
6487
}
6588

89+
6690
@OnClick(R.id.about_credits)
6791
public void launchCredits(View view) {
68-
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
92+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
93+
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
94+
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
95+
} else {
96+
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
97+
toast.show();
98+
}
6999
}
70100

71101
@OnClick(R.id.about_privacy_policy)
72102
public void launchPrivacyPolicy(View view) {
73-
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
103+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
104+
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
105+
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
106+
} else {
107+
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
108+
toast.show();
109+
}
74110
}
75111

76-
}
112+
}

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import fr.free.nrw.commons.ui.widget.CompatTextView;
3838
import timber.log.Timber;
3939

40+
import static android.widget.Toast.LENGTH_SHORT;
41+
4042
public class MediaDetailFragment extends CommonsDaggerSupportFragment {
4143

4244
private boolean editable;
@@ -305,7 +307,13 @@ private View buildCatLabel(final String catName, ViewGroup categoryContainer) {
305307
Intent viewIntent = new Intent();
306308
viewIntent.setAction(Intent.ACTION_VIEW);
307309
viewIntent.setData(new PageTitle(selectedCategoryTitle).getCanonicalUri());
308-
startActivity(viewIntent);
310+
//check if web browser available
311+
if(viewIntent.resolveActivity(getActivity().getPackageManager()) != null){
312+
startActivity(viewIntent);
313+
} else {
314+
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
315+
toast.show();
316+
}
309317
});
310318
}
311319
return item;
@@ -385,7 +393,14 @@ String licenseLink(Media media) {
385393

386394
private void openWebBrowser(String url) {
387395
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
388-
startActivity(browser);
396+
//check if web browser available
397+
if (browser.resolveActivity(getActivity().getPackageManager()) != null) {
398+
startActivity(browser);
399+
} else {
400+
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
401+
toast.show();
402+
}
403+
389404
}
390405

391406
private void openMap(LatLng coordinates) {

app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.view.MenuItem;
2525
import android.view.View;
2626
import android.view.ViewGroup;
27+
import android.widget.Toast;
2728

2829
import javax.inject.Inject;
2930
import javax.inject.Named;
@@ -40,6 +41,7 @@
4041
import static android.content.Context.DOWNLOAD_SERVICE;
4142
import static android.content.Intent.ACTION_VIEW;
4243
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
44+
import static android.widget.Toast.LENGTH_SHORT;
4345

4446
public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment implements ViewPager.OnPageChangeListener {
4547

@@ -118,7 +120,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
118120
Intent viewIntent = new Intent();
119121
viewIntent.setAction(ACTION_VIEW);
120122
viewIntent.setData(m.getFilePageTitle().getMobileUri());
121-
startActivity(viewIntent);
123+
//check if web browser available
124+
if(viewIntent.resolveActivity(getActivity().getPackageManager()) != null){
125+
startActivity(viewIntent);
126+
} else {
127+
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
128+
toast.show();
129+
}
130+
122131
return true;
123132
case R.id.menu_download_current_image:
124133
// Download

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.support.v7.widget.DividerItemDecoration;
99
import android.support.v7.widget.LinearLayoutManager;
1010
import android.support.v7.widget.RecyclerView;
11+
import android.widget.Toast;
1112

1213
import com.pedrogomez.renderers.RVRendererAdapter;
1314

@@ -25,6 +26,8 @@
2526
import io.reactivex.schedulers.Schedulers;
2627
import timber.log.Timber;
2728

29+
import static android.widget.Toast.LENGTH_SHORT;
30+
2831
/**
2932
* Created by root on 18.12.2017.
3033
*/
@@ -71,7 +74,14 @@ private void handleUrl(String url) {
7174
if (url == null || url.equals("")) {
7275
return;
7376
}
74-
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
77+
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
78+
//check if web browser available
79+
if(browser.resolveActivity(this.getPackageManager()) != null){
80+
startActivity(browser);
81+
} else {
82+
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
83+
toast.show();
84+
}
7585
}
7686

7787
private void setAdapter(List<Notification> notificationList) {

app/src/main/java/fr/free/nrw/commons/upload/SingleUploadFragment.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.widget.EditText;
2929
import android.widget.Spinner;
3030
import android.widget.TextView;
31+
import android.widget.Toast;
3132

3233
import java.util.ArrayList;
3334

@@ -65,9 +66,6 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
6566
@Override
6667
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
6768
inflater.inflate(R.menu.activity_share, menu);
68-
if (titleEdit != null) {
69-
menu.findItem(R.id.menu_upload_single).setEnabled(titleEdit.getText().length() != 0);
70-
}
7169
}
7270

7371
@Override
@@ -76,6 +74,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
7674
//What happens when the 'submit' icon is tapped
7775
case R.id.menu_upload_single:
7876

77+
if (titleEdit.getText().toString().isEmpty()) {
78+
Toast.makeText(getContext(), R.string.add_title_toast, Toast.LENGTH_LONG).show();
79+
return false;
80+
}
81+
7982
String title = titleEdit.getText().toString();
8083
String desc = descEdit.getText().toString();
8184

app/src/main/res/menu/activity_share.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<item android:id="@+id/menu_upload_single"
44
android:title="@string/menu_upload_single"
55
android:icon="@drawable/ic_send_white_24dp"
6-
android:enabled="false"
6+
android:enabled="true"
77
app:showAsAction="always" />
88
</menu>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="menu_share">Share</string>
3939
<string name="menu_open_in_browser">View in Browser</string>
4040
<string name="share_title_hint">Title</string>
41+
<string name="add_title_toast">Please give a Title to proceed</string>
4142
<string name="share_description_hint">Description</string>
4243
<string name="login_failed_network">Unable to login - network failure</string>
4344
<string name="login_failed_username">Unable to login - please check your username</string>
@@ -224,6 +225,7 @@
224225
<string name="login_to_your_account">Login to your account</string>
225226
<string name="send_log_file">Send log file</string>
226227
<string name="send_log_file_description">Send log file to developers via email</string>
228+
<string name="no_web_browser">No web browser found to open URL</string>
227229
<string name="null_url">Error! URL not found</string>
228230

229231
<string name="nearby_location_has_not_changed">Location has not changed.</string>

0 commit comments

Comments
 (0)