Rename `Library` to `Shelf`

pull/227/head
Zakhar Timoshenko 4 years ago
parent 734765dbdd
commit 3f6a103915

@ -1,15 +0,0 @@
package org.koitharu.kotatsu.library.ui.adapter
import android.view.View
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
import org.koitharu.kotatsu.parsers.model.Manga
interface LibraryListEventListener : ListStateHolderListener {
fun onItemClick(item: Manga, section: LibrarySectionModel, view: View)
fun onItemLongClick(item: Manga, section: LibrarySectionModel, view: View): Boolean
fun onSectionClick(section: LibrarySectionModel, view: View)
}

@ -34,7 +34,7 @@ import org.koitharu.kotatsu.base.ui.BaseActivity
import org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView import org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView
import org.koitharu.kotatsu.databinding.ActivityMainBinding import org.koitharu.kotatsu.databinding.ActivityMainBinding
import org.koitharu.kotatsu.details.ui.DetailsActivity import org.koitharu.kotatsu.details.ui.DetailsActivity
import org.koitharu.kotatsu.library.ui.LibraryFragment import org.koitharu.kotatsu.shelf.ui.ShelfFragment
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
@ -136,7 +136,7 @@ class MainActivity :
} }
override fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) { override fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {
if (fragment is LibraryFragment) { if (fragment is ShelfFragment) {
binding.fab?.show() binding.fab?.show()
} else { } else {
binding.fab?.hide() binding.fab?.hide()
@ -313,7 +313,7 @@ class MainActivity :
isResumeEnabled && isResumeEnabled &&
!actionModeDelegate.isActionModeStarted && !actionModeDelegate.isActionModeStarted &&
!isSearchOpened && !isSearchOpened &&
topFragment is LibraryFragment topFragment is ShelfFragment
) { ) {
if (fab?.isVisible == false) { if (fab?.isVisible == false) {
fab.show() fab.show()

@ -10,7 +10,7 @@ import com.google.android.material.navigation.NavigationBarView
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
import org.koitharu.kotatsu.explore.ui.ExploreFragment import org.koitharu.kotatsu.explore.ui.ExploreFragment
import org.koitharu.kotatsu.library.ui.LibraryFragment import org.koitharu.kotatsu.shelf.ui.ShelfFragment
import org.koitharu.kotatsu.settings.tools.ToolsFragment import org.koitharu.kotatsu.settings.tools.ToolsFragment
import org.koitharu.kotatsu.tracker.ui.FeedFragment import org.koitharu.kotatsu.tracker.ui.FeedFragment
import java.util.* import java.util.*
@ -73,7 +73,7 @@ class MainNavigationDelegate(
private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean { private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean {
setPrimaryFragment( setPrimaryFragment(
when (itemId) { when (itemId) {
R.id.nav_library -> LibraryFragment.newInstance() R.id.nav_shelf -> ShelfFragment.newInstance()
R.id.nav_explore -> ExploreFragment.newInstance() R.id.nav_explore -> ExploreFragment.newInstance()
R.id.nav_feed -> FeedFragment.newInstance() R.id.nav_feed -> FeedFragment.newInstance()
R.id.nav_tools -> ToolsFragment.newInstance() R.id.nav_tools -> ToolsFragment.newInstance()

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.domain package org.koitharu.kotatsu.shelf.domain
import javax.inject.Inject import javax.inject.Inject
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
@ -10,7 +10,7 @@ import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
import org.koitharu.kotatsu.favourites.data.toFavouriteCategory import org.koitharu.kotatsu.favourites.data.toFavouriteCategory
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
class LibraryRepository @Inject constructor( class ShelfRepository @Inject constructor(
private val db: MangaDatabase, private val db: MangaDatabase,
) { ) {

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui package org.koitharu.kotatsu.shelf.ui
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -19,13 +19,13 @@ import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
import org.koitharu.kotatsu.base.ui.util.ReversibleAction import org.koitharu.kotatsu.base.ui.util.ReversibleAction
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.databinding.FragmentLibraryBinding import org.koitharu.kotatsu.databinding.FragmentShelfBinding
import org.koitharu.kotatsu.details.ui.DetailsActivity import org.koitharu.kotatsu.details.ui.DetailsActivity
import org.koitharu.kotatsu.favourites.ui.FavouritesActivity import org.koitharu.kotatsu.favourites.ui.FavouritesActivity
import org.koitharu.kotatsu.history.ui.HistoryActivity import org.koitharu.kotatsu.history.ui.HistoryActivity
import org.koitharu.kotatsu.library.ui.adapter.LibraryAdapter import org.koitharu.kotatsu.shelf.ui.adapter.ShelfAdapter
import org.koitharu.kotatsu.library.ui.adapter.LibraryListEventListener import org.koitharu.kotatsu.shelf.ui.adapter.ShelfListEventListener
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel
import org.koitharu.kotatsu.list.ui.ItemSizeResolver import org.koitharu.kotatsu.list.ui.ItemSizeResolver
import org.koitharu.kotatsu.list.ui.model.ListModel import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner
@ -34,10 +34,10 @@ import org.koitharu.kotatsu.utils.ext.addMenuProvider
import org.koitharu.kotatsu.utils.ext.getDisplayMessage import org.koitharu.kotatsu.utils.ext.getDisplayMessage
@AndroidEntryPoint @AndroidEntryPoint
class LibraryFragment : class ShelfFragment :
BaseFragment<FragmentLibraryBinding>(), BaseFragment<FragmentShelfBinding>(),
RecyclerViewOwner, RecyclerViewOwner,
LibraryListEventListener { ShelfListEventListener {
@Inject @Inject
lateinit var coil: ImageLoader lateinit var coil: ImageLoader
@ -45,15 +45,15 @@ class LibraryFragment :
@Inject @Inject
lateinit var settings: AppSettings lateinit var settings: AppSettings
private val viewModel by viewModels<LibraryViewModel>() private val viewModel by viewModels<ShelfViewModel>()
private var adapter: LibraryAdapter? = null private var adapter: ShelfAdapter? = null
private var selectionController: SectionedSelectionController<LibrarySectionModel>? = null private var selectionController: SectionedSelectionController<ShelfSectionModel>? = null
override val recyclerView: RecyclerView override val recyclerView: RecyclerView
get() = binding.recyclerView get() = binding.recyclerView
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): FragmentLibraryBinding { override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): FragmentShelfBinding {
return FragmentLibraryBinding.inflate(inflater, container, false) return FragmentShelfBinding.inflate(inflater, container, false)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -62,9 +62,9 @@ class LibraryFragment :
selectionController = SectionedSelectionController( selectionController = SectionedSelectionController(
activity = requireActivity(), activity = requireActivity(),
owner = this, owner = this,
callback = LibrarySelectionCallback(binding.recyclerView, childFragmentManager, viewModel), callback = ShelfSelectionCallback(binding.recyclerView, childFragmentManager, viewModel),
) )
adapter = LibraryAdapter( adapter = ShelfAdapter(
lifecycleOwner = viewLifecycleOwner, lifecycleOwner = viewLifecycleOwner,
coil = coil, coil = coil,
listener = this, listener = this,
@ -73,7 +73,7 @@ class LibraryFragment :
) )
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
binding.recyclerView.setHasFixedSize(true) binding.recyclerView.setHasFixedSize(true)
addMenuProvider(LibraryMenuProvider(view.context, childFragmentManager, viewModel)) addMenuProvider(ShelfMenuProvider(view.context, childFragmentManager, viewModel))
viewModel.content.observe(viewLifecycleOwner, ::onListChanged) viewModel.content.observe(viewLifecycleOwner, ::onListChanged)
viewModel.onError.observe(viewLifecycleOwner, ::onError) viewModel.onError.observe(viewLifecycleOwner, ::onError)
@ -86,22 +86,22 @@ class LibraryFragment :
selectionController = null selectionController = null
} }
override fun onItemClick(item: Manga, section: LibrarySectionModel, view: View) { override fun onItemClick(item: Manga, section: ShelfSectionModel, view: View) {
if (selectionController?.onItemClick(section, item.id) != true) { if (selectionController?.onItemClick(section, item.id) != true) {
val intent = DetailsActivity.newIntent(view.context, item) val intent = DetailsActivity.newIntent(view.context, item)
startActivity(intent) startActivity(intent)
} }
} }
override fun onItemLongClick(item: Manga, section: LibrarySectionModel, view: View): Boolean { override fun onItemLongClick(item: Manga, section: ShelfSectionModel, view: View): Boolean {
return selectionController?.onItemLongClick(section, item.id) ?: false return selectionController?.onItemLongClick(section, item.id) ?: false
} }
override fun onSectionClick(section: LibrarySectionModel, view: View) { override fun onSectionClick(section: ShelfSectionModel, view: View) {
selectionController?.clear() selectionController?.clear()
val intent = when (section) { val intent = when (section) {
is LibrarySectionModel.History -> HistoryActivity.newIntent(view.context) is ShelfSectionModel.History -> HistoryActivity.newIntent(view.context)
is LibrarySectionModel.Favourites -> FavouritesActivity.newIntent(view.context, section.category) is ShelfSectionModel.Favourites -> FavouritesActivity.newIntent(view.context, section.category)
} }
startActivity(intent) startActivity(intent)
} }
@ -143,6 +143,6 @@ class LibraryFragment :
companion object { companion object {
fun newInstance() = LibraryFragment() fun newInstance() = ShelfFragment()
} }
} }

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui package org.koitharu.kotatsu.shelf.ui
import android.content.Context import android.content.Context
import android.view.Menu import android.view.Menu
@ -12,19 +12,19 @@ import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.dialog.RememberSelectionDialogListener import org.koitharu.kotatsu.base.ui.dialog.RememberSelectionDialogListener
import org.koitharu.kotatsu.library.ui.config.categories.LibraryCategoriesConfigSheet import org.koitharu.kotatsu.shelf.ui.config.categories.ShelfCategoriesConfigSheet
import org.koitharu.kotatsu.library.ui.config.size.LibrarySizeBottomSheet import org.koitharu.kotatsu.shelf.ui.config.size.ShelfSizeBottomSheet
import org.koitharu.kotatsu.local.ui.ImportDialogFragment import org.koitharu.kotatsu.local.ui.ImportDialogFragment
import org.koitharu.kotatsu.utils.ext.startOfDay import org.koitharu.kotatsu.utils.ext.startOfDay
class LibraryMenuProvider( class ShelfMenuProvider(
private val context: Context, private val context: Context,
private val fragmentManager: FragmentManager, private val fragmentManager: FragmentManager,
private val viewModel: LibraryViewModel, private val viewModel: ShelfViewModel,
) : MenuProvider { ) : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.opt_library, menu) menuInflater.inflate(R.menu.opt_shelf, menu)
} }
override fun onMenuItemSelected(menuItem: MenuItem): Boolean { override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
@ -34,7 +34,7 @@ class LibraryMenuProvider(
true true
} }
R.id.action_grid_size -> { R.id.action_grid_size -> {
LibrarySizeBottomSheet.show(fragmentManager) ShelfSizeBottomSheet.show(fragmentManager)
true true
} }
R.id.action_import -> { R.id.action_import -> {
@ -42,7 +42,7 @@ class LibraryMenuProvider(
true true
} }
R.id.action_categories -> { R.id.action_categories -> {
LibraryCategoriesConfigSheet.show(fragmentManager) ShelfCategoriesConfigSheet.show(fragmentManager)
true true
} }
else -> false else -> false

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui package org.koitharu.kotatsu.shelf.ui
import android.content.Context import android.content.Context
import android.view.Menu import android.view.Menu
@ -11,33 +11,33 @@ import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
import org.koitharu.kotatsu.download.ui.service.DownloadService import org.koitharu.kotatsu.download.ui.service.DownloadService
import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteCategoriesBottomSheet import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteCategoriesBottomSheet
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel
import org.koitharu.kotatsu.list.ui.MangaSelectionDecoration import org.koitharu.kotatsu.list.ui.MangaSelectionDecoration
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.util.flattenTo import org.koitharu.kotatsu.parsers.util.flattenTo
import org.koitharu.kotatsu.utils.ShareHelper import org.koitharu.kotatsu.utils.ShareHelper
import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations
class LibrarySelectionCallback( class ShelfSelectionCallback(
private val recyclerView: RecyclerView, private val recyclerView: RecyclerView,
private val fragmentManager: FragmentManager, private val fragmentManager: FragmentManager,
private val viewModel: LibraryViewModel, private val viewModel: ShelfViewModel,
) : SectionedSelectionController.Callback<LibrarySectionModel> { ) : SectionedSelectionController.Callback<ShelfSectionModel> {
private val context: Context private val context: Context
get() = recyclerView.context get() = recyclerView.context
override fun onCreateActionMode( override fun onCreateActionMode(
controller: SectionedSelectionController<LibrarySectionModel>, controller: SectionedSelectionController<ShelfSectionModel>,
mode: ActionMode, mode: ActionMode,
menu: Menu, menu: Menu,
): Boolean { ): Boolean {
mode.menuInflater.inflate(R.menu.mode_library, menu) mode.menuInflater.inflate(R.menu.mode_shelf, menu)
return true return true
} }
override fun onPrepareActionMode( override fun onPrepareActionMode(
controller: SectionedSelectionController<LibrarySectionModel>, controller: SectionedSelectionController<ShelfSectionModel>,
mode: ActionMode, mode: ActionMode,
menu: Menu, menu: Menu,
): Boolean { ): Boolean {
@ -47,7 +47,7 @@ class LibrarySelectionCallback(
} }
override fun onActionItemClicked( override fun onActionItemClicked(
controller: SectionedSelectionController<LibrarySectionModel>, controller: SectionedSelectionController<ShelfSectionModel>,
mode: ActionMode, mode: ActionMode,
item: MenuItem, item: MenuItem,
): Boolean { ): Boolean {
@ -70,8 +70,8 @@ class LibrarySelectionCallback(
R.id.action_remove -> { R.id.action_remove -> {
val (group, ids) = controller.snapshot().entries.singleOrNull { it.value.isNotEmpty() } ?: return false val (group, ids) = controller.snapshot().entries.singleOrNull { it.value.isNotEmpty() } ?: return false
when (group) { when (group) {
is LibrarySectionModel.Favourites -> viewModel.removeFromFavourites(group.category, ids) is ShelfSectionModel.Favourites -> viewModel.removeFromFavourites(group.category, ids)
is LibrarySectionModel.History -> viewModel.removeFromHistory(ids) is ShelfSectionModel.History -> viewModel.removeFromHistory(ids)
} }
mode.finish() mode.finish()
true true
@ -80,18 +80,18 @@ class LibrarySelectionCallback(
} }
} }
override fun onSelectionChanged(controller: SectionedSelectionController<LibrarySectionModel>, count: Int) { override fun onSelectionChanged(controller: SectionedSelectionController<ShelfSectionModel>, count: Int) {
recyclerView.invalidateNestedItemDecorations() recyclerView.invalidateNestedItemDecorations()
} }
override fun onCreateItemDecoration( override fun onCreateItemDecoration(
controller: SectionedSelectionController<LibrarySectionModel>, controller: SectionedSelectionController<ShelfSectionModel>,
section: LibrarySectionModel, section: ShelfSectionModel,
): AbstractSelectionItemDecoration = MangaSelectionDecoration(context) ): AbstractSelectionItemDecoration = MangaSelectionDecoration(context)
private fun collectSelectedItemsMap( private fun collectSelectedItemsMap(
controller: SectionedSelectionController<LibrarySectionModel>, controller: SectionedSelectionController<ShelfSectionModel>,
): Map<LibrarySectionModel, Set<Manga>> { ): Map<ShelfSectionModel, Set<Manga>> {
val snapshot = controller.peekCheckedIds() val snapshot = controller.peekCheckedIds()
if (snapshot.isEmpty()) { if (snapshot.isEmpty()) {
return emptyMap() return emptyMap()
@ -100,7 +100,7 @@ class LibrarySelectionCallback(
} }
private fun collectSelectedItems( private fun collectSelectedItems(
controller: SectionedSelectionController<LibrarySectionModel>, controller: SectionedSelectionController<ShelfSectionModel>,
): Set<Manga> { ): Set<Manga> {
val snapshot = controller.peekCheckedIds() val snapshot = controller.peekCheckedIds()
if (snapshot.isEmpty()) { if (snapshot.isEmpty()) {

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui package org.koitharu.kotatsu.shelf.ui
import androidx.collection.ArraySet import androidx.collection.ArraySet
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
@ -20,8 +20,8 @@ import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
import org.koitharu.kotatsu.history.domain.HistoryRepository import org.koitharu.kotatsu.history.domain.HistoryRepository
import org.koitharu.kotatsu.history.domain.MangaWithHistory import org.koitharu.kotatsu.history.domain.MangaWithHistory
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
import org.koitharu.kotatsu.library.domain.LibraryRepository import org.koitharu.kotatsu.shelf.domain.ShelfRepository
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel
import org.koitharu.kotatsu.list.domain.ListExtraProvider import org.koitharu.kotatsu.list.domain.ListExtraProvider
import org.koitharu.kotatsu.list.ui.model.* import org.koitharu.kotatsu.list.ui.model.*
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
@ -33,8 +33,8 @@ import org.koitharu.kotatsu.utils.ext.daysDiff
private const val HISTORY_MAX_SEGMENTS = 2 private const val HISTORY_MAX_SEGMENTS = 2
@HiltViewModel @HiltViewModel
class LibraryViewModel @Inject constructor( class ShelfViewModel @Inject constructor(
repository: LibraryRepository, repository: ShelfRepository,
private val historyRepository: HistoryRepository, private val historyRepository: HistoryRepository,
private val favouritesRepository: FavouritesRepository, private val favouritesRepository: FavouritesRepository,
private val trackingRepository: TrackingRepository, private val trackingRepository: TrackingRepository,
@ -101,7 +101,7 @@ class LibraryViewModel @Inject constructor(
val snapshot = content.value ?: return emptySet() val snapshot = content.value ?: return emptySet()
val result = ArraySet<Manga>(ids.size) val result = ArraySet<Manga>(ids.size)
for (section in snapshot) { for (section in snapshot) {
if (section !is LibrarySectionModel) { if (section !is ShelfSectionModel) {
continue continue
} }
for (item in section.items) { for (item in section.items) {
@ -140,7 +140,7 @@ class LibraryViewModel @Inject constructor(
} }
private suspend fun mapHistory( private suspend fun mapHistory(
destination: MutableList<in LibrarySectionModel.History>, destination: MutableList<in ShelfSectionModel.History>,
list: List<MangaWithHistory>, list: List<MangaWithHistory>,
) { ) {
val showPercent = settings.isReadingIndicatorsEnabled val showPercent = settings.isReadingIndicatorsEnabled
@ -151,7 +151,7 @@ class LibraryViewModel @Inject constructor(
groups[groups.keys.last()]?.addAll(subList) groups[groups.keys.last()]?.addAll(subList)
} }
for ((timeAgo, subList) in groups) { for ((timeAgo, subList) in groups) {
destination += LibrarySectionModel.History( destination += ShelfSectionModel.History(
items = subList.map { (manga, history) -> items = subList.map { (manga, history) ->
val counter = trackingRepository.getNewChaptersCount(manga.id) val counter = trackingRepository.getNewChaptersCount(manga.id)
val percent = if (showPercent) history.percent else PROGRESS_NONE val percent = if (showPercent) history.percent else PROGRESS_NONE
@ -164,12 +164,12 @@ class LibraryViewModel @Inject constructor(
} }
private suspend fun mapFavourites( private suspend fun mapFavourites(
destination: MutableList<in LibrarySectionModel.Favourites>, destination: MutableList<in ShelfSectionModel.Favourites>,
favourites: Map<FavouriteCategory, List<Manga>>, favourites: Map<FavouriteCategory, List<Manga>>,
) { ) {
for ((category, list) in favourites) { for ((category, list) in favourites) {
if (list.isNotEmpty()) { if (list.isNotEmpty()) {
destination += LibrarySectionModel.Favourites( destination += ShelfSectionModel.Favourites(
items = list.toUi(ListMode.GRID, this), items = list.toUi(ListMode.GRID, this),
category = category, category = category,
showAllButtonText = R.string.show_all, showAllButtonText = R.string.show_all,

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.adapter package org.koitharu.kotatsu.shelf.ui.adapter
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import org.koitharu.kotatsu.list.ui.adapter.MangaListAdapter import org.koitharu.kotatsu.list.ui.adapter.MangaListAdapter

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.adapter package org.koitharu.kotatsu.shelf.ui.adapter
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.adapter package org.koitharu.kotatsu.shelf.ui.adapter
import android.content.Context import android.content.Context
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
@ -9,7 +9,7 @@ import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
import kotlin.jvm.internal.Intrinsics import kotlin.jvm.internal.Intrinsics
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
import org.koitharu.kotatsu.base.ui.list.fastscroll.FastScroller import org.koitharu.kotatsu.base.ui.list.fastscroll.FastScroller
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel
import org.koitharu.kotatsu.list.ui.ItemSizeResolver import org.koitharu.kotatsu.list.ui.ItemSizeResolver
import org.koitharu.kotatsu.list.ui.adapter.emptyStateListAD import org.koitharu.kotatsu.list.ui.adapter.emptyStateListAD
import org.koitharu.kotatsu.list.ui.adapter.errorStateListAD import org.koitharu.kotatsu.list.ui.adapter.errorStateListAD
@ -17,19 +17,19 @@ import org.koitharu.kotatsu.list.ui.adapter.loadingFooterAD
import org.koitharu.kotatsu.list.ui.adapter.loadingStateAD import org.koitharu.kotatsu.list.ui.adapter.loadingStateAD
import org.koitharu.kotatsu.list.ui.model.ListModel import org.koitharu.kotatsu.list.ui.model.ListModel
class LibraryAdapter( class ShelfAdapter(
lifecycleOwner: LifecycleOwner, lifecycleOwner: LifecycleOwner,
coil: ImageLoader, coil: ImageLoader,
listener: LibraryListEventListener, listener: ShelfListEventListener,
sizeResolver: ItemSizeResolver, sizeResolver: ItemSizeResolver,
selectionController: SectionedSelectionController<LibrarySectionModel>, selectionController: SectionedSelectionController<ShelfSectionModel>,
) : AsyncListDifferDelegationAdapter<ListModel>(DiffCallback()), FastScroller.SectionIndexer { ) : AsyncListDifferDelegationAdapter<ListModel>(DiffCallback()), FastScroller.SectionIndexer {
init { init {
val pool = RecyclerView.RecycledViewPool() val pool = RecyclerView.RecycledViewPool()
delegatesManager delegatesManager
.addDelegate( .addDelegate(
libraryGroupAD( shelfGroupAD(
sharedPool = pool, sharedPool = pool,
lifecycleOwner = lifecycleOwner, lifecycleOwner = lifecycleOwner,
coil = coil, coil = coil,
@ -45,7 +45,7 @@ class LibraryAdapter(
} }
override fun getSectionText(context: Context, position: Int): CharSequence { override fun getSectionText(context: Context, position: Int): CharSequence {
val item = items.getOrNull(position) as? LibrarySectionModel val item = items.getOrNull(position) as? ShelfSectionModel
return item?.getTitle(context.resources) ?: "" return item?.getTitle(context.resources) ?: ""
} }
@ -53,7 +53,7 @@ class LibraryAdapter(
override fun areItemsTheSame(oldItem: ListModel, newItem: ListModel): Boolean { override fun areItemsTheSame(oldItem: ListModel, newItem: ListModel): Boolean {
return when { return when {
oldItem is LibrarySectionModel && newItem is LibrarySectionModel -> { oldItem is ShelfSectionModel && newItem is ShelfSectionModel -> {
oldItem.key == newItem.key oldItem.key == newItem.key
} }
else -> oldItem.javaClass == newItem.javaClass else -> oldItem.javaClass == newItem.javaClass
@ -66,7 +66,7 @@ class LibraryAdapter(
override fun getChangePayload(oldItem: ListModel, newItem: ListModel): Any? { override fun getChangePayload(oldItem: ListModel, newItem: ListModel): Any? {
return when { return when {
oldItem is LibrarySectionModel && newItem is LibrarySectionModel -> Unit oldItem is ShelfSectionModel && newItem is ShelfSectionModel -> Unit
else -> super.getChangePayload(oldItem, newItem) else -> super.getChangePayload(oldItem, newItem)
} }
} }

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.adapter package org.koitharu.kotatsu.shelf.ui.adapter
import android.view.View import android.view.View
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
@ -12,7 +12,7 @@ import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration
import org.koitharu.kotatsu.databinding.ItemListGroupBinding import org.koitharu.kotatsu.databinding.ItemListGroupBinding
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel
import org.koitharu.kotatsu.list.ui.ItemSizeResolver import org.koitharu.kotatsu.list.ui.ItemSizeResolver
import org.koitharu.kotatsu.list.ui.adapter.mangaGridItemAD import org.koitharu.kotatsu.list.ui.adapter.mangaGridItemAD
import org.koitharu.kotatsu.list.ui.model.ListModel import org.koitharu.kotatsu.list.ui.model.ListModel
@ -20,14 +20,14 @@ import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.utils.ext.removeItemDecoration import org.koitharu.kotatsu.utils.ext.removeItemDecoration
import org.koitharu.kotatsu.utils.ext.setTextAndVisible import org.koitharu.kotatsu.utils.ext.setTextAndVisible
fun libraryGroupAD( fun shelfGroupAD(
sharedPool: RecyclerView.RecycledViewPool, sharedPool: RecyclerView.RecycledViewPool,
lifecycleOwner: LifecycleOwner, lifecycleOwner: LifecycleOwner,
coil: ImageLoader, coil: ImageLoader,
sizeResolver: ItemSizeResolver, sizeResolver: ItemSizeResolver,
selectionController: SectionedSelectionController<LibrarySectionModel>, selectionController: SectionedSelectionController<ShelfSectionModel>,
listener: LibraryListEventListener, listener: ShelfListEventListener,
) = adapterDelegateViewBinding<LibrarySectionModel, ListModel, ItemListGroupBinding>( ) = adapterDelegateViewBinding<ShelfSectionModel, ListModel, ItemListGroupBinding>(
{ layoutInflater, parent -> ItemListGroupBinding.inflate(layoutInflater, parent, false) }, { layoutInflater, parent -> ItemListGroupBinding.inflate(layoutInflater, parent, false) },
) { ) {
val listenerAdapter = object : OnListItemClickListener<Manga>, View.OnClickListener { val listenerAdapter = object : OnListItemClickListener<Manga>, View.OnClickListener {

@ -0,0 +1,15 @@
package org.koitharu.kotatsu.shelf.ui.adapter
import android.view.View
import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
import org.koitharu.kotatsu.parsers.model.Manga
interface ShelfListEventListener : ListStateHolderListener {
fun onItemClick(item: Manga, section: ShelfSectionModel, view: View)
fun onItemLongClick(item: Manga, section: ShelfSectionModel, view: View): Boolean
fun onSectionClick(section: ShelfSectionModel, view: View)
}

@ -1,16 +1,16 @@
package org.koitharu.kotatsu.library.ui.config.categories package org.koitharu.kotatsu.shelf.ui.config.categories
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
import org.koitharu.kotatsu.core.model.FavouriteCategory import org.koitharu.kotatsu.core.model.FavouriteCategory
class LibraryCategoriesConfigAdapter( class ShelfCategoriesConfigAdapter(
listener: OnListItemClickListener<FavouriteCategory>, listener: OnListItemClickListener<FavouriteCategory>,
) : AsyncListDifferDelegationAdapter<FavouriteCategory>(DiffCallback()) { ) : AsyncListDifferDelegationAdapter<FavouriteCategory>(DiffCallback()) {
init { init {
delegatesManager.addDelegate(libraryCategoryAD(listener)) delegatesManager.addDelegate(shelfCategoryAD(listener))
} }
class DiffCallback : DiffUtil.ItemCallback<FavouriteCategory>() { class DiffCallback : DiffUtil.ItemCallback<FavouriteCategory>() {

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.config.categories package org.koitharu.kotatsu.shelf.ui.config.categories
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -15,12 +15,12 @@ import org.koitharu.kotatsu.core.model.FavouriteCategory
import org.koitharu.kotatsu.databinding.SheetBaseBinding import org.koitharu.kotatsu.databinding.SheetBaseBinding
@AndroidEntryPoint @AndroidEntryPoint
class LibraryCategoriesConfigSheet : class ShelfCategoriesConfigSheet :
BaseBottomSheet<SheetBaseBinding>(), BaseBottomSheet<SheetBaseBinding>(),
OnListItemClickListener<FavouriteCategory>, OnListItemClickListener<FavouriteCategory>,
View.OnClickListener { View.OnClickListener {
private val viewModel by viewModels<LibraryCategoriesConfigViewModel>() private val viewModel by viewModels<ShelfCategoriesConfigViewModel>()
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetBaseBinding { override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetBaseBinding {
return SheetBaseBinding.inflate(inflater, container, false) return SheetBaseBinding.inflate(inflater, container, false)
@ -31,7 +31,7 @@ class LibraryCategoriesConfigSheet :
binding.headerBar.toolbar.setTitle(R.string.favourites_categories) binding.headerBar.toolbar.setTitle(R.string.favourites_categories)
binding.buttonDone.isVisible = true binding.buttonDone.isVisible = true
binding.buttonDone.setOnClickListener(this) binding.buttonDone.setOnClickListener(this)
val adapter = LibraryCategoriesConfigAdapter(this) val adapter = ShelfCategoriesConfigAdapter(this)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
viewModel.content.observe(viewLifecycleOwner) { adapter.items = it } viewModel.content.observe(viewLifecycleOwner) { adapter.items = it }
@ -47,8 +47,8 @@ class LibraryCategoriesConfigSheet :
companion object { companion object {
private const val TAG = "LibraryCategoriesConfigSheet" private const val TAG = "ShelfCategoriesConfigSheet"
fun show(fm: FragmentManager) = LibraryCategoriesConfigSheet().show(fm, TAG) fun show(fm: FragmentManager) = ShelfCategoriesConfigSheet().show(fm, TAG)
} }
} }

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.config.categories package org.koitharu.kotatsu.shelf.ui.config.categories
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
@ -11,7 +11,7 @@ import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
@HiltViewModel @HiltViewModel
class LibraryCategoriesConfigViewModel @Inject constructor( class ShelfCategoriesConfigViewModel @Inject constructor(
private val favouritesRepository: FavouritesRepository, private val favouritesRepository: FavouritesRepository,
) : BaseViewModel() { ) : BaseViewModel() {

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.config.categories package org.koitharu.kotatsu.shelf.ui.config.categories
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter
@ -6,7 +6,7 @@ import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
import org.koitharu.kotatsu.core.model.FavouriteCategory import org.koitharu.kotatsu.core.model.FavouriteCategory
import org.koitharu.kotatsu.databinding.ItemCategoryCheckableMultipleBinding import org.koitharu.kotatsu.databinding.ItemCategoryCheckableMultipleBinding
fun libraryCategoryAD( fun shelfCategoryAD(
listener: OnListItemClickListener<FavouriteCategory>, listener: OnListItemClickListener<FavouriteCategory>,
) = adapterDelegateViewBinding<FavouriteCategory, FavouriteCategory, ItemCategoryCheckableMultipleBinding>( ) = adapterDelegateViewBinding<FavouriteCategory, FavouriteCategory, ItemCategoryCheckableMultipleBinding>(
{ layoutInflater, parent -> ItemCategoryCheckableMultipleBinding.inflate(layoutInflater, parent, false) }, { layoutInflater, parent -> ItemCategoryCheckableMultipleBinding.inflate(layoutInflater, parent, false) },

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.config.size package org.koitharu.kotatsu.shelf.ui.config.size
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -12,13 +12,13 @@ import javax.inject.Inject
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.BaseBottomSheet import org.koitharu.kotatsu.base.ui.BaseBottomSheet
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.databinding.SheetLibrarySizeBinding import org.koitharu.kotatsu.databinding.SheetShelfSizeBinding
import org.koitharu.kotatsu.utils.ext.setValueRounded import org.koitharu.kotatsu.utils.ext.setValueRounded
import org.koitharu.kotatsu.utils.progress.IntPercentLabelFormatter import org.koitharu.kotatsu.utils.progress.IntPercentLabelFormatter
@AndroidEntryPoint @AndroidEntryPoint
class LibrarySizeBottomSheet : class ShelfSizeBottomSheet :
BaseBottomSheet<SheetLibrarySizeBinding>(), BaseBottomSheet<SheetShelfSizeBinding>(),
Slider.OnChangeListener, Slider.OnChangeListener,
View.OnClickListener { View.OnClickListener {
@ -26,8 +26,8 @@ class LibrarySizeBottomSheet :
lateinit var settings: AppSettings lateinit var settings: AppSettings
private var labelFormatter: LabelFormatter? = null private var labelFormatter: LabelFormatter? = null
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetLibrarySizeBinding { override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetShelfSizeBinding {
return SheetLibrarySizeBinding.inflate(inflater, container, false) return SheetShelfSizeBinding.inflate(inflater, container, false)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -59,8 +59,8 @@ class LibrarySizeBottomSheet :
companion object { companion object {
private const val TAG = "LibrarySizeBottomSheet" private const val TAG = "ShelfSizeBottomSheet"
fun show(fm: FragmentManager) = LibrarySizeBottomSheet().show(fm, TAG) fun show(fm: FragmentManager) = ShelfSizeBottomSheet().show(fm, TAG)
} }
} }

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.library.ui.model package org.koitharu.kotatsu.shelf.ui.model
import android.content.res.Resources import android.content.res.Resources
import androidx.annotation.StringRes import androidx.annotation.StringRes
@ -8,7 +8,7 @@ import org.koitharu.kotatsu.core.ui.DateTimeAgo
import org.koitharu.kotatsu.list.ui.model.ListModel import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.list.ui.model.MangaItemModel import org.koitharu.kotatsu.list.ui.model.MangaItemModel
sealed class LibrarySectionModel( sealed class ShelfSectionModel(
val items: List<MangaItemModel>, val items: List<MangaItemModel>,
@StringRes val showAllButtonText: Int, @StringRes val showAllButtonText: Int,
) : ListModel { ) : ListModel {
@ -20,7 +20,7 @@ sealed class LibrarySectionModel(
items: List<MangaItemModel>, items: List<MangaItemModel>,
val timeAgo: DateTimeAgo?, val timeAgo: DateTimeAgo?,
showAllButtonText: Int, showAllButtonText: Int,
) : LibrarySectionModel(items, showAllButtonText) { ) : ShelfSectionModel(items, showAllButtonText) {
override val key: Any override val key: Any
get() = timeAgo?.javaClass ?: this::class.java get() = timeAgo?.javaClass ?: this::class.java
@ -58,7 +58,7 @@ sealed class LibrarySectionModel(
items: List<MangaItemModel>, items: List<MangaItemModel>,
val category: FavouriteCategory, val category: FavouriteCategory,
showAllButtonText: Int, showAllButtonText: Int,
) : LibrarySectionModel(items, showAllButtonText) { ) : ShelfSectionModel(items, showAllButtonText) {
override val key: Any override val key: Any
get() = category.id get() = category.id

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:id="@+id/nav_library" android:id="@+id/nav_shelf"
android:icon="@drawable/ic_bookshelf_selector" android:icon="@drawable/ic_bookshelf_selector"
android:title="@string/manga_shelf" /> android:title="@string/manga_shelf" />

Loading…
Cancel
Save