[Android] Improve subtitle error wording

Nicolas Pomepuy git at videolan.org
Thu Nov 21 13:19:11 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Nov  7 13:11:45 2024 +0100| [b025e49cc86cbed82e07b633ebfe5929259127ac] | committer: Duncan McNamara

Improve subtitle error wording

> https://code.videolan.org/videolan/vlc-android/commit/b025e49cc86cbed82e07b633ebfe5929259127ac
---

 .../org/videolan/resources/opensubtitles/OpenSubtitleService.kt     | 6 +++++-
 application/resources/src/main/res/values/strings.xml               | 2 +-
 application/vlc-android/res/layout/subtitle_downloader_dialog.xml   | 3 +++
 .../vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt   | 2 +-
 .../test/org/videolan/vlc/viewmodels/SubtitlesModelTest.kt          | 2 +-
 5 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt b/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt
index aeca614759..7c73f25bd3 100644
--- a/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt
+++ b/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt
@@ -14,6 +14,8 @@ import okhttp3.logging.HttpLoggingInterceptor
 import org.videolan.resources.AppContextProvider
 import org.videolan.resources.BuildConfig
 import org.videolan.resources.util.ConnectivityInterceptor
+import org.videolan.tools.forbiddenChars
+import org.videolan.tools.substrlng
 import retrofit2.Retrofit
 import retrofit2.converter.moshi.MoshiConverterFactory
 import java.util.Date
@@ -39,6 +41,8 @@ private fun buildClient() = Retrofit.Builder()
     .build()
     .create(IOpenSubtitleService::class.java)
 
+fun getOSK() = "${BuildConfig.VLC_OPEN_SUBTITLES_API_KEY}${(-47).forbiddenChars()}Y"
+
 private fun getOkHttpClient(): OkHttpClient {
     val builder = OkHttpClient.Builder()
 
@@ -69,7 +73,7 @@ private class UserAgentInterceptor(val userAgent: String): Interceptor {
         val request: Request = chain.request()
         val requestBuilder = request.newBuilder()
             .header("User-Agent", userAgent)
-            .header("Api-Key", BuildConfig.VLC_OPEN_SUBTITLES_API_KEY)
+            .header("Api-Key", getOSK().substrlng(55))
             .header("Accept", "application/json")
         if (OpenSubtitleClient.authorizationToken.isNotEmpty())requestBuilder.header("Authorization", OpenSubtitleClient.authorizationToken)
         return chain.proceed(requestBuilder.build())
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index cd7c76f4b3..e0b3e59bee 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -593,7 +593,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="open_subs_download_error">OpenSubtitles is currently unavailable. Please try again later</string>
 
     <string name="network_browsing">Local Network</string>
     <string name="browsing">Browsing</string>
diff --git a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
index 340f7ca480..073cc13a74 100644
--- a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
+++ b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
@@ -310,10 +310,13 @@
                     android:id="@+id/message"
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
+                    android:layout_marginStart="16dp"
+                    android:layout_marginEnd="16dp"
                     android:layout_marginBottom="9dp"
                     android:gravity="center_horizontal"
                     android:text="@{viewmodel.observableMessage}"
                     android:textColor="?attr/font_light"
+                    android:textSize="15sp"
                     android:visibility="@{state == state.Download && !TextUtils.isEmpty(viewmodel.observableMessage) ? View.VISIBLE : View.GONE}"
                     app:layout_constraintBottom_toTopOf="@+id/retry_button"
                     app:layout_constraintEnd_toEndOf="parent"
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 1708ac65d1..f55c5144fe 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
@@ -270,7 +270,7 @@ class SubtitlesModel(private val context: Context, private val mediaUri: Uri, pr
                 if (e is NoConnectivityException)
                     observableMessage.set(context.getString(R.string.no_internet_connection))
                 else
-                    observableMessage.set(context.getString(R.string.subs_download_error))
+                    observableMessage.set(context.getString(R.string.open_subs_download_error))
             } finally {
                 isApiLoading.postValue(false)
             }
diff --git a/application/vlc-android/test/org/videolan/vlc/viewmodels/SubtitlesModelTest.kt b/application/vlc-android/test/org/videolan/vlc/viewmodels/SubtitlesModelTest.kt
index 5d0cd61ad3..108a91ad76 100644
--- a/application/vlc-android/test/org/videolan/vlc/viewmodels/SubtitlesModelTest.kt
+++ b/application/vlc-android/test/org/videolan/vlc/viewmodels/SubtitlesModelTest.kt
@@ -244,6 +244,6 @@ class SubtitlesModelTest : BaseTest() {
                 .awaitValue(3, TimeUnit.SECONDS)
                 .assertValue { it.isEmpty() }
 
-        assertEquals(context.getString(R.string.subs_download_error), subtitlesModel.observableMessage.get())
+        assertEquals(context.getString(R.string.open_subs_download_error), subtitlesModel.observableMessage.get())
     }
 }
\ No newline at end of file



More information about the Android mailing list