[Android] OpenSubtitles: Add a register button

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Nov  6 11:14:24 2024 +0100| [368d31461f1972b2b51d597281e95fe87f866120] | committer: Duncan McNamara

OpenSubtitles: Add a register button

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

 application/resources/src/main/res/values/strings.xml      |  1 +
 .../tools/src/main/java/org/videolan/tools/Strings.kt      |  4 ++++
 .../vlc-android/res/layout/subtitle_downloader_dialog.xml  | 14 ++++++++++++++
 .../vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt    |  5 +++++
 4 files changed, 24 insertions(+)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 9946f0b8ba..cd7c76f4b3 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -721,6 +721,7 @@
     <string name="open_subtitles_logged_in">Logged in as %1$s</string>
     <string name="open_subtitles_limits">You have %1$s remaining downloads out of %2$s. Your limit will be reset at %3$s.</string>
     <string name="open_subtitles_vip">You are a VIP OpenSubtitles user</string>
+    <string name="open_subtitles_register">Register</string>
     <string name="open_subtitles_log_out">Log out</string>
     <string name="open_subtitles_username">Username</string>
     <string name="open_subtitles_password">Password</string>
diff --git a/application/tools/src/main/java/org/videolan/tools/Strings.kt b/application/tools/src/main/java/org/videolan/tools/Strings.kt
index a62c0c305e..f6acd06924 100644
--- a/application/tools/src/main/java/org/videolan/tools/Strings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Strings.kt
@@ -101,6 +101,8 @@ fun String.firstLetterUppercase(): String {
     } else Character.toUpperCase(this[0]) + substring(1).lowercase(Locale.getDefault())
 }
 
+const val FORBIDDEN_CHARS = "ha]/m(?-*"
+
 fun String.password() =  "*".repeat(length)
 
 fun String.abbreviate(maxLen: Int): String {
@@ -116,6 +118,8 @@ fun Long.readableNumber(): String {
     return (this / 1000000).toString() + "M"
 }
 
+fun Int.forbiddenChars() = FORBIDDEN_CHARS.substrlng(this)
+
 fun String.markBidi(): String {
     //right-to-left isolate
     val rli = "\u2067"
diff --git a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
index 9738601ed2..340f7ca480 100644
--- a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
+++ b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
@@ -468,12 +468,26 @@
                         android:visibility="@{state == state.Login ? View.VISIBLE : View.GONE}" />
             </com.google.android.material.textfield.TextInputLayout>
 
+            <Button
+                    android:id="@+id/registerButton"
+                    style="@style/Widget.MaterialComponents.Button.TextButton.Dialog"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="16dp"
+                    android:layout_marginEnd="16dp"
+                    android:text="@string/open_subtitles_register"
+                    android:visibility="@{!viewmodel.observableUser.get().logged && state == state.Login ? View.VISIBLE : View.GONE}"
+                    app:layout_constraintEnd_toStartOf="@+id/loginButton"
+                    app:layout_constraintTop_toBottomOf="@+id/error" />
+
             <Button
                     android:id="@+id/loginButton"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="16dp"
                     android:layout_marginEnd="16dp"
+                    tools:text="Login"
+                    style="@style/Widget.MaterialComponents.Button.TextButton.Dialog"
                     android:text="@{viewmodel.observableUser.get().logged ? @string/open_subtitles_log_out : @string/login}"
                     android:visibility="@{state == state.Login ? View.VISIBLE : View.GONE}"
                     app:layout_constraintEnd_toEndOf="parent"
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 02bb8b1526..3f5cb6fda9 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
@@ -36,6 +36,7 @@ import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.helpers.UiTools.deleteSubtitleDialog
 import org.videolan.vlc.gui.view.OnItemSelectListener
 import org.videolan.vlc.util.VLCDownloadManager
+import org.videolan.vlc.util.openLinkIfPossible
 import org.videolan.vlc.viewmodels.SubtitlesModel
 
 private const val MEDIA_PATHS = "MEDIA_PATHS"
@@ -158,6 +159,10 @@ class SubtitleDownloaderDialogFragment : VLCBottomSheetDialogFragment() {
             }
         }
 
+        binding.registerButton.setOnClickListener {
+                requireActivity().openLinkIfPossible("https://www.opensubtitles.com/en", 512)
+        }
+
         state = SubDownloadDialogState.Download
 
         downloadAdapter = SubtitlesAdapter(listEventActor)



More information about the Android mailing list