Update feed ui
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.koitharu.kotatsu.tracker
|
||||
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.dsl.module
|
||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||
@@ -11,5 +10,5 @@ val trackerModule
|
||||
|
||||
single { TrackingRepository(get()) }
|
||||
|
||||
viewModel { FeedViewModel(androidContext(), get()) }
|
||||
viewModel { FeedViewModel(get()) }
|
||||
}
|
||||
@@ -4,7 +4,9 @@ import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.divider.MaterialDividerItemDecoration
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.koin.android.ext.android.get
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
@@ -50,6 +52,9 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(), PaginationScrollListen
|
||||
adapter = feedAdapter
|
||||
setHasFixedSize(true)
|
||||
addOnScrollListener(PaginationScrollListener(4, this@FeedFragment))
|
||||
val dividerDecoration = MaterialDividerItemDecoration(context, RecyclerView.VERTICAL)
|
||||
dividerDecoration.setDividerInsetStartResource(context, R.dimen.feed_dividers_offset)
|
||||
addItemDecoration(dividerDecoration)
|
||||
}
|
||||
|
||||
viewModel.content.observe(viewLifecycleOwner, this::onListChanged)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.koitharu.kotatsu.tracker.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -22,7 +21,6 @@ import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||
import org.koitharu.kotatsu.utils.ext.mapItems
|
||||
|
||||
class FeedViewModel(
|
||||
context: Context,
|
||||
private val repository: TrackingRepository
|
||||
) : BaseViewModel() {
|
||||
|
||||
@@ -34,7 +32,7 @@ class FeedViewModel(
|
||||
val onFeedCleared = SingleLiveEvent<Unit>()
|
||||
val content = combine(
|
||||
logList.filterNotNull().mapItems {
|
||||
it.toFeedItem(context.resources)
|
||||
it.toFeedItem()
|
||||
},
|
||||
hasNextPage
|
||||
) { list, isHasNextPage ->
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.tracker.ui.model.FeedItem
|
||||
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||
|
||||
fun feedItemAD(
|
||||
coil: ImageLoader,
|
||||
@@ -39,6 +40,11 @@ fun feedItemAD(
|
||||
binding.textViewTitle.text = item.title
|
||||
binding.badge.text = item.subtitle
|
||||
binding.textViewChapters.text = item.chapters
|
||||
binding.textViewTruncated.textAndVisible = if (item.truncated > 0) {
|
||||
getString(R.string._and_x_more, item.truncated)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
onViewRecycled {
|
||||
|
||||
@@ -9,5 +9,6 @@ data class FeedItem(
|
||||
val title: String,
|
||||
val subtitle: String,
|
||||
val chapters: CharSequence,
|
||||
val manga: Manga
|
||||
val manga: Manga,
|
||||
val truncated: Int,
|
||||
) : ListModel
|
||||
@@ -1,19 +1,15 @@
|
||||
package org.koitharu.kotatsu.tracker.ui.model
|
||||
|
||||
import android.content.res.Resources
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.TrackingLogItem
|
||||
|
||||
fun TrackingLogItem.toFeedItem(resources: Resources): FeedItem {
|
||||
val chaptersString = if (chapters.size > MAX_CHAPTERS) {
|
||||
fun TrackingLogItem.toFeedItem(): FeedItem {
|
||||
val truncate = chapters.size > MAX_CHAPTERS
|
||||
val chaptersString = if (truncate) {
|
||||
chapters.joinToString(
|
||||
separator = "\n",
|
||||
limit = MAX_CHAPTERS - 1,
|
||||
truncated = resources.getString(
|
||||
R.string._and_x_more,
|
||||
chapters.size - MAX_CHAPTERS + 1
|
||||
)
|
||||
)
|
||||
truncated = "",
|
||||
).trimEnd()
|
||||
} else {
|
||||
chapters.joinToString("\n")
|
||||
}
|
||||
@@ -23,7 +19,8 @@ fun TrackingLogItem.toFeedItem(resources: Resources): FeedItem {
|
||||
title = manga.title,
|
||||
subtitle = chapters.size.toString(),
|
||||
chapters = chaptersString,
|
||||
manga = manga
|
||||
manga = manga,
|
||||
truncated = chapters.size - MAX_CHAPTERS + 1,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp">
|
||||
android:paddingVertical="6dp"
|
||||
android:paddingHorizontal="8dp">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/card_cover"
|
||||
@@ -75,11 +75,26 @@
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:ellipsize="none"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:lineSpacingExtra="4sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/card_cover"
|
||||
app:layout_constraintTop_toBottomOf="@id/title_container"
|
||||
tools:text="@tools:sample/lorem[25]" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_truncated"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:textColor="?android:textColorHint"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/card_cover"
|
||||
app:layout_constraintTop_toBottomOf="@id/textView_chapters"
|
||||
tools:text="@string/_and_x_more" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -25,6 +25,7 @@
|
||||
<dimen name="list_footer_height_inner">36dp</dimen>
|
||||
<dimen name="list_footer_height_outer">48dp</dimen>
|
||||
<dimen name="screen_padding">16dp</dimen>
|
||||
<dimen name="feed_dividers_offset">72dp</dimen>
|
||||
|
||||
<!--Text dimens-->
|
||||
<dimen name="text_size_h1">22sp</dimen>
|
||||
|
||||
Reference in New Issue
Block a user