diff --git a/.editorconfig b/.editorconfig index 8a224d86dc6..29f55693814 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,8 +11,14 @@ trim_trailing_whitespace = true ij_kotlin_imports_layout = * ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true +ij_kotlin_name_count_to_use_star_import = 999 +ij_kotlin_name_count_to_use_star_import_for_members = 999 +ij_kotlin_packages_to_use_import_on_demand = unset ktlint_code_style = intellij_idea ktlint_function_naming_ignore_when_annotated_with = Composable +ktlint_standard_discouraged-comment-location = disabled +ktlint_standard_function-expression-body = disabled +ktlint_compose_lambda-param-event-trailing = disabled [*.md] trim_trailing_whitespace = false diff --git a/app/src/main/kotlin/app/lawnchair/lawnicons/api/GithubApiModule.kt b/app/src/main/kotlin/app/lawnchair/lawnicons/api/GithubApiModule.kt index aae95b655bd..3642d46628c 100644 --- a/app/src/main/kotlin/app/lawnchair/lawnicons/api/GithubApiModule.kt +++ b/app/src/main/kotlin/app/lawnchair/lawnicons/api/GithubApiModule.kt @@ -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() + } } diff --git a/app/src/main/kotlin/app/lawnchair/lawnicons/api/WebsiteApiModule.kt b/app/src/main/kotlin/app/lawnchair/lawnicons/api/WebsiteApiModule.kt index fed3191c478..4826fe1dda9 100644 --- a/app/src/main/kotlin/app/lawnchair/lawnicons/api/WebsiteApiModule.kt +++ b/app/src/main/kotlin/app/lawnchair/lawnicons/api/WebsiteApiModule.kt @@ -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() + } } diff --git a/app/src/main/kotlin/app/lawnchair/lawnicons/model/IconInfo.kt b/app/src/main/kotlin/app/lawnchair/lawnicons/model/IconInfo.kt index 3d3f9b67429..c1ad53e9976 100644 --- a/app/src/main/kotlin/app/lawnchair/lawnicons/model/IconInfo.kt +++ b/app/src/main/kotlin/app/lawnchair/lawnicons/model/IconInfo.kt @@ -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.mergeByDrawableName(): List = groupBy { it.drawableName } - .map { (drawableName, icons) -> - val mergedComponentNames = icons.flatMap { it.componentNames } - IconInfo( - componentNames = mergedComponentNames, - drawableName = drawableName, - id = icons.first().id, - ) - } +fun List.mergeByDrawableName(): List { + 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 diff --git a/app/src/main/kotlin/app/lawnchair/lawnicons/repository/PreferenceManager.kt b/app/src/main/kotlin/app/lawnchair/lawnicons/repository/PreferenceManager.kt index 4e549fa11b0..22efe5df61c 100644 --- a/app/src/main/kotlin/app/lawnchair/lawnicons/repository/PreferenceManager.kt +++ b/app/src/main/kotlin/app/lawnchair/lawnicons/repository/PreferenceManager.kt @@ -35,15 +35,17 @@ abstract class BasePreferenceManager( fun toggle() = set(!get()) @Composable - fun asState(): State = 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 { + 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) } } } @@ -61,15 +63,17 @@ abstract class BasePreferenceManager( fun set(value: Int) = editor.putInt(key, value).apply() @Composable - fun asState(): State = 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 { + 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) } } } @@ -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()) + } } } diff --git a/app/src/main/kotlin/app/lawnchair/lawnicons/util/GetSystemPackageList.kt b/app/src/main/kotlin/app/lawnchair/lawnicons/util/GetSystemPackageList.kt index 37113c3c0bf..bb1e78e9707 100644 --- a/app/src/main/kotlin/app/lawnchair/lawnicons/util/GetSystemPackageList.kt +++ b/app/src/main/kotlin/app/lawnchair/lawnicons/util/GetSystemPackageList.kt @@ -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 = try { - packageManager.queryIntentActivities( - Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), - PackageManager.GET_RESOLVED_FILTER, - ) -} catch (e: Exception) { - listOf() +fun Context.getPackagesList(): List { + return try { + packageManager.queryIntentActivities( + Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), + PackageManager.GET_RESOLVED_FILTER, + ) + } catch (e: Exception) { + listOf() + } } -fun Context.getSystemIconInfoAppfilter(): List = getPackagesList().map { ri -> - with(ri) { - val riPkg = activityInfo.packageName - val component = "$riPkg/${activityInfo.name}" +fun Context.getSystemIconInfoAppfilter(): List { + 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, + ) + } } } diff --git a/build.gradle.kts b/build.gradle.kts index f252c537b92..d769d34a7f4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 "7.0.1" apply false id("org.gradle.android.cache-fix") version "3.0.1" apply false } diff --git a/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/AppfilterDiffCreator.kt b/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/AppfilterDiffCreator.kt index 9f5dcf3c919..eaed717ea0f 100644 --- a/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/AppfilterDiffCreator.kt +++ b/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/AppfilterDiffCreator.kt @@ -23,53 +23,61 @@ object AppfilterDiffCreator { private fun getPreviousReleaseLines( appFilterFile: String, - ): List = try { - runGitCommand(listOf("fetch", "--tags")) - - val tagCommand = - listOf("/usr/bin/bash", "-c", "git tag --sort=-creatordate | head -n 1") - val tagProcess = ProcessBuilder(tagCommand) - .redirectErrorStream(true) - .start() - - val latestTag = tagProcess.inputStream.bufferedReader().readLine() - if (tagProcess.waitFor() != 0) { - throw RuntimeException("Failed to get latest tag") - } + ): List { + return try { + runGitCommand(listOf("fetch", "--tags")) + + val tagCommand = + listOf("/usr/bin/bash", "-c", "git tag --sort=-creatordate | head -n 1") + val tagProcess = ProcessBuilder(tagCommand) + .redirectErrorStream(true) + .start() + + val latestTag = tagProcess.inputStream.bufferedReader().readLine() + if (tagProcess.waitFor() != 0) { + throw RuntimeException("Failed to get latest tag") + } - runGitCommand(listOf("show", "$latestTag:$appFilterFile")) - } catch (e: Exception) { - println(e) - listOf() + runGitCommand(listOf("show", "$latestTag:$appFilterFile")) + } catch (e: Exception) { + println(e) + listOf() + } } private fun runGitCommand( args: List, - ): List = try { - val command = listOf("git") + args + ): List { + return try { + val command = listOf("git") + args - val process = ProcessBuilder(command) - .redirectErrorStream(true) - .start() + val process = ProcessBuilder(command) + .redirectErrorStream(true) + .start() - val result = process.inputStream.bufferedReader().readLines() - if (process.waitFor() != 0) { - throw RuntimeException("Failed to execute $command: $result") - } - println("task git $args completed") + val result = process.inputStream.bufferedReader().readLines() + if (process.waitFor() != 0) { + throw RuntimeException("Failed to execute $command: $result") + } + println("task git $args completed") - result - } catch (e: Exception) { - println(e) - listOf() + result + } catch (e: Exception) { + println(e) + listOf() + } } - private fun readFileContents(filePath: String): List = File(filePath).readLines() + private fun readFileContents(filePath: String): List { + return File(filePath).readLines() + } private fun getLineDiff( mainLines: List, developLines: List, - ): List = developLines.filterNot { it in mainLines } + ): List { + return developLines.filterNot { it in mainLines } + } private fun writeDiffToFile( diff: List, diff --git a/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/XmlUtil.kt b/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/XmlUtil.kt index cc2f809671d..45db04313fb 100644 --- a/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/XmlUtil.kt +++ b/svg-processor/src/main/kotlin/app/lawnchair/lawnicons/helper/XmlUtil.kt @@ -28,9 +28,13 @@ import org.dom4j.io.XMLWriter object XmlUtil { private val UTF_8 = Charsets.UTF_8.name() - fun getElements(document: Document, path: String): List = document.rootElement.elements(path) + fun getElements(document: Document, path: String): List { + return document.rootElement.elements(path) + } - fun getDocument(xmlPath: String): Document = SAXReader().apply { encoding = UTF_8 }.read(xmlPath) + fun getDocument(xmlPath: String): Document { + return SAXReader().apply { encoding = UTF_8 }.read(xmlPath) + } fun getFileWithExtension(target: Path, extension: String = "xml"): String { val svgFilePath = target.toFile().absolutePath