Browse Source

Set DayNight option match the system capacity

Fix #1183
merge-requests/509/head
Geoffrey Métais 6 years ago
committed by Geoffrey Métais
parent
commit
7d09c519e9
  1. 2
      application/resources/src/main/java/org/videolan/resources/AndroidDevices.kt
  2. 3
      application/resources/src/main/res/values/strings.xml
  3. 33
      application/vlc-android/res/layout/onboarding_theme.xml
  4. 20
      application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingThemeFragment.kt

2
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 {

3
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>

33
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>

20
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
}
}
}

Loading…
Cancel
Save