diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/WidgetsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/WidgetsAdapter.kt index 0924e26..761f46a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/WidgetsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/WidgetsAdapter.kt @@ -3,7 +3,10 @@ package com.simplemobiletools.launcher.adapters import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide import com.simplemobiletools.commons.extensions.getProperTextColor import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.activities.SimpleActivity @@ -12,6 +15,7 @@ import com.simplemobiletools.launcher.helpers.WIDGET_LIST_SECTION import com.simplemobiletools.launcher.models.WidgetsListItem import com.simplemobiletools.launcher.models.WidgetsListItemsHolder import com.simplemobiletools.launcher.models.WidgetsListSection +import kotlinx.android.synthetic.main.item_widget_list_items_holder.view.* import kotlinx.android.synthetic.main.item_widget_list_section.view.* class WidgetsAdapter( @@ -57,7 +61,32 @@ class WidgetsAdapter( } } - private fun setupListItemsHolder(view: View, listItem: WidgetsListItem) {} + private fun setupListItemsHolder(view: View, listItem: WidgetsListItemsHolder) { + view.widget_list_items_holder.removeAllViews() + listItem.widgets.forEachIndexed { index, widget -> + val imageSize = activity.resources.getDimension(R.dimen.widget_preview_size).toInt() + val widgetPreview = LayoutInflater.from(activity).inflate(R.layout.item_widget_preview, null) as ImageView + view.widget_list_items_holder.addView(widgetPreview) + + val endMargin = if (index == listItem.widgets.size - 1) { + activity.resources.getDimension(R.dimen.medium_margin).toInt() + } else { + 0 + } + + (widgetPreview.layoutParams as LinearLayout.LayoutParams).apply { + marginStart = activity.resources.getDimension(R.dimen.activity_margin).toInt() + marginEnd = endMargin + width = imageSize + height = imageSize + } + + Glide.with(activity) + .load(widget.widgetPreviewImage) + .fitCenter() + .into(widgetPreview) + } + } inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { fun bindView(widgetListItem: WidgetsListItem, callback: (itemView: View, adapterPosition: Int) -> Unit) { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt index 106f3da..b147add 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt @@ -7,12 +7,12 @@ import android.content.pm.LauncherApps import android.content.pm.PackageManager import android.os.Process import android.util.AttributeSet +import android.util.DisplayMetrics import android.view.Surface import android.view.WindowManager import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.isRPlus -import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.activities.MainActivity import com.simplemobiletools.launcher.adapters.WidgetsAdapter import com.simplemobiletools.launcher.models.AppWidget @@ -49,13 +49,14 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment val appTitle = appMetadata.appTitle val appIcon = appMetadata.appIcon val widgetTitle = info.loadLabel(context.packageManager) + val widgetPreviewImage = info.loadPreviewImage(context, DisplayMetrics.DENSITY_MEDIUM) val width = info.minWidth val height = info.minHeight - val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, width, height) + val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, width, height) appWidgets.add(widget) } - // list also the widgets that are technically shortcuts + // show also the widgets that are technically shortcuts val intent = Intent(Intent.ACTION_CREATE_SHORTCUT, null) val list = context.packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED) for (info in list) { @@ -65,7 +66,8 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue val appIcon = appMetadata.appIcon val widgetTitle = info.loadLabel(context.packageManager).toString() - val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, 0, 0) + val widgetPreviewImage = info.loadIcon(context.packageManager) + val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0) appWidgets.add(widget) } @@ -138,7 +140,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment } } - widgets_list.setPadding(0, 0, resources.getDimension(R.dimen.medium_margin).toInt(), bottomListPadding) + widgets_list.setPadding(0, 0, 0, bottomListPadding) widgets_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0) } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt index 5147571..e27a370 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt @@ -2,5 +2,5 @@ package com.simplemobiletools.launcher.models import android.graphics.drawable.Drawable -data class AppWidget(var appPackageName: String, var appTitle: String, val appIcon: Drawable, val widgetTitle: String, var width: Int, val height: Int) : +data class AppWidget(var appPackageName: String, var appTitle: String, val appIcon: Drawable, val widgetTitle: String, val widgetPreviewImage: Drawable?, var width: Int, val height: Int) : WidgetsListItem() diff --git a/app/src/main/res/drawable/widget_preview_background.xml b/app/src/main/res/drawable/widget_preview_background.xml new file mode 100644 index 0000000..1da7309 --- /dev/null +++ b/app/src/main/res/drawable/widget_preview_background.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/item_widget_list_items_holder.xml b/app/src/main/res/layout/item_widget_list_items_holder.xml index a194410..93a62ba 100644 --- a/app/src/main/res/layout/item_widget_list_items_holder.xml +++ b/app/src/main/res/layout/item_widget_list_items_holder.xml @@ -1,8 +1,14 @@ - + android:scrollbars="none"> - + + + diff --git a/app/src/main/res/layout/item_widget_preview.xml b/app/src/main/res/layout/item_widget_preview.xml new file mode 100644 index 0000000..8f283c8 --- /dev/null +++ b/app/src/main/res/layout/item_widget_preview.xml @@ -0,0 +1,11 @@ + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 86b2344..4a00ab9 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,5 @@ 55dp 70dp + 140dp