Skip to content

Commit

Permalink
Add mode-specific theme toggle (closes #108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Sep 18, 2024
1 parent f9011fb commit d45c562
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 129 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
</activity>
<activity
android:name=".ui.activities.MainActivity"
android:configChanges="orientation|uiMode"
android:exported="true" />

<receiver
Expand Down
25 changes: 22 additions & 3 deletions app/src/main/java/com/drdisagree/colorblendr/common/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.drdisagree.colorblendr.common

import com.drdisagree.colorblendr.BuildConfig
import com.drdisagree.colorblendr.config.RPrefs
import com.drdisagree.colorblendr.utils.SystemUtil
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.util.concurrent.atomic.AtomicInteger
Expand All @@ -19,9 +20,27 @@ object Const {
const val FIRST_RUN: String = "firstRun"
const val THEMING_ENABLED: String = "themingEnabled"
const val MONET_STYLE: String = "customMonetStyle"
const val MONET_ACCENT_SATURATION: String = "monetAccentSaturationValue"
const val MONET_BACKGROUND_SATURATION: String = "monetBackgroundSaturationValue"
const val MONET_BACKGROUND_LIGHTNESS: String = "monetBackgroundLightnessValue"
const val MODE_SPECIFIC_THEMES: String = "modeSpecificThemes"
private val modeSpecificThemes: Boolean
get() = RPrefs.getBoolean(MODE_SPECIFIC_THEMES, false)
val MONET_ACCENT_SATURATION: String
get() = if (!modeSpecificThemes) {
"monetAccentSaturationValue"
} else {
if (SystemUtil.isDarkMode) "monetAccentSaturationValue" else "monetAccentSaturationValueLight"
}
val MONET_BACKGROUND_SATURATION: String
get() = if (!modeSpecificThemes) {
"monetBackgroundSaturationValue"
} else {
if (SystemUtil.isDarkMode) "monetBackgroundSaturationValue" else "monetBackgroundSaturationValueLight"
}
val MONET_BACKGROUND_LIGHTNESS: String
get() = if (!modeSpecificThemes) {
"monetBackgroundLightnessValue"
} else {
if (SystemUtil.isDarkMode) "monetBackgroundLightnessValue" else "monetBackgroundLightnessValueLight"
}
const val MONET_ACCURATE_SHADES: String = "monetAccurateShades"
const val MONET_PITCH_BLACK_THEME: String = "monetPitchBlackTheme"
const val MONET_SEED_COLOR_ENABLED: String = "monetSeedColorEnabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.CompoundButton
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.drdisagree.colorblendr.R
import com.drdisagree.colorblendr.common.Const
import com.drdisagree.colorblendr.common.Const.MODE_SPECIFIC_THEMES
import com.drdisagree.colorblendr.common.Const.MONET_LAST_UPDATED
import com.drdisagree.colorblendr.common.Const.MONET_SECONDARY_COLOR
import com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR_ENABLED
import com.drdisagree.colorblendr.common.Const.MONET_TERTIARY_COLOR
import com.drdisagree.colorblendr.common.Const.workingMethod
import com.drdisagree.colorblendr.config.RPrefs.getBoolean
import com.drdisagree.colorblendr.config.RPrefs.getInt
import com.drdisagree.colorblendr.config.RPrefs.putBoolean
import com.drdisagree.colorblendr.config.RPrefs.putInt
import com.drdisagree.colorblendr.config.RPrefs.putLong
import com.drdisagree.colorblendr.databinding.FragmentSettingsAdvancedBinding
import com.drdisagree.colorblendr.ui.viewmodels.SharedViewModel
import com.drdisagree.colorblendr.utils.MiscUtil.setToolbarTitle
import com.drdisagree.colorblendr.utils.OverlayManager.applyFabricatedColors
import kotlinx.coroutines.CoroutineScope
Expand All @@ -34,15 +35,8 @@ import me.jfenn.colorpickerdialog.views.picker.ImagePickerView
class SettingsAdvancedFragment : Fragment() {

private lateinit var binding: FragmentSettingsAdvancedBinding
private var sharedViewModel: SharedViewModel? = null
private val notShizukuMode: Boolean = workingMethod != Const.WorkMethod.SHIZUKU

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

sharedViewModel = ViewModelProvider(requireActivity())[SharedViewModel::class.java]
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -99,6 +93,14 @@ class SettingsAdvancedFragment : Fragment() {
.show(getChildFragmentManager(), "tertiaryColorPicker")
}

// Accurate shades
binding.modeSpecificThemes.setEnabled(notShizukuMode)
binding.modeSpecificThemes.isSwitchChecked = getBoolean(MODE_SPECIFIC_THEMES, false)
binding.modeSpecificThemes.setSwitchChangeListener { _: CompoundButton?, isChecked: Boolean ->
putBoolean(MODE_SPECIFIC_THEMES, isChecked)
applyFabricatedColors()
}

return binding.getRoot()
}

Expand Down
Loading

0 comments on commit d45c562

Please sign in to comment.