Improve editor choice & expanded stream UI

This commit is contained in:
Rahul Kumar Patel
2021-02-22 00:10:08 +05:30
parent 86fac3e7c7
commit 548cced8a2
14 changed files with 318 additions and 57 deletions

View File

@@ -23,7 +23,6 @@ import com.airbnb.epoxy.TypedEpoxyController
import com.aurora.gplayapi.data.models.editor.EditorChoiceBundle
import com.aurora.gplayapi.data.models.editor.EditorChoiceCluster
import com.aurora.store.view.epoxy.groups.EditorChoiceModelGroup
import com.aurora.store.view.epoxy.views.EditorHeadViewModel_
import com.aurora.store.view.epoxy.views.HeaderViewModel_
class EditorChoiceController(private val callbacks: Callbacks) :

View File

@@ -48,21 +48,32 @@ class EditorChoiceModelGroup(
val idPrefix = editorChoiceCluster.id
models.add(
EditorImageViewModel_()
.id("artwork_header_${idPrefix}")
.artwork(editorChoiceCluster.clusterArtwork[0])
.click { _ -> callbacks.onClick(editorChoiceCluster) }
)
models.add(
EditorHeadViewModel_()
.id("header_${idPrefix}")
.title(editorChoiceCluster.clusterTitle)
)
editorChoiceCluster.clusterArtwork.forEach {
clusterViewModels.add(
EditorImageViewModel_()
.id("artwork_${idPrefix}")
.artwork(it)
.click { _ -> callbacks.onClick(editorChoiceCluster) }
editorChoiceCluster.clusterArtwork
.drop(1)
.forEach {
clusterViewModels.add(
EditorImageViewModel_()
.id("artwork_${idPrefix}_${it.url}")
.artwork(it)
.click { _ -> callbacks.onClick(editorChoiceCluster) }
)
}
)
}
models.add(
CarouselHorizontalModel_()

View File

@@ -20,6 +20,7 @@
package com.aurora.store.view.epoxy.views
import android.content.Context
import android.content.res.Resources
import android.util.AttributeSet
import android.widget.RelativeLayout
import com.airbnb.epoxy.CallbackProp
@@ -31,6 +32,7 @@ import com.aurora.store.R
import com.aurora.store.databinding.ViewEditorImageBinding
import com.aurora.store.util.extensions.clear
import com.aurora.store.util.extensions.load
import com.aurora.store.util.extensions.px
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
@@ -67,18 +69,20 @@ class EditorImageView : RelativeLayout {
fun artwork(artwork: Artwork) {
when (artwork.type) {
14 -> {
B.img.layoutParams.width =
resources.getDimension(R.dimen.icon_size_large).toInt() * 2
B.img.layoutParams.height = 108.px.toInt()
B.img.layoutParams.width = 192.px.toInt()
B.img.requestLayout()
B.img.load(artwork.url, DrawableTransitionOptions.withCrossFade()) {
transform(RoundedCorners(16))
transform(RoundedCorners(8.px.toInt()))
}
}
else -> {
B.img.layoutParams.width = resources.getDimension(R.dimen.icon_size_large).toInt()
B.img.layoutParams.width = 24.px.toInt()
B.img.layoutParams.height = 24.px.toInt()
B.img.requestLayout()
B.img.load(artwork.url, DrawableTransitionOptions.withCrossFade()) {
transform(RoundedCorners(16))
transform(RoundedCorners(4.px.toInt()))
}
}
}

View File

@@ -0,0 +1,126 @@
/*
* Aurora Store
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
*
* Aurora Store is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Aurora Store is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.aurora.store.view.epoxy.views.details
import android.content.Context
import android.util.AttributeSet
import android.widget.RelativeLayout
import com.airbnb.epoxy.CallbackProp
import com.airbnb.epoxy.ModelProp
import com.airbnb.epoxy.ModelView
import com.airbnb.epoxy.OnViewRecycled
import com.aurora.gplayapi.data.models.Artwork
import com.aurora.store.R
import com.aurora.store.databinding.ViewScreenshotMiniBinding
import com.aurora.store.util.extensions.clear
import com.aurora.store.util.extensions.load
import com.aurora.store.util.extensions.px
import com.aurora.store.view.epoxy.views.BaseView
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
@ModelView(
autoLayout = ModelView.Size.WRAP_WIDTH_WRAP_HEIGHT,
baseModelClass = BaseView::class
)
class MiniScreenshotView : RelativeLayout {
private lateinit var B: ViewScreenshotMiniBinding
private var position: Int = 0
interface ScreenshotCallback {
fun onClick(position: Int = 0)
}
constructor(context: Context?) : super(context) {
init(context, null)
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs)
}
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
init(context, attrs)
}
private fun init(context: Context?, attrs: AttributeSet?) {
val view = inflate(context, R.layout.view_screenshot_mini, this)
B = ViewScreenshotMiniBinding.bind(view)
}
@ModelProp
fun position(pos: Int) {
position = pos
}
@ModelProp
fun artwork(artwork: Artwork) {
normalizeSize(artwork)
B.img.load("${artwork.url}=rw-w480-v1-e15", DrawableTransitionOptions.withCrossFade()) {
placeholder(R.drawable.bg_rounded)
transform(RoundedCorners(8.px.toInt()))
}
}
private fun normalizeSize(artwork: Artwork) {
if (artwork.height != 0 && artwork.width != 0) {
val artworkHeight = artwork.height
val artworkWidth = artwork.width
val normalizedHeight: Float
val normalizedWidth: Float
when {
artworkHeight == artworkWidth -> {
normalizedHeight = 120f
normalizedWidth = 120f
}
else -> {
val factor = artworkHeight / 120f
normalizedHeight = 120f
normalizedWidth = (artworkWidth / factor)
}
}
B.img.layoutParams.height = normalizedHeight.px.toInt()
B.img.layoutParams.width = normalizedWidth.px.toInt()
B.img.requestLayout()
}
}
@CallbackProp
fun callback(screenshotCallback: ScreenshotCallback?) {
B.img.setOnClickListener {
screenshotCallback?.onClick(position)
}
}
@OnViewRecycled
fun clear() {
B.img.clear()
}
}

View File

@@ -34,10 +34,7 @@ import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
import com.aurora.store.util.ViewUtil
import com.aurora.store.util.extensions.applyTheme
import com.aurora.store.view.ui.account.GoogleActivity
import com.aurora.store.view.ui.details.AppDetailsActivity
import com.aurora.store.view.ui.details.DetailsMoreActivity
import com.aurora.store.view.ui.details.DetailsReviewActivity
import com.aurora.store.view.ui.details.DevProfileActivity
import com.aurora.store.view.ui.details.*
import com.aurora.store.view.ui.sheets.NetworkDialogSheet
import com.google.gson.Gson
import com.google.gson.GsonBuilder
@@ -115,6 +112,23 @@ abstract class BaseActivity : AppCompatActivity(), NetworkProvider.NetworkListen
)
}
fun openScreenshotActivity(app: App, position: Int) {
val intent = Intent(
this,
ScreenshotActivity::class.java
).apply {
putExtra(Constants.STRING_EXTRA, gson.toJson(app.screenshots))
putExtra(Constants.INT_EXTRA, position)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val options =
ActivityOptions.makeSceneTransitionAnimation(this)
startActivity(intent, options.toBundle())
} else {
startActivity(intent)
}
}
fun openGoogleActivity() {
val intent = Intent(this, GoogleActivity::class.java)
startActivity(

View File

@@ -21,11 +21,15 @@ package com.aurora.store.view.ui.commons
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.airbnb.epoxy.EpoxyModel
import com.aurora.Constants
import com.aurora.gplayapi.data.models.App
import com.aurora.store.databinding.ActivityGenericRecyclerBinding
import com.aurora.store.util.extensions.close
import com.aurora.store.view.epoxy.groups.CarouselHorizontalModel_
import com.aurora.store.view.epoxy.views.app.AppListViewModel_
import com.aurora.store.view.epoxy.views.details.MiniScreenshotView
import com.aurora.store.view.epoxy.views.details.MiniScreenshotViewModel_
import com.aurora.store.view.epoxy.views.shimmer.AppListViewShimmerModel_
import com.aurora.store.viewmodel.editorschoice.EditorBrowseViewModel
@@ -92,6 +96,29 @@ class EditorStreamBrowseActivity : BaseActivity() {
}
} else {
appList.forEach {
val screenshotsViewModels = mutableListOf<EpoxyModel<*>>()
for ((position, artwork) in it.screenshots.withIndex()) {
screenshotsViewModels.add(
MiniScreenshotViewModel_()
.id(artwork.url)
.position(position)
.artwork(artwork)
.callback(object : MiniScreenshotView.ScreenshotCallback {
override fun onClick(position: Int) {
openScreenshotActivity(it, position)
}
})
)
}
if (screenshotsViewModels.isNotEmpty()) {
add(
CarouselHorizontalModel_()
.id("${it.id}_screenshots")
.models(screenshotsViewModels)
)
}
add(
AppListViewModel_()

View File

@@ -21,13 +21,17 @@ package com.aurora.store.view.ui.commons
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.airbnb.epoxy.EpoxyModel
import com.aurora.Constants
import com.aurora.gplayapi.data.models.StreamCluster
import com.aurora.store.databinding.ActivityGenericRecyclerBinding
import com.aurora.store.util.extensions.close
import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener
import com.aurora.store.view.epoxy.groups.CarouselHorizontalModel_
import com.aurora.store.view.epoxy.views.AppProgressViewModel_
import com.aurora.store.view.epoxy.views.app.AppListViewModel_
import com.aurora.store.view.epoxy.views.details.MiniScreenshotView
import com.aurora.store.view.epoxy.views.details.MiniScreenshotViewModel_
import com.aurora.store.view.epoxy.views.shimmer.AppListViewShimmerModel_
import com.aurora.store.viewmodel.browse.ExpandedStreamBrowseViewModel
@@ -118,6 +122,29 @@ class ExpandedStreamBrowseActivity : BaseActivity() {
}
} else {
streamCluster.clusterAppList.forEach {
val screenshotsViewModels = mutableListOf<EpoxyModel<*>>()
for ((position, artwork) in it.screenshots.withIndex()) {
screenshotsViewModels.add(
MiniScreenshotViewModel_()
.id(artwork.url)
.position(position)
.artwork(artwork)
.callback(object : MiniScreenshotView.ScreenshotCallback {
override fun onClick(position: Int) {
openScreenshotActivity(it, position)
}
})
)
}
if (screenshotsViewModels.isNotEmpty()) {
add(
CarouselHorizontalModel_()
.id("${it.id}_screenshots")
.models(screenshotsViewModels)
)
}
add(
AppListViewModel_()

View File

@@ -19,7 +19,6 @@
package com.aurora.store.view.ui.details
import android.app.ActivityOptions
import android.content.Intent
import android.os.Build
import android.text.Html
@@ -365,23 +364,6 @@ abstract class BaseDetailsActivity : BaseActivity() {
return null
}
private fun openScreenshotActivity(app: App, position: Int) {
val intent = Intent(
this,
ScreenshotActivity::class.java
).apply {
putExtra(Constants.STRING_EXTRA, gson.toJson(app.screenshots))
putExtra(Constants.INT_EXTRA, position)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val options =
ActivityOptions.makeSceneTransitionAnimation(this)
startActivity(intent, options.toBundle())
} else {
startActivity(intent)
}
}
private fun addAvgReviews(number: Int, max: Long, rating: Long): RelativeLayout {
return RatingView(this, number, max.toInt(), rating.toInt())
}

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Aurora Store
~ Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
~
~ Aurora Store is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 2 of the License, or
~ (at your option) any later version.
~
~ Aurora Store is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
~
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@color/colorScrim" />
</shape>

View File

@@ -17,18 +17,37 @@
~
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ViewStub
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/recycler_view" />
android:layout_gravity="start"
android:layout_marginStart="@dimen/margin_small"
android:layout_marginEnd="@dimen/margin_small"
android:orientation="horizontal">
<ViewStub
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inflatedId="@+id/title_view" />
</LinearLayout>
android:layout_centerVertical="true"
android:inflatedId="@+id/header_view" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/header_view"
android:orientation="vertical"
tools:ignore="UnknownIdInLayout">
<ViewStub
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/section_view" />
<ViewStub
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/recycler_view" />
</LinearLayout>
</RelativeLayout>

View File

@@ -21,21 +21,15 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/padding_large"
android:paddingTop="@dimen/padding_small"
android:paddingEnd="@dimen/padding_large"
android:paddingBottom="@dimen/padding_small">
android:padding="@dimen/padding_small">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
android:textAppearance="@style/TextAppearance.Aurora.Line1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_arrow_right"
android:drawablePadding="@dimen/padding_small"
android:maxLines="4"
android:gravity="center_vertical"
android:singleLine="false"
android:layout_centerInParent="true"
android:maxLines="4"
android:singleLine="false"
android:textAppearance="@style/TextAppearance.Aurora.Line1"
app:drawableTint="?colorControlNormal" />
</RelativeLayout>

View File

@@ -23,6 +23,6 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/img"
android:layout_width="@dimen/icon_size_large"
android:layout_height="@dimen/icon_size_large" />
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Aurora Store
~ Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
~
~ Aurora Store is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 2 of the License, or
~ (at your option) any later version.
~
~ Aurora Store is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
~
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/img"
android:layout_width="@dimen/screenshot_width_mini"
android:layout_height="@dimen/screenshot_height_mini"
android:adjustViewBounds="true" />
</RelativeLayout>

View File

@@ -47,6 +47,10 @@
<dimen name="screenshot_height">192dp</dimen>
<dimen name="screenshot_width">108dp</dimen>
<dimen name="screenshot_height_mini">120dp</dimen>
<dimen name="screenshot_width_mini">68dp</dimen>
<dimen name="height_bottom_adj">64dp</dimen>
<dimen name="cluster_size">128dp</dimen>