soul-browser/sources/java/com/mycompany/app/db/book/DbBookTheme.java
KaKi87 32481a1112
Make dark mode per-site (#10)
* Make Night Mode web theme per-site with Display as default

Settings → Display still owns the global Web page Light/Dark default
(PrefWeb.L). DialogSetDark now reads/writes a per-host override via
DbBookTheme, and WebViews resolve dark mode from the site override or
the Display default (System mode still follows the system).

Bump version to 2.0.0-testing.21.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Add Default option in Night Mode web theme

DialogSetDark Web page now offers Light / Dark / Default. Default means
no per-site override (follows Settings → Display). Selecting Default
clears the host row in DbBookTheme; sites with no override show Default.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix dark site override when Display theme is light

Algorithmic darkening only applies while the app is in night mode, so a
per-site Dark override was a no-op under a light Display setting. Force the
CSS invert path when MainApp.L1 is false, clear leftover CSS when returning
to the algorithmic path, and always re-apply on navigation.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Revert "Fix dark site override when Display theme is light"

This reverts commit 0abb88e91b2337dcfc770efa4b3f75a525c93889.

* Explain and gate dark site override when Web page is light

Revert the CSS algorithmic-darkening workaround. Document under Settings →
Display → Web page that per-site Dark only works when Web page is Dark, and
grey out the Night Mode site override when PrefWeb.L is light.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix Night Mode popup guard when Web page is light

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix Night Mode grey-out polarity and update Web page hint

The PrefWeb.L check used if-eq, so Light left the site override enabled.
Use if-ne so Light forces the row disabled, and update the Display hint text.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Match Web page hint wording exactly

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Show Default when site web theme override is greyed out

When Display Web page is Light, the Night Mode site row is disabled and
must display Default rather than a stale Light/Dark override value.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix Night Mode site menu blocked when Web page is Dark

The H() early-return used if-eq, so it aborted the popup when PrefWeb.L
was Dark. Use if-ne so only Light blocks the menu.

Co-authored-by: KaKi87 <KaKi87@pm.me>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-08-11 03:59:34 +02:00

95 lines
3.5 KiB
Java

package com.mycompany.app.db.book;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import com.mycompany.app.db.DbUtil;
import com.mycompany.app.main.MainUtil;
/** Per-host web page theme override (0 Light, 1 Dark). Absent host => Display default. */
public class DbBookTheme extends SQLiteOpenHelper {
public static DbBookTheme c;
public DbBookTheme(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
public static DbBookTheme a(Context context) {
if (c == null) {
synchronized (DbBookTheme.class) {
try {
if (c == null) {
c = new DbBookTheme(MainUtil.R(context), "DbBookTheme.db", null, 1);
}
} finally {
}
}
}
return c;
}
/** @return theme 0/1, or -1 if no override for host */
public static int b(Context context, String host) {
int theme = -1;
if (context == null || TextUtils.isEmpty(host)) {
return -1;
}
Cursor cursor = null;
try {
cursor = DbUtil.g(a(context).getWritableDatabase(), "DbBookTheme_table",
new String[]{"_rsv4"}, "_path=?", new String[]{host}, null);
if (cursor != null && cursor.moveToFirst()) {
theme = cursor.getInt(cursor.getColumnIndex("_rsv4"));
}
} catch (Exception unused) {
}
if (cursor != null) {
cursor.close();
}
return theme;
}
public static void c(Context context, String host, int theme) {
if (context == null || TextUtils.isEmpty(host)) {
return;
}
long now = System.currentTimeMillis();
String[] args = {host};
SQLiteDatabase db = a(context).getWritableDatabase();
int count = DbUtil.d(db, "DbBookTheme_table", null, "_path=?", args);
ContentValues values = new ContentValues();
values.put("_path", host);
values.put("_time", Long.valueOf(now));
values.put("_rsv4", Integer.valueOf(theme));
if (count == 1) {
DbUtil.h(db, "DbBookTheme_table", values, "_path=?", args);
} else if (count == 0) {
DbUtil.e(db, "DbBookTheme_table", values);
} else {
DbUtil.a(db, "DbBookTheme_table", "_path=?", args);
DbUtil.e(db, "DbBookTheme_table", values);
}
}
public static void d(Context context, String host) {
if (context == null || TextUtils.isEmpty(host)) {
return;
}
DbUtil.a(a(context).getWritableDatabase(), "DbBookTheme_table", "_path=?", new String[]{host});
}
@Override
public final void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE DbBookTheme_table (_id INTEGER PRIMARY KEY, _path TEXT, _title TEXT, _icon BLOB, _time INTEGER, _rsv1 TEXT, _rsv2 TEXT, _rsv3 TEXT, _rsv4 INTEGER, _rsv5 INTEGER, _rsv6 INTEGER);");
}
@Override
public final void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS DbBookTheme_table");
db.execSQL("CREATE TABLE DbBookTheme_table (_id INTEGER PRIMARY KEY, _path TEXT, _title TEXT, _icon BLOB, _time INTEGER, _rsv1 TEXT, _rsv2 TEXT, _rsv3 TEXT, _rsv4 INTEGER, _rsv5 INTEGER, _rsv6 INTEGER);");
}
}