From a277a7e18eccda9c59ca5145d44325ebd3d7d636 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 2 Feb 2023 21:35:11 -0500 Subject: [PATCH] clarify add repo box closes #216` Signed-off-by: androidacy-user --- .../mmm/settings/SettingsActivity.java | 47 ++++++++++++------- app/src/main/res/values/strings.xml | 3 +- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java index ed675ad..2b7018b 100644 --- a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java +++ b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java @@ -20,9 +20,12 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.provider.Settings; +import android.text.Html; +import android.text.method.LinkMovementMethod; import android.view.inputmethod.EditorInfo; import android.widget.AutoCompleteTextView; import android.widget.Button; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -1052,30 +1055,42 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity { input.setHint(R.string.custom_url); builder.setIcon(R.drawable.ic_baseline_add_box_24); builder.setTitle(R.string.add_repo); + // make link in message clickable + //noinspection deprecation + builder.setMessage(Html.fromHtml(getString(R.string.add_repo_message))); builder.setView(input); builder.setPositiveButton("OK", (dialog, which) -> { String text = String.valueOf(input.getText()); - if (customRepoManager.canAddRepo(text)) { - final CustomRepoData customRepoData = customRepoManager.addRepo(text); - new Thread("Add Custom Repo Thread") { - @Override - public void run() { - try { - customRepoData.quickPrePopulate(); - UiThreadHandler.handler.post(() -> updateCustomRepoList(false)); - } catch ( - Exception e) { - Timber.e(e); - // show new dialog - new Handler(Looper.getMainLooper()).post(() -> new MaterialAlertDialogBuilder(context).setTitle(R.string.error_adding).setMessage(e.getMessage()).setPositiveButton(android.R.string.ok, (dialog1, which1) -> { - }).show()); + // string should not be empty, start with https://, and not contain any spaces. http links are not allowed. + if (text.matches("^https://.*") && !text.contains(" ") && !text.isEmpty()) { + if (customRepoManager.canAddRepo(text)) { + final CustomRepoData customRepoData = customRepoManager.addRepo(text); + new Thread("Add Custom Repo Thread") { + @Override + public void run() { + try { + customRepoData.quickPrePopulate(); + UiThreadHandler.handler.post(() -> updateCustomRepoList(false)); + } catch ( + Exception e) { + Timber.e(e); + // show new dialog + new Handler(Looper.getMainLooper()).post(() -> new MaterialAlertDialogBuilder(context).setTitle(R.string.error_adding).setMessage(e.getMessage()).setPositiveButton(android.R.string.ok, (dialog1, which1) -> { + }).show()); + } } - } - }.start(); + }.start(); + } else { + Snackbar.make(requireView(), R.string.invalid_repo_url, BaseTransientBottomBar.LENGTH_LONG).show(); + } + } else { + Snackbar.make(requireView(), R.string.invalid_repo_url, BaseTransientBottomBar.LENGTH_LONG).show(); } }); builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel()); AlertDialog alertDialog = builder.show(); + //make message clickable + ((TextView) Objects.requireNonNull(alertDialog.findViewById(android.R.id.message))).setMovementMethod(LinkMovementMethod.getInstance()); final Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); input.setValidator(new AutoCompleteTextView.Validator() { @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4176d28..6ee9ceb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -340,5 +340,6 @@ An error occurred downloading the update information. ERROR: Failed to parse update information Downloading update… %1$d%% - Installing update…ERROR: Could not find update package.Check for app updatesTest update download mechanismNo changes yet!Cancel update + Installing update…ERROR: Could not find update package.Check for app updatesTest update download mechanismNo changes yet!Cancel updateThe URL you entered for the repo is invalid + Repos must be served over HTTPS, and must follow the spec outlined in the docs.