-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature|optimize|fix|doc]支持更换主题;引入DataStore;修复navController.popBackS…
…tack()方法使用问题(google/accompanist#1320)
- Loading branch information
Showing
58 changed files
with
1,790 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,19 @@ | ||
package com.skyd.raca.config | ||
|
||
import com.skyd.raca.ext.editor | ||
import com.skyd.raca.ext.sharedPreferences | ||
import com.skyd.raca.model.bean.ARTICLE_TABLE_NAME | ||
import com.skyd.raca.model.bean.ArticleBean.Companion.ARTICLE_COLUMN | ||
import com.skyd.raca.model.bean.ArticleBean.Companion.TITLE_COLUMN | ||
import com.skyd.raca.model.bean.ArticleBean.Companion.UUID_COLUMN | ||
import com.skyd.raca.model.bean.TAG_TABLE_NAME | ||
import com.skyd.raca.model.bean.TagBean.Companion.TAG_COLUMN | ||
|
||
var useRegexSearch = sharedPreferences().getBoolean("useRegexSearch", false) | ||
set(value) { | ||
field = value | ||
sharedPreferences().editor { putBoolean("useRegexSearch", value) } | ||
} | ||
|
||
val allSearchDomain: HashMap<Pair<String, String>, List<Pair<String, String>>> = hashMapOf( | ||
(ARTICLE_TABLE_NAME to "段落表") to listOf( | ||
UUID_COLUMN to "UUID", | ||
TITLE_COLUMN to "标题", | ||
ARTICLE_COLUMN to "段落", | ||
), | ||
(TAG_TABLE_NAME to "标签表") to listOf( | ||
// ARTICLE_ID_COLUMN to "段落ID", | ||
TAG_COLUMN to "标签", | ||
// CREATE_TIME_COLUMN to "创建时间" | ||
), | ||
) | ||
|
||
fun setSearchDomain( | ||
tableName: String, | ||
columnName: String, | ||
search: Boolean | ||
) { | ||
sharedPreferences("SearchDomain").editor { | ||
putBoolean("${tableName}/${columnName}", search) | ||
} | ||
} | ||
|
||
fun getSearchDomain( | ||
tableName: String, | ||
columnName: String, | ||
): Boolean { | ||
return sharedPreferences("SearchDomain") | ||
.getBoolean( | ||
"${tableName}/${columnName}", | ||
if (tableName == ARTICLE_TABLE_NAME && (columnName == TITLE_COLUMN || columnName == ARTICLE_COLUMN)) { | ||
true | ||
} else tableName == TAG_TABLE_NAME && columnName == TAG_COLUMN | ||
) | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.skyd.raca.db.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import com.skyd.raca.model.bean.* | ||
import com.skyd.raca.model.bean.SearchDomainBean.Companion.COLUMN_NAME_COLUMN | ||
import com.skyd.raca.model.bean.SearchDomainBean.Companion.SEARCH_COLUMN | ||
import com.skyd.raca.model.bean.SearchDomainBean.Companion.TABLE_NAME_COLUMN | ||
|
||
@Dao | ||
interface SearchDomainDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun setSearchDomain(searchDomainBean: SearchDomainBean) | ||
|
||
@Query( | ||
value = "SELECT $SEARCH_COLUMN FROM $SEARCH_DOMAIN_TABLE_NAME" + | ||
" WHERE $TABLE_NAME_COLUMN LIKE :tableName AND $COLUMN_NAME_COLUMN LIKE :columnName" | ||
) | ||
fun getSearchDomainOrNull(tableName: String, columnName: String): Boolean? | ||
|
||
fun getSearchDomain(tableName: String, columnName: String): Boolean { | ||
return getSearchDomainOrNull(tableName, columnName) | ||
?: if (tableName == ARTICLE_TABLE_NAME && | ||
(columnName == ArticleBean.TITLE_COLUMN || | ||
columnName == ArticleBean.ARTICLE_COLUMN) | ||
) true else tableName == TAG_TABLE_NAME && columnName == TagBean.TAG_COLUMN | ||
} | ||
|
||
@Query(value = "SELECT * FROM $SEARCH_DOMAIN_TABLE_NAME") | ||
fun getAllSearchDomain(): List<SearchDomainBean> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.skyd.raca.ext | ||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.ReadOnlyComposable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.graphics.Color | ||
import com.skyd.raca.model.preference.theme.DarkModePreference | ||
import com.skyd.raca.ui.local.LocalDarkMode | ||
import java.lang.Long.parseLong | ||
|
||
fun String.toColorOrNull(): Color? = try { | ||
Color(parseLong(this, 16)) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
|
||
fun String.checkColorHex(): String? { | ||
var s = this.trim() | ||
if (s.length > 6) { | ||
s = s.substring(s.length - 6) | ||
} | ||
return "[0-9a-fA-F]{6}".toRegex().find(s)?.value | ||
} | ||
|
||
@Composable | ||
infix fun Color.onLight(lightColor: Color): Color = | ||
if (!DarkModePreference.isInDark(value = LocalDarkMode.current)) lightColor else this | ||
|
||
@Composable | ||
infix fun Color.onDark(darkColor: Color): Color = | ||
if (DarkModePreference.isInDark(value = LocalDarkMode.current)) darkColor else this | ||
|
||
@Stable | ||
@Composable | ||
@ReadOnlyComposable | ||
infix fun Color.alwaysLight(isAlways: Boolean): Color { | ||
val colorScheme = MaterialTheme.colorScheme | ||
return if (isAlways && DarkModePreference.isInDark(value = LocalDarkMode.current)) { | ||
when (this) { | ||
colorScheme.primary -> colorScheme.onPrimary | ||
colorScheme.secondary -> colorScheme.onSecondary | ||
colorScheme.tertiary -> colorScheme.onTertiary | ||
colorScheme.background -> colorScheme.onBackground | ||
colorScheme.error -> colorScheme.onError | ||
colorScheme.surface -> colorScheme.onSurface | ||
colorScheme.surfaceVariant -> colorScheme.onSurfaceVariant | ||
colorScheme.primaryContainer -> colorScheme.onPrimaryContainer | ||
colorScheme.secondaryContainer -> colorScheme.onSecondaryContainer | ||
colorScheme.tertiaryContainer -> colorScheme.onTertiaryContainer | ||
colorScheme.errorContainer -> colorScheme.onErrorContainer | ||
colorScheme.inverseSurface -> colorScheme.inverseOnSurface | ||
|
||
colorScheme.onPrimary -> colorScheme.primary | ||
colorScheme.onSecondary -> colorScheme.secondary | ||
colorScheme.onTertiary -> colorScheme.tertiary | ||
colorScheme.onBackground -> colorScheme.background | ||
colorScheme.onError -> colorScheme.error | ||
colorScheme.onSurface -> colorScheme.surface | ||
colorScheme.onSurfaceVariant -> colorScheme.surfaceVariant | ||
colorScheme.onPrimaryContainer -> colorScheme.primaryContainer | ||
colorScheme.onSecondaryContainer -> colorScheme.secondaryContainer | ||
colorScheme.onTertiaryContainer -> colorScheme.tertiaryContainer | ||
colorScheme.onErrorContainer -> colorScheme.errorContainer | ||
colorScheme.inverseOnSurface -> colorScheme.inverseSurface | ||
|
||
else -> Color.Unspecified | ||
} | ||
} else { | ||
this | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.skyd.raca.ext | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.emptyPreferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.withContext | ||
import java.io.IOException | ||
|
||
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "App") | ||
|
||
suspend fun <T> DataStore<Preferences>.put(key: Preferences.Key<T>, value: T) { | ||
this.edit { | ||
withContext(Dispatchers.IO) { | ||
it[key] = value | ||
} | ||
} | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> DataStore<Preferences>.get(key: Preferences.Key<T>): T? { | ||
return runBlocking { | ||
this@get.data.catch { exception -> | ||
if (exception is IOException) { | ||
exception.printStackTrace() | ||
emit(emptyPreferences()) | ||
} else { | ||
throw exception | ||
} | ||
}.map { | ||
it[key] | ||
}.first() as T | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.