Rename Library to Shelf
This commit is contained in:
@@ -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.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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
) {
|
||||
|
||||
@@ -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<FragmentLibraryBinding>(),
|
||||
class ShelfFragment :
|
||||
BaseFragment<FragmentShelfBinding>(),
|
||||
RecyclerViewOwner,
|
||||
LibraryListEventListener {
|
||||
ShelfListEventListener {
|
||||
|
||||
@Inject
|
||||
lateinit var coil: ImageLoader
|
||||
@@ -45,15 +45,15 @@ class LibraryFragment :
|
||||
@Inject
|
||||
lateinit var settings: AppSettings
|
||||
|
||||
private val viewModel by viewModels<LibraryViewModel>()
|
||||
private var adapter: LibraryAdapter? = null
|
||||
private var selectionController: SectionedSelectionController<LibrarySectionModel>? = null
|
||||
private val viewModel by viewModels<ShelfViewModel>()
|
||||
private var adapter: ShelfAdapter? = null
|
||||
private var selectionController: SectionedSelectionController<ShelfSectionModel>? = 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()
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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<LibrarySectionModel> {
|
||||
private val viewModel: ShelfViewModel,
|
||||
) : SectionedSelectionController.Callback<ShelfSectionModel> {
|
||||
|
||||
private val context: Context
|
||||
get() = recyclerView.context
|
||||
|
||||
override fun onCreateActionMode(
|
||||
controller: SectionedSelectionController<LibrarySectionModel>,
|
||||
controller: SectionedSelectionController<ShelfSectionModel>,
|
||||
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<LibrarySectionModel>,
|
||||
controller: SectionedSelectionController<ShelfSectionModel>,
|
||||
mode: ActionMode,
|
||||
menu: Menu,
|
||||
): Boolean {
|
||||
@@ -47,7 +47,7 @@ class LibrarySelectionCallback(
|
||||
}
|
||||
|
||||
override fun onActionItemClicked(
|
||||
controller: SectionedSelectionController<LibrarySectionModel>,
|
||||
controller: SectionedSelectionController<ShelfSectionModel>,
|
||||
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<LibrarySectionModel>, count: Int) {
|
||||
override fun onSelectionChanged(controller: SectionedSelectionController<ShelfSectionModel>, count: Int) {
|
||||
recyclerView.invalidateNestedItemDecorations()
|
||||
}
|
||||
|
||||
override fun onCreateItemDecoration(
|
||||
controller: SectionedSelectionController<LibrarySectionModel>,
|
||||
section: LibrarySectionModel,
|
||||
controller: SectionedSelectionController<ShelfSectionModel>,
|
||||
section: ShelfSectionModel,
|
||||
): AbstractSelectionItemDecoration = MangaSelectionDecoration(context)
|
||||
|
||||
private fun collectSelectedItemsMap(
|
||||
controller: SectionedSelectionController<LibrarySectionModel>,
|
||||
): Map<LibrarySectionModel, Set<Manga>> {
|
||||
controller: SectionedSelectionController<ShelfSectionModel>,
|
||||
): Map<ShelfSectionModel, Set<Manga>> {
|
||||
val snapshot = controller.peekCheckedIds()
|
||||
if (snapshot.isEmpty()) {
|
||||
return emptyMap()
|
||||
@@ -100,7 +100,7 @@ class LibrarySelectionCallback(
|
||||
}
|
||||
|
||||
private fun collectSelectedItems(
|
||||
controller: SectionedSelectionController<LibrarySectionModel>,
|
||||
controller: SectionedSelectionController<ShelfSectionModel>,
|
||||
): Set<Manga> {
|
||||
val snapshot = controller.peekCheckedIds()
|
||||
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.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<Manga>(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<in LibrarySectionModel.History>,
|
||||
destination: MutableList<in ShelfSectionModel.History>,
|
||||
list: List<MangaWithHistory>,
|
||||
) {
|
||||
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<in LibrarySectionModel.Favourites>,
|
||||
destination: MutableList<in ShelfSectionModel.Favourites>,
|
||||
favourites: Map<FavouriteCategory, List<Manga>>,
|
||||
) {
|
||||
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,
|
||||
@@ -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<ListModel>() {
|
||||
else -> super.getChangePayload(oldItem, newItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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<LibrarySectionModel>,
|
||||
selectionController: SectionedSelectionController<ShelfSectionModel>,
|
||||
) : AsyncListDifferDelegationAdapter<ListModel>(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)
|
||||
}
|
||||
}
|
||||
@@ -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<LibrarySectionModel>,
|
||||
listener: LibraryListEventListener,
|
||||
) = adapterDelegateViewBinding<LibrarySectionModel, ListModel, ItemListGroupBinding>(
|
||||
selectionController: SectionedSelectionController<ShelfSectionModel>,
|
||||
listener: ShelfListEventListener,
|
||||
) = adapterDelegateViewBinding<ShelfSectionModel, ListModel, ItemListGroupBinding>(
|
||||
{ layoutInflater, parent -> ItemListGroupBinding.inflate(layoutInflater, parent, false) },
|
||||
) {
|
||||
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 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<FavouriteCategory>,
|
||||
) : AsyncListDifferDelegationAdapter<FavouriteCategory>(DiffCallback()) {
|
||||
|
||||
init {
|
||||
delegatesManager.addDelegate(libraryCategoryAD(listener))
|
||||
delegatesManager.addDelegate(shelfCategoryAD(listener))
|
||||
}
|
||||
|
||||
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.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<SheetBaseBinding>(),
|
||||
OnListItemClickListener<FavouriteCategory>,
|
||||
View.OnClickListener {
|
||||
|
||||
private val viewModel by viewModels<LibraryCategoriesConfigViewModel>()
|
||||
private val viewModel by viewModels<ShelfCategoriesConfigViewModel>()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<FavouriteCategory>,
|
||||
) = adapterDelegateViewBinding<FavouriteCategory, FavouriteCategory, ItemCategoryCheckableMultipleBinding>(
|
||||
{ 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.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<SheetLibrarySizeBinding>(),
|
||||
class ShelfSizeBottomSheet :
|
||||
BaseBottomSheet<SheetShelfSizeBinding>(),
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -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<MangaItemModel>,
|
||||
@StringRes val showAllButtonText: Int,
|
||||
) : ListModel {
|
||||
@@ -20,7 +20,7 @@ sealed class LibrarySectionModel(
|
||||
items: List<MangaItemModel>,
|
||||
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<MangaItemModel>,
|
||||
val category: FavouriteCategory,
|
||||
showAllButtonText: Int,
|
||||
) : LibrarySectionModel(items, showAllButtonText) {
|
||||
) : ShelfSectionModel(items, showAllButtonText) {
|
||||
|
||||
override val key: Any
|
||||
get() = category.id
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_library"
|
||||
android:id="@+id/nav_shelf"
|
||||
android:icon="@drawable/ic_bookshelf_selector"
|
||||
android:title="@string/manga_shelf" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user