-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "feat: Integrate tl.android.lint plugin for unified Lint confi…
- Loading branch information
1 parent
2732b71
commit 2a3f479
Showing
6 changed files
with
87 additions
and
150 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
30 changes: 0 additions & 30 deletions
30
build-logic/convention/src/main/kotlin/AndroidLintConventionPlugin.kt
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
195 changes: 84 additions & 111 deletions
195
core/datastore/src/main/java/com/wei/picquest/core/datastore/PqPreferencesDataSource.kt
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,141 +1,114 @@ | ||
package com.wei.picquest.core.datastore | ||
|
||
import android.util.Log | ||
import androidx.datastore.core.DataStore | ||
import com.wei.picquest.core.model.data.DarkThemeConfig | ||
import com.wei.picquest.core.model.data.LanguageConfig | ||
import com.wei.picquest.core.model.data.ThemeBrand | ||
import com.wei.picquest.core.model.data.UserData | ||
import kotlinx.coroutines.flow.map | ||
import timber.log.Timber | ||
import java.io.IOException | ||
import javax.inject.Inject | ||
|
||
class PqPreferencesDataSource | ||
@Inject | ||
constructor( | ||
private val userPreferences: DataStore<UserPreferences>, | ||
) { | ||
val userData = | ||
userPreferences.data.map { | ||
UserData( | ||
isFirstTimeUser = it.isFirstTimeUser, | ||
tokenString = it.tokenString, | ||
userName = it.userName, | ||
useDynamicColor = it.useDynamicColor, | ||
themeBrand = | ||
when (it.themeBrand) { | ||
null, | ||
ThemeBrandProto.THEME_BRAND_UNSPECIFIED, | ||
ThemeBrandProto.UNRECOGNIZED, | ||
ThemeBrandProto.THEME_BRAND_DEFAULT, | ||
-> ThemeBrand.DEFAULT | ||
|
||
ThemeBrandProto.THEME_BRAND_ANDROID -> ThemeBrand.ANDROID | ||
}, | ||
darkThemeConfig = | ||
when (it.darkThemeConfig) { | ||
null, | ||
DarkThemeConfigProto.DARK_THEME_CONFIG_UNSPECIFIED, | ||
DarkThemeConfigProto.UNRECOGNIZED, | ||
DarkThemeConfigProto.DARK_THEME_CONFIG_FOLLOW_SYSTEM, | ||
-> DarkThemeConfig.FOLLOW_SYSTEM | ||
|
||
DarkThemeConfigProto.DARK_THEME_CONFIG_LIGHT -> DarkThemeConfig.LIGHT | ||
DarkThemeConfigProto.DARK_THEME_CONFIG_DARK -> DarkThemeConfig.DARK | ||
}, | ||
languageConfig = | ||
when (it.languageConfig) { | ||
null, | ||
LanguageConfigProto.LANGUAGE_CONFIG_UNSPECIFIED, | ||
LanguageConfigProto.UNRECOGNIZED, | ||
LanguageConfigProto.LANGUAGE_CONFIG_FOLLOW_SYSTEM, | ||
-> LanguageConfig.FOLLOW_SYSTEM | ||
|
||
LanguageConfigProto.LANGUAGE_CONFIG_ENGLISH -> LanguageConfig.ENGLISH | ||
LanguageConfigProto.LANGUAGE_CONFIG_CHINESE -> LanguageConfig.CHINESE | ||
}, | ||
recentSearchPhotoQueries = it.recentSearchPhotoQueriesList, | ||
recentSearchVideoQueries = it.recentSearchVideoQueriesList, | ||
) | ||
} | ||
class PqPreferencesDataSource @Inject constructor( | ||
private val userPreferences: DataStore<UserPreferences>, | ||
) { | ||
val userData = userPreferences.data.map { | ||
UserData( | ||
isFirstTimeUser = it.isFirstTimeUser, | ||
tokenString = it.tokenString, | ||
userName = it.userName, | ||
useDynamicColor = it.useDynamicColor, | ||
themeBrand = when (it.themeBrand) { | ||
null, ThemeBrandProto.THEME_BRAND_UNSPECIFIED, ThemeBrandProto.UNRECOGNIZED, ThemeBrandProto.THEME_BRAND_DEFAULT -> ThemeBrand.DEFAULT | ||
ThemeBrandProto.THEME_BRAND_ANDROID -> ThemeBrand.ANDROID | ||
}, | ||
darkThemeConfig = when (it.darkThemeConfig) { | ||
null, DarkThemeConfigProto.DARK_THEME_CONFIG_UNSPECIFIED, DarkThemeConfigProto.UNRECOGNIZED, DarkThemeConfigProto.DARK_THEME_CONFIG_FOLLOW_SYSTEM -> DarkThemeConfig.FOLLOW_SYSTEM | ||
DarkThemeConfigProto.DARK_THEME_CONFIG_LIGHT -> DarkThemeConfig.LIGHT | ||
DarkThemeConfigProto.DARK_THEME_CONFIG_DARK -> DarkThemeConfig.DARK | ||
}, | ||
languageConfig = when (it.languageConfig) { | ||
null, LanguageConfigProto.LANGUAGE_CONFIG_UNSPECIFIED, LanguageConfigProto.UNRECOGNIZED, LanguageConfigProto.LANGUAGE_CONFIG_FOLLOW_SYSTEM -> LanguageConfig.FOLLOW_SYSTEM | ||
LanguageConfigProto.LANGUAGE_CONFIG_ENGLISH -> LanguageConfig.ENGLISH | ||
LanguageConfigProto.LANGUAGE_CONFIG_CHINESE -> LanguageConfig.CHINESE | ||
}, | ||
recentSearchPhotoQueries = it.recentSearchPhotoQueriesList, | ||
recentSearchVideoQueries = it.recentSearchVideoQueriesList, | ||
) | ||
} | ||
|
||
suspend fun setTokenString(tokenString: String) { | ||
try { | ||
userPreferences.updateData { | ||
it.copy { | ||
this.tokenString = tokenString | ||
} | ||
suspend fun setTokenString(tokenString: String) { | ||
try { | ||
userPreferences.updateData { | ||
it.copy { | ||
this.tokenString = tokenString | ||
} | ||
} catch (ioException: IOException) { | ||
Timber.tag("PqPreferences").e(ioException, "Failed to update user preferences") | ||
} | ||
} catch (ioException: IOException) { | ||
Log.e("PqPreferences", "Failed to update user preferences", ioException) | ||
} | ||
} | ||
|
||
suspend fun addRecentSearchPhotoQuery(newQuery: String) { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
val updatedQueries = | ||
preferences.recentSearchPhotoQueriesList.toMutableList().apply { | ||
// 移除既有相同的查詢(如果存在),然後添加到列表末尾 | ||
remove(newQuery) | ||
add(newQuery) | ||
if (size > 10) removeAt(0) | ||
} | ||
preferences.toBuilder() | ||
.clearRecentSearchPhotoQueries() | ||
.addAllRecentSearchPhotoQueries(updatedQueries) | ||
.build() | ||
suspend fun addRecentSearchPhotoQuery(newQuery: String) { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
val updatedQueries = preferences.recentSearchPhotoQueriesList.toMutableList().apply { | ||
// 移除既有相同的查詢(如果存在),然後添加到列表末尾 | ||
remove(newQuery) | ||
add(newQuery) | ||
if (size > 10) removeAt(0) | ||
} | ||
} catch (ioException: IOException) { | ||
Timber.tag("PqPreferencesDataSource") | ||
.e(ioException, "Failed to update recent search photo queries") | ||
preferences.toBuilder() | ||
.clearRecentSearchPhotoQueries() | ||
.addAllRecentSearchPhotoQueries(updatedQueries) | ||
.build() | ||
} | ||
} catch (ioException: IOException) { | ||
Log.e("PqPreferencesDataSource", "Failed to update recent search photo queries", ioException) | ||
} | ||
} | ||
|
||
suspend fun clearRecentSearchPhotoQueries() { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
preferences.toBuilder() | ||
.clearRecentSearchPhotoQueries() | ||
.build() | ||
} | ||
} catch (ioException: IOException) { | ||
Timber.tag("PqPreferencesDataSource") | ||
.e(ioException, "Failed to clear recent search photo queries") | ||
suspend fun clearRecentSearchPhotoQueries() { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
preferences.toBuilder() | ||
.clearRecentSearchPhotoQueries() | ||
.build() | ||
} | ||
} catch (ioException: IOException) { | ||
Log.e("PqPreferencesDataSource", "Failed to clear recent search photo queries", ioException) | ||
} | ||
} | ||
|
||
suspend fun addRecentSearchVideoQuery(newQuery: String) { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
val updatedQueries = | ||
preferences.recentSearchVideoQueriesList.toMutableList().apply { | ||
// 移除既有相同的查詢(如果存在),然後添加到列表末尾 | ||
remove(newQuery) | ||
add(newQuery) | ||
if (size > 10) removeAt(0) | ||
} | ||
preferences.toBuilder() | ||
.clearRecentSearchVideoQueries() | ||
.addAllRecentSearchVideoQueries(updatedQueries) | ||
.build() | ||
suspend fun addRecentSearchVideoQuery(newQuery: String) { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
val updatedQueries = preferences.recentSearchVideoQueriesList.toMutableList().apply { | ||
// 移除既有相同的查詢(如果存在),然後添加到列表末尾 | ||
remove(newQuery) | ||
add(newQuery) | ||
if (size > 10) removeAt(0) | ||
} | ||
} catch (ioException: IOException) { | ||
Timber.tag("PqPreferencesDataSource") | ||
.e(ioException, "Failed to update recent search video queries") | ||
preferences.toBuilder() | ||
.clearRecentSearchVideoQueries() | ||
.addAllRecentSearchVideoQueries(updatedQueries) | ||
.build() | ||
} | ||
} catch (ioException: IOException) { | ||
Log.e("PqPreferencesDataSource", "Failed to update recent search video queries", ioException) | ||
} | ||
} | ||
|
||
suspend fun clearRecentSearchVideoQueries() { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
preferences.toBuilder() | ||
.clearRecentSearchVideoQueries() | ||
.build() | ||
} | ||
} catch (ioException: IOException) { | ||
Timber.tag("PqPreferencesDataSource") | ||
.e(ioException, "Failed to clear recent search video queries") | ||
suspend fun clearRecentSearchVideoQueries() { | ||
try { | ||
userPreferences.updateData { preferences -> | ||
preferences.toBuilder() | ||
.clearRecentSearchVideoQueries() | ||
.build() | ||
} | ||
} catch (ioException: IOException) { | ||
Log.e("PqPreferencesDataSource", "Failed to clear recent search video queries", ioException) | ||
} | ||
} | ||
} |