From ca6700e28de32e99080d9b975fac83303bb5a0cc Mon Sep 17 00:00:00 2001 From: self-similarity <137652432+self-similarity@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:21:20 +0000 Subject: [PATCH] More meaningful errors when adding repositories (#537) * More meaningful errors when adding repositories --- .../settings/extensions/ExtensionsFragment.kt | 21 +++++++++++++++++-- .../settings/extensions/PluginsViewModel.kt | 12 +++++++---- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt index 7b72fc3b..8bc947c5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt @@ -224,14 +224,31 @@ class ExtensionsFragment : Fragment() { showToast(R.string.error_invalid_data, Toast.LENGTH_SHORT) } } else { + val repository = RepositoryManager.parseRepository(url) + + // Exit if wrong repository + if (repository == null) { + showToast(R.string.no_repository_found_error, Toast.LENGTH_LONG) + return@ioSafe + } + val fixedName = if (!name.isNullOrBlank()) name - else RepositoryManager.parseRepository(url)?.name ?: "No name" + else repository.name val newRepo = RepositoryData(fixedName, url) RepositoryManager.addRepository(newRepo) extensionViewModel.loadStats() extensionViewModel.loadRepositories() - this@ExtensionsFragment.activity?.downloadAllPluginsDialog(url, fixedName) + + val plugins = RepositoryManager.getRepoPlugins(url) + if (plugins.isNullOrEmpty()) { + showToast(R.string.no_plugins_found_error, Toast.LENGTH_LONG) + } else { + this@ExtensionsFragment.activity?.downloadAllPluginsDialog( + url, + fixedName + ) + } } } dialog.dismissSafe(activity) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt index 6c68ac17..471105be 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt @@ -86,13 +86,17 @@ class PluginsViewModel : ViewModel() { }.also { list -> main { showToast( - if (list.isEmpty()) { - txt( + when { + // No plugins at all + plugins.isEmpty() -> txt( + R.string.no_plugins_found_error, + ) + // All plugins downloaded + list.isEmpty() -> txt( R.string.batch_download_nothing_to_download_format, txt(R.string.plugin) ) - } else { - txt( + else -> txt( R.string.batch_download_start_format, list.size, txt(if (list.size == 1) R.string.plugin_singular else R.string.plugin) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4dd6eadc..3df4b8c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -572,6 +572,8 @@ Started downloading %d %s… Downloaded %d %s All %s already downloaded + No plugins found in repository + Repository not found, check the URL and try VPN Batch download plugin plugins