Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to follow system theme & implement dark mode everywhere #106

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Alkitab/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

<activity
android:name="yuku.alkitab.base.IsiActivity"
android:configChanges="colorMode|uiMode"
yukuku marked this conversation as resolved.
Show resolved Hide resolved
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -248,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 @@ -275,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 @@ -285,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
76 changes: 9 additions & 67 deletions Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1710,14 +1708,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) {
Expand Down Expand Up @@ -2015,47 +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))
override fun createTextAppearancePanel(): TextAppearancePanel? {
val panel = super.createTextAppearancePanel()
configureTextAppearancePanelForSplitVersion()
return panel
}

private fun openVersionsDialog() {
Expand Down Expand Up @@ -2392,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 @@ -2808,21 +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 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

This file was deleted.

Loading
Loading