Merge pull request #1166 from hismaeel/master

Issue #1156
This commit is contained in:
Josephine Lim 2018-03-02 03:10:48 +10:00 committed by GitHub
commit ef5fafad8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 12 deletions

View file

@ -1,12 +1,15 @@
package fr.free.nrw.commons; package fr.free.nrw.commons;
import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.support.customtabs.CustomTabsIntent; import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -14,6 +17,8 @@ import butterknife.OnClick;
import fr.free.nrw.commons.theme.NavigationBaseActivity; import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.ui.widget.HtmlTextView; import fr.free.nrw.commons.ui.widget.HtmlTextView;
import static android.widget.Toast.LENGTH_SHORT;
/** /**
* Represents about screen of this app * Represents about screen of this app
*/ */
@ -27,12 +32,12 @@ public class AboutActivity extends NavigationBaseActivity {
* @param savedInstanceState Data bundle * @param savedInstanceState Data bundle
*/ */
@Override @Override
@SuppressLint("StringFormatInvalid")
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about); setContentView(R.layout.activity_about);
ButterKnife.bind(this); ButterKnife.bind(this);
String aboutText = getString(R.string.about_license); String aboutText = getString(R.string.about_license);
aboutLicenseText.setHtmlText(aboutText); aboutLicenseText.setHtmlText(aboutText);
@ -42,35 +47,66 @@ public class AboutActivity extends NavigationBaseActivity {
@OnClick(R.id.facebook_launch_icon) @OnClick(R.id.facebook_launch_icon)
public void launchFacebook(View view) { public void launchFacebook(View view) {
Intent intent; Intent intent;
try { try {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + "1921335171459985")); intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + "1921335171459985"));
intent.setPackage("com.facebook.katana"); intent.setPackage("com.facebook.katana");
startActivity(intent); startActivity(intent);
} catch (Exception e) { } catch (Exception e) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + "1921335171459985\\"));
if(intent.resolveActivity(this.getPackageManager()) != null){
Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985")); Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985"));
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
} }
} }
@OnClick(R.id.github_launch_icon) @OnClick(R.id.github_launch_icon)
public void launchGithub(View view) { public void launchGithub(View view) {
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\")); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
//check if web browser available
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
} }
@OnClick(R.id.website_launch_icon) @OnClick(R.id.website_launch_icon)
public void launchWebsite(View view) { public void launchWebsite(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://commons-app.github.io/\\"));
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\")); Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
} }
}
@OnClick(R.id.about_credits) @OnClick(R.id.about_credits)
public void launchCredits(View view) { public void launchCredits(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\")); Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
} }
@OnClick(R.id.about_privacy_policy) @OnClick(R.id.about_privacy_policy)
public void launchPrivacyPolicy(View view) { public void launchPrivacyPolicy(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\")); Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
} }
} }

View file

@ -37,6 +37,8 @@ import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.ui.widget.CompatTextView; import fr.free.nrw.commons.ui.widget.CompatTextView;
import timber.log.Timber; import timber.log.Timber;
import static android.widget.Toast.LENGTH_SHORT;
public class MediaDetailFragment extends CommonsDaggerSupportFragment { public class MediaDetailFragment extends CommonsDaggerSupportFragment {
private boolean editable; private boolean editable;
@ -305,7 +307,13 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
Intent viewIntent = new Intent(); Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW); viewIntent.setAction(Intent.ACTION_VIEW);
viewIntent.setData(new PageTitle(selectedCategoryTitle).getCanonicalUri()); viewIntent.setData(new PageTitle(selectedCategoryTitle).getCanonicalUri());
//check if web browser available
if(viewIntent.resolveActivity(getActivity().getPackageManager()) != null){
startActivity(viewIntent); startActivity(viewIntent);
} else {
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
}); });
} }
return item; return item;
@ -385,7 +393,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
private void openWebBrowser(String url) { private void openWebBrowser(String url) {
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
//check if web browser available
if (browser.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(browser); startActivity(browser);
} else {
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
} }
private void openMap(LatLng coordinates) { private void openMap(LatLng coordinates) {

View file

@ -24,6 +24,7 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -40,6 +41,7 @@ import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.content.Context.DOWNLOAD_SERVICE; import static android.content.Context.DOWNLOAD_SERVICE;
import static android.content.Intent.ACTION_VIEW; import static android.content.Intent.ACTION_VIEW;
import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.widget.Toast.LENGTH_SHORT;
public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment implements ViewPager.OnPageChangeListener { public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment implements ViewPager.OnPageChangeListener {
@ -118,7 +120,14 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
Intent viewIntent = new Intent(); Intent viewIntent = new Intent();
viewIntent.setAction(ACTION_VIEW); viewIntent.setAction(ACTION_VIEW);
viewIntent.setData(m.getFilePageTitle().getMobileUri()); viewIntent.setData(m.getFilePageTitle().getMobileUri());
//check if web browser available
if(viewIntent.resolveActivity(getActivity().getPackageManager()) != null){
startActivity(viewIntent); startActivity(viewIntent);
} else {
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
return true; return true;
case R.id.menu_download_current_image: case R.id.menu_download_current_image:
// Download // Download

View file

@ -8,6 +8,7 @@ import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.widget.Toast;
import com.pedrogomez.renderers.RVRendererAdapter; import com.pedrogomez.renderers.RVRendererAdapter;
@ -25,6 +26,8 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import timber.log.Timber; import timber.log.Timber;
import static android.widget.Toast.LENGTH_SHORT;
/** /**
* Created by root on 18.12.2017. * Created by root on 18.12.2017.
*/ */
@ -71,7 +74,14 @@ public class NotificationActivity extends NavigationBaseActivity {
if (url == null || url.equals("")) { if (url == null || url.equals("")) {
return; return;
} }
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
//check if web browser available
if(browser.resolveActivity(this.getPackageManager()) != null){
startActivity(browser);
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
toast.show();
}
} }
private void setAdapter(List<Notification> notificationList) { private void setAdapter(List<Notification> notificationList) {

View file

@ -224,6 +224,7 @@
<string name="login_to_your_account">Login to your account</string> <string name="login_to_your_account">Login to your account</string>
<string name="send_log_file">Send log file</string> <string name="send_log_file">Send log file</string>
<string name="send_log_file_description">Send log file to developers via email</string> <string name="send_log_file_description">Send log file to developers via email</string>
<string name="no_web_browser">No web browser found to open URL</string>
<string name="null_url">Error! URL not found</string> <string name="null_url">Error! URL not found</string>
<string name="nearby_location_has_not_changed">Location has not changed.</string> <string name="nearby_location_has_not_changed">Location has not changed.</string>