From ba0b070988c4aa08fddcfd31e38c27b484d40eb0 Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Tue, 16 Nov 2021 00:54:27 +0100 Subject: [PATCH] Update: Extend AppInfo's view with screenshots section --- .../looker/droidify/screen/ProductAdapter.kt | 43 +++++++++++++++-- src/main/res/layout/item_app_info_x.xml | 46 +++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt b/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt index 4b5d4433..8e58db40 100644 --- a/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt +++ b/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt @@ -23,18 +23,18 @@ import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.widget.TextView -import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.widget.LinearLayoutCompat import androidx.core.content.res.ResourcesCompat import androidx.core.net.toUri import androidx.core.text.HtmlCompat import androidx.core.text.util.LinkifyCompat import androidx.core.view.doOnPreDraw +import androidx.core.widget.NestedScrollView +import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import coil.load import com.google.android.material.button.MaterialButton import com.google.android.material.card.MaterialCardView -import com.google.android.material.circularreveal.CircularRevealFrameLayout import com.google.android.material.divider.MaterialDivider import com.google.android.material.imageview.ShapeableImageView import com.google.android.material.progressindicator.LinearProgressIndicator @@ -131,7 +131,12 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int) abstract val descriptor: String abstract val viewType: ViewType - class AppInfoItem(val repository: Repository, val product: Product) : Item() { + class AppInfoItem( + val repository: Repository, + val product: Product, + val packageName: String, + val screenshots: List, + ) : Item() { override val descriptor: String get() = "app_info.${product.name}" @@ -313,6 +318,12 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int) val statusLayout = itemView.findViewById(R.id.status_layout)!! val status = itemView.findViewById(R.id.status)!! val progress = itemView.findViewById(R.id.progress)!! + val screenshotsSection = + itemView.findViewById(R.id.screenshots_section)!! + val screenshotsSectionIcon = + itemView.findViewById(R.id.screenshots_section_icon)!! + val screenshotsView = itemView.findViewById(R.id.screenshots_view)!! + val screenshotsRecycler = itemView.findViewById(R.id.screenshots_recycler)!! val progressIcon: Drawable val defaultIcon: Drawable @@ -606,7 +617,12 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int) items.clear() if (productRepository != null) { - items += Item.AppInfoItem(productRepository.second, productRepository.first) + items += Item.AppInfoItem( + productRepository.second, + productRepository.first, + packageName, + productRepository.first.screenshots + ) if (installedItem != null) { items.add( @@ -1128,6 +1144,25 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int) iconTint = if (action == Action.CANCEL) holder.actionTintOnCancel else holder.actionTintOnNormal } + if (item.screenshots.isEmpty()) { + holder.screenshotsSection.visibility = View.GONE + holder.screenshotsView.visibility = View.GONE + } else { + holder.screenshotsSection.visibility = View.VISIBLE + holder.screenshotsView.visibility = View.VISIBLE + holder.screenshotsSection.setOnClickListener { + val isExpanded = holder.screenshotsView.visibility == View.VISIBLE + holder.screenshotsSectionIcon.scaleY = if (isExpanded) -1f else 1f + holder.screenshotsView.visibility = + if (isExpanded) View.GONE else View.VISIBLE + } + holder.screenshotsRecycler.layoutManager = + LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + holder.screenshotsRecycler.adapter = + ScreenshotsAdapter { callbacks.onScreenshotClick(it) }.apply { + setScreenshots(item.repository, item.packageName, item.screenshots) + } + } } if (updateAll || updateStatus) { val status = status diff --git a/src/main/res/layout/item_app_info_x.xml b/src/main/res/layout/item_app_info_x.xml index 86109603..ed979f96 100644 --- a/src/main/res/layout/item_app_info_x.xml +++ b/src/main/res/layout/item_app_info_x.xml @@ -235,8 +235,54 @@ android:layout_height="56dp" android:layout_marginHorizontal="12dp" app:iconGravity="textStart" + app:layout_constraintBottom_toTopOf="@id/screenshots_section" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/status_layout" app:shapeAppearanceOverlay="@style/PillShapeAppearance" /> + + + + + + + + + + + +