Recommendation item on explore screen (not finished)

This commit is contained in:
Zakhar Timoshenko
2023-07-02 02:15:07 +03:00
parent e2835e3e95
commit b2817a2ce7
11 changed files with 171 additions and 12 deletions

View File

@@ -75,7 +75,7 @@ class TipView @JvmOverloads constructor(
icon = getDrawableCompat(context, R.styleable.TipView_icon)
primaryButtonText = getString(R.styleable.TipView_primaryButtonText)
secondaryButtonText = getString(R.styleable.TipView_secondaryButtonText)
val shapeAppearanceModel = ShapeAppearanceModel.builder(context, attrs, defStyleAttr, 0).setAllCornerSizes(12f).build()
val shapeAppearanceModel = ShapeAppearanceModel.builder(context, attrs, defStyleAttr, 0).build()
background = MaterialShapeDrawable(shapeAppearanceModel).also {
it.fillColor = getColorStateList(R.styleable.TipView_cardBackgroundColor)
?: context.getThemeColorStateList(materialR.attr.colorBackgroundFloating)

View File

@@ -25,6 +25,7 @@ import org.koitharu.kotatsu.explore.domain.ExploreRepository
import org.koitharu.kotatsu.explore.ui.model.ExploreItem
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.model.MangaState
import javax.inject.Inject
private const val TIP_SUGGESTIONS = "suggestions"
@@ -102,6 +103,26 @@ class ExploreViewModel @Inject constructor(
result += ExploreItem.Buttons(
isSuggestionsEnabled = settings.isSuggestionsEnabled,
)
result += ExploreItem.Header(R.string.suggestions, isButtonVisible = false)
result += ExploreItem.Recommendation(
Manga(
0,
"Test",
"Test",
"Test",
"Test",
0f,
false,
"http://images.ctfassets.net/yadj1kx9rmg0/wtrHxeu3zEoEce2MokCSi/cf6f68efdcf625fdc060607df0f3baef/quwowooybuqbl6ntboz3.jpg",
emptySet(),
MangaState.ONGOING,
"Test",
"http://images.ctfassets.net/yadj1kx9rmg0/wtrHxeu3zEoEce2MokCSi/cf6f68efdcf625fdc060607df0f3baef/quwowooybuqbl6ntboz3.jpg",
"Test",
emptyList(),
MangaSource.DESUME,
),
) // TODO
result += ExploreItem.Header(R.string.remote_sources, sources.isNotEmpty())
if (sources.isNotEmpty()) {
sources.mapTo(result) { ExploreItem.Source(it, isGrid) }

View File

@@ -16,6 +16,8 @@ class ExploreAdapter(
init {
delegatesManager
.addDelegate(ITEM_TYPE_BUTTONS, exploreButtonsAD(listener))
.addDelegate(ITEM_TYPE_RECOMMENDATION_HEADER, exploreRecommendationHeaderAD())
.addDelegate(ITEM_TYPE_RECOMMENDATION, exploreRecommendationItemAD(coil, lifecycleOwner))
.addDelegate(ITEM_TYPE_HEADER, exploreSourcesHeaderAD(listener))
.addDelegate(ITEM_TYPE_SOURCE_LIST, exploreSourceListItemAD(coil, clickListener, lifecycleOwner))
.addDelegate(ITEM_TYPE_SOURCE_GRID, exploreSourceGridItemAD(coil, clickListener, lifecycleOwner))
@@ -31,5 +33,7 @@ class ExploreAdapter(
const val ITEM_TYPE_SOURCE_GRID = 3
const val ITEM_TYPE_HINT = 4
const val ITEM_TYPE_LOADING = 5
const val ITEM_TYPE_RECOMMENDATION_HEADER = 6
const val ITEM_TYPE_RECOMMENDATION = 7
}
}

View File

@@ -21,6 +21,7 @@ import org.koitharu.kotatsu.databinding.ItemExploreButtonsBinding
import org.koitharu.kotatsu.databinding.ItemExploreSourceGridBinding
import org.koitharu.kotatsu.databinding.ItemExploreSourceListBinding
import org.koitharu.kotatsu.databinding.ItemHeaderButtonBinding
import org.koitharu.kotatsu.databinding.ItemRecommendationBinding
import org.koitharu.kotatsu.explore.ui.model.ExploreItem
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
@@ -42,6 +43,37 @@ fun exploreButtonsAD(
//}
}
fun exploreRecommendationHeaderAD() = adapterDelegateViewBinding<ExploreItem.Header, ExploreItem, ItemHeaderButtonBinding>(
{ layoutInflater, parent -> ItemHeaderButtonBinding.inflate(layoutInflater, parent, false) }
) {
bind {
binding.textViewTitle.setText(item.titleResId)
binding.buttonMore.isVisible = false
}
}
fun exploreRecommendationItemAD(
coil: ImageLoader,
lifecycleOwner: LifecycleOwner,
) = adapterDelegateViewBinding<ExploreItem.Recommendation, ExploreItem, ItemRecommendationBinding>(
{ layoutInflater, parent -> ItemRecommendationBinding.inflate(layoutInflater, parent, false) }
) {
bind {
binding.textViewTitle.text = item.manga.title
binding.textViewSubtitle.text = item.manga.title
binding.imageViewCover.newImageRequest(lifecycleOwner, item.manga.coverUrl)?.run {
source(item.manga.source)
enqueueWith(coil)
}
}
onViewRecycled {
binding.imageViewCover.disposeImageRequest()
}
}
fun exploreSourcesHeaderAD(
listener: ExploreListEventListener,
) = adapterDelegateViewBinding<ExploreItem.Header, ExploreItem, ItemHeaderButtonBinding>(

View File

@@ -4,6 +4,7 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import org.koitharu.kotatsu.list.ui.model.EmptyState
import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaSource
sealed interface ExploreItem : ListModel {
@@ -48,6 +49,25 @@ sealed interface ExploreItem : ListModel {
}
}
class Recommendation(
val manga: Manga
) : ExploreItem {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Recommendation
return manga == other.manga
}
override fun hashCode(): Int {
return 31 * manga.hashCode()
}
}
class Source(
val source: MangaSource,
val isGrid: Boolean,

View File

@@ -41,7 +41,7 @@ class MemoryUsageView @JvmOverloads constructor(
fun bind(usage: StorageUsage?) {
val storageSegment = SegmentedBarView.Segment(usage?.savedManga?.percent ?: 0f, segmentColor(com.google.android.material.R.attr.colorPrimary))
val pagesSegment = SegmentedBarView.Segment(usage?.pagesCache?.percent ?: 0f, segmentColor(com.google.android.material.R.attr.colorSecondary))
val pagesSegment = SegmentedBarView.Segment(usage?.pagesCache?.percent ?: 0f, segmentColor(com.google.android.material.R.attr.colorOnPrimaryContainer))
val otherSegment = SegmentedBarView.Segment(usage?.otherCache?.percent ?: 0f, segmentColor(com.google.android.material.R.attr.colorTertiary))
with(binding) {

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="4dp" />
<solid android:color="?colorSurface" />
<size
android:width="12dp"
android:height="12dp" />
</shape>

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:clipChildren="false">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imageView_cover"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.Kotatsu.Cover.Small"
tools:src="@tools:sample/backgrounds/scenic" />
<TextView
android:id="@+id/textView_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceBodyLarge"
app:layout_constraintBottom_toTopOf="@+id/textView_subtitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView_cover"
app:layout_constraintTop_toTopOf="@+id/imageView_cover"
tools:text="@tools:sample/lorem" />
<TextView
android:id="@+id/textView_subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceBodyMedium"
app:layout_constraintBottom_toBottomOf="@+id/imageView_cover"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView_cover"
app:layout_constraintTop_toBottomOf="@+id/textView_title"
tools:text="@tools:sample/lorem/random" />
<com.google.android.material.button.MaterialButton
style="@style/Widget.Kotatsu.ExploreButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:text="@string/more"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView_subtitle" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -49,7 +49,7 @@
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginEnd="@dimen/screen_padding"
android:text="@string/saved_manga"
app:drawableStartCompat="@drawable/bg_circle"
app:drawableStartCompat="@drawable/bg_rounded_square"
tools:drawableTint="?colorPrimary" />
<TextView
@@ -61,7 +61,7 @@
android:layout_marginTop="@dimen/margin_small"
android:layout_marginEnd="@dimen/screen_padding"
android:text="@string/pages_cache"
app:drawableStartCompat="@drawable/bg_circle"
app:drawableStartCompat="@drawable/bg_rounded_square"
tools:drawableTint="?colorSecondary" />
<TextView
@@ -73,7 +73,7 @@
android:layout_marginTop="@dimen/margin_small"
android:layout_marginEnd="@dimen/screen_padding"
android:text="@string/other_cache"
app:drawableStartCompat="@drawable/bg_circle"
app:drawableStartCompat="@drawable/bg_rounded_square"
tools:drawableTint="?colorTertiary" />
<TextView
@@ -86,7 +86,7 @@
android:layout_marginEnd="@dimen/screen_padding"
android:layout_marginBottom="@dimen/screen_padding"
android:text="@string/computing_"
app:drawableStartCompat="@drawable/bg_circle"
app:drawableStartCompat="@drawable/bg_rounded_square"
app:drawableTint="?colorSecondaryContainer" />
</merge>

View File

@@ -56,10 +56,8 @@
<item>SOCKS</item>
</string-array>
<string-array name="chart_colors" translatable="false">
<item>#E480F4</item>
<item>#6CC3F3</item>
<item>#7167ED</item>
<item>#D9455F</item>
<item>#6054EA</item>
<item>#6750A4</item>
<item>#21005E</item>
<item>#7D5260</item>
</string-array>
</resources>

View File

@@ -9,7 +9,7 @@
<!--Navigation Views-->
<style name="Widget.Kotatsu.BottomNavigationView" parent="Widget.Material3.BottomNavigationView">
<item name="labelVisibilityMode">unlabeled</item>
<item name="labelVisibilityMode">labeled</item>
<item name="android:background">?attr/colorSurfaceContainerHighest</item>
<item name="compatShadowEnabled">false</item>
</style>