Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,58 @@
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
id("kotlin-android")
|
||||
id("kotlin-android-extensions")
|
||||
}
|
||||
|
||||
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 {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.bundles.kotlin)
|
||||
implementation(libs.androidx.core)
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.androidx.media2)
|
||||
implementation(libs.androidx.constraintlayout)
|
||||
|
||||
implementation(libs.bundles.androidx.lifecycle)
|
||||
|
||||
implementation(libs.materialcomponents)
|
||||
|
||||
implementation(project(":weather"))
|
||||
implementation(project(":calendar"))
|
||||
implementation(project(":music"))
|
||||
implementation(project(":ktx"))
|
||||
implementation(project(":transition"))
|
||||
implementation(project(":base"))
|
||||
implementation(project(":preferences"))
|
||||
implementation(project(":database"))
|
||||
|
||||
}
|
||||
Vendored
+21
@@ -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.kts.kts.kts.kts.kts.kts.kts.kts.kts.kts.
|
||||
#
|
||||
# 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
|
||||
@@ -0,0 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.mm20.launcher2.widgets">
|
||||
|
||||
/
|
||||
</manifest>
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import de.mm20.launcher2.database.entities.WidgetEntity
|
||||
|
||||
data class Widget(
|
||||
val type: WidgetType,
|
||||
var data: String,
|
||||
var height: Int,
|
||||
val label: String = ""
|
||||
) {
|
||||
constructor(entity: WidgetEntity) : this(
|
||||
type = if (entity.type == "internal") WidgetType.INTERNAL else WidgetType. THIRD_PARTY,
|
||||
data = entity.data,
|
||||
height = entity.height,
|
||||
label = entity.label
|
||||
)
|
||||
|
||||
fun toDatabaseEntity(position: Int): WidgetEntity {
|
||||
return WidgetEntity(
|
||||
type = if (type == WidgetType.INTERNAL) "internal" else "3rdparty",
|
||||
label = label,
|
||||
position = position,
|
||||
height = height,
|
||||
data = data
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
enum class WidgetType {
|
||||
INTERNAL,
|
||||
THIRD_PARTY
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.content.Context
|
||||
import de.mm20.launcher2.widgets.R
|
||||
import de.mm20.launcher2.database.AppDatabase
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
internal class WidgetRepository(
|
||||
val context: Context
|
||||
) {
|
||||
|
||||
suspend fun getWidgets(): List<Widget> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).widgetDao().getWidgets().map { Widget(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun getInternalWidgets(): List<Widget> {
|
||||
return listOf(
|
||||
Widget(WidgetType.INTERNAL, "weather", -1, context.getString(R.string.widget_name_weather))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
suspend fun saveWidgets(widgets: List<Widget>) {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).widgetDao().updateWidgets(widgets.mapIndexed { i, widget -> widget.toDatabaseEntity(i) })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import de.mm20.launcher2.calendar.CalendarRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class WidgetViewModel(app: Application) : AndroidViewModel(app) {
|
||||
|
||||
private val widgetRepository: WidgetRepository by lazy {
|
||||
WidgetRepository(app)
|
||||
}
|
||||
|
||||
suspend fun getWidgets(): List<Widget> {
|
||||
return withContext(viewModelScope.coroutineContext + Dispatchers.IO) {
|
||||
widgetRepository.getWidgets()
|
||||
}
|
||||
}
|
||||
|
||||
fun saveWidgets(widgets: List<Widget>) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
widgetRepository.saveWidgets(widgets)
|
||||
}
|
||||
}
|
||||
|
||||
fun getInternalWidgets(): List<Widget> {
|
||||
return widgetRepository.getInternalWidgets()
|
||||
}
|
||||
|
||||
private val calendarRepository: CalendarRepository by lazy {
|
||||
CalendarRepository.getInstance(app)
|
||||
}
|
||||
|
||||
fun requestCalendarUpdate() {
|
||||
calendarRepository.requestCalendarUpdate()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user