Skip to content

Commit

Permalink
Just black theme
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Aug 1, 2022
1 parent 25ffa76 commit 4381a0c
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ class AppPreferences {
}

var themePref: Int
get() = sharedPreferences.getInt(APP_THEME, 2)
get() = sharedPreferences.getInt(APP_THEME, FOLLOW_SYSTEM_THEME)
set(value) = sharedPreferences.edit().putInt(APP_THEME, value).apply()

@NightMode val nightMode: Int
get() = when (themePref) {
0 -> AppCompatDelegate.MODE_NIGHT_NO
1 -> AppCompatDelegate.MODE_NIGHT_YES
2 -> {
LIGHT_THEME -> AppCompatDelegate.MODE_NIGHT_NO
DARK_THEME, JUST_BLACK_THEME -> AppCompatDelegate.MODE_NIGHT_YES
FOLLOW_SYSTEM_THEME -> {
if (supportSystemNightMode) AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
else AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
}
Expand Down Expand Up @@ -239,6 +239,10 @@ class AppPreferences {
const val TRANSLUCENT = 2
const val LIGHT = 1
const val DARK = 2
const val LIGHT_THEME = 0
const val DARK_THEME = 1
const val FOLLOW_SYSTEM_THEME = 2
const val JUST_BLACK_THEME = 3

val TIME_FORMATTER: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm")
val DATE_FORMATTER: DateTimeFormatter = DateTimeFormatter.ofLocalizedDate(MEDIUM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding
import com.github.premnirmal.ticker.AppPreferences
import com.github.premnirmal.ticker.analytics.Analytics
import com.github.premnirmal.ticker.components.Injector
import com.github.premnirmal.ticker.model.IStocksProvider
import com.github.premnirmal.ticker.model.IStocksProvider.FetchState
import com.github.premnirmal.ticker.showDialog
import com.github.premnirmal.tickerwidget.R
import com.google.android.material.color.DynamicColors
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
Expand All @@ -32,6 +34,9 @@ abstract class BaseActivity<T: ViewBinding> : AppCompatActivity() {
) {
super.onCreate(savedInstanceState)
DynamicColors.applyToActivityIfAvailable(this)
if (holder.appPreferences.themePref == AppPreferences.JUST_BLACK_THEME) {
theme.applyStyle(R.style.AppTheme_Overlay_JustBlack, true)
}
setContentView(binding.root)
savedInstanceState?.let { isErrorDialogShowing = it.getBoolean(IS_ERROR_DIALOG_SHOWING, false) }
}
Expand Down Expand Up @@ -87,6 +92,7 @@ abstract class BaseActivity<T: ViewBinding> : AppCompatActivity() {
class InjectionHolder {
@Inject internal lateinit var analytics: Analytics
@Inject internal lateinit var stocksProvider: IStocksProvider
@Inject internal lateinit var appPreferences: AppPreferences

init {
Injector.appComponent.inject(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class SettingsFragment : PreferenceFragmentCompat(), ChildFragment,
val index = listPreference.findIndexOfValue(stringValue)
appPreferences.themePref = index
themePref.summary = listPreference.entries[index]
if (index == AppPreferences.JUST_BLACK_THEME) {
requireActivity().recreate()
}
AppCompatDelegate.setDefaultNightMode(appPreferences.nightMode)
InAppMessage.showMessage(requireView(), R.string.theme_updated_message)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ class WidgetData {
@ColorRes get() {
return when (textColorPref()) {
SYSTEM -> {
R.color.text_widget_positive
if (appPreferences.themePref == AppPreferences.JUST_BLACK_THEME || nightMode) {
R.color.text_widget_positive_light
} else {
R.color.text_widget_positive
}
}
DARK -> {
R.color.text_widget_positive_dark
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<item>Hell</item>
<item>Dunkel</item>
<item>Systemstandardeinstellung</item>
<item>Nur schwarz</item>
</string-array>

<string-array name="layout_types">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<item>Clara</item>
<item>Oscura</item>
<item>Seguir sistema</item>
<item>Solo negra</item>
</string-array>

<string-array name="layout_types">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<item>Clair</item>
<item>Sombre</item>
<item>Selon le système</item>
<item>Juste noir</item>
</string-array>

<string-array name="layout_types">
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/res/values-it/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
<item>Chiaro</item>
<item>Scuro</item>
<item>Come da sistema</item>
</string-array>
<string-array name="app_themes_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>Solo nero</item>
</string-array>

<string-array name="layout_types">
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values-night/base_themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@
<item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item>
</style>

<style name="AppTheme.Overlay.JustBlack" parent="ThemeOverlay.Material3">
<item name="colorSurface">@color/black</item>
<item name="colorSurfaceVariant">@color/black</item>
<item name="android:colorBackground">@color/black</item>
<item name="android:statusBarColor">@color/black</item>
<item name="android:navigationBarColor">@color/black</item>
</style>

</resources>
6 changes: 1 addition & 5 deletions app/src/main/res/values-pt-rBR/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
<item>Claro</item>
<item>Escuro</item>
<item>Como o sistema</item>
</string-array>
<string-array name="app_themes_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>Apenas preto</item>
</string-array>

<string-array name="layout_types">
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/base_themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@
<item name="colorChangeTint">#62e04f</item>
<item name="harmonizeColorChangeTint">true</item>
</style>

<style name="AppTheme.Overlay.JustBlack" parent="ThemeOverlay.Material3">
<item name="colorSurface">@color/black</item>
<item name="colorSurfaceVariant">@color/black</item>
<item name="android:colorBackground">@color/black</item>
<item name="android:statusBarColor">@color/black</item>
<item name="android:navigationBarColor">@color/black</item>
</style>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
<item>Light</item>
<item>Dark</item>
<item>Follow system</item>
<item>Just black</item>
</string-array>
<string-array name="app_themes_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>

<string-array name="layout_types">
Expand Down

0 comments on commit 4381a0c

Please sign in to comment.