diff --git a/.gitignore b/.gitignore index a9d1f4e7..bd508887 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ gps/ Clover/app/keys.properties Clover/app/version.properties +Clover/app/src/main/res/values/private_strings.xml # Built application files *.apk diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java index 4d01828a..e93d1135 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java @@ -18,7 +18,10 @@ package org.floens.chan.ui.controller; import android.content.Context; +import android.content.Intent; import android.content.pm.PackageManager; +import android.net.Uri; +import android.text.TextUtils; import android.view.View; import android.widget.LinearLayout; import android.widget.Toast; @@ -37,6 +40,7 @@ import org.floens.chan.ui.settings.StringSettingView; import org.floens.chan.ui.toolbar.ToolbarMenu; import org.floens.chan.ui.toolbar.ToolbarMenuItem; import org.floens.chan.ui.view.FloatingMenuItem; +import org.floens.chan.utils.AndroidUtils; import org.floens.chan.utils.AnimationUtils; import java.util.ArrayList; @@ -240,6 +244,43 @@ public class MainSettingsController extends SettingsController implements Toolba } })); + int extraAbouts = context.getResources().getIdentifier("extra_abouts", "array", context.getPackageName()); + if (extraAbouts != 0) { + String[] abouts = context.getResources().getStringArray(extraAbouts); + if (abouts.length % 3 == 0) { + for (int i = 0, aboutsLength = abouts.length; i < aboutsLength; i += 3) { + String aboutName = abouts[i]; + String aboutDescription = abouts[i + 1]; + if (TextUtils.isEmpty(aboutDescription)) { + aboutDescription = null; + } + String aboutLink = abouts[i + 2]; + if (TextUtils.isEmpty(aboutLink)) { + aboutLink = null; + } + + final String finalAboutLink = aboutLink; + about.add(new LinkSettingView(this, aboutName, aboutDescription, new View.OnClickListener() { + @Override + public void onClick(View v) { + if (finalAboutLink != null) { + if (finalAboutLink.contains("__EMAIL__")) { + String[] email = finalAboutLink.split("__EMAIL__"); + Intent intent = new Intent(Intent.ACTION_SENDTO); + intent.setData(Uri.parse("mailto:")); + intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email[0]}); + intent.putExtra(Intent.EXTRA_SUBJECT, email[1]); + AndroidUtils.openIntent(intent); + } else { + AndroidUtils.openLink(finalAboutLink); + } + } + } + })); + } + } + } + about.add(new LinkSettingView(this, s(R.string.settings_about_license), s(R.string.settings_about_license_description), new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/Clover/app/src/main/java/org/floens/chan/utils/AndroidUtils.java b/Clover/app/src/main/java/org/floens/chan/utils/AndroidUtils.java index 33f24f5f..aa845d6e 100644 --- a/Clover/app/src/main/java/org/floens/chan/utils/AndroidUtils.java +++ b/Clover/app/src/main/java/org/floens/chan/utils/AndroidUtils.java @@ -113,28 +113,32 @@ public class AndroidUtils { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); ComponentName resolvedActivity = intent.resolveActivity(pm); - boolean thisAppIsDefault = resolvedActivity.getPackageName().equals(getAppContext().getPackageName()); - if (!thisAppIsDefault) { - openIntent(intent); + if (resolvedActivity == null) { + openIntentFailed(); } else { - // Get all intents that match, and filter out this app - List resolveInfos = pm.queryIntentActivities(intent, 0); - List filteredIntents = new ArrayList<>(resolveInfos.size()); - for (ResolveInfo info : resolveInfos) { - if (!info.activityInfo.packageName.equals(getAppContext().getPackageName())) { - Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); - i.setPackage(info.activityInfo.packageName); - filteredIntents.add(i); + boolean thisAppIsDefault = resolvedActivity.getPackageName().equals(getAppContext().getPackageName()); + if (!thisAppIsDefault) { + openIntent(intent); + } else { + // Get all intents that match, and filter out this app + List resolveInfos = pm.queryIntentActivities(intent, 0); + List filteredIntents = new ArrayList<>(resolveInfos.size()); + for (ResolveInfo info : resolveInfos) { + if (!info.activityInfo.packageName.equals(getAppContext().getPackageName())) { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); + i.setPackage(info.activityInfo.packageName); + filteredIntents.add(i); + } } - } - if (filteredIntents.size() > 0) { - // Create a chooser for the last app in the list, and add the rest with EXTRA_INITIAL_INTENTS that get placed above - Intent chooser = Intent.createChooser(filteredIntents.remove(filteredIntents.size() - 1), null); - chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, filteredIntents.toArray(new Intent[filteredIntents.size()])); - openIntent(chooser); - } else { - openIntentFailed(); + if (filteredIntents.size() > 0) { + // Create a chooser for the last app in the list, and add the rest with EXTRA_INITIAL_INTENTS that get placed above + Intent chooser = Intent.createChooser(filteredIntents.remove(filteredIntents.size() - 1), null); + chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, filteredIntents.toArray(new Intent[filteredIntents.size()])); + openIntent(chooser); + } else { + openIntentFailed(); + } } } }