Skip to content

Commit

Permalink
Spotless 7.0.0 (#2508)
Browse files Browse the repository at this point in the history
* chore(deps): update plugin com.diffplug.spotless to v7

* Fix styles

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Goooler <[email protected]>
  • Loading branch information
renovate[bot] and Goooler authored Jan 7, 2025
1 parent f4e2957 commit ddbfbff
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ class GithubApiModule {

@Provides
@Singleton
fun providesGitHubContributorsApi(): GitHubContributorsAPI {
return Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(kotlinxJson.asConverterFactory("application/json".toMediaType()))
.build()
.create()
}
fun providesGitHubContributorsApi(): GitHubContributorsAPI = 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,11 +33,9 @@ class WebsiteApiModule {

@Provides
@Singleton
fun providesWebsiteIconRequestApi(): IconRequestSettingsAPI {
return Retrofit.Builder()
.baseUrl("https://lawnchair.app/")
.addConverterFactory(kotlinxJson.asConverterFactory("application/json".toMediaType()))
.build()
.create()
}
fun providesWebsiteIconRequestApi(): IconRequestSettingsAPI = 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,6 +15,5 @@ object OssLibraryRepositoryModule {

@Provides
@Singleton
fun provideOssLibraryRepository(application: Application): OssLibraryRepository =
OssLibraryRepositoryImpl(application = application)
fun provideOssLibraryRepository(application: Application): OssLibraryRepository = OssLibraryRepositoryImpl(application = application)
}
20 changes: 9 additions & 11 deletions app/src/main/kotlin/app/lawnchair/lawnicons/model/IconInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ 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> {
return 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> = 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,31 +101,30 @@ 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 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 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,
)
}
iconRequestList.value = IconRequestModel(
list = commonItems,
iconCount = commonItems.size,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@ abstract class BasePreferenceManager(
fun toggle() = set(!get())

@Composable
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)
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
}
}
prefs.registerOnSharedPreferenceChangeListener(listener)
awaitDispose {
prefs.unregisterOnSharedPreferenceChangeListener(listener)
}
}
}

Expand All @@ -63,18 +61,16 @@ abstract class BasePreferenceManager(
fun set(value: Int) = editor.putInt(key, value).apply()

@Composable
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)
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
}
}
prefs.registerOnSharedPreferenceChangeListener(listener)
awaitDispose {
prefs.unregisterOnSharedPreferenceChangeListener(listener)
}
}
}
}
Expand All @@ -101,20 +97,16 @@ class PreferenceManager private constructor(
/**
* Returns a singleton instance of [PreferenceManager]
*/
fun getInstance(context: Context): PreferenceManager {
return instance ?: synchronized(this) {
instance ?: PreferenceManager(
context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE),
).also { instance = it }
}
fun getInstance(context: Context): PreferenceManager = 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 {
return PreferenceManager(DummySharedPreferences())
}
fun getDummyInstance(): PreferenceManager = PreferenceManager(DummySharedPreferences())
}
}

Expand Down Expand Up @@ -152,7 +144,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,8 +249,7 @@ 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,7 +25,8 @@ 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 @@ -43,7 +44,8 @@ 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,32 +7,28 @@ import android.content.pm.ResolveInfo
import app.lawnchair.lawnicons.model.IconInfo
import app.lawnchair.lawnicons.model.LabelAndComponent

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.getPackagesList(): List<ResolveInfo> = try {
packageManager.queryIntentActivities(
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
PackageManager.GET_RESOLVED_FILTER,
)
} catch (e: Exception) {
listOf()
}

fun Context.getSystemIconInfoAppfilter(): List<IconInfo> {
return getPackagesList().map { ri ->
with(ri) {
val riPkg = activityInfo.packageName
val component = "$riPkg/${activityInfo.name}"
fun Context.getSystemIconInfoAppfilter(): List<IconInfo> = 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,8 +20,7 @@ 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,7 +43,8 @@ class LawniconsViewModelImpl @Inject constructor(
private val iconRepository: IconRepository,
private val newIconsRepository: NewIconsRepository,
private val iconRequestSettingsRepository: IconRequestSettingsRepository,
) : LawniconsViewModel, ViewModel() {
) : ViewModel(),
LawniconsViewModel {
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 "6.25.0" apply false
id("com.diffplug.spotless") version "7.0.0" apply false
id("org.gradle.android.cache-fix") version "3.0.1" apply false
}

Expand Down
Loading

0 comments on commit ddbfbff

Please sign in to comment.