Skip to content

Commit

Permalink
Add night mode to devotions and songs
Browse files Browse the repository at this point in the history
  • Loading branch information
mminer237 committed Jun 2, 2024
1 parent 9a0c421 commit 4b1b6e4
Show file tree
Hide file tree
Showing 21 changed files with 461 additions and 301 deletions.
9 changes: 6 additions & 3 deletions Alkitab/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@
android:windowSoftInputMode="adjustResize" />
<activity
android:name="yuku.alkitab.base.ac.DevotionActivity"
android:label="@string/menuDevotion">
android:label="@string/menuDevotion"
android:configChanges="colorMode|uiMode">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="yuku.alkitab.base.IsiActivity" />
Expand All @@ -276,7 +277,8 @@
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="yuku.alkitab.songs.SongViewActivity"
android:label="@string/sn_songs_activity_title" />
android:label="@string/sn_songs_activity_title"
android:configChanges="colorMode|uiMode" />
<activity
android:name="yuku.alkitab.base.ac.SecretSettingsActivity"
android:label="Secret settings" />
Expand All @@ -286,7 +288,8 @@
<activity android:name="yuku.alkitab.base.ac.ReadingPlanActivity" />
<activity
android:name="yuku.alkitab.base.ac.PatchTextActivity"
android:windowSoftInputMode="adjustResize" />
android:windowSoftInputMode="adjustResize"
android:configChanges="colorMode|uiMode" />
<activity
android:name="yuku.alkitab.base.sync.SyncSettingsActivity"
android:label="@string/sync_status_activity_title" />
Expand Down
5 changes: 5 additions & 0 deletions Alkitab/src/main/assets/templates/song.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

body {
margin: 0;
padding: 24px 16px;
}

.code {
font-family: sans-serif;
font-weight: bold;
Expand Down
8 changes: 4 additions & 4 deletions Alkitab/src/main/assets/templates/song.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
</script>
</head>

<body onload="body_load()" style="padding: 16px 8px">
<body onload="body_load()">
<div class='song'>
{{div:code}}
{{div:title}}
Expand Down
105 changes: 9 additions & 96 deletions Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Alkitab/src/main/java/yuku/alkitab/base/S.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ object S {
return null // not known
}

@JvmStatic
fun recalculateAppliedValuesBasedOnPreferences() {
CalculatedDimensionsHolder.applied = calculateDimensionsFromPreferences()
}
Expand Down
41 changes: 29 additions & 12 deletions Alkitab/src/main/java/yuku/alkitab/base/ac/DevotionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -210,6 +223,7 @@ public int getPrefetchDays() {
DrawerLayout drawerLayout;
LeftDrawer.Devotion leftDrawer;

FrameLayout overlayContainer;
TwofingerLinearLayout root;
TextView lContent;
NestedScrollView scrollContent;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 4b1b6e4

Please sign in to comment.