diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt index ec93fcaef..253827e88 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt @@ -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) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/select/adapter/CategoriesHeaderAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/select/adapter/CategoriesHeaderAD.kt index cc878a1ac..2b7ad5686 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/select/adapter/CategoriesHeaderAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/select/adapter/CategoriesHeaderAD.kt @@ -15,13 +15,13 @@ fun categoriesHeaderAD() = adapterDelegateViewBinding 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) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/sheet/FilterSheetFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/sheet/FilterSheetFragment.kt index 1dcdf9814..28e13931a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/sheet/FilterSheetFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/sheet/FilterSheetFragment.kt @@ -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) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt index c3eb9f94f..cb4640e48 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt @@ -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(), 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(), 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(), 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 { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewViewModel.kt index a2856fd3f..e3e03d63b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewViewModel.kt @@ -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(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 + } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionTagsAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionTagsAD.kt index 7360de65c..633592471 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionTagsAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionTagsAD.kt @@ -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(R.layout.item_search_suggestion_tags) { +) = adapterDelegateViewBinding( + { 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) } } diff --git a/app/src/main/res/layout/fragment_preview.xml b/app/src/main/res/layout/fragment_preview.xml index 127ef5308..02e5f8a96 100644 --- a/app/src/main/res/layout/fragment_preview.xml +++ b/app/src/main/res/layout/fragment_preview.xml @@ -1,165 +1,197 @@ - - + android:layout_height="wrap_content" + android:scrollIndicators="bottom"> - - - + android:paddingBottom="?actionBarSize"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_gravity="end|center_vertical" + android:layout_marginHorizontal="@dimen/toolbar_button_margin" + android:enabled="false" + android:text="@string/read" + android:textAllCaps="false" + app:iconGravity="textStart" + app:iconPadding="8dp" + tools:enabled="true" + tools:icon="@drawable/ic_read" /> - + - - - - - - - - - - - - - - - + diff --git a/app/src/main/res/layout/item_categories_header.xml b/app/src/main/res/layout/item_categories_header.xml index 62af75fc9..7f99680a7 100644 --- a/app/src/main/res/layout/item_categories_header.xml +++ b/app/src/main/res/layout/item_categories_header.xml @@ -1,34 +1,34 @@ - + android:scrollbars="none"> -