From 01cd897fd7ab8f6b3226dd7234d9a24cc090b339 Mon Sep 17 00:00:00 2001 From: Matthew Miner Date: Sat, 7 Oct 2023 15:27:39 -0500 Subject: [PATCH 1/3] Revert "Revert "Add option to follow system theme"" This reverts commit a6678e9515d556e807b8b2def295447d370d3ba1. --- .../java/yuku/alkitab/base/IsiActivity.kt | 20 ++++++++++++++++ .../java/yuku/alkitab/base/storage/Prefkey.kt | 3 +++ .../yuku/alkitab/base/widget/LeftDrawer.java | 24 ++++++++++++++++++- .../src/main/res/layout/left_drawer_text.xml | 12 ++++++++++ Alkitab/src/main/res/values-af/strings.xml | 1 + Alkitab/src/main/res/values-bg/strings.xml | 1 + Alkitab/src/main/res/values-ceb/strings.xml | 1 + Alkitab/src/main/res/values-cs/strings.xml | 1 + Alkitab/src/main/res/values-da/strings.xml | 1 + Alkitab/src/main/res/values-de/strings.xml | 1 + Alkitab/src/main/res/values-el/strings.xml | 1 + Alkitab/src/main/res/values-es/strings.xml | 1 + Alkitab/src/main/res/values-fr/strings.xml | 1 + Alkitab/src/main/res/values-hu/strings.xml | 1 + Alkitab/src/main/res/values-in/strings.xml | 1 + Alkitab/src/main/res/values-it/strings.xml | 1 + Alkitab/src/main/res/values-ja/strings.xml | 1 + Alkitab/src/main/res/values-ko/strings.xml | 1 + Alkitab/src/main/res/values-lv/strings.xml | 1 + Alkitab/src/main/res/values-ms/strings.xml | 1 + Alkitab/src/main/res/values-my/strings.xml | 1 + Alkitab/src/main/res/values-nl/strings.xml | 1 + Alkitab/src/main/res/values-pl/strings.xml | 1 + .../src/main/res/values-pt-rBR/strings.xml | 1 + Alkitab/src/main/res/values-pt/strings.xml | 1 + Alkitab/src/main/res/values-ro/strings.xml | 1 + Alkitab/src/main/res/values-ru/strings.xml | 1 + Alkitab/src/main/res/values-th/strings.xml | 1 + Alkitab/src/main/res/values-tl/strings.xml | 1 + Alkitab/src/main/res/values-tr/strings.xml | 1 + Alkitab/src/main/res/values-vi/strings.xml | 1 + .../src/main/res/values-zh-rCN/strings.xml | 1 + .../src/main/res/values-zh-rTW/strings.xml | 1 + Alkitab/src/main/res/values/strings.xml | 1 + 34 files changed, 88 insertions(+), 1 deletion(-) diff --git a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt index 49bab84a4..667ccaa48 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt @@ -9,6 +9,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.res.Configuration import android.graphics.Point import android.net.Uri import android.os.Bundle @@ -2058,6 +2059,19 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { App.getLbm().sendBroadcast(Intent(ACTION_NIGHT_MODE_CHANGED)) } + private fun setFollowSystemTheme(yes: Boolean, cNightMode: SwitchCompat) { + val previousValue = Preferences.getBoolean(Prefkey.follow_system_theme, true) + if (previousValue == yes) return + + Preferences.setBoolean(Prefkey.follow_system_theme, yes) + + if (yes) { + val systemTheme = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + cNightMode.isChecked = systemTheme == Configuration.UI_MODE_NIGHT_YES + setNightMode(systemTheme == Configuration.UI_MODE_NIGHT_YES) + } + } + private fun openVersionsDialog() { // If there is no db versions, immediately open manage version screen. if (S.db.listAllVersions().isEmpty()) { @@ -2823,6 +2837,12 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { setNightMode(isChecked) } + override fun cFollowSystemTheme_checkedChange(isChecked: Boolean, cNightMode: SwitchCompat) { + Tracker.trackEvent("left_drawer_follow_system_theme_click") + cNightMode.isEnabled = !isChecked + setFollowSystemTheme(isChecked, cNightMode) + } + override fun cSplitVersion_checkedChange(cSplitVersion: SwitchCompat, isChecked: Boolean) { Tracker.trackEvent("left_drawer_split_click") if (isChecked) { diff --git a/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.kt b/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.kt index 2b91b49f3..8f563a937 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.kt @@ -35,6 +35,9 @@ enum class Prefkey { /** Night mode activated (boolean) */ is_night_mode, + /** Night mode follows system theme (boolean) */ + follow_system_theme, + /** marker (bookmark) list selected sorting option */ marker_list_sort_column, marker_list_sort_ascending, diff --git a/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java b/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java index 1f00ec8f7..a49ce3b6c 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Configuration; import android.graphics.Typeface; import androidx.annotation.NonNull; import androidx.core.content.res.ResourcesCompat; @@ -237,6 +238,8 @@ public interface Listener { void cNightMode_checkedChange(boolean isChecked); + void cFollowSystemTheme_checkedChange(boolean isChecked, final SwitchCompat cNightMode); + void cSplitVersion_checkedChange(final SwitchCompat cSplitVersion, boolean isChecked); void bProgressMarkList_click(); @@ -258,6 +261,7 @@ public interface Handle { View bDisplay; SwitchCompat cFullScreen; SwitchCompat cNightMode; + SwitchCompat cFollowSystemTheme; SwitchCompat cSplitVersion; View bProgressMarkList; @@ -304,6 +308,7 @@ protected void onFinishInflate() { bDisplay = findViewById(R.id.bDisplay); cFullScreen = findViewById(R.id.cFullScreen); cNightMode = findViewById(R.id.cNightMode); + cFollowSystemTheme = findViewById(R.id.cFollowSystemTheme); cSplitVersion = findViewById(R.id.cSplitVersion); bProgressMarkList = findViewById(R.id.bProgressMarkList); @@ -317,7 +322,15 @@ protected void onFinishInflate() { bCurrentReadingClose = findViewById(R.id.bCurrentReadingClose); bCurrentReadingReference = findViewById(R.id.bCurrentReadingReference); - cNightMode.setChecked(!isInEditMode() && Preferences.getBoolean(Prefkey.is_night_mode, false)); + final boolean followSystemTheme = Preferences.getBoolean(Prefkey.follow_system_theme, true); + if (followSystemTheme) { + final int systemTheme = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + cNightMode.setChecked(!isInEditMode() && systemTheme == Configuration.UI_MODE_NIGHT_YES); + } else { + cNightMode.setChecked(!isInEditMode() && Preferences.getBoolean(Prefkey.is_night_mode, false)); + } + cNightMode.setEnabled(!followSystemTheme); + cFollowSystemTheme.setChecked(followSystemTheme); bProgressMarkList.setOnClickListener(v -> listener.bProgressMarkList_click()); @@ -355,6 +368,8 @@ protected void onFinishInflate() { cNightMode.setOnCheckedChangeListener(cNightMode_checkedChange); + cFollowSystemTheme.setOnCheckedChangeListener(cFollowSystemTheme_checkedChange); + cSplitVersion.setOnCheckedChangeListener(cSplitVersion_checkedChange); bCurrentReadingClose.setOnClickListener(v -> listener.bCurrentReadingClose_click()); @@ -414,6 +429,13 @@ public void onCheckedChanged(final CompoundButton buttonView, final boolean isCh } }; + CompoundButton.OnCheckedChangeListener cFollowSystemTheme_checkedChange = new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { + listener.cFollowSystemTheme_checkedChange(isChecked, cNightMode); + } + }; + CompoundButton.OnCheckedChangeListener cSplitVersion_checkedChange = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { diff --git a/Alkitab/src/main/res/layout/left_drawer_text.xml b/Alkitab/src/main/res/layout/left_drawer_text.xml index 57a645309..3bb411c6e 100644 --- a/Alkitab/src/main/res/layout/left_drawer_text.xml +++ b/Alkitab/src/main/res/layout/left_drawer_text.xml @@ -193,6 +193,18 @@ android:textColor="#fff" android:textSize="16sp" /> + + Netwerk fout tydens aflaai van ^1. Bediener fout tydens aflaai van ^1. Nag modus + Volg stelsel tema Ander Kleure Vergelyk \'n Fout het ontstaan met die speel van die lied:%1$d, %2$d. diff --git a/Alkitab/src/main/res/values-bg/strings.xml b/Alkitab/src/main/res/values-bg/strings.xml index 808ef94e7..807d0b843 100644 --- a/Alkitab/src/main/res/values-bg/strings.xml +++ b/Alkitab/src/main/res/values-bg/strings.xml @@ -363,6 +363,7 @@ Мрежова грешка при изтегляне ^1. Грешка в сървъра при изтегляне ^1. Нощен режим + Следвайте темата на системата Други цветове Сравни Възникна грешка при възпроизвеждане на тази песен: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-ceb/strings.xml b/Alkitab/src/main/res/values-ceb/strings.xml index 7390728ba..da233374e 100644 --- a/Alkitab/src/main/res/values-ceb/strings.xml +++ b/Alkitab/src/main/res/values-ceb/strings.xml @@ -361,6 +361,7 @@ Kasamtangan nasayop ang network sa pag-download ^1. Kasamtangan nasayop ang server sa pag-download ^1. Pang-gabie na mode + Sunda ang tema sa sistema Ubang mga kolor Itandi Naai na sugatan na sayop samtang nag patukar ining kantaha: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-cs/strings.xml b/Alkitab/src/main/res/values-cs/strings.xml index c2199ee8d..06e8a5173 100644 --- a/Alkitab/src/main/res/values-cs/strings.xml +++ b/Alkitab/src/main/res/values-cs/strings.xml @@ -364,6 +364,7 @@ Chyba sítě při stahování ^1. Chyba serveru při stahování ^1. Noční mód + Sledování systémového tématu Jiné barvy Porovnat Chyba při přehrávání: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-da/strings.xml b/Alkitab/src/main/res/values-da/strings.xml index e8537563e..67bca1ef2 100644 --- a/Alkitab/src/main/res/values-da/strings.xml +++ b/Alkitab/src/main/res/values-da/strings.xml @@ -362,6 +362,7 @@ Netværksfejl under hentning af ^1. Server fejl ved hentning af ^1. Natfunktion + Følg systemtemaet Dine markørfarver Sammenlign Der opstår en fejl, når denne sang afspilles: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-de/strings.xml b/Alkitab/src/main/res/values-de/strings.xml index 354a97c39..5c492c3ff 100644 --- a/Alkitab/src/main/res/values-de/strings.xml +++ b/Alkitab/src/main/res/values-de/strings.xml @@ -366,6 +366,7 @@ Netzwerkfehler beim Herunterladen von ^1. Serverfehler beim Herunterladen von ^1. Nachtmodus + Dem Systemthema folgen Weitere Farben Vergleichen Beim Abspielen dieses Liedes ist ein Fehler aufgetreten: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-el/strings.xml b/Alkitab/src/main/res/values-el/strings.xml index 093f38164..7cc5296dc 100644 --- a/Alkitab/src/main/res/values-el/strings.xml +++ b/Alkitab/src/main/res/values-el/strings.xml @@ -362,6 +362,7 @@ Σφάλμα στο διαδίκτυο στο άνοιγμα ^1. Σφάλμα διακομιστή κατά το άνοιγμα του ^1. Νυχτερινή λειτουργία + Ακολουθήστε το θέμα του συστήματος Άλλα χρώματα Σύγκριση Εντοπίστηκε σφάλμα κατά το παίξιμο αυτού του ύμνου: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-es/strings.xml b/Alkitab/src/main/res/values-es/strings.xml index 4ce8d4e15..eb71dfe52 100644 --- a/Alkitab/src/main/res/values-es/strings.xml +++ b/Alkitab/src/main/res/values-es/strings.xml @@ -366,6 +366,7 @@ Error de red al descargar ^1. Error de servidor al descargar ^1. Modo nocturno + Seguir el tema del sistema Otros colores Comparar Se encontró un error mientras se reproducía está canción: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-fr/strings.xml b/Alkitab/src/main/res/values-fr/strings.xml index 6e8e253a7..4298390fd 100644 --- a/Alkitab/src/main/res/values-fr/strings.xml +++ b/Alkitab/src/main/res/values-fr/strings.xml @@ -366,6 +366,7 @@ Erreur de réseau lors du téléchargement de ^1. Erreur de serveur lors du téléchargement de ^1. Mode nuit + Suivre le thème du système Autres couleurs Comparer Erreur lors de l\'écoute de ce chant : %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-hu/strings.xml b/Alkitab/src/main/res/values-hu/strings.xml index 53e21357c..e6cc7ea97 100644 --- a/Alkitab/src/main/res/values-hu/strings.xml +++ b/Alkitab/src/main/res/values-hu/strings.xml @@ -361,6 +361,7 @@ Hálózati hiba ^1 letöltése közben. Szerverhiba ^1 letöltése közben. Éjszakai mód + Kövesse a rendszer témáját Más színek Összehasonlítás Hiba történt a dal lejátszása során: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-in/strings.xml b/Alkitab/src/main/res/values-in/strings.xml index 93f6212ed..47e7e975b 100644 --- a/Alkitab/src/main/res/values-in/strings.xml +++ b/Alkitab/src/main/res/values-in/strings.xml @@ -374,6 +374,7 @@ Kesalahan jaringan saat mengunduh ^1. Kesalahan server saat mengunduh ^1. Mode gelap + Ikuti tema sistem Warna lainnya Bandingkan Ada kesalahan ketika memainkan lagu ini: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-it/strings.xml b/Alkitab/src/main/res/values-it/strings.xml index 32c0ebf47..0711ffb10 100644 --- a/Alkitab/src/main/res/values-it/strings.xml +++ b/Alkitab/src/main/res/values-it/strings.xml @@ -366,6 +366,7 @@ Errore di rete durante il download ^1. Errore del server durante il download ^1. Modalità notturna + Seguire il tema del sistema Altri colori Compara Si è verificato un errore durante la riproduzione di questo brano: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-ja/strings.xml b/Alkitab/src/main/res/values-ja/strings.xml index e3d31e86e..f9bf1eb68 100644 --- a/Alkitab/src/main/res/values-ja/strings.xml +++ b/Alkitab/src/main/res/values-ja/strings.xml @@ -363,6 +363,7 @@ ^1をダウンロードした時のネットワークエラー。 ^1をダウンロードした時のサーバーエラー。 夜間モード + システムテーマに沿って その他の色 比較する 聖歌 %1$d %2$d 再生中にエラーになりました diff --git a/Alkitab/src/main/res/values-ko/strings.xml b/Alkitab/src/main/res/values-ko/strings.xml index 961502d41..62df0766f 100644 --- a/Alkitab/src/main/res/values-ko/strings.xml +++ b/Alkitab/src/main/res/values-ko/strings.xml @@ -363,6 +363,7 @@ ^1을(를) 다운로드하는 도중 네트워크 오류가 발생했습니다. ^1을(를) 다운로드하는 도중 서버 오류가 발생했습니다. 야간모드 + 시스템 테마 팔로우 다른 색상 번역본 대조 찬양 재생 중 오류 발생: %1$d,%2$d diff --git a/Alkitab/src/main/res/values-lv/strings.xml b/Alkitab/src/main/res/values-lv/strings.xml index db3f210ad..5c286aed5 100644 --- a/Alkitab/src/main/res/values-lv/strings.xml +++ b/Alkitab/src/main/res/values-lv/strings.xml @@ -364,6 +364,7 @@ Radās tīkla kļūda lejuplādējot ^1. Servera kļūda lejuplādējot ^1. Nakts režīms + Sekojiet sistēmas tēmai Citas krāsas Salīdzināt Atskaņojot šo dziesmu ir radusies kļūda: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-ms/strings.xml b/Alkitab/src/main/res/values-ms/strings.xml index b528ee3ef..1bfc7f184 100644 --- a/Alkitab/src/main/res/values-ms/strings.xml +++ b/Alkitab/src/main/res/values-ms/strings.xml @@ -362,6 +362,7 @@ Talian bermasalah semasa muat turun ^1. Pelayan bermasalah semasa muat turun ^1. Mod malam + Ikut tema sistem Warna lain Bandingkan Ralat berlaku semasa bermain lagu ini: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-my/strings.xml b/Alkitab/src/main/res/values-my/strings.xml index 89660d9e4..f347548f2 100644 --- a/Alkitab/src/main/res/values-my/strings.xml +++ b/Alkitab/src/main/res/values-my/strings.xml @@ -363,6 +363,7 @@ ^1 ကို ဒေါင်းလုဒ်ဆွဲရာတွင် ကွန်ယက်ချို့ယွင်းချက်ဖြင့် ကြုံရခြင်း။ ^1 ကို ဒေါင်းလုဒ်ဆွဲရာတွင် ဆာဗာချို့ယွင်းချက်ဖြင့် ကြုံရခြင်း။ ညကြည့် အသွင် + စနစ်အပြင်အဆင်ကို လိုက်နာပါ။ အခြားအရောင်များ နှိုင်းယှဉ်ရန် ဤသီချင်းကို ဖွင့်စဉ်မှာ အမှားကြုံတွေ့ရသည်- %1$d, %2$d။ diff --git a/Alkitab/src/main/res/values-nl/strings.xml b/Alkitab/src/main/res/values-nl/strings.xml index e47ecb925..7c40a88b7 100644 --- a/Alkitab/src/main/res/values-nl/strings.xml +++ b/Alkitab/src/main/res/values-nl/strings.xml @@ -366,6 +366,7 @@ Netwerkfout tijdens het downloaden. Serverfout tijdens het downloaden. Nachtmodus + Volg het systeemthema Andere kleuren Vergelijken Er is een fout opgetreden bij het afspelen van dit lied: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-pl/strings.xml b/Alkitab/src/main/res/values-pl/strings.xml index 888469106..0cc002835 100644 --- a/Alkitab/src/main/res/values-pl/strings.xml +++ b/Alkitab/src/main/res/values-pl/strings.xml @@ -366,6 +366,7 @@ Błąd sieci podczas pobierania ^1. Błąd serwera podczas pobierania ^1. Tryb nocny + Postępuj zgodnie z tematem systemu Inne kolory Porównaj Wystąpił błąd podczas odtwarzania pieśni: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-pt-rBR/strings.xml b/Alkitab/src/main/res/values-pt-rBR/strings.xml index 75aafb980..68d90a5bc 100644 --- a/Alkitab/src/main/res/values-pt-rBR/strings.xml +++ b/Alkitab/src/main/res/values-pt-rBR/strings.xml @@ -366,6 +366,7 @@ Erro de rede ao fazer o download ^1. Erro do Servidor ao realizar o download ^1. Modo noturno + Seguir o tema do sistema Outras cores Comparar Ocorreu um erro ao reproduzir esta canção: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-pt/strings.xml b/Alkitab/src/main/res/values-pt/strings.xml index 39bb8b42d..87bce6a9d 100644 --- a/Alkitab/src/main/res/values-pt/strings.xml +++ b/Alkitab/src/main/res/values-pt/strings.xml @@ -363,6 +363,7 @@ Erro do network baixando ^1. Erro do servidor baixando ^1. Modo de noite + Seguir o tema do sistema Outras cores Comparar Um erro ocorre quando toca esta música: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-ro/strings.xml b/Alkitab/src/main/res/values-ro/strings.xml index 5140ed59c..67b683fbf 100644 --- a/Alkitab/src/main/res/values-ro/strings.xml +++ b/Alkitab/src/main/res/values-ro/strings.xml @@ -366,6 +366,7 @@ Erori de internet la descărcare ^1. Eroare de server la descărcarea ^1. Mod nocturn + Urmează tema sistemului Alte culori Compară O eroare a fost întâlnită în timpul redării acestui cântec: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-ru/strings.xml b/Alkitab/src/main/res/values-ru/strings.xml index f2fa0a8ef..2f787ce78 100644 --- a/Alkitab/src/main/res/values-ru/strings.xml +++ b/Alkitab/src/main/res/values-ru/strings.xml @@ -366,6 +366,7 @@ Сетевая ошибка при скачивании ^1. Ошибка сервера при скачивании ^1. Ночной режим + Следуйте системной теме Другие цвета Сравнить Произошла ошибка при воспроизведении этой песни : %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-th/strings.xml b/Alkitab/src/main/res/values-th/strings.xml index 71bcbd8a0..6c077d82b 100644 --- a/Alkitab/src/main/res/values-th/strings.xml +++ b/Alkitab/src/main/res/values-th/strings.xml @@ -363,6 +363,7 @@ เกิดการผิดพลาดขณะดาวน์โหลด เหตุเชื่อมต่อเครือข่ายไม่สำเร็จ ^1. เกิดการผิดพลาดขณะเรียกข้อมูลกลับคืนจากเซิร์ฟเวอร์ ^1. โหมดกลางคืน + ติดตามธีมของระบบ สีอื่นๆ เทียบ เกิดการผิดพลาดระหว่างที่เปิดฟังเพลงนี้: %1$d, %2$d ค่ะ diff --git a/Alkitab/src/main/res/values-tl/strings.xml b/Alkitab/src/main/res/values-tl/strings.xml index 15a5245c2..18b205c62 100644 --- a/Alkitab/src/main/res/values-tl/strings.xml +++ b/Alkitab/src/main/res/values-tl/strings.xml @@ -362,6 +362,7 @@ Network error habang dina-download ^1. Server error habang dina-download ^1. Night mode + Sundin ang tema ng system Ibang mga kulay Kumpara Isang error ang na-encounter habang pinapatugtog ang kantang ito: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-tr/strings.xml b/Alkitab/src/main/res/values-tr/strings.xml index b23fafb58..f600847c9 100644 --- a/Alkitab/src/main/res/values-tr/strings.xml +++ b/Alkitab/src/main/res/values-tr/strings.xml @@ -366,6 +366,7 @@ İndirme yaparken ağ hatası ^1. İndirme yaparken sunucu hatası ^1. Gece modu + Sistem temasını takip et Diğer renkler Karşılaştır Bu şarkıyı çalarken bir hata oluştu: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-vi/strings.xml b/Alkitab/src/main/res/values-vi/strings.xml index bdf41d934..f1c7fbe94 100644 --- a/Alkitab/src/main/res/values-vi/strings.xml +++ b/Alkitab/src/main/res/values-vi/strings.xml @@ -366,6 +366,7 @@ Hệ thống bị trục trặc trong lúc tải về máy. Máy chủ bị trục trặc trong lúc tải về máy. Chế độ ban đêm + Theo chủ đề hệ thống Màu sắc khác So sánh Một lỗi xảy ra khi chơi bài hát này: %1$d, %2$d. diff --git a/Alkitab/src/main/res/values-zh-rCN/strings.xml b/Alkitab/src/main/res/values-zh-rCN/strings.xml index c3d43b9cd..fb00726aa 100644 --- a/Alkitab/src/main/res/values-zh-rCN/strings.xml +++ b/Alkitab/src/main/res/values-zh-rCN/strings.xml @@ -366,6 +366,7 @@ 下载^1时网络出现错误。 下载^1时服务出现错误。 夜间模式 + 遵循系统主题 其他颜色 比较 播放歌曲%1$d, %2$d的时候遇到问题。 diff --git a/Alkitab/src/main/res/values-zh-rTW/strings.xml b/Alkitab/src/main/res/values-zh-rTW/strings.xml index 3ed7f3882..49d0779be 100644 --- a/Alkitab/src/main/res/values-zh-rTW/strings.xml +++ b/Alkitab/src/main/res/values-zh-rTW/strings.xml @@ -361,6 +361,7 @@ 下載^1時出現網絡錯誤。 下載^1時出現服務器錯誤。 夜間模式 + 遵循系統主題 其他顏色 比較 播放歌曲%1$d, %2$d的時候遇到問題。 diff --git a/Alkitab/src/main/res/values/strings.xml b/Alkitab/src/main/res/values/strings.xml index 25d6cc039..663f4e8cb 100644 --- a/Alkitab/src/main/res/values/strings.xml +++ b/Alkitab/src/main/res/values/strings.xml @@ -392,6 +392,7 @@ Server error when downloading ^1. Night mode + Follow system theme Other colors Compare An error was encountered when playing this song: %1$d, %2$d. From 9a0c421f84fe7b219d2c5c2a9d6f66139a84d763 Mon Sep 17 00:00:00 2001 From: Matthew Miner Date: Mon, 16 Oct 2023 20:12:30 -0500 Subject: [PATCH 2/3] Update night mode on system change --- Alkitab/src/main/AndroidManifest.xml | 1 + .../java/yuku/alkitab/base/IsiActivity.kt | 9 +++++++++ .../yuku/alkitab/base/widget/LeftDrawer.java | 19 ++++++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Alkitab/src/main/AndroidManifest.xml b/Alkitab/src/main/AndroidManifest.xml index a605a35ca..aebda8baa 100644 --- a/Alkitab/src/main/AndroidManifest.xml +++ b/Alkitab/src/main/AndroidManifest.xml @@ -43,6 +43,7 @@ diff --git a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt index 667ccaa48..c066296ad 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt @@ -136,6 +136,7 @@ private const val EXTRA_verseUrl = "verseUrl" private const val INSTANCE_STATE_ari = "ari" class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { + private lateinit var mPrevConfig: Configuration var uncheckVersesWhenActionModeDestroyed = true var needsRestart = false // whether this activity needs to be restarted @@ -1711,6 +1712,14 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { return arrayOf(res0.toString(), res1.toString()) } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + + leftDrawer.checkSystemTheme() + + mPrevConfig = Configuration(newConfig) + } + fun applyPreferences() { // make sure S applied variables are set first S.recalculateAppliedValuesBasedOnPreferences() diff --git a/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java b/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java index a49ce3b6c..1afadf9b7 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java @@ -322,13 +322,7 @@ protected void onFinishInflate() { bCurrentReadingClose = findViewById(R.id.bCurrentReadingClose); bCurrentReadingReference = findViewById(R.id.bCurrentReadingReference); - final boolean followSystemTheme = Preferences.getBoolean(Prefkey.follow_system_theme, true); - if (followSystemTheme) { - final int systemTheme = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - cNightMode.setChecked(!isInEditMode() && systemTheme == Configuration.UI_MODE_NIGHT_YES); - } else { - cNightMode.setChecked(!isInEditMode() && Preferences.getBoolean(Prefkey.is_night_mode, false)); - } + final boolean followSystemTheme = checkSystemTheme(); cNightMode.setEnabled(!followSystemTheme); cFollowSystemTheme.setChecked(followSystemTheme); @@ -386,6 +380,17 @@ protected void onFinishInflate() { App.getLbm().registerReceiver(currentReadingChangeReceiver, filter); } + public boolean checkSystemTheme() { + final boolean followSystemTheme = Preferences.getBoolean(Prefkey.follow_system_theme, true); + if (followSystemTheme) { + final int systemTheme = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + cNightMode.setChecked(!isInEditMode() && systemTheme == Configuration.UI_MODE_NIGHT_YES); + } else { + cNightMode.setChecked(!isInEditMode() && Preferences.getBoolean(Prefkey.is_night_mode, false)); + } + return followSystemTheme; + } + @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); From 4b1b6e40363f5388c938d667b4892d35080339d9 Mon Sep 17 00:00:00 2001 From: Matthew Miner Date: Sun, 2 Jun 2024 17:34:03 -0500 Subject: [PATCH 3/3] Add night mode to devotions and songs --- Alkitab/src/main/AndroidManifest.xml | 9 +- Alkitab/src/main/assets/templates/song.css | 5 + Alkitab/src/main/assets/templates/song.html | 8 +- .../java/yuku/alkitab/base/IsiActivity.kt | 105 ++------------ Alkitab/src/main/java/yuku/alkitab/base/S.kt | 1 + .../alkitab/base/ac/DevotionActivity.java | 41 ++++-- .../alkitab/base/ac/PatchTextActivity.java | 17 +++ .../alkitab/base/ac/ReadingPlanActivity.java | 12 ++ .../base/ac/base/BaseLeftDrawerActivity.java | 21 --- .../base/ac/base/BaseLeftDrawerActivity.kt | 137 ++++++++++++++++++ .../yuku/alkitab/base/widget/LeftDrawer.java | 123 +++++++++------- .../base/widget/TextAppearancePanel.java | 4 +- .../java/yuku/alkitab/songs/SongFragment.kt | 13 ++ .../yuku/alkitab/songs/SongViewActivity.kt | 41 ++++-- .../res/layout/activity_devotion_content.xml | 55 ++++--- .../res/layout/activity_song_view_content.xml | 71 +++++---- .../main/res/layout/left_drawer_devotion.xml | 5 + .../res/layout/left_drawer_display_button.xml | 16 ++ .../left_drawer_night_mode_switches.xml | 34 +++++ .../src/main/res/layout/left_drawer_songs.xml | 5 + .../src/main/res/layout/left_drawer_text.xml | 39 +---- 21 files changed, 461 insertions(+), 301 deletions(-) delete mode 100644 Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.java create mode 100644 Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.kt create mode 100644 Alkitab/src/main/res/layout/left_drawer_display_button.xml create mode 100644 Alkitab/src/main/res/layout/left_drawer_night_mode_switches.xml diff --git a/Alkitab/src/main/AndroidManifest.xml b/Alkitab/src/main/AndroidManifest.xml index aebda8baa..05557c7ab 100644 --- a/Alkitab/src/main/AndroidManifest.xml +++ b/Alkitab/src/main/AndroidManifest.xml @@ -249,7 +249,8 @@ android:windowSoftInputMode="adjustResize" /> + android:label="@string/menuDevotion" + android:configChanges="colorMode|uiMode"> @@ -276,7 +277,8 @@ android:windowSoftInputMode="adjustResize|stateHidden" /> + android:label="@string/sn_songs_activity_title" + android:configChanges="colorMode|uiMode" /> @@ -286,7 +288,8 @@ + android:windowSoftInputMode="adjustResize" + android:configChanges="colorMode|uiMode" /> diff --git a/Alkitab/src/main/assets/templates/song.css b/Alkitab/src/main/assets/templates/song.css index 901bc63ed..191c21fdf 100644 --- a/Alkitab/src/main/assets/templates/song.css +++ b/Alkitab/src/main/assets/templates/song.css @@ -1,4 +1,9 @@ +body { + margin: 0; + padding: 24px 16px; +} + .code { font-family: sans-serif; font-weight: bold; diff --git a/Alkitab/src/main/assets/templates/song.html b/Alkitab/src/main/assets/templates/song.html index 804d21696..ec043973a 100644 --- a/Alkitab/src/main/assets/templates/song.html +++ b/Alkitab/src/main/assets/templates/song.html @@ -21,19 +21,19 @@ function body_load() { var test_tobehidden = document.getElementById('test_tobehidden'); var test_line = document.getElementById('test_line'); - + var h = test_line.clientHeight; var lh = (h * {{$line_spacing_mult}}) + 'px'; - + var lines = document.getElementsByClassName('line'); for (var i = 0; i < lines.length; i++) lines[i].style.lineHeight = lh; - + test_tobehidden.parentNode.removeChild(test_tobehidden); } - +
{{div:code}} {{div:title}} diff --git a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt index c066296ad..000822148 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt @@ -9,7 +9,6 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager -import android.content.res.Configuration import android.graphics.Point import android.net.Uri import android.os.Bundle @@ -29,7 +28,6 @@ import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver import android.view.WindowManager -import android.widget.FrameLayout import android.widget.ImageButton import android.widget.LinearLayout import android.widget.TextView @@ -136,7 +134,6 @@ private const val EXTRA_verseUrl = "verseUrl" private const val INSTANCE_STATE_ari = "ari" class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { - private lateinit var mPrevConfig: Configuration var uncheckVersesWhenActionModeDestroyed = true var needsRestart = false // whether this activity needs to be restarted @@ -244,10 +241,10 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { } private lateinit var drawerLayout: DrawerLayout - lateinit var leftDrawer: LeftDrawer.Text + override lateinit var leftDrawer: LeftDrawer.Text - private lateinit var overlayContainer: FrameLayout - lateinit var root: ViewGroup + override lateinit var overlayContainer: ViewGroup + override lateinit var root: ViewGroup lateinit var toolbar: Toolbar private lateinit var nontoolbar: View lateinit var lsSplit0: VersesController @@ -293,7 +290,6 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { var actionMode: ActionMode? = null private var dictionaryMode = false - var textAppearancePanel: TextAppearancePanel? = null /** * The following "esvsbasal" thing is a personal thing by yuku that doesn't matter to anyone else. @@ -1712,22 +1708,9 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { return arrayOf(res0.toString(), res1.toString()) } - override fun onConfigurationChanged(newConfig: Configuration) { - super.onConfigurationChanged(newConfig) - - leftDrawer.checkSystemTheme() - - mPrevConfig = Configuration(newConfig) - } - - fun applyPreferences() { - // make sure S applied variables are set first - S.recalculateAppliedValuesBasedOnPreferences() - - // apply background color, and clear window background to prevent overdraw - window.setBackgroundDrawableResource(android.R.color.transparent) + override fun applyPreferences() { + super.applyPreferences() val backgroundColor = S.applied().backgroundColor - root.setBackgroundColor(backgroundColor) // scrollbar must be visible! val thumb = if (ColorUtils.calculateLuminance(backgroundColor) > 0.5) { @@ -2025,60 +2008,10 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { } } - private fun setShowTextAppearancePanel(yes: Boolean) { - if (!yes) { - textAppearancePanel?.hide() - textAppearancePanel = null - return - } - - if (textAppearancePanel == null) { // not showing yet - textAppearancePanel = TextAppearancePanel( - this, - overlayContainer, - object : TextAppearancePanel.Listener { - override fun onValueChanged() { - applyPreferences() - } - - override fun onCloseButtonClick() { - textAppearancePanel?.hide() - textAppearancePanel = null - } - }, - RequestCodes.FromActivity.TextAppearanceGetFonts, - RequestCodes.FromActivity.TextAppearanceCustomColors - ) - configureTextAppearancePanelForSplitVersion() - textAppearancePanel?.show() - } - } - - private fun setNightMode(yes: Boolean) { - val previousValue = Preferences.getBoolean(Prefkey.is_night_mode, false) - if (previousValue == yes) return - - Preferences.setBoolean(Prefkey.is_night_mode, yes) - - applyPreferences() - applyNightModeColors() - - textAppearancePanel?.displayValues() - - App.getLbm().sendBroadcast(Intent(ACTION_NIGHT_MODE_CHANGED)) - } - - private fun setFollowSystemTheme(yes: Boolean, cNightMode: SwitchCompat) { - val previousValue = Preferences.getBoolean(Prefkey.follow_system_theme, true) - if (previousValue == yes) return - - Preferences.setBoolean(Prefkey.follow_system_theme, yes) - - if (yes) { - val systemTheme = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - cNightMode.isChecked = systemTheme == Configuration.UI_MODE_NIGHT_YES - setNightMode(systemTheme == Configuration.UI_MODE_NIGHT_YES) - } + override fun createTextAppearancePanel(): TextAppearancePanel? { + val panel = super.createTextAppearancePanel() + configureTextAppearancePanelForSplitVersion() + return panel } private fun openVersionsDialog() { @@ -2415,10 +2348,6 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { return super.onKeyUp(keyCode, event) } - override fun getLeftDrawer(): LeftDrawer { - return leftDrawer - } - fun bLeft_click() { Tracker.trackEvent("nav_left_click") val currentBook = activeSplit0.book @@ -2831,27 +2760,11 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { startActivity(MarkersActivity.createIntent()) } - override fun bDisplay_click() { - Tracker.trackEvent("left_drawer_display_click") - setShowTextAppearancePanel(textAppearancePanel == null) - } - override fun cFullScreen_checkedChange(isChecked: Boolean) { Tracker.trackEvent("left_drawer_full_screen_click") setFullScreen(isChecked) } - override fun cNightMode_checkedChange(isChecked: Boolean) { - Tracker.trackEvent("left_drawer_night_mode_click") - setNightMode(isChecked) - } - - override fun cFollowSystemTheme_checkedChange(isChecked: Boolean, cNightMode: SwitchCompat) { - Tracker.trackEvent("left_drawer_follow_system_theme_click") - cNightMode.isEnabled = !isChecked - setFollowSystemTheme(isChecked, cNightMode) - } - override fun cSplitVersion_checkedChange(cSplitVersion: SwitchCompat, isChecked: Boolean) { Tracker.trackEvent("left_drawer_split_click") if (isChecked) { diff --git a/Alkitab/src/main/java/yuku/alkitab/base/S.kt b/Alkitab/src/main/java/yuku/alkitab/base/S.kt index 1f8c57971..edfcb3ee7 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/S.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/S.kt @@ -167,6 +167,7 @@ object S { return null // not known } + @JvmStatic fun recalculateAppliedValuesBasedOnPreferences() { CalculatedDimensionsHolder.applied = calculateDimensionsFromPreferences() } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/DevotionActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/DevotionActivity.java index 66af9101c..36a93e281 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/DevotionActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/DevotionActivity.java @@ -14,6 +14,8 @@ import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; +import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.TextView; import androidx.annotation.Keep; import androidx.annotation.NonNull; @@ -107,11 +109,22 @@ public void cbKind_itemSelected(final DevotionKind kind) { display(); } + @NonNull @Override protected LeftDrawer getLeftDrawer() { return leftDrawer; } + @Nullable + @Override + protected ViewGroup getOverlayContainer() { return overlayContainer; } + + @NonNull + @Override + public DrawerLayout getRoot() { + return drawerLayout; + } + public enum DevotionKind { SH("sh", "Santapan Harian", "Persekutuan Pembaca Alkitab") { @Override @@ -210,6 +223,7 @@ public int getPrefetchDays() { DrawerLayout drawerLayout; LeftDrawer.Devotion leftDrawer; + FrameLayout overlayContainer; TwofingerLinearLayout root; TextView lContent; NestedScrollView scrollContent; @@ -305,6 +319,7 @@ protected void onCreate(Bundle savedInstanceState) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); + overlayContainer = findViewById(R.id.overlayContainer); root = findViewById(R.id.root); lContent = findViewById(R.id.lContent); scrollContent = findViewById(R.id.scrollContent); @@ -326,18 +341,7 @@ protected void onCreate(Bundle savedInstanceState) { protected void onStart() { super.onStart(); - final S.CalculatedDimensions applied = S.applied(); - - { // apply background color, and clear window background to prevent overdraw - getWindow().setBackgroundDrawableResource(android.R.color.transparent); - scrollContent.setBackgroundColor(applied.backgroundColor); - } - - // text formats - lContent.setTextColor(applied.fontColor); - lContent.setTypeface(applied.fontFace, applied.fontBold); - lContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, applied.fontSize2dp); - lContent.setLineSpacing(0, applied.lineSpacingMult); + applyPreferences(); final Rect padding = SettingsActivity.getPaddingBasedOnPreferences(); lContent.setPadding(padding.left, padding.top, padding.right, padding.bottom); @@ -347,6 +351,19 @@ protected void onStart() { App.getLbm().registerReceiver(br, new IntentFilter(DevotionDownloader.ACTION_DOWNLOADED)); } + @Override + public void applyPreferences() { + super.applyPreferences(); + + final S.CalculatedDimensions applied = S.applied(); + + // text formats + lContent.setTextColor(applied.fontColor); + lContent.setTypeface(applied.fontFace, applied.fontBold); + lContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, applied.fontSize2dp); + lContent.setLineSpacing(0, applied.lineSpacingMult); + } + @Override protected void onStop() { super.onStop(); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java index 3fa6b8bf9..c4b7c06e9 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java @@ -1,6 +1,7 @@ package yuku.alkitab.base.ac; import android.content.Intent; +import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.util.TypedValue; @@ -14,9 +15,11 @@ import com.example.android.wizardpager.AlkitabFeedbackActivity; import java.util.LinkedList; import name.fraser.neil.plaintext.diff_match_patch; +import yuku.afw.storage.Preferences; import yuku.alkitab.base.App; import yuku.alkitab.base.S; import yuku.alkitab.base.ac.base.BaseActivity; +import yuku.alkitab.base.storage.Prefkey; import yuku.alkitab.base.widget.MaterialDialogJavaHelper; import yuku.alkitab.debug.R; @@ -96,6 +99,20 @@ public boolean onOptionsItemSelected(final MenuItem item) { return super.onOptionsItemSelected(item); } + @Override + public void onConfigurationChanged(@NonNull Configuration newConfig) { + super.onConfigurationChanged(newConfig); + final boolean followSystemTheme = Preferences.getBoolean(Prefkey.follow_system_theme, true); + if (followSystemTheme) { + Preferences.setBoolean(Prefkey.is_night_mode, (newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES); + S.recalculateAppliedValuesBasedOnPreferences(); + applyNightModeColors(); + final S.CalculatedDimensions applied = S.applied(); + tBody.setTextColor(applied.fontColor); + tBody.setBackgroundColor(applied.backgroundColor); + } + } + void menuSend_click() { final String baseText = baseBody.toString(); final String currentText = tBody.getText().toString(); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java index 9ef857ab5..217285e40 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java @@ -24,6 +24,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.Toolbar; @@ -539,11 +540,22 @@ public void bRestart_click() { leftDrawer.closeDrawer(); } + @NonNull @Override protected LeftDrawer getLeftDrawer() { return leftDrawer; } + @Nullable + @Override + protected ViewGroup getOverlayContainer() { return null; } + + @NonNull + @Override + public DrawerLayout getRoot() { + return drawerLayout; + } + private void openDownloadReadingPlanPage() { startActivityForResult( HelpActivity.createIntent( diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.java deleted file mode 100644 index 4e8f4a5b1..000000000 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.java +++ /dev/null @@ -1,21 +0,0 @@ -package yuku.alkitab.base.ac.base; - -import android.view.KeyEvent; -import yuku.alkitab.base.widget.LeftDrawer; - -public abstract class BaseLeftDrawerActivity extends BaseActivity { - @Override - public boolean onKeyUp(final int keyCode, final KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_MENU) { - openOrCloseLeftDrawer(); - return true; - } - return super.onKeyUp(keyCode, event); - } - - private void openOrCloseLeftDrawer() { - getLeftDrawer().toggleDrawer(); - } - - protected abstract LeftDrawer getLeftDrawer(); -} diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.kt b/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.kt new file mode 100644 index 000000000..c8e6d5aeb --- /dev/null +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseLeftDrawerActivity.kt @@ -0,0 +1,137 @@ +package yuku.alkitab.base.ac.base + +import android.content.Intent +import android.content.pm.ActivityInfo +import android.content.res.Configuration +import android.view.KeyEvent +import android.view.ViewGroup +import androidx.appcompat.widget.SwitchCompat +import yuku.afw.storage.Preferences +import yuku.alkitab.base.App +import yuku.alkitab.base.S +import yuku.alkitab.base.storage.Prefkey +import yuku.alkitab.base.util.RequestCodes +import yuku.alkitab.base.widget.LeftDrawer +import yuku.alkitab.base.widget.TextAppearancePanel +import yuku.alkitab.tracking.Tracker + + +abstract class BaseLeftDrawerActivity : BaseActivity(), LeftDrawer.Listener { + protected abstract val overlayContainer: ViewGroup? + private lateinit var mPrevConfig: Configuration + protected var textAppearancePanel: TextAppearancePanel? = null + protected abstract val leftDrawer: LeftDrawer + abstract val root: ViewGroup + + override fun onCreate(savedInstanceState: android.os.Bundle?) { + super.onCreate(savedInstanceState) + mPrevConfig = Configuration(resources.configuration) + } + + override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean { + if (keyCode == KeyEvent.KEYCODE_MENU) { + openOrCloseLeftDrawer() + return true + } + return super.onKeyUp(keyCode, event) + } + + private fun openOrCloseLeftDrawer() { + leftDrawer.toggleDrawer() + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + if (newConfig.diff(mPrevConfig) and ActivityInfo.CONFIG_UI_MODE != 0) { + leftDrawer.checkSystemTheme() + mPrevConfig = Configuration(newConfig) + } + } + + open fun applyPreferences() { + // make sure S applied variables are set first + S.recalculateAppliedValuesBasedOnPreferences() + + // apply background color, and clear window background to prevent overdraw + window.setBackgroundDrawableResource(android.R.color.transparent) + val backgroundColor = S.applied().backgroundColor + root.setBackgroundColor(backgroundColor) + } + + override fun cNightMode_checkedChange(isChecked: Boolean) { + Tracker.trackEvent("left_drawer_night_mode_click") + setNightMode(isChecked) + } + + override fun cFollowSystemTheme_checkedChange(isChecked: Boolean, cNightMode: SwitchCompat) { + Tracker.trackEvent("left_drawer_follow_system_theme_click") + cNightMode.setEnabled(!isChecked) + setFollowSystemTheme(isChecked, cNightMode) + } + + private fun setNightMode(yes: Boolean) { + val previousValue = Preferences.getBoolean(Prefkey.is_night_mode, false) + if (previousValue == yes) return + + Preferences.setBoolean(Prefkey.is_night_mode, yes) + + applyPreferences() + applyNightModeColors() + + textAppearancePanel?.displayValues() + + App.getLbm().sendBroadcast(Intent(ACTION_NIGHT_MODE_CHANGED)) + } + + private fun setFollowSystemTheme(yes: Boolean, cNightMode: SwitchCompat) { + Preferences.setBoolean(Prefkey.follow_system_theme, yes) + + if (yes) { + val systemTheme = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + cNightMode.isChecked = systemTheme == Configuration.UI_MODE_NIGHT_YES + setNightMode(systemTheme == Configuration.UI_MODE_NIGHT_YES) + } + } + + private fun setShowTextAppearancePanel(yes: Boolean) { + if (!yes) { + textAppearancePanel?.hide() + textAppearancePanel = null + return + } + + if (textAppearancePanel == null) { // not showing yet + textAppearancePanel = createTextAppearancePanel() + textAppearancePanel?.show() + } + } + + protected open fun createTextAppearancePanel(): TextAppearancePanel? { + if (overlayContainer == null) return null + return TextAppearancePanel( + this, + overlayContainer, + object : TextAppearancePanel.Listener { + override fun onValueChanged() { + applyPreferences() + } + + override fun onCloseButtonClick() { + textAppearancePanel?.hide() + textAppearancePanel = null + } + }, + RequestCodes.FromActivity.TextAppearanceGetFonts, + RequestCodes.FromActivity.TextAppearanceCustomColors + ) + } + + override fun bDisplay_click() { + Tracker.trackEvent("left_drawer_display_click") + setShowTextAppearancePanel(textAppearancePanel == null) + } + + companion object { + const val ACTION_NIGHT_MODE_CHANGED = "yuku.alkitab.base.IsiActivity.action.NIGHT_MODE_CHANGED" + } +} diff --git a/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java b/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java index 1afadf9b7..fefc302c5 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/widget/LeftDrawer.java @@ -57,6 +57,7 @@ public abstract class LeftDrawer extends NestedScrollView { TextView bDevotion; TextView bReadingPlan; TextView bSongs; + View bDisplay; View bSettings; View bHelp; @@ -64,10 +65,36 @@ public abstract class LeftDrawer extends NestedScrollView { final Activity activity; // for closing drawer DrawerLayout drawerLayout; + SwitchCompat cNightMode; + SwitchCompat cFollowSystemTheme; + final Listener listener; + CompoundButton.OnCheckedChangeListener cNightMode_checkedChange = new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { + assert listener != null; + listener.cNightMode_checkedChange(isChecked); + } + }; + CompoundButton.OnCheckedChangeListener cFollowSystemTheme_checkedChange = new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { + assert listener != null; + listener.cFollowSystemTheme_checkedChange(isChecked, cNightMode); + } + }; + + public interface Listener { + void bDisplay_click(); + + void cNightMode_checkedChange(boolean isChecked); + + void cFollowSystemTheme_checkedChange(boolean isChecked, SwitchCompat cNightMode); + } public LeftDrawer(final Context context, final AttributeSet attrs) { super(context, attrs); activity = isInEditMode() ? null : (Activity) context; + listener = (Listener) context; } @Override @@ -83,6 +110,9 @@ protected void onFinishInflate() { bDevotion = findViewById(R.id.bDevotion); bReadingPlan = findViewById(R.id.bReadingPlan); bSongs = findViewById(R.id.bSongs); + bDisplay = findViewById(R.id.bDisplay); + cNightMode = findViewById(R.id.cNightMode); + cFollowSystemTheme = findViewById(R.id.cFollowSystemTheme); bSettings = findViewById(R.id.bSettings); bHelp = findViewById(R.id.bHelp); @@ -117,6 +147,19 @@ protected void onFinishInflate() { closeDrawer(); }); + bDisplay.setOnClickListener(v -> { + listener.bDisplay_click(); + closeDrawer(); + }); + + if (cNightMode != null) { + cNightMode.setOnCheckedChangeListener(cNightMode_checkedChange); + } + + if (cFollowSystemTheme != null) { + cFollowSystemTheme.setOnCheckedChangeListener(cFollowSystemTheme_checkedChange); + } + bSettings.setOnClickListener(v -> { bSettings_click(); closeDrawer(); @@ -128,6 +171,16 @@ protected void onFinishInflate() { }); } + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + + if (cFollowSystemTheme != null) { + final boolean followSystemTheme = checkSystemTheme(); + cFollowSystemTheme.setChecked(followSystemTheme); + } + } + void setDrawerItemSelected(@NonNull TextView drawerItem) { final int selectedTextColor = ResourcesCompat.getColor(getResources(), R.color.accent, getContext().getTheme()); drawerItem.setTextColor(selectedTextColor); @@ -218,6 +271,17 @@ void bDevotion_click() { } } + public boolean checkSystemTheme() { + final boolean followSystemTheme = Preferences.getBoolean(Prefkey.follow_system_theme, true); + if (followSystemTheme) { + final int systemTheme = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + cNightMode.setChecked(!isInEditMode() && systemTheme == Configuration.UI_MODE_NIGHT_YES); + } else { + cNightMode.setChecked(!isInEditMode() && Preferences.getBoolean(Prefkey.is_night_mode, false)); + } + return followSystemTheme; + } + /** * This clears all activity on this stack and starts {@link yuku.alkitab.base.IsiActivity}. */ @@ -229,17 +293,11 @@ void bBible_click() { } public static class Text extends LeftDrawer { - public interface Listener { + public interface Listener extends LeftDrawer.Listener { void bMarkers_click(); - void bDisplay_click(); - void cFullScreen_checkedChange(boolean isChecked); - void cNightMode_checkedChange(boolean isChecked); - - void cFollowSystemTheme_checkedChange(boolean isChecked, final SwitchCompat cNightMode); - void cSplitVersion_checkedChange(final SwitchCompat cSplitVersion, boolean isChecked); void bProgressMarkList_click(); @@ -258,10 +316,7 @@ public interface Handle { } View bMarkers; - View bDisplay; SwitchCompat cFullScreen; - SwitchCompat cNightMode; - SwitchCompat cFollowSystemTheme; SwitchCompat cSplitVersion; View bProgressMarkList; @@ -307,8 +362,6 @@ protected void onFinishInflate() { bMarkers = findViewById(R.id.bMarkers); bDisplay = findViewById(R.id.bDisplay); cFullScreen = findViewById(R.id.cFullScreen); - cNightMode = findViewById(R.id.cNightMode); - cFollowSystemTheme = findViewById(R.id.cFollowSystemTheme); cSplitVersion = findViewById(R.id.cSplitVersion); bProgressMarkList = findViewById(R.id.bProgressMarkList); @@ -322,10 +375,6 @@ protected void onFinishInflate() { bCurrentReadingClose = findViewById(R.id.bCurrentReadingClose); bCurrentReadingReference = findViewById(R.id.bCurrentReadingReference); - final boolean followSystemTheme = checkSystemTheme(); - cNightMode.setEnabled(!followSystemTheme); - cFollowSystemTheme.setChecked(followSystemTheme); - bProgressMarkList.setOnClickListener(v -> listener.bProgressMarkList_click()); final View[] views = new View[]{bProgress1, bProgress2, bProgress3, bProgress4, bProgress5}; @@ -353,17 +402,8 @@ protected void onFinishInflate() { closeDrawer(); }); - bDisplay.setOnClickListener(v -> { - listener.bDisplay_click(); - closeDrawer(); - }); - cFullScreen.setOnCheckedChangeListener(cFullScreen_checkedChange); - cNightMode.setOnCheckedChangeListener(cNightMode_checkedChange); - - cFollowSystemTheme.setOnCheckedChangeListener(cFollowSystemTheme_checkedChange); - cSplitVersion.setOnCheckedChangeListener(cSplitVersion_checkedChange); bCurrentReadingClose.setOnClickListener(v -> listener.bCurrentReadingClose_click()); @@ -380,17 +420,6 @@ protected void onFinishInflate() { App.getLbm().registerReceiver(currentReadingChangeReceiver, filter); } - public boolean checkSystemTheme() { - final boolean followSystemTheme = Preferences.getBoolean(Prefkey.follow_system_theme, true); - if (followSystemTheme) { - final int systemTheme = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - cNightMode.setChecked(!isInEditMode() && systemTheme == Configuration.UI_MODE_NIGHT_YES); - } else { - cNightMode.setChecked(!isInEditMode() && Preferences.getBoolean(Prefkey.is_night_mode, false)); - } - return followSystemTheme; - } - @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); @@ -427,20 +456,6 @@ public void onCheckedChanged(final CompoundButton buttonView, final boolean isCh } }; - CompoundButton.OnCheckedChangeListener cNightMode_checkedChange = new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { - listener.cNightMode_checkedChange(isChecked); - } - }; - - CompoundButton.OnCheckedChangeListener cFollowSystemTheme_checkedChange = new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { - listener.cFollowSystemTheme_checkedChange(isChecked, cNightMode); - } - }; - CompoundButton.OnCheckedChangeListener cSplitVersion_checkedChange = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { @@ -464,7 +479,7 @@ public static class Devotion extends LeftDrawer { DevotionKindAdapter adapter; - public interface Listener { + public interface Listener extends LeftDrawer.Listener { void bPrev_click(); void bNext_click(); @@ -520,7 +535,6 @@ protected void onFinishInflate() { bNext = findViewById(R.id.bNext); bReload = findViewById(R.id.bReload); - cbKind.setAdapter(adapter = new DevotionKindAdapter()); cbKind.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override @@ -533,7 +547,6 @@ public void onNothingSelected(final AdapterView parent) { } }); - bPrev.setOnClickListener(v -> listener.bPrev_click()); bNext.setOnClickListener(v -> listener.bNext_click()); @@ -605,7 +618,7 @@ public int getPositionForKind(final DevotionActivity.DevotionKind kind) { } public static class ReadingPlan extends LeftDrawer { - public interface Listener { + public interface Listener extends LeftDrawer.Listener { void bRestart_click(); } @@ -664,7 +677,7 @@ public void configure(T listener, DrawerLayout d } public static class Songs extends LeftDrawer { - public interface Listener { + public interface Listener extends LeftDrawer.Listener { void songKeypadButton_click(View v); void songBookSelected(String name); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.java b/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.java index 050fb3ba8..f4879d3c1 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.java @@ -43,7 +43,7 @@ public interface Listener { } final Activity activity; - final FrameLayout parent; + final ViewGroup parent; final Listener listener; final View content; final int reqcodeGetFonts; @@ -67,7 +67,7 @@ public interface Listener { String splitVersionId; String splitVersionLongName; - public TextAppearancePanel(Activity activity, FrameLayout parent, Listener listener, int reqcodeGetFonts, int reqcodeCustomColors) { + public TextAppearancePanel(Activity activity, ViewGroup parent, Listener listener, int reqcodeGetFonts, int reqcodeCustomColors) { this.activity = activity; this.parent = parent; this.listener = listener; diff --git a/Alkitab/src/main/java/yuku/alkitab/songs/SongFragment.kt b/Alkitab/src/main/java/yuku/alkitab/songs/SongFragment.kt index d7cf5811b..a768f0458 100644 --- a/Alkitab/src/main/java/yuku/alkitab/songs/SongFragment.kt +++ b/Alkitab/src/main/java/yuku/alkitab/songs/SongFragment.kt @@ -120,6 +120,19 @@ class SongFragment : BaseFragment() { return template.replace("{{$$name}}", value?.toString() ?: "") } + fun updateTheme(customVars: Bundle) { + val font = if (customVars.getString("text_font") == "DEFAULT") "sans-serif" else customVars.getString("text_font") + arguments = Bundle().apply { + webview.evaluateJavascript(""" + document.body.style.backgroundColor = '${customVars.getString("background_color")}'; + document.body.style.color = '${customVars.getString("text_color")}'; + document.body.style.fontSize = '${customVars.getString("text_size")}'; + Array.from(document.getElementsByClassName('line')).forEach(x => x.style.lineHeight = '${customVars.getString("line_spacing_mult")}'); + document.body.style.fontFamily = '${font}'; + """, null) + } + } + var webViewTextZoom: Int get() { return if (view == null) 0 else webview.settings.textZoom diff --git a/Alkitab/src/main/java/yuku/alkitab/songs/SongViewActivity.kt b/Alkitab/src/main/java/yuku/alkitab/songs/SongViewActivity.kt index 7ceb0505e..bb11636ba 100644 --- a/Alkitab/src/main/java/yuku/alkitab/songs/SongViewActivity.kt +++ b/Alkitab/src/main/java/yuku/alkitab/songs/SongViewActivity.kt @@ -71,9 +71,10 @@ private const val FRAGMENT_TAG_SONG = "song" class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUrlLoadingHandler, LeftDrawer.Songs.Listener, MediaStateListener { private lateinit var drawerLayout: DrawerLayout - private lateinit var leftDrawer: LeftDrawer.Songs + override lateinit var leftDrawer: LeftDrawer.Songs - private lateinit var root: TwofingerLinearLayout + override lateinit var overlayContainer: ViewGroup + override lateinit var root: TwofingerLinearLayout private lateinit var no_song_data_container: ViewGroup private lateinit var bDownload: View private lateinit var circular_progress: View @@ -128,8 +129,6 @@ class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUr private val mediaState = MediaState() - override fun getLeftDrawer() = leftDrawer - inner class MediaState { var enabled = false @@ -268,6 +267,7 @@ class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUr } }) + overlayContainer = findViewById(R.id.overlayContainer) root = findViewById(R.id.root) no_song_data_container = findViewById(R.id.no_song_data_container) bDownload = findViewById(R.id.bDownload) @@ -315,10 +315,26 @@ class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUr override fun onStart() { super.onStart() + applyPreferences() + + // show latest viewed song + val bookName = Preferences.getString(Prefkey.song_last_bookName, null) + val code = Preferences.getString(Prefkey.song_last_code, null) + + if (bookName == null || code == null) { + displaySong(null, null, true) + } else { + displaySong(bookName, S.songDb.getSong(bookName, code), true) + } + + window.decorView.keepScreenOn = Preferences.getBoolean(getString(R.string.pref_keepScreenOn_key), resources.getBoolean(R.bool.pref_keepScreenOn_default)) + } + + override fun applyPreferences() { + super.applyPreferences() + val applied = S.applied() - // apply background color, and clear window background to prevent overdraw - window.setBackgroundDrawableResource(android.R.color.transparent) findViewById(android.R.id.content).setBackgroundColor(applied.backgroundColor) templateCustomVars.clear() @@ -341,17 +357,10 @@ class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUr } templateCustomVars.putString("text_font", fontName) - // show latest viewed song - val bookName = Preferences.getString(Prefkey.song_last_bookName, null) - val code = Preferences.getString(Prefkey.song_last_code, null) - - if (bookName == null || code == null) { - displaySong(null, null, true) - } else { - displaySong(bookName, S.songDb.getSong(bookName, code), true) + val fragment = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG_SONG) + if (fragment != null) { + (fragment as SongFragment).updateTheme(templateCustomVars) } - - window.decorView.keepScreenOn = Preferences.getBoolean(getString(R.string.pref_keepScreenOn_key), resources.getBoolean(R.bool.pref_keepScreenOn_default)) } /** diff --git a/Alkitab/src/main/res/layout/activity_devotion_content.xml b/Alkitab/src/main/res/layout/activity_devotion_content.xml index 6e147cf92..52d9ef846 100644 --- a/Alkitab/src/main/res/layout/activity_devotion_content.xml +++ b/Alkitab/src/main/res/layout/activity_devotion_content.xml @@ -1,35 +1,42 @@ - + android:layout_height="match_parent"> - + android:layout_height="match_parent" + android:orientation="vertical"> - + - - - + + + + - - \ No newline at end of file + + + \ No newline at end of file diff --git a/Alkitab/src/main/res/layout/activity_song_view_content.xml b/Alkitab/src/main/res/layout/activity_song_view_content.xml index f8594b640..d2eae6a60 100644 --- a/Alkitab/src/main/res/layout/activity_song_view_content.xml +++ b/Alkitab/src/main/res/layout/activity_song_view_content.xml @@ -1,42 +1,49 @@ - + android:layout_height="match_parent"> - + android:layout_height="match_parent" + android:orientation="vertical"> - + - + - + - + + + -