[Android] Set DayNight option match the system capacity

Geoffrey Métais git at videolan.org
Tue Mar 17 15:10:57 CET 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 16 18:22:19 2020 +0100| [7d09c519e9505b957ad265905e7d67ac7fb1ed4f] | committer: Geoffrey Métais

Set DayNight option match the system capacity

Fix #1183

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

 .../java/org/videolan/resources/AndroidDevices.kt  |  2 +-
 .../resources/src/main/res/values/strings.xml      |  3 +-
 .../vlc-android/res/layout/onboarding_theme.xml    | 33 +---------------------
 .../vlc/gui/onboarding/OnboardingThemeFragment.kt  | 20 +++----------
 4 files changed, 8 insertions(+), 50 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/AndroidDevices.kt b/application/resources/src/main/java/org/videolan/resources/AndroidDevices.kt
index 51bb3b5f7..f715c9c6c 100644
--- a/application/resources/src/main/java/org/videolan/resources/AndroidDevices.kt
+++ b/application/resources/src/main/java/org/videolan/resources/AndroidDevices.kt
@@ -166,7 +166,7 @@ object AndroidDevices {
     }
 
     fun canUseSystemNightMode(): Boolean {
-        return Build.VERSION.SDK_INT > Build.VERSION_CODES.P || Build.VERSION.SDK_INT == Build.VERSION_CODES.P && "samsung" == Build.MANUFACTURER.toLowerCase()
+        return Build.VERSION.SDK_INT > VERSION_CODES.P || Build.VERSION.SDK_INT == VERSION_CODES.P && "samsung" == Build.MANUFACTURER.toLowerCase(Locale.US)
     }
 
     private fun hasPlayServices(pm: PackageManager): Boolean {
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index f89d14f8d..de90c241b 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -695,7 +695,8 @@
     <string name="onboarding_theme_title">Make yourself at home</string>
     <string name="done">Done</string>
     <string name="onboarding_scan_title">Auto-discover your media</string>
-    <string name="daynight_explanation">VLC will automatically switch to night mode at appropriate time</string>
+    <string name="daynight_system_explanation">VLC will automatically switch to dark mode accordingly with system setting</string>
+    <string name="daynight_legacy_explanation">VLC will automatically switch to night mode at appropriate time</string>
     <string name="onboarding_scanning_enable">Let VLC scan my device for media content</string>
     <string name="onboarding_scan_whole">VLC will scan my whole SDCard</string>
     <string name="onboarding_scan_customize">Let me choose which folders VLC will scan</string>
diff --git a/application/vlc-android/res/layout/onboarding_theme.xml b/application/vlc-android/res/layout/onboarding_theme.xml
index 786084772..b758e77c8 100644
--- a/application/vlc-android/res/layout/onboarding_theme.xml
+++ b/application/vlc-android/res/layout/onboarding_theme.xml
@@ -117,41 +117,10 @@
         android:maxWidth="250dp"
         android:background="@drawable/theme_selection_rounded"
         android:padding="8dp"
-        android:text="@string/daynight_explanation"
+        android:text="@string/daynight_legacy_explanation"
         android:textAlignment="center"
         android:textColor="@color/white"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/darkTheme" />
-
-    <Switch
-        android:id="@+id/follow_system_switch"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="16dp"
-        android:layout_marginEnd="8dp"
-        android:layout_marginBottom="8dp"
-        android:text="@string/theme_follow_system_mode"
-        app:layout_constraintTop_toBottomOf="@+id/themeDescription"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        android:checked="true"
-        android:textSize="18sp"
-        android:visibility="gone"/>
-
-    <!--Switch
-        android:id="@+id/follow_battery_switch"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="16dp"
-        android:layout_marginEnd="8dp"
-        android:layout_marginBottom="8dp"
-        android:text="Follow battery saver mode"
-        app:layout_constraintTop_toBottomOf="@+id/follow_system_switch"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        android:checked="true"
-        android:textSize="18sp"/-->
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingThemeFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingThemeFragment.kt
index 6ecfb80a0..d4d4dc9b0 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingThemeFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingThemeFragment.kt
@@ -13,7 +13,7 @@ import kotlinx.android.synthetic.main.onboarding_theme.*
 import org.videolan.vlc.R
 import org.videolan.resources.AndroidDevices
 
-class OnboardingThemeFragment : Fragment(), CompoundButton.OnCheckedChangeListener, View.OnClickListener {
+class OnboardingThemeFragment : Fragment(), View.OnClickListener {
 
     private lateinit var viewModel: OnboardingViewModel
 
@@ -29,19 +29,10 @@ class OnboardingThemeFragment : Fragment(), CompoundButton.OnCheckedChangeListen
     override fun onActivityCreated(savedInstanceState: Bundle?) {
         super.onActivityCreated(savedInstanceState)
 
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) follow_system_switch.visibility = View.VISIBLE
-
+        themeDescription.setText(if (AndroidDevices.canUseSystemNightMode())R.string.daynight_system_explanation else R.string.daynight_legacy_explanation)
         lightTheme.setOnClickListener(this)
         darkTheme.setOnClickListener(this)
         dayNightTheme.setOnClickListener(this)
-        follow_system_switch.isChecked = AndroidDevices.canUseSystemNightMode()
-        follow_system_switch.setOnCheckedChangeListener(this)
-    }
-
-    override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
-        when (buttonView) {
-            follow_system_switch -> viewModel.theme = if (isChecked) AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM else AppCompatDelegate.MODE_NIGHT_AUTO
-        }
     }
 
     override fun onClick(view: View) {
@@ -52,21 +43,18 @@ class OnboardingThemeFragment : Fragment(), CompoundButton.OnCheckedChangeListen
                 dayNightTheme.background = null
                 viewModel.theme = AppCompatDelegate.MODE_NIGHT_NO
                 themeDescription.setText(R.string.light_theme)
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) follow_system_switch.visibility = View.GONE
             }
             darkTheme -> {
                 themeDescription.setText(R.string.enable_black_theme)
                 lightTheme.background = null
                 dayNightTheme.background = null
                 viewModel.theme = AppCompatDelegate.MODE_NIGHT_YES
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) follow_system_switch.visibility = View.GONE
             }
             dayNightTheme -> {
-                themeDescription.setText(R.string.daynight_explanation)
+                themeDescription.setText(if (AndroidDevices.canUseSystemNightMode())R.string.daynight_system_explanation else R.string.daynight_legacy_explanation)
                 lightTheme.background = null
                 darkTheme.background = null
-                viewModel.theme = AppCompatDelegate.MODE_NIGHT_AUTO
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) follow_system_switch.visibility = View.VISIBLE
+                viewModel.theme = if (AndroidDevices.canUseSystemNightMode()) AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM else AppCompatDelegate.MODE_NIGHT_AUTO
             }
         }
     }



More information about the Android mailing list