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

支持设置深色主题,并跟随系统设置改变 #38

Merged
merged 1 commit into from
Mar 22, 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
36 changes: 34 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,21 @@
<activity
android:name=".view.activity.LoginActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/activity_label_login"
android:windowSoftInputMode="stateVisible|adjustResize" />

<activity
android:name=".view.page.app.AppLoginActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/action_app_login"
android:windowSoftInputMode="stateVisible|adjustResize" />

<activity
android:name=".view.activity.ForumActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan">
<intent-filter>
Expand All @@ -82,37 +85,44 @@
<activity
android:name=".view.activity.SettingsActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/settings" />

<activity
android:name=".view.activity.HelpActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/help"
android:process=":webView" />

<activity
android:name=".view.activity.FavouriteListActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.ThreadListActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.page.post.PostListActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.page.app.AppPostListActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.page.post.PostListGatewayActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:theme="@style/Theme.Translucent.Light">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
Expand Down Expand Up @@ -174,37 +184,44 @@

<activity
android:name=".view.activity.ReplyActivity"
android:colorMode="wideColorGamut" />
android:colorMode="wideColorGamut"
android:configChanges="uiMode" />

<activity
android:name=".view.activity.NewThreadActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/title_new_thread" />

<activity
android:name=".view.page.edit.EditPostActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/title_edit_post" />

<activity
android:name=".view.activity.GalleryActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:theme="@style/Theme.Gallery" />

<activity
android:name=".view.activity.PmActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/pms"
android:windowSoftInputMode="adjustResize" />

<activity
android:name=".view.activity.NewPmActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/title_new_pm" />

<activity
android:name=".view.activity.SearchActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
Expand All @@ -214,65 +231,77 @@
<activity
android:name=".view.activity.NoteActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/title_note"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.UserHomeActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label=""
android:theme="@style/Theme.Translucent.AfternoonTea"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.FriendListActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/title_friends"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.UserThreadActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.UserReplyActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.NewRateActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.NewReportActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.HistoryActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/title_history"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.DarkRoomActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.OpenSourceLicensesActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/open_source_licenses" />

<activity
android:name=".view.activity.OpenSourceLicenseDetailActivity"
android:colorMode="wideColorGamut" />
android:colorMode="wideColorGamut"
android:configChanges="uiMode" />

<activity
android:name=".view.activity.WebViewActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan" />

<!-- FilePicker -->
Expand All @@ -290,6 +319,7 @@
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/app_name"
android:theme="@style/FilePickerTheme">
<intent-filter>
Expand All @@ -301,11 +331,13 @@
<activity
android:name=".view.activity.RateDetailsListActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:label="@string/rate" />

