replace tile counts with "Shortcut" at shortcut widgets

This commit is contained in:
tibbi 2022-09-16 11:24:06 +02:00
parent 3e79d22fbb
commit 480de21288
3 changed files with 13 additions and 5 deletions

View File

@ -82,7 +82,11 @@ class WidgetsAdapter(
} }
widgetPreview.widget_size.apply { widgetPreview.widget_size.apply {
text = "${widget.widthTiles} x ${widget.heightTiles}" text = if (widget.isShortcut) {
activity.getString(R.string.shortcut)
} else {
"${widget.widthTiles} x ${widget.heightTiles}"
}
setTextColor(textColor) setTextColor(textColor)
} }

View File

@ -52,7 +52,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon
val widthTileCount = getTileCount(info.minWidth) val widthTileCount = getTileCount(info.minWidth)
val heightTileCount = getTileCount(info.minHeight) val heightTileCount = getTileCount(info.minHeight)
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthTileCount, heightTileCount) val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthTileCount, heightTileCount, false)
appWidgets.add(widget) appWidgets.add(widget)
} }
@ -67,7 +67,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val appIcon = appMetadata.appIcon val appIcon = appMetadata.appIcon
val widgetTitle = info.loadLabel(packageManager).toString() val widgetTitle = info.loadLabel(packageManager).toString()
val widgetPreviewImage = packageManager.getDrawable(componentInfo.packageName, info.iconResource, componentInfo) val widgetPreviewImage = packageManager.getDrawable(componentInfo.packageName, info.iconResource, componentInfo)
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0) val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0, true)
appWidgets.add(widget) appWidgets.add(widget)
} }
@ -76,7 +76,10 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
} }
} }
private fun getTileCount(size: Int) = Math.ceil(((size / resources.displayMetrics.density) - 30) / 70.0).toInt() private fun getTileCount(size: Int): Int {
val tiles = Math.ceil(((size / resources.displayMetrics.density) - 30) / 70.0).toInt()
return Math.max(tiles, 1)
}
private fun splitWidgetsByApps(appWidgets: ArrayList<AppWidget>) { private fun splitWidgetsByApps(appWidgets: ArrayList<AppWidget>) {
var currentAppPackageName = "" var currentAppPackageName = ""

View File

@ -9,5 +9,6 @@ data class AppWidget(
val widgetTitle: String, val widgetTitle: String,
val widgetPreviewImage: Drawable?, val widgetPreviewImage: Drawable?,
var widthTiles: Int, var widthTiles: Int,
val heightTiles: Int val heightTiles: Int,
val isShortcut: Boolean
) : WidgetsListItem() ) : WidgetsListItem()