[Android] Improve the subtitle login UI
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 08:10:16 2024 +0100| [f9550f9ec93f29d4cc3fa61cab91e91b7e9905da] | committer: Duncan McNamara
Improve the subtitle login UI
> https://code.videolan.org/videolan/vlc-android/commit/f9550f9ec93f29d4cc3fa61cab91e91b7e9905da
---
.../resources/opensubtitles/OpenSubtitlesLimit.kt | 9 +++++++-
.../resources/src/main/res/values/strings.xml | 4 ++--
.../res/layout/subtitle_downloader_dialog.xml | 27 ++++++++++++----------
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitlesLimit.kt b/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitlesLimit.kt
index 26b7f47afa..3d84b7bd08 100644
--- a/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitlesLimit.kt
+++ b/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitlesLimit.kt
@@ -24,6 +24,8 @@
package main.java.org.videolan.resources.opensubtitles
+import android.content.Context
+import android.text.format.DateFormat
import java.util.Date
data class OpenSubtitlesLimit (
@@ -31,7 +33,7 @@ data class OpenSubtitlesLimit (
var max: Int = 5,
val resetTime: Date? = null
) {
- private fun getRemaining(): Int {
+ fun getRemaining(): Int {
if (resetTime != null && Date().after(resetTime)) return max
return max - requests
}
@@ -39,4 +41,9 @@ data class OpenSubtitlesLimit (
val remaining = getRemaining()
return "$remaining/$max"
}
+
+ fun getResetTime(context:Context): String {
+ if (resetTime == null) return ""
+ return DateFormat.getTimeFormat(context).format(resetTime.time)
+ }
}
\ No newline at end of file
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 5c0ca137b7..207093f43e 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -717,9 +717,9 @@
<string name="popup_expand">Expand video</string>
<string name="download_subtitles">Download subtitles</string>
<string name="powered_opensubtitles">Powered by OpenSubtitles. Remaining downloads : %s</string>
- <string name="open_subtitles_login_title">Open subtitles login</string>
<string name="open_subtitles_not_logged_in">You are not logged in</string>
- <string name="open_subtitles_logged_in">Welcome %1$s</string>
+ <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_log_out">Log out</string>
<string name="open_subtitles_username">Username</string>
diff --git a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
index ca8bb11d24..be833e9492 100644
--- a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
+++ b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
@@ -354,9 +354,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
+ android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
- android:text="@string/open_subtitles_login_title"
- android:textColor="?attr/font_default"
+ android:fontFamily="sans-serif-medium"
+ android:text="@{viewmodel.observableUser.get().logged ? @{@string/open_subtitles_logged_in(viewmodel.observableUser.get().username)} : @string/open_subtitles_not_logged_in}"
+ android:textColor="?attr/colorPrimary"
android:textSize="16sp"
android:visibility="@{state == state.Login ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
@@ -368,9 +370,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
+ android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
- android:text="@{viewmodel.observableUser.get().logged ? @{@string/open_subtitles_logged_in(viewmodel.observableUser.get().username)} : @string/open_subtitles_not_logged_in}"
- android:visibility="@{state == state.Login ? View.VISIBLE : View.GONE}"
+ android:fontFamily="sans-serif-medium"
+ android:text="@{viewmodel.observableUser.get().isVip() ? @string/open_subtitles_is_vip : @string/open_subtitles_is_not_vip}"
+ android:visibility="@{viewmodel.observableUser.get().logged && state == state.Login ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView37" />
@@ -381,7 +385,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
- android:text="@{viewmodel.observableUser.get().isVip() ? @string/open_subtitles_is_vip : @string/open_subtitles_is_not_vip}"
+ android:text="@{@string/open_subtitles_limits(viewmodel.observableLimit.get().getRemaining(), viewmodel.observableLimit.get().max, viewmodel.observableLimit.get().getResetTime(context))}"
android:visibility="@{state == state.Login && viewmodel.observableUser.get().logged ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@@ -422,10 +426,9 @@
android:ems="10"
android:focusable="true"
android:hint="@string/open_subtitles_username"
- android:imeOptions="actionDone"
- android:nextFocusRight="@+id/search_button"
- android:nextFocusDown="@+id/search_button"
- android:nextFocusForward="@+id/search_button"
+ android:nextFocusRight="@+id/password"
+ android:nextFocusDown="@+id/password"
+ android:nextFocusForward="@+id/password"
android:visibility="@{state == state.Login ? View.VISIBLE : View.GONE}" />
</com.google.android.material.textfield.TextInputLayout>
@@ -448,9 +451,9 @@
android:focusable="true"
android:hint="@string/open_subtitles_password"
android:imeOptions="actionDone"
- android:nextFocusRight="@+id/search_button"
- android:nextFocusDown="@+id/search_button"
- android:nextFocusForward="@+id/search_button"
+ android:nextFocusRight="@+id/loginButton"
+ android:nextFocusDown="@+id/loginButton"
+ android:nextFocusForward="@+id/loginButton"
android:password="true"
android:visibility="@{state == state.Login ? View.VISIBLE : View.GONE}" />
</com.google.android.material.textfield.TextInputLayout>
More information about the Android
mailing list