diff --git a/Alkitab/src/main/AndroidManifest.xml b/Alkitab/src/main/AndroidManifest.xml index a605a35ca..05557c7ab 100644 --- a/Alkitab/src/main/AndroidManifest.xml +++ b/Alkitab/src/main/AndroidManifest.xml @@ -43,6 +43,7 @@ @@ -248,7 +249,8 @@ android:windowSoftInputMode="adjustResize" /> + android:label="@string/menuDevotion" + android:configChanges="colorMode|uiMode"> @@ -275,7 +277,8 @@ android:windowSoftInputMode="adjustResize|stateHidden" /> + android:label="@string/sn_songs_activity_title" + android:configChanges="colorMode|uiMode" /> @@ -285,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 664a99d9c..dfb1b27cb 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt @@ -28,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 @@ -242,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 @@ -291,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. @@ -1728,14 +1726,9 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener { return arrayOf(res0.toString(), res1.toString()) } - 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) { @@ -2033,47 +2026,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)) + override fun createTextAppearancePanel(): TextAppearancePanel? { + val panel = super.createTextAppearancePanel() + configureTextAppearancePanelForSplitVersion() + return panel } private fun openVersionsDialog() { @@ -2410,10 +2366,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 @@ -2826,21 +2778,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 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 ee03554fc..d6779ce45 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/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..fefc302c5 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; @@ -56,6 +57,7 @@ public abstract class LeftDrawer extends NestedScrollView { TextView bDevotion; TextView bReadingPlan; TextView bSongs; + View bDisplay; View bSettings; View bHelp; @@ -63,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 @@ -82,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); @@ -116,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(); @@ -127,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); @@ -217,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}. */ @@ -228,15 +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 cSplitVersion_checkedChange(final SwitchCompat cSplitVersion, boolean isChecked); void bProgressMarkList_click(); @@ -255,9 +316,7 @@ public interface Handle { } View bMarkers; - View bDisplay; SwitchCompat cFullScreen; - SwitchCompat cNightMode; SwitchCompat cSplitVersion; View bProgressMarkList; @@ -303,7 +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); cSplitVersion = findViewById(R.id.cSplitVersion); bProgressMarkList = findViewById(R.id.bProgressMarkList); @@ -317,8 +375,6 @@ protected void onFinishInflate() { bCurrentReadingClose = findViewById(R.id.bCurrentReadingClose); bCurrentReadingReference = findViewById(R.id.bCurrentReadingReference); - cNightMode.setChecked(!isInEditMode() && Preferences.getBoolean(Prefkey.is_night_mode, false)); - bProgressMarkList.setOnClickListener(v -> listener.bProgressMarkList_click()); final View[] views = new View[]{bProgress1, bProgress2, bProgress3, bProgress4, bProgress5}; @@ -346,15 +402,8 @@ protected void onFinishInflate() { closeDrawer(); }); - bDisplay.setOnClickListener(v -> { - listener.bDisplay_click(); - closeDrawer(); - }); - cFullScreen.setOnCheckedChangeListener(cFullScreen_checkedChange); - cNightMode.setOnCheckedChangeListener(cNightMode_checkedChange); - cSplitVersion.setOnCheckedChangeListener(cSplitVersion_checkedChange); bCurrentReadingClose.setOnClickListener(v -> listener.bCurrentReadingClose_click()); @@ -407,13 +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 cSplitVersion_checkedChange = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { @@ -437,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(); @@ -493,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 @@ -506,7 +547,6 @@ public void onNothingSelected(final AdapterView parent) { } }); - bPrev.setOnClickListener(v -> listener.bPrev_click()); bNext.setOnClickListener(v -> listener.bNext_click()); @@ -578,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(); } @@ -637,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 c2f6d8d73..c7ab29a04 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"> - + - + - + - + + + -