Compare commits

...

3 Commits

Author SHA1 Message Date
Amine Louveau
ab4b1ae644 Merge pull request 'Theme should automatically change on phone settings change.' (#95) from theme-update into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform/pulls/95
2022-11-08 07:38:54 +00:00
aminecmi
87ea44754e Font update.
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-07 22:36:20 +01:00
aminecmi
04dec50808 Theme should automatically change on phone settings change.
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is passing
2022-11-07 22:07:35 +01:00
10 changed files with 47 additions and 2 deletions

View File

@@ -15,7 +15,8 @@
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/NoBar"
android:dataExtractionRules="@xml/data_extraction_rules">
android:dataExtractionRules="@xml/data_extraction_rules"
android:configChanges="uiMode">
<activity
android:name=".MainActivity"
android:theme="@style/SplashTheme"

View File

@@ -3,11 +3,14 @@ package bou.amine.apps.readerforselfossv2.android
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.res.Configuration
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.*
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
@@ -48,6 +51,7 @@ class MyApp : MultiDexApplication(), DIAware {
private val viewModel: AppViewModel by instance()
private val connectivityStatus: ConnectivityStatus by instance()
private val driverFactory: DriverFactory by instance()
private val appSettingsService : AppSettingsService by instance()
// TODO: handle with the "previous" way
private val isConnectionAvailable: MutableStateFlow<Boolean> = MutableStateFlow(true)
@@ -132,6 +136,19 @@ class MyApp : MultiDexApplication(), DIAware {
}
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
if (appSettingsService.getCurrentTheme() == MODE_NIGHT_FOLLOW_SYSTEM) {
var mode = when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> MODE_NIGHT_YES
else -> MODE_NIGHT_NO
}
setDefaultNightMode(mode)
}
}
class AppLifeCycleObserver(val connectivityStatus: ConnectivityStatus, val repository: Repository) : DefaultLifecycleObserver {
override fun onResume(owner: LifecycleOwner) {

View File

@@ -410,6 +410,7 @@ class ArticleFragment : Fragment(), DIAware {
val fontName = when (font) {
getString(R.string.open_sans_font_id) -> "Open Sans"
getString(R.string.roboto_font_id) -> "Roboto"
getString(R.string.source_code_pro_font_id) -> "Source Code Pro"
else -> ""
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="name=Source Code Pro&amp;weight=500"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>

View File

@@ -9,7 +9,7 @@
<string-array name="ModeValues">
<item>1</item> <!--MODE_NIGHT_NO-->
<item>2</item> <!--MODE_NIGHT_YES-->
<item>0</item> <!--MODE_NIGHT_AUTO_TIME-->
<item>-1</item> <!--MODE_NIGHT_FOLLOW_SYSTEM-->
</string-array>
<string-array name="Voice">

View File

@@ -3,5 +3,6 @@
<array name="preloaded_fonts" translatable="false">
<item>@font/open_sans</item>
<item>@font/roboto</item>
<item>@font/source_code_pro_medium</item>
</array>
</resources>

View File

@@ -4,5 +4,6 @@
<item></item>
<item>@string/open_sans_font_id</item>
<item>@string/roboto_font_id</item>
<item>@string/source_code_pro_font_id</item>
</array>
</resources>

View File

@@ -4,5 +4,6 @@
<item>Systems</item>
<item>Open Sans</item>
<item>Roboto</item>
<item>Source Code Pro</item>
</array>
</resources>

View File

@@ -125,6 +125,7 @@
<string name="reader_text_align_left">Align left</string>
<string name="reader_text_align_justify">Justify</string>
<string name="settings_reader_font">Reader font</string>
<string name="source_code_pro_font_id" translatable="false">source_code_pro_medium</string>
<string name="open_sans_font_id" translatable="false">open_sans</string>
<string name="roboto_font_id" translatable="false">roboto</string>
<string name="reader_static_bar_title">Static bottom bar in the article viewer</string>

View File

@@ -35,6 +35,7 @@ class AppSettingsService {
private var _fontSize: Int? = null
private var _staticBar: Boolean? = null
private var _font: String = ""
private var _theme: Int? = null
init {
@@ -318,6 +319,17 @@ class AppSettingsService {
return _font
}
private fun refreshCurrentTheme() {
_theme = settings.getString(CURRENT_THEME, "-1").toInt()
}
fun getCurrentTheme(): Int {
if (_theme == null) {
refreshCurrentTheme()
}
return _theme ?: -1
}
fun refreshApiSettings() {
refreshPassword()
refreshUsername()
@@ -346,6 +358,7 @@ class AppSettingsService {
refreshFontSize()
refreshFont()
refreshStaticBarEnabled()
refreshCurrentTheme()
}
fun refreshLoginInformation(
@@ -444,5 +457,7 @@ class AppSettingsService {
const val INFINITE_LOADING = "infinite_loading"
const val ITEMS_CACHING = "items_caching"
const val CURRENT_THEME = "currentMode"
}
}