[Android] Add a retry button for the subtitle downloads
Nicolas Pomepuy
git at videolan.org
Tue Feb 15 10:52:29 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Feb 14 12:09:41 2022 +0100| [3f996f1873fe334925a691ac727a653d3a7ee667] | committer: Nicolas Pomepuy
Add a retry button for the subtitle downloads
Fixes #2147
> https://code.videolan.org/videolan/vlc-android/commit/3f996f1873fe334925a691ac727a653d3a7ee667
---
.../resources/src/main/res/values/strings.xml | 1 +
.../res/layout/subtitle_downloader_dialog.xml | 23 +++++++++++++++++++---
.../dialogs/SubtitleDownloaderDialogFragment.kt | 9 +++++++++
.../org/videolan/vlc/viewmodels/SubtitlesModel.kt | 3 +++
4 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 8c0699c13..adacf706d 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -478,6 +478,7 @@
<string name="no_result">No results found</string>
<string name="no_internet_connection">Check your internet connection</string>
+ <string name="retry">Retry</string>
<string name="subs_download_error">Service unavailable. Please try again later</string>
<string name="network_browsing">Local Network</string>
diff --git a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
index bdca62dfb..a5c7bc49a 100644
--- a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
+++ b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
@@ -17,6 +17,10 @@
name="state"
type="org.videolan.vlc.gui.dialogs.SubDownloadDialogState" />
+ <variable
+ name="inError"
+ type="Boolean" />
+
</data>
<androidx.core.widget.NestedScrollView
@@ -142,13 +146,26 @@
android:layout_marginBottom="9dp"
android:gravity="center_horizontal"
android:text="@{viewmodel.observableMessage}"
- android:textColor="@color/orange500"
+ android:textColor="?attr/font_light"
android:visibility="@{state == state.Download && !TextUtils.isEmpty(viewmodel.observableMessage) ? View.VISIBLE : View.GONE}"
- app:layout_constraintBottom_toBottomOf="@+id/subs_download_list"
+ app:layout_constraintBottom_toTopOf="@+id/retry_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/subs_download_list"
- app:layout_goneMarginTop="40dp" />
+ app:layout_constraintVertical_chainStyle="packed"
+ app:layout_goneMarginTop="40dp"
+ tools:text="No results found" />
+
+ <Button
+ android:id="@+id/retry_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/retry"
+ app:layout_constraintEnd_toEndOf="parent"
+ android:visibility="@{viewmodel.observableError ? View.VISIBLE : View.GONE}"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/message"
+ app:layout_constraintBottom_toBottomOf="@id/subs_download_list"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/subs_history_list"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt
index 6e5cc81a0..7ae745fc5 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt
@@ -91,6 +91,11 @@ class SubtitleDownloaderDialogFragment : VLCBottomSheetDialogFragment() {
if (uris.isEmpty()) dismiss()
}
+ override fun onResume() {
+ viewModel.onRefresh()
+ super.onResume()
+ }
+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
binding = SubtitleDownloaderDialogBinding.inflate(inflater, container, false)
@@ -149,6 +154,10 @@ class SubtitleDownloaderDialogFragment : VLCBottomSheetDialogFragment() {
}
})
+ binding.retryButton.setOnClickListener {
+ viewModel.onRefresh()
+ }
+
binding.languageListSpinner.setSelection(viewModel.getLastUsedLanguage().map { binding.languageListSpinner.allValuesOfLanguages.indexOf(it) })
binding.episode.setOnEditorActionListener { v, actionId, event ->
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
index 0bc4bb748..b71e04e9d 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
@@ -43,6 +43,7 @@ class SubtitlesModel(private val context: Context, private val mediaUri: Uri, pr
val isApiLoading: MediatorLiveData<Boolean> = MediatorLiveData()
val observableMessage = ObservableField<String>()
+ val observableError = ObservableField<Boolean>()
val observableResultDescription = ObservableField<Spanned>()
private val apiResultLiveData: MutableLiveData<List<OpenSubtitle>> = MutableLiveData()
@@ -141,6 +142,7 @@ class SubtitlesModel(private val context: Context, private val mediaUri: Uri, pr
searchJob?.cancel()
isApiLoading.postValue(true)
observableMessage.set("")
+ observableError.set(false)
apiResultLiveData.postValue(listOf())
searchJob = viewModelScope.launch {
@@ -168,6 +170,7 @@ class SubtitlesModel(private val context: Context, private val mediaUri: Uri, pr
if (subs.isEmpty()) observableMessage.set(context.getString(R.string.no_result))
} catch (e: Exception) {
Log.e("SubtitlesModel", e.message, e)
+ observableError.set(true)
if (e is NoConnectivityException)
observableMessage.set(context.getString(R.string.no_internet_connection))
else
More information about the Android
mailing list