Skip to content

Commit

Permalink
Revert "Spotless 7.0.0 (#2508)"
Browse files Browse the repository at this point in the history
This reverts commit ddbfbff.
  • Loading branch information
Goooler committed Jan 8, 2025
1 parent bf22168 commit 7fd622d
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class GithubApiModule {

@Provides
@Singleton
fun providesGitHubContributorsApi(): GitHubContributorsAPI = Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(kotlinxJson.asConverterFactory("application/json".toMediaType()))
.build()
.create()
fun providesGitHubContributorsApi(): GitHubContributorsAPI {
return Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(kotlinxJson.asConverterFactory("application/json".toMediaType()))
.build()
.create()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class WebsiteApiModule {

@Provides
@Singleton
fun providesWebsiteIconRequestApi(): IconRequestSettingsAPI = Retrofit.Builder()
.baseUrl("https://lawnchair.app/")
.addConverterFactory(kotlinxJson.asConverterFactory("application/json".toMediaType()))
.build()
.create()
fun providesWebsiteIconRequestApi(): IconRequestSettingsAPI {
return Retrofit.Builder()
.baseUrl("https://lawnchair.app/")
.addConverterFactory(kotlinxJson.asConverterFactory("application/json".toMediaType()))
.build()
.create()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ object OssLibraryRepositoryModule {

@Provides
@Singleton
fun provideOssLibraryRepository(application: Application): OssLibraryRepository = OssLibraryRepositoryImpl(application = application)
fun provideOssLibraryRepository(application: Application): OssLibraryRepository =
OssLibraryRepositoryImpl(application = application)
}
20 changes: 11 additions & 9 deletions app/src/main/kotlin/app/lawnchair/lawnicons/model/IconInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ data class IconInfo(
* @return A new list of [IconInfo] objects with merged component names for icons
* sharing the same drawable name.
*/
fun List<IconInfo>.mergeByDrawableName(): List<IconInfo> = groupBy { it.drawableName }
.map { (drawableName, icons) ->
val mergedComponentNames = icons.flatMap { it.componentNames }
IconInfo(
componentNames = mergedComponentNames,
drawableName = drawableName,
id = icons.first().id,
)
}
fun List<IconInfo>.mergeByDrawableName(): List<IconInfo> {
return groupBy { it.drawableName }
.map { (drawableName, icons) ->
val mergedComponentNames = icons.flatMap { it.componentNames }
IconInfo(
componentNames = mergedComponentNames,
drawableName = drawableName,
id = icons.first().id,
)
}
}

/**
* Splits [IconInfo] objects with multiple component names into a list where each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,31 @@ class IconRepositoryImpl @Inject constructor(application: Application) : IconRep
_searchedIconInfoModel.value = _iconInfoModel.value
}

private suspend fun getIconRequestList(systemPackageList: List<IconInfo>) = withContext(Dispatchers.Default) {
val lawniconsData = _iconInfoModel.value.iconInfo
private suspend fun getIconRequestList(systemPackageList: List<IconInfo>) =
withContext(Dispatchers.Default) {
val lawniconsData = _iconInfoModel.value.iconInfo

val systemData = systemPackageList.map { info ->
info.getFirstLabelAndComponent()
}

val lawniconsComponents = lawniconsData
.splitByComponentName()
.map { it.getFirstLabelAndComponent().componentName }
.sortedBy { it.lowercase() }
.toSet()

val commonItems = systemData.filter { it.componentName !in lawniconsComponents }
.map {
IconRequest(
label = it.label,
componentName = it.componentName,
)
val systemData = systemPackageList.map { info ->
info.getFirstLabelAndComponent()
}

iconRequestList.value = IconRequestModel(
list = commonItems,
iconCount = commonItems.size,
)
}
val lawniconsComponents = lawniconsData
.splitByComponentName()
.map { it.getFirstLabelAndComponent().componentName }
.sortedBy { it.lowercase() }
.toSet()

val commonItems = systemData.filter { it.componentName !in lawniconsComponents }
.map {
IconRequest(
label = it.label,
componentName = it.componentName,
)
}

iconRequestList.value = IconRequestModel(
list = commonItems,
iconCount = commonItems.size,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ abstract class BasePreferenceManager(
fun toggle() = set(!get())

@Composable
fun asState(): State<Boolean> = produceState(initialValue = get(), this) {
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey ->
if (changedKey == key) {
value = get() // Update the state value when the preference changes
fun asState(): State<Boolean> {
return produceState(initialValue = get(), this) {
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey ->
if (changedKey == key) {
value = get() // Update the state value when the preference changes
}
}
prefs.registerOnSharedPreferenceChangeListener(listener)
awaitDispose {
prefs.unregisterOnSharedPreferenceChangeListener(listener)
}
}
prefs.registerOnSharedPreferenceChangeListener(listener)
awaitDispose {
prefs.unregisterOnSharedPreferenceChangeListener(listener)
}
}
}
Expand All @@ -61,15 +63,17 @@ abstract class BasePreferenceManager(
fun set(value: Int) = editor.putInt(key, value).apply()

@Composable
fun asState(): State<Int> = produceState(initialValue = get(), this) {
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey ->
if (changedKey == key) {
value = get() // Update the state value when the preference changes
fun asState(): State<Int> {
return produceState(initialValue = get(), this) {
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey ->
if (changedKey == key) {
value = get() // Update the state value when the preference changes
}
}
prefs.registerOnSharedPreferenceChangeListener(listener)
awaitDispose {
prefs.unregisterOnSharedPreferenceChangeListener(listener)
}
}
prefs.registerOnSharedPreferenceChangeListener(listener)
awaitDispose {
prefs.unregisterOnSharedPreferenceChangeListener(listener)
}
}
}
Expand Down Expand Up @@ -97,16 +101,20 @@ class PreferenceManager private constructor(
/**
* Returns a singleton instance of [PreferenceManager]
*/
fun getInstance(context: Context): PreferenceManager = instance ?: synchronized(this) {
instance ?: PreferenceManager(
context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE),
).also { instance = it }
fun getInstance(context: Context): PreferenceManager {
return instance ?: synchronized(this) {
instance ?: PreferenceManager(
context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE),
).also { instance = it }
}
}

/**
* Get dummy instance of [PreferenceManager] for testing and Compose previews
*/
fun getDummyInstance(): PreferenceManager = PreferenceManager(DummySharedPreferences())
fun getDummyInstance(): PreferenceManager {
return PreferenceManager(DummySharedPreferences())
}
}
}

Expand Down Expand Up @@ -144,7 +152,7 @@ class DummySharedPreferences : SharedPreferences {
/**
* Dummy implementation of [SharedPreferences.Editor] for Compose previews
*/
class DummyEditor : SharedPreferences.Editor {
class DummyEditor() : SharedPreferences.Editor {
override fun putString(key: String?, value: String?) = DummyEditor()
override fun putStringSet(key: String?, values: MutableSet<String>?) = DummyEditor()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ private fun HandleTouchInteractions(
}
}

private fun formatIconRequestList(iconRequestList: List<IconRequest>) = iconRequestList.joinToString("\n") { "${it.label}\n${it.componentName}" }
private fun formatIconRequestList(iconRequestList: List<IconRequest>) =
iconRequestList.joinToString("\n") { "${it.label}\n${it.componentName}" }

private fun handleRequestClick(
iconRequestList: List<IconRequest>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ fun Context.getIconInfo(
while (
(
parser.next()
.also { type = it } != XmlPullParser.END_TAG ||
parser.depth > depth
.also { type = it } != XmlPullParser.END_TAG || parser.depth > depth
) &&
type != XmlPullParser.END_DOCUMENT
) {
Expand All @@ -44,8 +43,7 @@ fun Context.getIconInfo(
val parsedComponent =
component.substring(componentInfoPrefixLength, component.length - 1)

if (parsedComponent.isNotEmpty() &&
!parsedComponent.startsWith("/") &&
if (parsedComponent.isNotEmpty() && !parsedComponent.startsWith("/") &&
!parsedComponent.endsWith("/")
) {
actualComponent = parsedComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ import android.content.pm.ResolveInfo
import app.lawnchair.lawnicons.model.IconInfo
import app.lawnchair.lawnicons.model.LabelAndComponent

fun Context.getPackagesList(): List<ResolveInfo> = try {
packageManager.queryIntentActivities(
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
PackageManager.GET_RESOLVED_FILTER,
)
} catch (e: Exception) {
listOf()
fun Context.getPackagesList(): List<ResolveInfo> {
return try {
packageManager.queryIntentActivities(
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
PackageManager.GET_RESOLVED_FILTER,
)
} catch (e: Exception) {
listOf()
}
}

fun Context.getSystemIconInfoAppfilter(): List<IconInfo> = getPackagesList().map { ri ->
with(ri) {
val riPkg = activityInfo.packageName
val component = "$riPkg/${activityInfo.name}"
fun Context.getSystemIconInfoAppfilter(): List<IconInfo> {
return getPackagesList().map { ri ->
with(ri) {
val riPkg = activityInfo.packageName
val component = "$riPkg/${activityInfo.name}"

val name = loadLabel(packageManager) ?: riPkg
val name = loadLabel(packageManager) ?: riPkg

IconInfo(
drawableName = "",
componentNames = listOf(
LabelAndComponent(name.toString(), component),
),
id = 0,
)
IconInfo(
drawableName = "",
componentNames = listOf(
LabelAndComponent(name.toString(), component),
),
id = 0,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import kotlinx.coroutines.flow.stateIn
@HiltViewModel
class AcknowledgementViewModel @Inject constructor(
private val ossLibraryRepository: OssLibraryRepository,
) : ViewModel() {
) :
ViewModel() {

val ossLibraries = ossLibraryRepository.ossLibraries

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class LawniconsViewModelImpl @Inject constructor(
private val iconRepository: IconRepository,
private val newIconsRepository: NewIconsRepository,
private val iconRequestSettingsRepository: IconRequestSettingsRepository,
) : ViewModel(),
LawniconsViewModel {
) : LawniconsViewModel, ViewModel() {
override val iconInfoModel = iconRepository.iconInfoModel
override val searchedIconInfoModel = iconRepository.searchedIconInfoModel
override val iconRequestModel = iconRepository.iconRequestList
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
id("com.google.devtools.ksp") version "2.1.0-1.0.29" apply false
id("com.google.dagger.hilt.android") version "2.54" apply false
id("app.cash.licensee") version "1.12.0" apply false
id("com.diffplug.spotless") version "7.0.0" apply false
id("com.diffplug.spotless") version "6.25.0" apply false
id("org.gradle.android.cache-fix") version "3.0.1" apply false
}

Expand Down
Loading

0 comments on commit 7fd622d

Please sign in to comment.