Skip to content

Commit

Permalink
Revert "feat: Integrate tl.android.lint plugin for unified Lint confi…
Browse files Browse the repository at this point in the history
…gurations across modules (#105)"

This reverts commit 2732b71.
  • Loading branch information
azrael8576 committed Feb 15, 2024
1 parent 2732b71 commit 2a3f479
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 150 deletions.
4 changes: 0 additions & 4 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ gradlePlugin {
id = "pq.android.application.flavors"
implementationClass = "AndroidApplicationFlavorsConventionPlugin"
}
register("androidLint") {
id = "pq.android.lint"
implementationClass = "AndroidLintConventionPlugin"
}
register("jvmLibrary") {
id = "pq.jvm.library"
implementationClass = "JvmLibraryConventionPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.wei.picquest.configureGradleManagedDevices
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.wei.picquest.configureKotlinAndroid
import com.wei.picquest.configurePrintApksTask
import org.gradle.api.Plugin
Expand All @@ -13,7 +13,6 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
with(pluginManager) {
apply("com.android.application")
apply("org.jetbrains.kotlin.android")
apply("pq.android.lint")
}

extensions.configure<ApplicationExtension> {
Expand All @@ -26,4 +25,5 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
apply("pq.android.lint")
}

extensions.configure<LibraryExtension> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class JvmLibraryConventionPlugin : Plugin<Project> {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.jvm")
apply("pq.android.lint")
}
configureKotlinJvm()
}
Expand Down
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)
}
}
}

0 comments on commit 2a3f479

Please sign in to comment.