Initial commit for customattrs module
This commit is contained in:
parent
e3de50693f
commit
5bd86e6f95
@ -8,7 +8,7 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath("com.android.tools.build:gradle:7.2.1")
|
classpath("com.android.tools.build:gradle:7.2.1")
|
||||||
classpath(libs.kotlin.gradle)
|
classpath(libs.kotlin.gradle)
|
||||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
|
|||||||
1
customattrs/.gitignore
vendored
Normal file
1
customattrs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
47
customattrs/build.gradle.kts
Normal file
47
customattrs/build.gradle.kts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
plugins {
|
||||||
|
id("com.android.library")
|
||||||
|
id("kotlin-android")
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk = sdk.versions.compileSdk.get().toInt()
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = sdk.versions.minSdk.get().toInt()
|
||||||
|
targetSdk = sdk.versions.targetSdk.get().toInt()
|
||||||
|
|
||||||
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
consumerProguardFiles("consumer-rules.pro")
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
proguardFiles(
|
||||||
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
|
"proguard-rules.pro"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
namespace = "de.mm20.launcher2.customattrs"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(libs.bundles.kotlin)
|
||||||
|
implementation(libs.androidx.core)
|
||||||
|
|
||||||
|
implementation(libs.koin.android)
|
||||||
|
|
||||||
|
implementation(project(":database"))
|
||||||
|
implementation(project(":search"))
|
||||||
|
implementation(project(":ktx"))
|
||||||
|
|
||||||
|
}
|
||||||
0
customattrs/consumer-rules.pro
Normal file
0
customattrs/consumer-rules.pro
Normal file
21
customattrs/proguard-rules.pro
vendored
Normal file
21
customattrs/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
5
customattrs/src/main/AndroidManifest.xml
Normal file
5
customattrs/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="de.mm20.launcher2.customattrs">
|
||||||
|
|
||||||
|
</manifest>
|
||||||
@ -0,0 +1,153 @@
|
|||||||
|
package de.mm20.launcher2.customattrs
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.util.Log
|
||||||
|
import de.mm20.launcher2.database.entities.CustomAttributeEntity
|
||||||
|
import de.mm20.launcher2.ktx.jsonObjectOf
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
sealed interface CustomAttribute {
|
||||||
|
fun toDatabaseEntity(key: String): CustomAttributeEntity
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
internal fun fromDatabaseEntity(entity: CustomAttributeEntity): CustomAttribute? {
|
||||||
|
return when (entity.type) {
|
||||||
|
CustomAttributeType.Label.value -> CustomLabel(
|
||||||
|
label = entity.value
|
||||||
|
)
|
||||||
|
CustomAttributeType.Tag.value -> CustomTag(
|
||||||
|
tagName = entity.value
|
||||||
|
)
|
||||||
|
CustomAttributeType.Icon.value -> CustomIcon.fromDatabaseEntity(entity)
|
||||||
|
else -> {
|
||||||
|
Log.e("MM20", "Invalid custom attribute type: ${entity.type}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CustomLabel(
|
||||||
|
val label: String,
|
||||||
|
) : CustomAttribute {
|
||||||
|
override fun toDatabaseEntity(key: String): CustomAttributeEntity {
|
||||||
|
return CustomAttributeEntity(
|
||||||
|
key = key,
|
||||||
|
type = CustomAttributeType.Label.value,
|
||||||
|
value = label,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomTag(
|
||||||
|
val tagName: String
|
||||||
|
): CustomAttribute {
|
||||||
|
override fun toDatabaseEntity(key: String): CustomAttributeEntity {
|
||||||
|
return CustomAttributeEntity(
|
||||||
|
key = key,
|
||||||
|
type = CustomAttributeType.Tag.value,
|
||||||
|
value = tagName,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sealed class CustomIcon : CustomAttribute {
|
||||||
|
|
||||||
|
override fun toDatabaseEntity(key: String): CustomAttributeEntity {
|
||||||
|
return CustomAttributeEntity(
|
||||||
|
key = key,
|
||||||
|
type = CustomAttributeType.Icon.value,
|
||||||
|
value = this.toDatabaseValue()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal abstract fun toDatabaseValue(): String
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
internal fun fromDatabaseEntity(entity: CustomAttributeEntity): CustomIcon? {
|
||||||
|
val payload = JSONObject(entity.value)
|
||||||
|
val type = payload.getString("type")
|
||||||
|
return when (type) {
|
||||||
|
"custom_icon_pack_icon" -> {
|
||||||
|
CustomIconPackIcon(
|
||||||
|
iconName = payload.getString("icon"),
|
||||||
|
iconPackPackage = payload.getString("icon_pack")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
"custom_themed_icon" -> {
|
||||||
|
CustomThemedIcon(
|
||||||
|
iconName = payload.getString("icon"),
|
||||||
|
iconPackPackage = payload.getString("icon_pack")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
"adaptified_legacy_icon" -> {
|
||||||
|
AdaptifiedLegacyIcon(
|
||||||
|
fgScale = payload.getDouble("fg_scale").toFloat(),
|
||||||
|
bgColor = payload.getInt("bg_color")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class CustomIconPackIcon(
|
||||||
|
val iconPackPackage: String,
|
||||||
|
val iconName: String,
|
||||||
|
) : CustomIcon() {
|
||||||
|
override fun toDatabaseValue(): String {
|
||||||
|
return jsonObjectOf(
|
||||||
|
"type" to "custom_icon_pack_icon",
|
||||||
|
"icon" to iconName,
|
||||||
|
"icon_pack" to iconPackPackage,
|
||||||
|
).toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class AdaptifiedLegacyIcon(
|
||||||
|
val fgScale: Float,
|
||||||
|
/**
|
||||||
|
* The background color in ARGB format or [UnspecifiedColor] or [ThemeColor]
|
||||||
|
*/
|
||||||
|
val bgColor: Int = UnspecifiedColor,
|
||||||
|
): CustomIcon() {
|
||||||
|
override fun toDatabaseValue(): String {
|
||||||
|
return jsonObjectOf(
|
||||||
|
"type" to "adaptified_legacy_icon",
|
||||||
|
"fg_scale" to fgScale,
|
||||||
|
"bg_color" to bgColor,
|
||||||
|
).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Extract color from foreground icon
|
||||||
|
*/
|
||||||
|
const val UnspecifiedColor = 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use color from theme
|
||||||
|
*/
|
||||||
|
const val ThemeColor = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
data class CustomThemedIcon(
|
||||||
|
val iconPackPackage: String,
|
||||||
|
val iconName: String,
|
||||||
|
) : CustomIcon() {
|
||||||
|
override fun toDatabaseValue(): String {
|
||||||
|
return jsonObjectOf(
|
||||||
|
"type" to "custom_themed_icon",
|
||||||
|
"icon" to iconName,
|
||||||
|
"icon_pack" to iconPackPackage,
|
||||||
|
).toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package de.mm20.launcher2.customattrs
|
||||||
|
|
||||||
|
enum class CustomAttributeType(val value: String) {
|
||||||
|
Icon("icon"),
|
||||||
|
Label("label"),
|
||||||
|
Tag("tag");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
internal fun fromValue(value: String): CustomAttributeType {
|
||||||
|
return values().first { it.value == value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package de.mm20.launcher2.customattrs
|
||||||
|
|
||||||
|
import de.mm20.launcher2.search.data.Searchable
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface CustomAttributesRepository {
|
||||||
|
fun getCustomAttributes(searchable: Searchable, type: CustomAttributeType? = null): Flow<List<CustomAttribute>>
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package de.mm20.launcher2.customattrs
|
||||||
|
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val customAttrsModule = module {
|
||||||
|
|
||||||
|
}
|
||||||
@ -390,3 +390,4 @@ include(":accounts")
|
|||||||
include(":appshortcuts")
|
include(":appshortcuts")
|
||||||
include(":material-color-utilities")
|
include(":material-color-utilities")
|
||||||
include(":backup")
|
include(":backup")
|
||||||
|
include(":customattrs")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user