pref: 优化夜间模式自动切换
This commit is contained in:
parent
30f71131e4
commit
8ce4ca4159
|
|
@ -51,8 +51,7 @@ abstract class BaseActivity : SwipeBackActivity(), ExtraRefreshable, CoroutineSc
|
||||||
private var customStatusColor = -1
|
private var customStatusColor = -1
|
||||||
private var statusBarTinted = false
|
private var statusBarTinted = false
|
||||||
|
|
||||||
val appPreferences: AppPreferencesUtils
|
val appPreferences: AppPreferencesUtils by lazy { AppPreferencesUtils(this) }
|
||||||
get() = AppPreferencesUtils(this)
|
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
|
@ -112,6 +111,15 @@ abstract class BaseActivity : SwipeBackActivity(), ExtraRefreshable, CoroutineSc
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
isActivityRunning = true
|
isActivityRunning = true
|
||||||
|
if (appPreferences.followSystemNight) {
|
||||||
|
if (BaseApplication.isSystemNight && !ThemeUtil.isNightMode(this)) {
|
||||||
|
SharedPreferencesUtil.put(ThemeUtil.getSharedPreferences(this), MainActivity.SP_SHOULD_SHOW_SNACKBAR, true)
|
||||||
|
ThemeUtil.switchToNightMode(this, false)
|
||||||
|
} else if (!BaseApplication.isSystemNight && ThemeUtil.isNightMode(this)) {
|
||||||
|
SharedPreferencesUtil.put(ThemeUtil.getSharedPreferences(this), MainActivity.SP_SHOULD_SHOW_SNACKBAR, true)
|
||||||
|
ThemeUtil.switchFromNightMode(this, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
refreshUIIfNeed()
|
refreshUIIfNeed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationMenuView
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView.OnNavigationItemReselectedListener
|
import com.google.android.material.bottomnavigation.BottomNavigationView.OnNavigationItemReselectedListener
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.huanchengfly.tieba.post.BaseApplication
|
import com.huanchengfly.tieba.post.*
|
||||||
import com.huanchengfly.tieba.post.R
|
|
||||||
import com.huanchengfly.tieba.post.adapters.ViewPagerAdapter
|
import com.huanchengfly.tieba.post.adapters.ViewPagerAdapter
|
||||||
import com.huanchengfly.tieba.post.api.Error
|
import com.huanchengfly.tieba.post.api.Error
|
||||||
import com.huanchengfly.tieba.post.api.LiteApi.Companion.instance
|
import com.huanchengfly.tieba.post.api.LiteApi.Companion.instance
|
||||||
|
|
@ -39,15 +38,13 @@ import com.huanchengfly.tieba.post.fragments.MainForumListFragment
|
||||||
import com.huanchengfly.tieba.post.fragments.MessageFragment
|
import com.huanchengfly.tieba.post.fragments.MessageFragment
|
||||||
import com.huanchengfly.tieba.post.fragments.MyInfoFragment
|
import com.huanchengfly.tieba.post.fragments.MyInfoFragment
|
||||||
import com.huanchengfly.tieba.post.fragments.PersonalizedFeedFragment
|
import com.huanchengfly.tieba.post.fragments.PersonalizedFeedFragment
|
||||||
import com.huanchengfly.tieba.post.getColorCompat
|
|
||||||
import com.huanchengfly.tieba.post.goToActivity
|
|
||||||
import com.huanchengfly.tieba.post.interfaces.Refreshable
|
import com.huanchengfly.tieba.post.interfaces.Refreshable
|
||||||
import com.huanchengfly.tieba.post.models.MyInfoBean
|
import com.huanchengfly.tieba.post.models.MyInfoBean
|
||||||
import com.huanchengfly.tieba.post.services.NotifyJobService
|
import com.huanchengfly.tieba.post.services.NotifyJobService
|
||||||
import com.huanchengfly.tieba.post.utils.*
|
import com.huanchengfly.tieba.post.utils.*
|
||||||
import com.huanchengfly.tieba.post.widgets.MyViewPager
|
import com.huanchengfly.tieba.post.widgets.MyViewPager
|
||||||
|
|
||||||
class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelectedListener, OnNavigationItemReselectedListener {
|
open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelectedListener, OnNavigationItemReselectedListener {
|
||||||
var mAdapter: ViewPagerAdapter = ViewPagerAdapter(supportFragmentManager)
|
var mAdapter: ViewPagerAdapter = ViewPagerAdapter(supportFragmentManager)
|
||||||
|
|
||||||
@BindView(R.id.mViewPager)
|
@BindView(R.id.mViewPager)
|
||||||
|
|
@ -70,23 +67,12 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelect
|
||||||
get() = if (hideExplore) 1 else 2
|
get() = if (hideExplore) 1 else 2
|
||||||
|
|
||||||
public override fun onResume() {
|
public override fun onResume() {
|
||||||
val reason = ThemeUtil.getSharedPreferences(this).getString(ThemeUtil.SP_SWITCH_REASON, null)
|
|
||||||
val followSystemNight = appPreferences.followSystemNight
|
|
||||||
if (followSystemNight) {
|
|
||||||
if (BaseApplication.isSystemNight && !ThemeUtil.isNightMode(this)) {
|
|
||||||
SharedPreferencesUtil.put(ThemeUtil.getSharedPreferences(this), SP_SHOULD_SHOW_SNACKBAR, true)
|
|
||||||
ThemeUtil.switchToNightMode(this, ThemeUtil.REASON_FOLLOW_SYSTEM, false)
|
|
||||||
} else if (!BaseApplication.isSystemNight && ThemeUtil.isNightMode(this) && TextUtils.equals(reason, ThemeUtil.REASON_FOLLOW_SYSTEM)) {
|
|
||||||
SharedPreferencesUtil.put(ThemeUtil.getSharedPreferences(this), SP_SHOULD_SHOW_SNACKBAR, true)
|
|
||||||
ThemeUtil.switchFromNightMode(this, ThemeUtil.REASON_FOLLOW_SYSTEM, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.onResume()
|
super.onResume()
|
||||||
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background))
|
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background))
|
||||||
if (ThemeUtil.THEME_TRANSLUCENT == ThemeUtil.getTheme(this)) {
|
mBottomNavigationView.elevation = if (ThemeUtil.THEME_TRANSLUCENT == ThemeUtil.getTheme(this)) {
|
||||||
mBottomNavigationView.elevation = 0f
|
0f
|
||||||
} else {
|
} else {
|
||||||
mBottomNavigationView.elevation = DisplayUtil.dp2px(this, 4f).toFloat()
|
4f.dpToPxFloat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,14 +148,7 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelect
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
private fun shouldShowSwitchSnackbar(): Boolean {
|
||||||
protected fun clearSwitchReason() {
|
|
||||||
if (TextUtils.equals(ThemeUtil.getSharedPreferences(this).getString(ThemeUtil.SP_SWITCH_REASON, null), ThemeUtil.REASON_MANUALLY)) {
|
|
||||||
ThemeUtil.getSharedPreferences(this).edit().remove(ThemeUtil.SP_SWITCH_REASON).commit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun shouldShowSwitchSnackbar(): Boolean {
|
|
||||||
return ThemeUtil.getSharedPreferences(this).getBoolean(SP_SHOULD_SHOW_SNACKBAR, false)
|
return ThemeUtil.getSharedPreferences(this).getBoolean(SP_SHOULD_SHOW_SNACKBAR, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,9 +171,6 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelect
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.create())
|
.create())
|
||||||
}
|
}
|
||||||
if (savedInstanceState == null) {
|
|
||||||
clearSwitchReason()
|
|
||||||
}
|
|
||||||
if (shouldShowSwitchSnackbar()) {
|
if (shouldShowSwitchSnackbar()) {
|
||||||
Util.createSnackbar(mViewPager, if (ThemeUtil.isNightMode(this)) R.string.snackbar_auto_switch_to_night else R.string.snackbar_auto_switch_from_night, Snackbar.LENGTH_SHORT)
|
Util.createSnackbar(mViewPager, if (ThemeUtil.isNightMode(this)) R.string.snackbar_auto_switch_to_night else R.string.snackbar_auto_switch_from_night, Snackbar.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
|
|
|
||||||
|
|
@ -1,100 +1,88 @@
|
||||||
package com.huanchengfly.tieba.post.activities;
|
package com.huanchengfly.tieba.post.activities
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.os.Bundle
|
||||||
import android.content.Intent;
|
import androidx.appcompat.widget.Toolbar
|
||||||
import android.os.Bundle;
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||||
|
import butterknife.BindView
|
||||||
|
import com.huanchengfly.tieba.post.R
|
||||||
|
import com.huanchengfly.tieba.post.adapters.ThemeAdapter
|
||||||
|
import com.huanchengfly.tieba.post.goToActivity
|
||||||
|
import com.huanchengfly.tieba.post.interfaces.OnItemClickListener
|
||||||
|
import com.huanchengfly.tieba.post.utils.DialogUtil
|
||||||
|
import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil
|
||||||
|
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
||||||
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
class ThemeActivity : BaseActivity() {
|
||||||
import androidx.appcompat.widget.Toolbar;
|
@BindView(R.id.theme_list)
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
lateinit var mRecyclerView: RecyclerView
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
|
||||||
|
|
||||||
import com.huanchengfly.tieba.post.R;
|
override fun getLayoutId(): Int {
|
||||||
import com.huanchengfly.tieba.post.adapters.ThemeAdapter;
|
return R.layout.activity_theme
|
||||||
import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil;
|
}
|
||||||
import com.huanchengfly.tieba.post.utils.ThemeUtil;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
import java.util.List;
|
super.onCreate(savedInstanceState)
|
||||||
|
mRecyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
import static com.huanchengfly.tieba.post.utils.ThemeUtil.SP_TRANSLUCENT_THEME_BACKGROUND_PATH;
|
val themeAdapter = ThemeAdapter(this)
|
||||||
import static com.huanchengfly.tieba.post.utils.ThemeUtil.THEME_TRANSLUCENT;
|
mRecyclerView.adapter = themeAdapter
|
||||||
|
if (mRecyclerView.itemAnimator != null) {
|
||||||
public class ThemeActivity extends BaseActivity {
|
mRecyclerView.itemAnimator!!.addDuration = 0
|
||||||
public static final String TAG = "ThemeActivity";
|
mRecyclerView.itemAnimator!!.changeDuration = 0
|
||||||
|
mRecyclerView.itemAnimator!!.moveDuration = 0
|
||||||
private long lastClickTimestamp = 0;
|
mRecyclerView.itemAnimator!!.removeDuration = 0
|
||||||
private int clickTimes = 0;
|
(mRecyclerView.itemAnimator as SimpleItemAnimator?)!!.supportsChangeAnimations = false
|
||||||
|
|
||||||
private RecyclerView mRecyclerView;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_theme);
|
|
||||||
mRecyclerView = (RecyclerView) findViewById(R.id.theme_list);
|
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
||||||
ThemeAdapter themeAdapter = new ThemeAdapter(this);
|
|
||||||
mRecyclerView.setAdapter(themeAdapter);
|
|
||||||
if (mRecyclerView.getItemAnimator() != null) {
|
|
||||||
mRecyclerView.getItemAnimator().setAddDuration(0);
|
|
||||||
mRecyclerView.getItemAnimator().setChangeDuration(0);
|
|
||||||
mRecyclerView.getItemAnimator().setMoveDuration(0);
|
|
||||||
mRecyclerView.getItemAnimator().setRemoveDuration(0);
|
|
||||||
((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
|
||||||
}
|
}
|
||||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
val toolbar = findViewById(R.id.toolbar) as Toolbar
|
||||||
/*
|
setSupportActionBar(toolbar)
|
||||||
toolbar.setOnClickListener(v -> {
|
val actionBar = supportActionBar
|
||||||
if (System.currentTimeMillis() - lastClickTimestamp < 2000) {
|
|
||||||
clickTimes += 1;
|
|
||||||
} else {
|
|
||||||
clickTimes = 0;
|
|
||||||
}
|
|
||||||
if (clickTimes >= 7) {
|
|
||||||
clickTimes = 0;
|
|
||||||
startActivity(new Intent(this, TranslucentThemeActivity.class));
|
|
||||||
Toast.makeText(this, "\uD83D\uDC23", Toast.LENGTH_SHORT).show();
|
|
||||||
finish();
|
|
||||||
} else if (clickTimes >= 2) {
|
|
||||||
Toast.makeText(this, "\uD83E\uDD5A", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
lastClickTimestamp = System.currentTimeMillis();
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||||
actionBar.setTitle(R.string.title_theme);
|
actionBar.setTitle(R.string.title_theme)
|
||||||
}
|
}
|
||||||
List<String> values = Arrays.asList(getResources().getStringArray(R.array.theme_values));
|
val values = listOf(*resources.getStringArray(R.array.theme_values))
|
||||||
themeAdapter.setOnItemClickListener((itemView, str, position, viewType) -> {
|
themeAdapter.onItemClickListener = OnItemClickListener { _, _, position: Int, _ ->
|
||||||
String backgroundFilePath = SharedPreferencesUtil.get(this, SharedPreferencesUtil.SP_SETTINGS)
|
val backgroundFilePath = SharedPreferencesUtil.get(this, SharedPreferencesUtil.SP_SETTINGS)
|
||||||
.getString(SP_TRANSLUCENT_THEME_BACKGROUND_PATH, null);
|
.getString(ThemeUtil.SP_TRANSLUCENT_THEME_BACKGROUND_PATH, null)
|
||||||
if (values.get(position).equals(THEME_TRANSLUCENT) && backgroundFilePath == null) {
|
val theme = values[position]
|
||||||
startActivity(new Intent(this, TranslucentThemeActivity.class));
|
if (theme == ThemeUtil.THEME_TRANSLUCENT && backgroundFilePath == null) {
|
||||||
|
goToActivity<TranslucentThemeActivity>()
|
||||||
|
}
|
||||||
|
if (ThemeUtil.isNightMode(theme) != ThemeUtil.isNightMode(appPreferences.theme)) {
|
||||||
|
DialogUtil.build(this)
|
||||||
|
.setMessage(R.string.message_dialog_follow_system_night)
|
||||||
|
.setPositiveButton(R.string.btn_keep_following) { _, _ ->
|
||||||
|
themeAdapter.refresh()
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.btn_close_following) { _, _ ->
|
||||||
|
appPreferences.followSystemNight = false
|
||||||
|
setTheme(theme)
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
setTheme(theme)
|
||||||
}
|
}
|
||||||
setTheme(values.get(position));
|
|
||||||
});
|
|
||||||
mRecyclerView.setAdapter(themeAdapter);
|
|
||||||
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
|
||||||
private void setTheme(String theme) {
|
|
||||||
ThemeUtil.getSharedPreferences(ThemeActivity.this).edit().putString(ThemeUtil.SP_THEME, theme).commit();
|
|
||||||
if (!theme.contains("dark")) {
|
|
||||||
ThemeUtil.getSharedPreferences(ThemeActivity.this).edit().putString(ThemeUtil.SP_OLD_THEME, theme).commit();
|
|
||||||
}
|
}
|
||||||
refreshUIIfNeed();
|
mRecyclerView.adapter = themeAdapter
|
||||||
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background));
|
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setTheme(theme: String) {
|
||||||
|
appPreferences.theme = theme
|
||||||
|
if (!theme.contains("dark")) {
|
||||||
|
appPreferences.oldTheme = theme
|
||||||
|
}
|
||||||
|
refreshUIIfNeed()
|
||||||
|
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background))
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "ThemeActivity"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +48,12 @@ public class ThemeAdapter extends RecyclerView.Adapter<MyViewHolder> implements
|
||||||
selectedPosition = themeList.indexOf(ThemeUtil.getTheme(mContext));
|
selectedPosition = themeList.indexOf(ThemeUtil.getTheme(mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
List<String> themeList = Arrays.asList(themes);
|
||||||
|
selectedPosition = themeList.indexOf(ThemeUtil.getTheme(mContext));
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public OnItemClickListener<String> getOnItemClickListener() {
|
public OnItemClickListener<String> getOnItemClickListener() {
|
||||||
return onItemClickListener;
|
return onItemClickListener;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,9 +207,7 @@ class MyInfoFragment : BaseFragment(), View.OnClickListener, CompoundButton.OnCh
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
nightSwitch.setOnCheckedChangeListener(null)
|
refreshNightModeStatus()
|
||||||
nightSwitch.isChecked = ThemeUtil.isNightMode(attachContext)
|
|
||||||
nightSwitch.setOnCheckedChangeListener(this)
|
|
||||||
listOf(
|
listOf(
|
||||||
R.id.my_info_history,
|
R.id.my_info_history,
|
||||||
R.id.my_info_service_center,
|
R.id.my_info_service_center,
|
||||||
|
|
@ -249,13 +247,36 @@ class MyInfoFragment : BaseFragment(), View.OnClickListener, CompoundButton.OnCh
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
|
override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
|
||||||
if (isChecked) {
|
if (appPreferences.followSystemNight) {
|
||||||
|
DialogUtil.build(attachContext)
|
||||||
|
.setMessage(R.string.message_dialog_follow_system_night)
|
||||||
|
.setPositiveButton(R.string.btn_keep_following) { _, _ ->
|
||||||
|
refreshNightModeStatus()
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.btn_close_following) { _, _ ->
|
||||||
|
attachContext.appPreferences.followSystemNight = false
|
||||||
|
switchNightMode(isChecked)
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
switchNightMode(isChecked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun switchNightMode(isNightMode: Boolean) {
|
||||||
|
if (isNightMode) {
|
||||||
ThemeUtil.switchToNightMode(attachContext as Activity)
|
ThemeUtil.switchToNightMode(attachContext as Activity)
|
||||||
} else {
|
} else {
|
||||||
ThemeUtil.switchFromNightMode(attachContext as Activity)
|
ThemeUtil.switchFromNightMode(attachContext as Activity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun refreshNightModeStatus() {
|
||||||
|
nightSwitch.setOnCheckedChangeListener(null)
|
||||||
|
nightSwitch.isChecked = ThemeUtil.isNightMode(attachContext)
|
||||||
|
nightSwitch.setOnCheckedChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRefresh() {
|
override fun onRefresh() {
|
||||||
if (isFragmentVisible) {
|
if (isFragmentVisible) {
|
||||||
refresh(true)
|
refresh(true)
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ open class AppPreferencesUtils(context: Context) {
|
||||||
|
|
||||||
var loadPictureWhenScroll by SharedPreferenceDelegates.boolean(defaultValue = true)
|
var loadPictureWhenScroll by SharedPreferenceDelegates.boolean(defaultValue = true)
|
||||||
|
|
||||||
|
var oldTheme by SharedPreferenceDelegates.string(key = "old_theme")
|
||||||
|
|
||||||
var oksignSlowMode by SharedPreferenceDelegates.boolean(defaultValue = true, key = "oksign_slow_mode")
|
var oksignSlowMode by SharedPreferenceDelegates.boolean(defaultValue = true, key = "oksign_slow_mode")
|
||||||
|
|
||||||
var radius by SharedPreferenceDelegates.int(defaultValue = 8)
|
var radius by SharedPreferenceDelegates.int(defaultValue = 8)
|
||||||
|
|
@ -62,6 +64,8 @@ open class AppPreferencesUtils(context: Context) {
|
||||||
|
|
||||||
var statusBarDarker by SharedPreferenceDelegates.boolean(defaultValue = true, key = "status_bar_darker")
|
var statusBarDarker by SharedPreferenceDelegates.boolean(defaultValue = true, key = "status_bar_darker")
|
||||||
|
|
||||||
|
var theme by SharedPreferenceDelegates.string(defaultValue = ThemeUtil.THEME_WHITE)
|
||||||
|
|
||||||
var translucentBackgroundAlpha by SharedPreferenceDelegates.int(defaultValue = 255, key = "translucent_background_alpha")
|
var translucentBackgroundAlpha by SharedPreferenceDelegates.int(defaultValue = 255, key = "translucent_background_alpha")
|
||||||
|
|
||||||
var translucentBackgroundBlur by SharedPreferenceDelegates.int(key = "translucent_background_blur")
|
var translucentBackgroundBlur by SharedPreferenceDelegates.int(key = "translucent_background_blur")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import android.widget.TextView;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringDef;
|
|
||||||
import androidx.annotation.StyleRes;
|
import androidx.annotation.StyleRes;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
@ -68,9 +67,6 @@ public class ThemeUtil {
|
||||||
public static final String SP_CUSTOM_STATUS_BAR_FONT_DARK = "custom_status_bar_font_dark";
|
public static final String SP_CUSTOM_STATUS_BAR_FONT_DARK = "custom_status_bar_font_dark";
|
||||||
public static final String SP_CUSTOM_TOOLBAR_PRIMARY_COLOR = "custom_toolbar_primary_color";
|
public static final String SP_CUSTOM_TOOLBAR_PRIMARY_COLOR = "custom_toolbar_primary_color";
|
||||||
|
|
||||||
public static final String REASON_MANUALLY = "manually";
|
|
||||||
public static final String REASON_FOLLOW_SYSTEM = "follow_system";
|
|
||||||
public static final String REASON_TIME = "time";
|
|
||||||
public static final String SP_TRANSLUCENT_THEME_BACKGROUND_PATH = "translucent_theme_background_path";
|
public static final String SP_TRANSLUCENT_THEME_BACKGROUND_PATH = "translucent_theme_background_path";
|
||||||
|
|
||||||
public static int fixColorForTranslucentTheme(int color) {
|
public static int fixColorForTranslucentTheme(int color) {
|
||||||
|
|
@ -89,11 +85,7 @@ public class ThemeUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void switchToNightMode(Activity context) {
|
public static void switchToNightMode(Activity context) {
|
||||||
switchToNightMode(context, REASON_MANUALLY);
|
switchToNightMode(context, true);
|
||||||
}
|
|
||||||
|
|
||||||
public static void switchToNightMode(Activity context, @Reason String reason) {
|
|
||||||
switchToNightMode(context, reason, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshUI(Activity activity) {
|
public static void refreshUI(Activity activity) {
|
||||||
|
|
@ -105,10 +97,9 @@ public class ThemeUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public static void switchToNightMode(Activity context, @Reason String reason, boolean recreate) {
|
public static void switchToNightMode(Activity context, boolean recreate) {
|
||||||
getSharedPreferences(context)
|
getSharedPreferences(context)
|
||||||
.edit()
|
.edit()
|
||||||
.putString(SP_SWITCH_REASON, reason)
|
|
||||||
.putString(SP_OLD_THEME, getTheme(context))
|
.putString(SP_OLD_THEME, getTheme(context))
|
||||||
.putString(SP_THEME, getSharedPreferences(context).getString(SP_DARK_THEME, THEME_BLUE_DARK))
|
.putString(SP_THEME, getSharedPreferences(context).getString(SP_DARK_THEME, THEME_BLUE_DARK))
|
||||||
.commit();
|
.commit();
|
||||||
|
|
@ -119,28 +110,18 @@ public class ThemeUtil {
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public static void switchFromNightMode(Activity context) {
|
public static void switchFromNightMode(Activity context) {
|
||||||
switchFromNightMode(context, REASON_MANUALLY);
|
switchFromNightMode(context, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public static void switchFromNightMode(Activity context, boolean recreate) {
|
public static void switchFromNightMode(Activity context, boolean recreate) {
|
||||||
switchFromNightMode(context, REASON_MANUALLY, recreate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
|
||||||
public static void switchFromNightMode(Activity context, @Reason String reason) {
|
|
||||||
switchFromNightMode(context, reason, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
|
||||||
public static void switchFromNightMode(Activity context, @Reason String reason, boolean recreate) {
|
|
||||||
getSharedPreferences(context)
|
getSharedPreferences(context)
|
||||||
.edit()
|
.edit()
|
||||||
.putString(SP_SWITCH_REASON, reason)
|
|
||||||
.putString(SP_THEME, getSharedPreferences(context).getString(SP_OLD_THEME, ThemeUtil.THEME_WHITE))
|
.putString(SP_THEME, getSharedPreferences(context).getString(SP_OLD_THEME, ThemeUtil.THEME_WHITE))
|
||||||
.commit();
|
.commit();
|
||||||
//context.recreate();
|
if (recreate) {
|
||||||
if (recreate) refreshUI(context);
|
refreshUI(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SharedPreferences getSharedPreferences(Context context) {
|
public static SharedPreferences getSharedPreferences(Context context) {
|
||||||
|
|
@ -394,8 +375,4 @@ public class ThemeUtil {
|
||||||
return THEME_WHITE;
|
return THEME_WHITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@StringDef({REASON_MANUALLY, REASON_FOLLOW_SYSTEM, REASON_TIME})
|
|
||||||
public @interface Reason {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -451,4 +451,7 @@
|
||||||
<string name="btn_post">发贴</string>
|
<string name="btn_post">发贴</string>
|
||||||
<string name="btn_refresh">刷新</string>
|
<string name="btn_refresh">刷新</string>
|
||||||
<string name="btn_back_to_top">回到顶部</string>
|
<string name="btn_back_to_top">回到顶部</string>
|
||||||
|
<string name="message_dialog_follow_system_night">您已开启跟随系统夜间模式,手动切换日夜模式需要关闭跟随系统,确定要取消跟随吗?</string>
|
||||||
|
<string name="btn_keep_following">保持跟随</string>
|
||||||
|
<string name="btn_close_following">取消跟随</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue