Skip to content

Commit

Permalink
Handle theme change
Browse files Browse the repository at this point in the history
  • Loading branch information
nicbn committed Feb 1, 2022
1 parent 71f1270 commit aec1382
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class PreferenceActivity extends BasicActivity {

@Override
public void onCreate(final Bundle savedInstanceState) {
// Fragments are created before the super call returns, so we must
// initialize sharedPrefs before the super call otherwise it cannot be used by fragments
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.readystatesoftware.systembartint.SystemBarTintManager;

import android.app.ActivityManager;
import android.content.res.Configuration;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -43,12 +44,14 @@
import android.widget.FrameLayout;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;

/** Created by arpitkh996 on 03-03-2016. */
public class ThemedActivity extends PreferenceActivity {
private int uiModeNight = -1;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -112,6 +115,26 @@ public void initStatusBarResources(View parentView) {
}
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);

final int newUiModeNight = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK;

// System theme change
if (uiModeNight != newUiModeNight
&& getPrefs().getString(PreferencesConstants.FRAGMENT_THEME, "4").equals("4")) {
uiModeNight = newUiModeNight;

getUtilsProvider().getThemeManager().setAppTheme(AppTheme.getTheme(this, 4));
// Recreate activity, handling saved state
//
// Not smooth, but will only be called if the user changes the system theme, not
// the app theme.
recreate();
}
}

public UserColorPreferences getCurrentColorPreference() {
return getColorPreference().getCurrentUserColorPreferences(this, getPrefs());
}
Expand Down Expand Up @@ -273,6 +296,8 @@ void setTheme() {
@Override
protected void onResume() {
super.onResume();

uiModeNight = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
setTheme();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2020 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
* Copyright (C) 2014-2021 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
*
* This file is part of Amaze File Manager.
Expand Down

0 comments on commit aec1382

Please sign in to comment.