2020-11-20 15:38:08 +01:00
|
|
|
package com.cappielloantonio.play.helper;
|
|
|
|
|
|
|
|
|
|
import android.os.Build;
|
2021-04-12 17:56:09 +02:00
|
|
|
import android.util.Log;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.appcompat.app.AppCompatDelegate;
|
|
|
|
|
|
|
|
|
|
public class ThemeHelper {
|
2021-04-12 17:56:09 +02:00
|
|
|
private static final String TAG = "ThemeHelper";
|
|
|
|
|
|
2020-11-20 15:38:08 +01:00
|
|
|
public static final String LIGHT_MODE = "light";
|
|
|
|
|
public static final String DARK_MODE = "dark";
|
|
|
|
|
public static final String DEFAULT_MODE = "default";
|
|
|
|
|
|
|
|
|
|
public static void applyTheme(@NonNull String themePref) {
|
|
|
|
|
switch (themePref) {
|
|
|
|
|
case LIGHT_MODE: {
|
|
|
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DARK_MODE: {
|
|
|
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
|
|
|
|
} else {
|
|
|
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|