More meaningful errors when adding repositories (#537)

* More meaningful errors when adding repositories
This commit is contained in:
self-similarity 2023-08-04 15:21:20 +00:00 committed by GitHub
parent 5103ad09dc
commit ca6700e28d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 6 deletions

View File

@ -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)

View File

@ -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)

View File

@ -572,6 +572,8 @@
<string name="batch_download_start_format" formatted="true">Started downloading %d %s…</string>
<string name="batch_download_finish_format" formatted="true">Downloaded %d %s</string>
<string name="batch_download_nothing_to_download_format" formatted="true">All %s already downloaded</string>
<string name="no_plugins_found_error">No plugins found in repository</string>
<string name="no_repository_found_error">Repository not found, check the URL and try VPN</string>
<string name="batch_download">Batch download</string>
<string name="plugin_singular">plugin</string>
<string name="plugin">plugins</string>