Recommendation item on explore screen (not finished)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user