<activity
android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity"
android:colorMode="wideColorGamut"
android:configChanges="uiMode"
android:exported="true" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class GeneralPreferencesImpl(context: Context, sharedPreferences: SharedPreferen
override var themeIndex: Int by PreferenceDelegates.int(
R.string.pref_key_theme, R.string.pref_theme_default_value)

override var darkThemeIndex: Int by PreferenceDelegates.int(
R.string.pref_key_dark_theme, R.string.pref_dark_theme_default_value)

override val fontScale: Float
get() = getPrefString(R.string.pref_key_font_size, R.string.pref_font_size_default_value)?.toFloat()?:1.0f

Expand All @@ -33,6 +36,7 @@ class GeneralPreferencesImpl(context: Context, sharedPreferences: SharedPreferen

interface GeneralPreferences {
var themeIndex: Int
var darkThemeIndex: Int
val fontScale: Float
val isSignatureEnabled: Boolean
var isPostSelectable: Boolean
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/me/ykrank/s1next/data/pref/ThemeManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.ykrank.s1next.data.pref;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
Expand Down Expand Up @@ -49,7 +50,14 @@ public final class ThemeManager {

@Override
public Theme get() {
Theme theme = Theme.VALUES.get(mGeneralPreferencesProvider.getThemeIndex());
Theme theme;

int currentNightMode = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
theme = Theme.VALUES.get(mGeneralPreferencesProvider.getDarkThemeIndex());
} else {
theme = Theme.VALUES.get(mGeneralPreferencesProvider.getThemeIndex());
}
invalidateAccentColor(theme);

return theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ abstract class BaseActivity : LibBaseActivity() {
}
}


super.onCreate(savedInstanceState)

mRxBus.get()
Expand Down Expand Up @@ -223,7 +224,8 @@ abstract class BaseActivity : LibBaseActivity() {
super.onConfigurationChanged(newConfig)

drawerLayoutDelegate?.onConfigurationChanged(newConfig)

mThemeManager.invalidateTheme()
mRxBus.post(ThemeChangeEvent())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GeneralPreferenceFragment : BasePreferenceFragment(), Preference.OnPrefere
if (!isAdded) {
return
}
if (key == getString(R.string.pref_key_theme)) {
if (key == getString(R.string.pref_key_theme) || key == getString(R.string.pref_key_dark_theme)) {
trackAgent.post(ThemeChangeTrackEvent(false))
mThemeManager.invalidateTheme()
mRxBus.post(ThemeChangeEvent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class PostListFragment : BaseViewPagerFragment(), PostListPagerFragment.PagerCal
trackAgent.post(ViewThreadTrackEvent(mThreadTitle, mThreadId, hashMapOf(
Pair("Type", type.toString()),
Pair("Theme", mGeneralPreferencesManager.themeIndex.toString()),
Pair("Dark Theme", mGeneralPreferencesManager.darkThemeIndex.toString()),
Pair("FontScale", mGeneralPreferencesManager.fontScale.toString()),
Pair("SignatureEnabled", mGeneralPreferencesManager.isSignatureEnabled.toString()),
Pair("PostSelectable", mGeneralPreferencesManager.isPostSelectable.toString()),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/string_pref_value.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<string name="pref_theme">主題</string>

<string name="pref_dark_theme">深色主題</string>

<string name="pref_font_size">字體大小</string>

<string name="pref_signature">尾巴</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/string_pref_value.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<string name="pref_general">常规</string>
<string name="pref_theme">主题</string>
<string name="pref_dark_theme">深色主题</string>
<string name="pref_font_size">字体大小</string>
<string name="pref_signature">尾巴</string>
<string name="pref_advanced">高级</string>
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@
<item>8</item>
</string-array>

<!-- settings -->
<string-array name="pref_dark_theme_entries">
<item>@string/pref_theme_entries_0</item>
<item>@string/pref_theme_entries_1</item>
<item>@string/pref_theme_entries_2</item>
<item>@string/pref_theme_entries_3</item>
<item>@string/pref_theme_entries_4</item>
<item>@string/pref_theme_entries_5</item>
<item>@string/pref_theme_entries_6</item>
<item>@string/pref_theme_entries_7</item>
<item>@string/pref_theme_entries_8</item>
</string-array>

<string-array name="pref_dark_theme_entry_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
</string-array>


<string-array name="pref_font_size_entries">
<item>@string/pref_font_size_entries_1</item>
<item>@string/pref_font_size_entries_2</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/string_pref_key.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<!-- General -->
<string name="pref_key_theme" translatable="false">pref_key_theme</string>
<string name="pref_key_dark_theme" translatable="false">pref_key_dark_theme</string>
<string name="pref_key_font_size" translatable="false">pref_key_font_size_v2</string>
<string name="pref_key_signature" translatable="false">pref_key_signature</string>
<string name="pref_key_downloads" translatable="false">pref_key_downloads</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/string_pref_value.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<string name="pref_general">General</string>
<string name="pref_theme">Theme</string>
<string name="pref_theme_default_value" translatable="false">0</string>
<string name="pref_dark_theme">Dark Theme</string>
<string name="pref_dark_theme_default_value" translatable="false">6</string>
<string name="pref_font_size">Font size</string>
<string name="pref_font_size_default_value" translatable="false">1.0</string>
<string name="pref_signature">Signature</string>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/preference_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
android:title="@string/pref_theme"
app:iconSpaceReserved="false" />

<ListPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="@string/pref_dark_theme_default_value"
android:entries="@array/pref_dark_theme_entries"
android:entryValues="@array/pref_dark_theme_entry_values"
android:key="@string/pref_key_dark_theme"
android:summary="%s"
android:title="@string/pref_dark_theme"
app:iconSpaceReserved="false" />

<ListPreference
android:defaultValue="@string/pref_font_size_default_value"
android:entries="@array/pref_font_size_entries"
Expand Down