From c6ba8d72ed596b53c511b17de2a5b0070cee97c9 Mon Sep 17 00:00:00 2001 From: LooKeR Date: Tue, 23 Nov 2021 12:15:01 +0530 Subject: [PATCH] Improve: Fix weird behaviour on scroll I wonder why nobody noticed but scrolling is weird in App Detail page --- .../looker/droidify/screen/ProductAdapter.kt | 82 ++++++++++++------- src/main/res/layout/item_app_info_x.xml | 45 ---------- src/main/res/layout/screenshot_scrollview.xml | 47 +++++++++++ 3 files changed, 100 insertions(+), 74 deletions(-) create mode 100644 src/main/res/layout/screenshot_scrollview.xml diff --git a/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt b/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt index dd9995a1..12075fec 100644 --- a/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt +++ b/src/main/kotlin/com/looker/droidify/screen/ProductAdapter.kt @@ -87,7 +87,7 @@ class ProductAdapter(private val callbacks: Callbacks) : data class Downloading(val read: Long, val total: Long?) : Status() } - enum class ViewType { APP_INFO, SWITCH, SECTION, EXPAND, TEXT, LINK, PERMISSIONS, RELEASE, EMPTY } + enum class ViewType { APP_INFO, SCREENSHOT, SWITCH, SECTION, EXPAND, TEXT, LINK, PERMISSIONS, RELEASE, EMPTY } private enum class SwitchType(val titleResId: Int) { IGNORE_ALL_UPDATES(R.string.ignore_all_updates), @@ -105,7 +105,7 @@ class ProductAdapter(private val callbacks: Callbacks) : internal enum class ExpandType { NOTHING, DESCRIPTION, CHANGES, - LINKS, DONATES, PERMISSIONS, SCREENSHOTS, VERSIONS + LINKS, DONATES, PERMISSIONS, VERSIONS } private enum class TextType { DESCRIPTION, ANTI_FEATURES, CHANGES } @@ -131,7 +131,6 @@ class ProductAdapter(private val callbacks: Callbacks) : val repository: Repository, val product: Product, val packageName: String, - val screenshots: List, ) : Item() { override val descriptor: String get() = "app_info.${product.name}" @@ -140,6 +139,18 @@ class ProductAdapter(private val callbacks: Callbacks) : get() = ViewType.APP_INFO } + class ScreenshotItem( + val screenshots: List, + val packageName: String, + val repository: Repository, + ) : Item() { + override val descriptor: String + get() = "screenshot.${screenshots.size}" + override val viewType: ViewType + get() = ViewType.SCREENSHOT + + } + class SwitchItem( val switchType: SwitchType, val packageName: String, @@ -314,12 +325,6 @@ class ProductAdapter(private val callbacks: Callbacks) : 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 @@ -346,6 +351,16 @@ class ProductAdapter(private val callbacks: Callbacks) : val dev = itemView.findViewById(R.id.dev_block)!! } + private class ScreenShotViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + + 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)!! + } + private class SwitchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val enabled = itemView.findViewById(R.id.enabled)!! @@ -554,8 +569,12 @@ class ProductAdapter(private val callbacks: Callbacks) : items += Item.AppInfoItem( productRepository.second, productRepository.first, + packageName + ) + items += Item.ScreenshotItem( + productRepository.first.screenshots, packageName, - productRepository.first.screenshots + productRepository.second ) if (installedItem != null) { @@ -892,6 +911,7 @@ class ProductAdapter(private val callbacks: Callbacks) : ViewType.APP_INFO -> AppInfoViewHolder(parent.inflate(R.layout.item_app_info_x)).apply { action.setOnClickListener { this@ProductAdapter.action?.let(callbacks::onActionClick) } } + ViewType.SCREENSHOT -> ScreenShotViewHolder(parent.inflate(R.layout.screenshot_scrollview)) ViewType.SWITCH -> SwitchViewHolder(parent.inflate(R.layout.switch_item)).apply { itemView.setOnClickListener { val switchItem = items[adapterPosition] as Item.SwitchItem @@ -1074,25 +1094,6 @@ class ProductAdapter(private val callbacks: Callbacks) : 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 @@ -1165,6 +1166,29 @@ class ProductAdapter(private val callbacks: Callbacks) : true } } + ViewType.SCREENSHOT -> { + holder as ScreenShotViewHolder + item as Item.ScreenshotItem + 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) + } + } + } ViewType.SWITCH -> { holder as SwitchViewHolder item as Item.SwitchItem diff --git a/src/main/res/layout/item_app_info_x.xml b/src/main/res/layout/item_app_info_x.xml index da101288..27c82aff 100644 --- a/src/main/res/layout/item_app_info_x.xml +++ b/src/main/res/layout/item_app_info_x.xml @@ -235,54 +235,9 @@ 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" /> - - - - - - - - - - - diff --git a/src/main/res/layout/screenshot_scrollview.xml b/src/main/res/layout/screenshot_scrollview.xml new file mode 100644 index 00000000..fb0fdc3c --- /dev/null +++ b/src/main/res/layout/screenshot_scrollview.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + \ No newline at end of file