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 97fe27aa4..895190003 100644 --- a/app/src/main/java/fr/free/nrw/commons/AboutActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/AboutActivity.java @@ -58,37 +58,18 @@ public class AboutActivity extends NavigationBaseActivity { intent.setPackage("com.facebook.katana"); startActivity(intent); } 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")); - } else { - Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT); - toast.show(); - } + Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985")); } } @OnClick(R.id.github_launch_icon) public void launchGithub(View view) { - 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(); - } + Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons\\")); } @OnClick(R.id.website_launch_icon) 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/\\")); - } else { - Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT); - toast.show(); - } + Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\")); } @OnClick(R.id.about_rate_us) @@ -98,29 +79,16 @@ public class AboutActivity extends NavigationBaseActivity { @OnClick(R.id.about_credits) 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/\\")); - } else { - Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT); - toast.show(); - } + Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\")); } @OnClick(R.id.about_privacy_policy) 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\\")); - } else { - Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT); - toast.show(); - } + Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\")); } @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\\")); } - } diff --git a/app/src/main/java/fr/free/nrw/commons/Utils.java b/app/src/main/java/fr/free/nrw/commons/Utils.java index 2b6ba9907..05873782c 100644 --- a/app/src/main/java/fr/free/nrw/commons/Utils.java +++ b/app/src/main/java/fr/free/nrw/commons/Utils.java @@ -7,6 +7,7 @@ import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.customtabs.CustomTabsIntent; import android.support.v4.content.ContextCompat; +import android.widget.Toast; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; @@ -15,7 +16,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; -import java.net.URL; import java.net.URLEncoder; import java.util.Locale; import java.util.regex.Matcher; @@ -24,6 +24,8 @@ import java.util.regex.Pattern; import fr.free.nrw.commons.settings.Prefs; import timber.log.Timber; +import static android.widget.Toast.LENGTH_SHORT; + public class Utils { /** @@ -176,6 +178,13 @@ public class Utils { } public static void handleWebUrl(Context context,Uri url){ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, url); + if (browserIntent.resolveActivity(context.getPackageManager()) == null) { + Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT); + toast.show(); + return; + } + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(context, R.color.primaryColor)); builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor)); diff --git a/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java b/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java index 8a41664a9..7af3c05f6 100644 --- a/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java @@ -37,6 +37,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; import fr.free.nrw.commons.BuildConfig; import fr.free.nrw.commons.PageTitle; import fr.free.nrw.commons.R; @@ -132,6 +133,10 @@ public class LoginActivity extends AccountAuthenticatorActivity { Utils.handleWebUrl(this, Uri.parse(BuildConfig.FORGOT_PASSWORD_URL)); } + @OnClick(R.id.about_privacy_policy) + void onPrivacyPolicyClicked() { + Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\")); + } public void hideKeyboard(View view) { InputMethodManager inputMethodManager =(InputMethodManager)this.getSystemService(Activity.INPUT_METHOD_SERVICE);