From 3f6a1039151543165a207b170c9065aa66ccca8b Mon Sep 17 00:00:00 2001 From: Zakhar Timoshenko Date: Wed, 14 Sep 2022 18:46:32 +0300 Subject: [PATCH] Rename `Library` to `Shelf` --- .../ui/adapter/LibraryListEventListener.kt | 15 ------- .../koitharu/kotatsu/main/ui/MainActivity.kt | 6 +-- .../kotatsu/main/ui/MainNavigationDelegate.kt | 4 +- .../domain/ShelfRepository.kt} | 4 +- .../ui/ShelfFragment.kt} | 44 +++++++++---------- .../ui/ShelfMenuProvider.kt} | 16 +++---- .../ui/ShelfSelectionCallback.kt} | 34 +++++++------- .../ui/ShelfViewModel.kt} | 20 ++++----- .../ui/adapter/MangaItemDiffCallback.kt | 4 +- .../ui/adapter/ScrollKeepObserver.kt | 2 +- .../ui/adapter/ShelfAdapter.kt} | 18 ++++---- .../ui/adapter/ShelfGroupAD.kt} | 12 ++--- .../ui/adapter/ShelfListEventListener.kt | 15 +++++++ .../ShelfCategoriesConfigAdapter.kt} | 6 +-- .../categories/ShelfCategoriesConfigSheet.kt} | 12 ++--- .../ShelfCategoriesConfigViewModel.kt} | 4 +- .../ui/config/categories/ShelfCategoryAD.kt} | 4 +- .../ui/config/size/ShelfSizeBottomSheet.kt} | 16 +++---- .../ui/model/ShelfSectionModel.kt} | 8 ++-- ...ragment_library.xml => fragment_shelf.xml} | 0 ..._library_size.xml => sheet_shelf_size.xml} | 0 .../menu/{mode_library.xml => mode_shelf.xml} | 0 app/src/main/res/menu/nav_bottom.xml | 2 +- .../menu/{opt_library.xml => opt_shelf.xml} | 0 24 files changed, 123 insertions(+), 123 deletions(-) delete mode 100644 app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryListEventListener.kt rename app/src/main/java/org/koitharu/kotatsu/{library/domain/LibraryRepository.kt => shelf/domain/ShelfRepository.kt} (93%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/LibraryFragment.kt => shelf/ui/ShelfFragment.kt} (73%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/LibraryMenuProvider.kt => shelf/ui/ShelfMenuProvider.kt} (82%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/LibrarySelectionCallback.kt => shelf/ui/ShelfSelectionCallback.kt} (73%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/LibraryViewModel.kt => shelf/ui/ShelfViewModel.kt} (91%) rename app/src/main/java/org/koitharu/kotatsu/{library => shelf}/ui/adapter/MangaItemDiffCallback.kt (95%) rename app/src/main/java/org/koitharu/kotatsu/{library => shelf}/ui/adapter/ScrollKeepObserver.kt (95%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/adapter/LibraryAdapter.kt => shelf/ui/adapter/ShelfAdapter.kt} (81%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/adapter/LibraryGroupAD.kt => shelf/ui/adapter/ShelfGroupAD.kt} (88%) create mode 100644 app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfListEventListener.kt rename app/src/main/java/org/koitharu/kotatsu/{library/ui/config/categories/LibraryCategoriesConfigAdapter.kt => shelf/ui/config/categories/ShelfCategoriesConfigAdapter.kt} (86%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/config/categories/LibraryCategoriesConfigSheet.kt => shelf/ui/config/categories/ShelfCategoriesConfigSheet.kt} (79%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/config/categories/LibraryCategoriesConfigViewModel.kt => shelf/ui/config/categories/ShelfCategoriesConfigViewModel.kt} (88%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/config/categories/LibraryCategoryAD.kt => shelf/ui/config/categories/ShelfCategoryAD.kt} (91%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/config/size/LibrarySizeBottomSheet.kt => shelf/ui/config/size/ShelfSizeBottomSheet.kt} (80%) rename app/src/main/java/org/koitharu/kotatsu/{library/ui/model/LibrarySectionModel.kt => shelf/ui/model/ShelfSectionModel.kt} (92%) rename app/src/main/res/layout/{fragment_library.xml => fragment_shelf.xml} (100%) rename app/src/main/res/layout/{sheet_library_size.xml => sheet_shelf_size.xml} (100%) rename app/src/main/res/menu/{mode_library.xml => mode_shelf.xml} (100%) rename app/src/main/res/menu/{opt_library.xml => opt_shelf.xml} (100%) diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryListEventListener.kt b/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryListEventListener.kt deleted file mode 100644 index 8416c458b..000000000 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryListEventListener.kt +++ /dev/null @@ -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) -} \ No newline at end of file diff --git a/app/src/main/java/org/koitharu/kotatsu/main/ui/MainActivity.kt b/app/src/main/java/org/koitharu/kotatsu/main/ui/MainActivity.kt index 8a32d5c62..c050a1c2c 100644 --- a/app/src/main/java/org/koitharu/kotatsu/main/ui/MainActivity.kt +++ b/app/src/main/java/org/koitharu/kotatsu/main/ui/MainActivity.kt @@ -34,7 +34,7 @@ import org.koitharu.kotatsu.base.ui.BaseActivity import org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView import org.koitharu.kotatsu.databinding.ActivityMainBinding 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.BottomNavOwner import org.koitharu.kotatsu.parsers.model.Manga @@ -136,7 +136,7 @@ class MainActivity : } override fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) { - if (fragment is LibraryFragment) { + if (fragment is ShelfFragment) { binding.fab?.show() } else { binding.fab?.hide() @@ -313,7 +313,7 @@ class MainActivity : isResumeEnabled && !actionModeDelegate.isActionModeStarted && !isSearchOpened && - topFragment is LibraryFragment + topFragment is ShelfFragment ) { if (fab?.isVisible == false) { fab.show() diff --git a/app/src/main/java/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt b/app/src/main/java/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt index 01e870565..93dbc98b7 100644 --- a/app/src/main/java/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt +++ b/app/src/main/java/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt @@ -10,7 +10,7 @@ import com.google.android.material.navigation.NavigationBarView import org.koitharu.kotatsu.R import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner 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.tracker.ui.FeedFragment import java.util.* @@ -73,7 +73,7 @@ class MainNavigationDelegate( private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean { setPrimaryFragment( when (itemId) { - R.id.nav_library -> LibraryFragment.newInstance() + R.id.nav_shelf -> ShelfFragment.newInstance() R.id.nav_explore -> ExploreFragment.newInstance() R.id.nav_feed -> FeedFragment.newInstance() R.id.nav_tools -> ToolsFragment.newInstance() diff --git a/app/src/main/java/org/koitharu/kotatsu/library/domain/LibraryRepository.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/domain/ShelfRepository.kt similarity index 93% rename from app/src/main/java/org/koitharu/kotatsu/library/domain/LibraryRepository.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/domain/ShelfRepository.kt index a2457fb30..b8f59ca21 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/domain/LibraryRepository.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/domain/ShelfRepository.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.domain +package org.koitharu.kotatsu.shelf.domain import javax.inject.Inject 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.parsers.model.Manga -class LibraryRepository @Inject constructor( +class ShelfRepository @Inject constructor( private val db: MangaDatabase, ) { diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryFragment.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfFragment.kt similarity index 73% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryFragment.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfFragment.kt index eef0fe765..a59b7bfb5 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryFragment.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfFragment.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui +package org.koitharu.kotatsu.shelf.ui import android.os.Bundle 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.ReversibleAction 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.favourites.ui.FavouritesActivity import org.koitharu.kotatsu.history.ui.HistoryActivity -import org.koitharu.kotatsu.library.ui.adapter.LibraryAdapter -import org.koitharu.kotatsu.library.ui.adapter.LibraryListEventListener -import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel +import org.koitharu.kotatsu.shelf.ui.adapter.ShelfAdapter +import org.koitharu.kotatsu.shelf.ui.adapter.ShelfListEventListener +import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel import org.koitharu.kotatsu.list.ui.ItemSizeResolver import org.koitharu.kotatsu.list.ui.model.ListModel 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 @AndroidEntryPoint -class LibraryFragment : - BaseFragment(), +class ShelfFragment : + BaseFragment(), RecyclerViewOwner, - LibraryListEventListener { + ShelfListEventListener { @Inject lateinit var coil: ImageLoader @@ -45,15 +45,15 @@ class LibraryFragment : @Inject lateinit var settings: AppSettings - private val viewModel by viewModels() - private var adapter: LibraryAdapter? = null - private var selectionController: SectionedSelectionController? = null + private val viewModel by viewModels() + private var adapter: ShelfAdapter? = null + private var selectionController: SectionedSelectionController? = null override val recyclerView: RecyclerView get() = binding.recyclerView - override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): FragmentLibraryBinding { - return FragmentLibraryBinding.inflate(inflater, container, false) + override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): FragmentShelfBinding { + return FragmentShelfBinding.inflate(inflater, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -62,9 +62,9 @@ class LibraryFragment : selectionController = SectionedSelectionController( activity = requireActivity(), owner = this, - callback = LibrarySelectionCallback(binding.recyclerView, childFragmentManager, viewModel), + callback = ShelfSelectionCallback(binding.recyclerView, childFragmentManager, viewModel), ) - adapter = LibraryAdapter( + adapter = ShelfAdapter( lifecycleOwner = viewLifecycleOwner, coil = coil, listener = this, @@ -73,7 +73,7 @@ class LibraryFragment : ) binding.recyclerView.adapter = adapter binding.recyclerView.setHasFixedSize(true) - addMenuProvider(LibraryMenuProvider(view.context, childFragmentManager, viewModel)) + addMenuProvider(ShelfMenuProvider(view.context, childFragmentManager, viewModel)) viewModel.content.observe(viewLifecycleOwner, ::onListChanged) viewModel.onError.observe(viewLifecycleOwner, ::onError) @@ -86,22 +86,22 @@ class LibraryFragment : 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) { val intent = DetailsActivity.newIntent(view.context, item) 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 } - override fun onSectionClick(section: LibrarySectionModel, view: View) { + override fun onSectionClick(section: ShelfSectionModel, view: View) { selectionController?.clear() val intent = when (section) { - is LibrarySectionModel.History -> HistoryActivity.newIntent(view.context) - is LibrarySectionModel.Favourites -> FavouritesActivity.newIntent(view.context, section.category) + is ShelfSectionModel.History -> HistoryActivity.newIntent(view.context) + is ShelfSectionModel.Favourites -> FavouritesActivity.newIntent(view.context, section.category) } startActivity(intent) } @@ -143,6 +143,6 @@ class LibraryFragment : companion object { - fun newInstance() = LibraryFragment() + fun newInstance() = ShelfFragment() } } diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryMenuProvider.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfMenuProvider.kt similarity index 82% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryMenuProvider.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfMenuProvider.kt index f00570421..589432ed7 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryMenuProvider.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfMenuProvider.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui +package org.koitharu.kotatsu.shelf.ui import android.content.Context import android.view.Menu @@ -12,19 +12,19 @@ import java.util.* import java.util.concurrent.TimeUnit import org.koitharu.kotatsu.R import org.koitharu.kotatsu.base.ui.dialog.RememberSelectionDialogListener -import org.koitharu.kotatsu.library.ui.config.categories.LibraryCategoriesConfigSheet -import org.koitharu.kotatsu.library.ui.config.size.LibrarySizeBottomSheet +import org.koitharu.kotatsu.shelf.ui.config.categories.ShelfCategoriesConfigSheet +import org.koitharu.kotatsu.shelf.ui.config.size.ShelfSizeBottomSheet import org.koitharu.kotatsu.local.ui.ImportDialogFragment import org.koitharu.kotatsu.utils.ext.startOfDay -class LibraryMenuProvider( +class ShelfMenuProvider( private val context: Context, private val fragmentManager: FragmentManager, - private val viewModel: LibraryViewModel, + private val viewModel: ShelfViewModel, ) : MenuProvider { 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 { @@ -34,7 +34,7 @@ class LibraryMenuProvider( true } R.id.action_grid_size -> { - LibrarySizeBottomSheet.show(fragmentManager) + ShelfSizeBottomSheet.show(fragmentManager) true } R.id.action_import -> { @@ -42,7 +42,7 @@ class LibraryMenuProvider( true } R.id.action_categories -> { - LibraryCategoriesConfigSheet.show(fragmentManager) + ShelfCategoriesConfigSheet.show(fragmentManager) true } else -> false diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibrarySelectionCallback.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfSelectionCallback.kt similarity index 73% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/LibrarySelectionCallback.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfSelectionCallback.kt index 3eb0c0ec4..f343ad825 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibrarySelectionCallback.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfSelectionCallback.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui +package org.koitharu.kotatsu.shelf.ui import android.content.Context 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.download.ui.service.DownloadService 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.parsers.model.Manga import org.koitharu.kotatsu.parsers.util.flattenTo import org.koitharu.kotatsu.utils.ShareHelper import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations -class LibrarySelectionCallback( +class ShelfSelectionCallback( private val recyclerView: RecyclerView, private val fragmentManager: FragmentManager, - private val viewModel: LibraryViewModel, -) : SectionedSelectionController.Callback { + private val viewModel: ShelfViewModel, +) : SectionedSelectionController.Callback { private val context: Context get() = recyclerView.context override fun onCreateActionMode( - controller: SectionedSelectionController, + controller: SectionedSelectionController, mode: ActionMode, menu: Menu, ): Boolean { - mode.menuInflater.inflate(R.menu.mode_library, menu) + mode.menuInflater.inflate(R.menu.mode_shelf, menu) return true } override fun onPrepareActionMode( - controller: SectionedSelectionController, + controller: SectionedSelectionController, mode: ActionMode, menu: Menu, ): Boolean { @@ -47,7 +47,7 @@ class LibrarySelectionCallback( } override fun onActionItemClicked( - controller: SectionedSelectionController, + controller: SectionedSelectionController, mode: ActionMode, item: MenuItem, ): Boolean { @@ -70,8 +70,8 @@ class LibrarySelectionCallback( R.id.action_remove -> { val (group, ids) = controller.snapshot().entries.singleOrNull { it.value.isNotEmpty() } ?: return false when (group) { - is LibrarySectionModel.Favourites -> viewModel.removeFromFavourites(group.category, ids) - is LibrarySectionModel.History -> viewModel.removeFromHistory(ids) + is ShelfSectionModel.Favourites -> viewModel.removeFromFavourites(group.category, ids) + is ShelfSectionModel.History -> viewModel.removeFromHistory(ids) } mode.finish() true @@ -80,18 +80,18 @@ class LibrarySelectionCallback( } } - override fun onSelectionChanged(controller: SectionedSelectionController, count: Int) { + override fun onSelectionChanged(controller: SectionedSelectionController, count: Int) { recyclerView.invalidateNestedItemDecorations() } override fun onCreateItemDecoration( - controller: SectionedSelectionController, - section: LibrarySectionModel, + controller: SectionedSelectionController, + section: ShelfSectionModel, ): AbstractSelectionItemDecoration = MangaSelectionDecoration(context) private fun collectSelectedItemsMap( - controller: SectionedSelectionController, - ): Map> { + controller: SectionedSelectionController, + ): Map> { val snapshot = controller.peekCheckedIds() if (snapshot.isEmpty()) { return emptyMap() @@ -100,7 +100,7 @@ class LibrarySelectionCallback( } private fun collectSelectedItems( - controller: SectionedSelectionController, + controller: SectionedSelectionController, ): Set { val snapshot = controller.peekCheckedIds() if (snapshot.isEmpty()) { diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryViewModel.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfViewModel.kt similarity index 91% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryViewModel.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfViewModel.kt index 140be0638..99164a2ab 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/LibraryViewModel.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/ShelfViewModel.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui +package org.koitharu.kotatsu.shelf.ui import androidx.collection.ArraySet 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.MangaWithHistory import org.koitharu.kotatsu.history.domain.PROGRESS_NONE -import org.koitharu.kotatsu.library.domain.LibraryRepository -import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel +import org.koitharu.kotatsu.shelf.domain.ShelfRepository +import org.koitharu.kotatsu.shelf.ui.model.ShelfSectionModel import org.koitharu.kotatsu.list.domain.ListExtraProvider import org.koitharu.kotatsu.list.ui.model.* 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 @HiltViewModel -class LibraryViewModel @Inject constructor( - repository: LibraryRepository, +class ShelfViewModel @Inject constructor( + repository: ShelfRepository, private val historyRepository: HistoryRepository, private val favouritesRepository: FavouritesRepository, private val trackingRepository: TrackingRepository, @@ -101,7 +101,7 @@ class LibraryViewModel @Inject constructor( val snapshot = content.value ?: return emptySet() val result = ArraySet(ids.size) for (section in snapshot) { - if (section !is LibrarySectionModel) { + if (section !is ShelfSectionModel) { continue } for (item in section.items) { @@ -140,7 +140,7 @@ class LibraryViewModel @Inject constructor( } private suspend fun mapHistory( - destination: MutableList, + destination: MutableList, list: List, ) { val showPercent = settings.isReadingIndicatorsEnabled @@ -151,7 +151,7 @@ class LibraryViewModel @Inject constructor( groups[groups.keys.last()]?.addAll(subList) } for ((timeAgo, subList) in groups) { - destination += LibrarySectionModel.History( + destination += ShelfSectionModel.History( items = subList.map { (manga, history) -> val counter = trackingRepository.getNewChaptersCount(manga.id) val percent = if (showPercent) history.percent else PROGRESS_NONE @@ -164,12 +164,12 @@ class LibraryViewModel @Inject constructor( } private suspend fun mapFavourites( - destination: MutableList, + destination: MutableList, favourites: Map>, ) { for ((category, list) in favourites) { if (list.isNotEmpty()) { - destination += LibrarySectionModel.Favourites( + destination += ShelfSectionModel.Favourites( items = list.toUi(ListMode.GRID, this), category = category, showAllButtonText = R.string.show_all, diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/MangaItemDiffCallback.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/MangaItemDiffCallback.kt similarity index 95% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/MangaItemDiffCallback.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/MangaItemDiffCallback.kt index e39d60454..a934dbd52 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/MangaItemDiffCallback.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/MangaItemDiffCallback.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui.adapter +package org.koitharu.kotatsu.shelf.ui.adapter import androidx.recyclerview.widget.DiffUtil import org.koitharu.kotatsu.list.ui.adapter.MangaListAdapter @@ -27,4 +27,4 @@ class MangaItemDiffCallback : DiffUtil.ItemCallback() { else -> super.getChangePayload(oldItem, newItem) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/ScrollKeepObserver.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ScrollKeepObserver.kt similarity index 95% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/ScrollKeepObserver.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ScrollKeepObserver.kt index e15aeec3f..397b8192d 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/ScrollKeepObserver.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ScrollKeepObserver.kt @@ -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.RecyclerView diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryAdapter.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfAdapter.kt similarity index 81% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryAdapter.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfAdapter.kt index 2e2e64faa..9afd2fdec 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryAdapter.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfAdapter.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui.adapter +package org.koitharu.kotatsu.shelf.ui.adapter import android.content.Context import androidx.lifecycle.LifecycleOwner @@ -9,7 +9,7 @@ import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter import kotlin.jvm.internal.Intrinsics import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController 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.adapter.emptyStateListAD 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.model.ListModel -class LibraryAdapter( +class ShelfAdapter( lifecycleOwner: LifecycleOwner, coil: ImageLoader, - listener: LibraryListEventListener, + listener: ShelfListEventListener, sizeResolver: ItemSizeResolver, - selectionController: SectionedSelectionController, + selectionController: SectionedSelectionController, ) : AsyncListDifferDelegationAdapter(DiffCallback()), FastScroller.SectionIndexer { init { val pool = RecyclerView.RecycledViewPool() delegatesManager .addDelegate( - libraryGroupAD( + shelfGroupAD( sharedPool = pool, lifecycleOwner = lifecycleOwner, coil = coil, @@ -45,7 +45,7 @@ class LibraryAdapter( } 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) ?: "" } @@ -53,7 +53,7 @@ class LibraryAdapter( override fun areItemsTheSame(oldItem: ListModel, newItem: ListModel): Boolean { return when { - oldItem is LibrarySectionModel && newItem is LibrarySectionModel -> { + oldItem is ShelfSectionModel && newItem is ShelfSectionModel -> { oldItem.key == newItem.key } else -> oldItem.javaClass == newItem.javaClass @@ -66,7 +66,7 @@ class LibraryAdapter( override fun getChangePayload(oldItem: ListModel, newItem: ListModel): Any? { return when { - oldItem is LibrarySectionModel && newItem is LibrarySectionModel -> Unit + oldItem is ShelfSectionModel && newItem is ShelfSectionModel -> Unit else -> super.getChangePayload(oldItem, newItem) } } diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfGroupAD.kt similarity index 88% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfGroupAD.kt index c7384037d..a85e6de29 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfGroupAD.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui.adapter +package org.koitharu.kotatsu.shelf.ui.adapter import android.view.View 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.SpacingItemDecoration 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.adapter.mangaGridItemAD 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.setTextAndVisible -fun libraryGroupAD( +fun shelfGroupAD( sharedPool: RecyclerView.RecycledViewPool, lifecycleOwner: LifecycleOwner, coil: ImageLoader, sizeResolver: ItemSizeResolver, - selectionController: SectionedSelectionController, - listener: LibraryListEventListener, -) = adapterDelegateViewBinding( + selectionController: SectionedSelectionController, + listener: ShelfListEventListener, +) = adapterDelegateViewBinding( { layoutInflater, parent -> ItemListGroupBinding.inflate(layoutInflater, parent, false) }, ) { val listenerAdapter = object : OnListItemClickListener, View.OnClickListener { diff --git a/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfListEventListener.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfListEventListener.kt new file mode 100644 index 000000000..af34933d2 --- /dev/null +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/adapter/ShelfListEventListener.kt @@ -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) +} diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigAdapter.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigAdapter.kt similarity index 86% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigAdapter.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigAdapter.kt index 7610bf597..12d0b4a5d 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigAdapter.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigAdapter.kt @@ -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 com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.model.FavouriteCategory -class LibraryCategoriesConfigAdapter( +class ShelfCategoriesConfigAdapter( listener: OnListItemClickListener, ) : AsyncListDifferDelegationAdapter(DiffCallback()) { init { - delegatesManager.addDelegate(libraryCategoryAD(listener)) + delegatesManager.addDelegate(shelfCategoryAD(listener)) } class DiffCallback : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigSheet.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigSheet.kt similarity index 79% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigSheet.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigSheet.kt index 0808de746..5df721191 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigSheet.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigSheet.kt @@ -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.view.LayoutInflater @@ -15,12 +15,12 @@ import org.koitharu.kotatsu.core.model.FavouriteCategory import org.koitharu.kotatsu.databinding.SheetBaseBinding @AndroidEntryPoint -class LibraryCategoriesConfigSheet : +class ShelfCategoriesConfigSheet : BaseBottomSheet(), OnListItemClickListener, View.OnClickListener { - private val viewModel by viewModels() + private val viewModel by viewModels() override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetBaseBinding { return SheetBaseBinding.inflate(inflater, container, false) @@ -31,7 +31,7 @@ class LibraryCategoriesConfigSheet : binding.headerBar.toolbar.setTitle(R.string.favourites_categories) binding.buttonDone.isVisible = true binding.buttonDone.setOnClickListener(this) - val adapter = LibraryCategoriesConfigAdapter(this) + val adapter = ShelfCategoriesConfigAdapter(this) binding.recyclerView.adapter = adapter viewModel.content.observe(viewLifecycleOwner) { adapter.items = it } @@ -47,8 +47,8 @@ class LibraryCategoriesConfigSheet : 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) } } diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigViewModel.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigViewModel.kt similarity index 88% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigViewModel.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigViewModel.kt index 49be1d853..1c77b243e 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoriesConfigViewModel.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoriesConfigViewModel.kt @@ -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 dagger.hilt.android.lifecycle.HiltViewModel @@ -11,7 +11,7 @@ import org.koitharu.kotatsu.favourites.domain.FavouritesRepository import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct @HiltViewModel -class LibraryCategoriesConfigViewModel @Inject constructor( +class ShelfCategoriesConfigViewModel @Inject constructor( private val favouritesRepository: FavouritesRepository, ) : BaseViewModel() { diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoryAD.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoryAD.kt similarity index 91% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoryAD.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoryAD.kt index a482bc11a..9aa529210 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/categories/LibraryCategoryAD.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/categories/ShelfCategoryAD.kt @@ -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 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.databinding.ItemCategoryCheckableMultipleBinding -fun libraryCategoryAD( +fun shelfCategoryAD( listener: OnListItemClickListener, ) = adapterDelegateViewBinding( { layoutInflater, parent -> ItemCategoryCheckableMultipleBinding.inflate(layoutInflater, parent, false) }, diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/size/LibrarySizeBottomSheet.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/size/ShelfSizeBottomSheet.kt similarity index 80% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/config/size/LibrarySizeBottomSheet.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/size/ShelfSizeBottomSheet.kt index cb8199a56..dd84a891b 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/config/size/LibrarySizeBottomSheet.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/config/size/ShelfSizeBottomSheet.kt @@ -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.view.LayoutInflater @@ -12,13 +12,13 @@ import javax.inject.Inject import org.koitharu.kotatsu.R import org.koitharu.kotatsu.base.ui.BaseBottomSheet 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.progress.IntPercentLabelFormatter @AndroidEntryPoint -class LibrarySizeBottomSheet : - BaseBottomSheet(), +class ShelfSizeBottomSheet : + BaseBottomSheet(), Slider.OnChangeListener, View.OnClickListener { @@ -26,8 +26,8 @@ class LibrarySizeBottomSheet : lateinit var settings: AppSettings private var labelFormatter: LabelFormatter? = null - override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetLibrarySizeBinding { - return SheetLibrarySizeBinding.inflate(inflater, container, false) + override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetShelfSizeBinding { + return SheetShelfSizeBinding.inflate(inflater, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -59,8 +59,8 @@ class LibrarySizeBottomSheet : 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) } } diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/model/LibrarySectionModel.kt b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/model/ShelfSectionModel.kt similarity index 92% rename from app/src/main/java/org/koitharu/kotatsu/library/ui/model/LibrarySectionModel.kt rename to app/src/main/java/org/koitharu/kotatsu/shelf/ui/model/ShelfSectionModel.kt index 4b53017e1..e9df8971c 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/model/LibrarySectionModel.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shelf/ui/model/ShelfSectionModel.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.library.ui.model +package org.koitharu.kotatsu.shelf.ui.model import android.content.res.Resources 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.MangaItemModel -sealed class LibrarySectionModel( +sealed class ShelfSectionModel( val items: List, @StringRes val showAllButtonText: Int, ) : ListModel { @@ -20,7 +20,7 @@ sealed class LibrarySectionModel( items: List, val timeAgo: DateTimeAgo?, showAllButtonText: Int, - ) : LibrarySectionModel(items, showAllButtonText) { + ) : ShelfSectionModel(items, showAllButtonText) { override val key: Any get() = timeAgo?.javaClass ?: this::class.java @@ -58,7 +58,7 @@ sealed class LibrarySectionModel( items: List, val category: FavouriteCategory, showAllButtonText: Int, - ) : LibrarySectionModel(items, showAllButtonText) { + ) : ShelfSectionModel(items, showAllButtonText) { override val key: Any get() = category.id diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_shelf.xml similarity index 100% rename from app/src/main/res/layout/fragment_library.xml rename to app/src/main/res/layout/fragment_shelf.xml diff --git a/app/src/main/res/layout/sheet_library_size.xml b/app/src/main/res/layout/sheet_shelf_size.xml similarity index 100% rename from app/src/main/res/layout/sheet_library_size.xml rename to app/src/main/res/layout/sheet_shelf_size.xml diff --git a/app/src/main/res/menu/mode_library.xml b/app/src/main/res/menu/mode_shelf.xml similarity index 100% rename from app/src/main/res/menu/mode_library.xml rename to app/src/main/res/menu/mode_shelf.xml diff --git a/app/src/main/res/menu/nav_bottom.xml b/app/src/main/res/menu/nav_bottom.xml index bb892fb76..bf1aed02b 100644 --- a/app/src/main/res/menu/nav_bottom.xml +++ b/app/src/main/res/menu/nav_bottom.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/app/src/main/res/menu/opt_library.xml b/app/src/main/res/menu/opt_shelf.xml similarity index 100% rename from app/src/main/res/menu/opt_library.xml rename to app/src/main/res/menu/opt_shelf.xml