UI improvements
This commit is contained in:
@@ -65,10 +65,7 @@ fun categoryAD(
|
||||
binding.imageViewEdit.setOnClickListener(eventListener)
|
||||
binding.imageViewHandle.setOnTouchListener(eventListener)
|
||||
|
||||
bind { payloads ->
|
||||
if (payloads.isNotEmpty()) {
|
||||
return@bind
|
||||
}
|
||||
bind {
|
||||
binding.textViewTitle.text = item.category.title
|
||||
binding.textViewSubtitle.text = if (item.mangaCount == 0) {
|
||||
getString(R.string.empty)
|
||||
|
||||
@@ -15,13 +15,13 @@ fun categoriesHeaderAD() = adapterDelegateViewBinding<CategoriesHeaderItem, List
|
||||
|
||||
val onClickListener = View.OnClickListener { v ->
|
||||
val intent = when (v.id) {
|
||||
R.id.button_create -> FavouritesCategoryEditActivity.newIntent(v.context)
|
||||
R.id.button_manage -> FavouriteCategoriesActivity.newIntent(v.context)
|
||||
R.id.chip_create -> FavouritesCategoryEditActivity.newIntent(v.context)
|
||||
R.id.chip_manage -> FavouriteCategoriesActivity.newIntent(v.context)
|
||||
else -> return@OnClickListener
|
||||
}
|
||||
v.context.startActivity(intent)
|
||||
}
|
||||
|
||||
binding.buttonCreate.setOnClickListener(onClickListener)
|
||||
binding.buttonManage.setOnClickListener(onClickListener)
|
||||
binding.chipCreate.setOnClickListener(onClickListener)
|
||||
binding.chipManage.setOnClickListener(onClickListener)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.google.android.material.chip.Chip
|
||||
import org.koitharu.kotatsu.R
|
||||
@@ -39,8 +40,11 @@ class FilterSheetFragment :
|
||||
|
||||
override fun onViewBindingCreated(binding: SheetFilterBinding, savedInstanceState: Bundle?) {
|
||||
super.onViewBindingCreated(binding, savedInstanceState)
|
||||
if (dialog == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.scrollView.scrollIndicators = 0
|
||||
if (dialog == null) {
|
||||
binding.layoutBody.updatePadding(top = binding.layoutBody.paddingBottom)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.scrollView.scrollIndicators = 0
|
||||
}
|
||||
}
|
||||
val filter = requireFilter()
|
||||
filter.filterSortOrder.observe(viewLifecycleOwner, this::onSortOrderChanged)
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.koitharu.kotatsu.filter.ui.FilterOwner
|
||||
import org.koitharu.kotatsu.image.ui.ImageActivity
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||
import org.koitharu.kotatsu.search.ui.SearchActivity
|
||||
import javax.inject.Inject
|
||||
@@ -56,8 +57,10 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), View.OnClickList
|
||||
binding.textViewAuthor.setOnClickListener(this)
|
||||
binding.imageViewCover.setOnClickListener(this)
|
||||
binding.buttonOpen.setOnClickListener(this)
|
||||
binding.buttonRead.setOnClickListener(this)
|
||||
|
||||
viewModel.manga.observe(viewLifecycleOwner, ::onMangaUpdated)
|
||||
viewModel.footer.observe(viewLifecycleOwner, ::onFooterUpdated)
|
||||
viewModel.tagsChips.observe(viewLifecycleOwner, ::onTagsChipsChanged)
|
||||
viewModel.description.observe(viewLifecycleOwner, ::onDescriptionChanged)
|
||||
}
|
||||
@@ -70,6 +73,14 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), View.OnClickList
|
||||
DetailsActivity.newIntent(v.context, manga),
|
||||
)
|
||||
|
||||
R.id.button_read -> {
|
||||
startActivity(
|
||||
ReaderActivity.IntentBuilder(v.context)
|
||||
.manga(manga)
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
R.id.textView_author -> startActivity(
|
||||
SearchActivity.newIntent(
|
||||
context = v.context,
|
||||
@@ -118,6 +129,43 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), View.OnClickList
|
||||
}
|
||||
}
|
||||
|
||||
private fun onFooterUpdated(footer: PreviewViewModel.FooterInfo?) {
|
||||
with(requireViewBinding()) {
|
||||
toolbarBottom.isVisible = footer != null
|
||||
if (footer == null) {
|
||||
return
|
||||
}
|
||||
toolbarBottom.title = when {
|
||||
footer.isInProgress() -> {
|
||||
getString(R.string.chapter_d_of_d, footer.currentChapter, footer.totalChapters)
|
||||
}
|
||||
|
||||
footer.totalChapters > 0 -> {
|
||||
resources.getQuantityString(R.plurals.chapters, footer.totalChapters, footer.totalChapters)
|
||||
}
|
||||
|
||||
else -> {
|
||||
getString(R.string.no_chapters)
|
||||
}
|
||||
}
|
||||
buttonRead.isEnabled = footer.totalChapters > 0
|
||||
buttonRead.setIconResource(
|
||||
when {
|
||||
footer.isIncognito -> R.drawable.ic_incognito
|
||||
footer.isInProgress() -> R.drawable.ic_play
|
||||
else -> R.drawable.ic_read
|
||||
},
|
||||
)
|
||||
buttonRead.setText(
|
||||
if (footer.isInProgress()) {
|
||||
R.string._continue
|
||||
} else {
|
||||
R.string.read
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDescriptionChanged(description: CharSequence?) {
|
||||
val tv = viewBinding?.textViewDescription ?: return
|
||||
when {
|
||||
|
||||
@@ -13,11 +13,14 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.transformLatest
|
||||
import kotlinx.coroutines.plus
|
||||
import org.koitharu.kotatsu.core.model.getPreferredBranch
|
||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||
import org.koitharu.kotatsu.core.parser.MangaIntent
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
@@ -25,6 +28,7 @@ import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||
import org.koitharu.kotatsu.core.util.ext.require
|
||||
import org.koitharu.kotatsu.core.util.ext.sanitize
|
||||
import org.koitharu.kotatsu.history.data.HistoryRepository
|
||||
import org.koitharu.kotatsu.list.domain.ListExtraProvider
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -33,6 +37,7 @@ class PreviewViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val extraProvider: ListExtraProvider,
|
||||
private val repositoryFactory: MangaRepository.Factory,
|
||||
private val historyRepository: HistoryRepository,
|
||||
private val imageGetter: Html.ImageGetter,
|
||||
) : BaseViewModel() {
|
||||
|
||||
@@ -40,6 +45,26 @@ class PreviewViewModel @Inject constructor(
|
||||
savedStateHandle.require<ParcelableManga>(MangaIntent.KEY_MANGA).manga,
|
||||
)
|
||||
|
||||
val footer = combine(
|
||||
manga,
|
||||
historyRepository.observeOne(manga.value.id),
|
||||
manga.flatMapLatest { historyRepository.observeShouldSkip(it) }.distinctUntilChanged(),
|
||||
) { m, history, incognito ->
|
||||
if (m.chapters == null) {
|
||||
return@combine null
|
||||
}
|
||||
val b = m.getPreferredBranch(history)
|
||||
val chapters = m.getChapters(b).orEmpty()
|
||||
FooterInfo(
|
||||
branch = b,
|
||||
currentChapter = history?.chapterId?.let {
|
||||
chapters.indexOfFirst { x -> x.id == it }
|
||||
} ?: -1,
|
||||
totalChapters = chapters.size,
|
||||
isIncognito = incognito,
|
||||
)
|
||||
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, null)
|
||||
|
||||
val description = manga
|
||||
.distinctUntilChangedBy { it.description.orEmpty() }
|
||||
.transformLatest {
|
||||
@@ -82,4 +107,14 @@ class PreviewViewModel @Inject constructor(
|
||||
}
|
||||
return spannable.trim()
|
||||
}
|
||||
|
||||
data class FooterInfo(
|
||||
val branch: String?,
|
||||
val currentChapter: Int,
|
||||
val totalChapters: Int,
|
||||
val isIncognito: Boolean,
|
||||
) {
|
||||
|
||||
fun isInProgress() = currentChapter >= 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.koitharu.kotatsu.search.ui.suggestion.adapter
|
||||
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegate
|
||||
import org.koitharu.kotatsu.R
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||
import org.koitharu.kotatsu.databinding.ItemSearchSuggestionTagsBinding
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionListener
|
||||
import org.koitharu.kotatsu.search.ui.suggestion.model.SearchSuggestionItem
|
||||
|
||||
fun searchSuggestionTagsAD(
|
||||
listener: SearchSuggestionListener,
|
||||
) = adapterDelegate<SearchSuggestionItem.Tags, SearchSuggestionItem>(R.layout.item_search_suggestion_tags) {
|
||||
) = adapterDelegateViewBinding<SearchSuggestionItem.Tags, SearchSuggestionItem, ItemSearchSuggestionTagsBinding>(
|
||||
{ layoutInflater, parent -> ItemSearchSuggestionTagsBinding.inflate(layoutInflater, parent, false) },
|
||||
) {
|
||||
|
||||
val chipGroup = itemView as ChipsView
|
||||
|
||||
chipGroup.onChipClickListener = ChipsView.OnChipClickListener { _, data ->
|
||||
binding.chipsGenres.onChipClickListener = ChipsView.OnChipClickListener { _, data ->
|
||||
listener.onTagClick(data as? MangaTag ?: return@OnChipClickListener)
|
||||
}
|
||||
|
||||
bind {
|
||||
chipGroup.setChips(item.tags)
|
||||
binding.chipsGenres.setChips(item.tags)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user