Add Widget::getLabel method
This commit is contained in:
@@ -2,8 +2,10 @@ package de.mm20.launcher2.widgets
|
||||
|
||||
import android.app.Activity
|
||||
import android.appwidget.AppWidgetHost
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import de.mm20.launcher2.database.entities.PartialWidgetEntity
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -34,6 +36,23 @@ data class AppWidget(
|
||||
)
|
||||
}
|
||||
|
||||
private var label: String? = null
|
||||
|
||||
override fun getLabel(context: Context): String {
|
||||
if (label != null) return label!!
|
||||
val widgetInfo = AppWidgetManager.getInstance(context).getAppWidgetInfo(config.widgetId)
|
||||
if (widgetInfo == null) {
|
||||
label = ""
|
||||
return label!!
|
||||
}
|
||||
try {
|
||||
label = widgetInfo.loadLabel(context.packageManager)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
label = ""
|
||||
}
|
||||
return label!!
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Type = "app"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.content.Context
|
||||
import de.mm20.launcher2.database.entities.PartialWidgetEntity
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
@@ -27,6 +28,10 @@ data class AppsWidget(
|
||||
)
|
||||
}
|
||||
|
||||
override fun getLabel(context: Context): String {
|
||||
return context.getString(R.string.widget_name_apps)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Type = "favorites"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.content.Context
|
||||
import de.mm20.launcher2.database.entities.PartialWidgetEntity
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -31,6 +32,10 @@ data class CalendarWidget(
|
||||
)
|
||||
}
|
||||
|
||||
override fun getLabel(context: Context): String {
|
||||
return context.getString(R.string.widget_name_calendar)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Type = "calendar"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.content.Context
|
||||
import de.mm20.launcher2.database.entities.PartialWidgetEntity
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
@@ -22,6 +23,10 @@ data class MusicWidget(
|
||||
)
|
||||
}
|
||||
|
||||
override fun getLabel(context: Context): String {
|
||||
return context.getString(R.string.widget_name_music)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Type = "music"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.content.Context
|
||||
import de.mm20.launcher2.database.entities.PartialWidgetEntity
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
@@ -33,6 +34,10 @@ data class NotesWidget(
|
||||
)
|
||||
}
|
||||
|
||||
override fun getLabel(context: Context): String {
|
||||
return context.getString(R.string.widget_name_notes)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Type = "notes"
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.app.Activity
|
||||
import android.appwidget.AppWidgetHost
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import de.mm20.launcher2.database.entities.PartialWidgetEntity
|
||||
import de.mm20.launcher2.ktx.tryStartActivity
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.util.UUID
|
||||
|
||||
@@ -31,6 +25,10 @@ data class WeatherWidget(
|
||||
)
|
||||
}
|
||||
|
||||
override fun getLabel(context: Context): String {
|
||||
return context.getString(R.string.widget_name_weather)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Type = "weather"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.mm20.launcher2.widgets
|
||||
|
||||
import android.content.Context
|
||||
import de.mm20.launcher2.database.entities.PartialWidgetEntity
|
||||
import de.mm20.launcher2.database.entities.WidgetEntity
|
||||
import de.mm20.launcher2.ktx.decodeFromStringOrNull
|
||||
@@ -21,6 +22,8 @@ sealed class Widget {
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun getLabel(context: Context): String
|
||||
|
||||
abstract fun toDatabaseEntity(): PartialWidgetEntity
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user