Commit cc42e18e authored by Geoffrey Métais's avatar Geoffrey Métais

DayNight mode migration

parent dd3f1a32
......@@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.onboarding_theme.*
import org.videolan.vlc.R
import org.videolan.vlc.util.AndroidDevices
class OnboardingThemeFragment : Fragment(), CompoundButton.OnCheckedChangeListener, View.OnClickListener {
......@@ -33,7 +34,7 @@ class OnboardingThemeFragment : Fragment(), CompoundButton.OnCheckedChangeListen
lightTheme.setOnClickListener(this)
darkTheme.setOnClickListener(this)
dayNightTheme.setOnClickListener(this)
follow_system_switch.isChecked = viewModel.enableSystemNight
follow_system_switch.isChecked = AndroidDevices.canUseSystemNightMode()
follow_system_switch.setOnCheckedChangeListener(this)
}
......
package org.videolan.vlc.gui.onboarding
import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import org.videolan.vlc.util.AndroidDevices
class OnboardingViewModel() : ViewModel() {
......@@ -13,8 +13,7 @@ class OnboardingViewModel() : ViewModel() {
var customizeMediaFolders = false
var permissionGranted = false
var adapterCount = 3
var enableSystemNight = Build.VERSION.SDK_INT > Build.VERSION_CODES.P || Build.VERSION.SDK_INT == Build.VERSION_CODES.P && "samsung" == Build.MANUFACTURER.toLowerCase()
var theme = if (enableSystemNight) AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM else AppCompatDelegate.MODE_NIGHT_AUTO
var theme = if (AndroidDevices.canUseSystemNightMode()) AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM else AppCompatDelegate.MODE_NIGHT_AUTO
}
fun FragmentActivity.getOnboardingModel() = ViewModelProviders.of(this).get(OnboardingViewModel::class.java)
......
......@@ -31,6 +31,7 @@ import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.LocalePair;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
......@@ -48,6 +49,29 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
return R.string.interface_prefs_screen;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
findPreference("resume_playback").setVisible(AndroidDevices.isPhone);
prepareLocaleList();
setupTheme();
}
private void setupTheme() {
final SharedPreferences prefs = getPreferenceScreen().getSharedPreferences();
if (!prefs.contains("app_theme")) {
int theme = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
if (prefs.getBoolean("daynight", false) && !AndroidDevices.canUseSystemNightMode()) {
theme = AppCompatDelegate.MODE_NIGHT_AUTO;
} else if (prefs.contains("enable_black_theme")) {
if (prefs.getBoolean("enable_black_theme", false))
theme = AppCompatDelegate.MODE_NIGHT_YES;
else theme = AppCompatDelegate.MODE_NIGHT_NO;
}
prefs.edit().putString("app_theme", String.valueOf(theme)).apply();
}
}
@Override
public void onStart() {
super.onStart();
......@@ -61,13 +85,6 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
findPreference("resume_playback").setVisible(AndroidDevices.isPhone);
prepareLocaleList();
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference.getKey() == null) return false;
......
......@@ -191,6 +191,11 @@ public class AndroidDevices {
return false;
}
public static boolean canUseSystemNightMode() {
return Build.VERSION.SDK_INT > Build.VERSION_CODES.P ||
Build.VERSION.SDK_INT == Build.VERSION_CODES.P && "samsung".equals(Build.MANUFACTURER.toLowerCase());
}
private static boolean hasPlayServices(PackageManager pm) {
try {
pm.getPackageInfo("com.google.android.gsf", PackageManager.GET_SERVICES);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment