|
|
|
@ -2,9 +2,11 @@ package org.koitharu.kotatsu.favourites.ui.categories.select
|
|
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.Toast
|
|
|
|
import android.widget.Toast
|
|
|
|
|
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
|
|
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
|
|
|
import org.koin.core.parameter.parametersOf
|
|
|
|
import org.koin.core.parameter.parametersOf
|
|
|
|
@ -23,7 +25,8 @@ import org.koitharu.kotatsu.utils.ext.withArgs
|
|
|
|
class FavouriteCategoriesBottomSheet :
|
|
|
|
class FavouriteCategoriesBottomSheet :
|
|
|
|
BaseBottomSheet<DialogFavoriteCategoriesBinding>(),
|
|
|
|
BaseBottomSheet<DialogFavoriteCategoriesBinding>(),
|
|
|
|
OnListItemClickListener<MangaCategoryItem>,
|
|
|
|
OnListItemClickListener<MangaCategoryItem>,
|
|
|
|
View.OnClickListener {
|
|
|
|
View.OnClickListener,
|
|
|
|
|
|
|
|
Toolbar.OnMenuItemClickListener {
|
|
|
|
|
|
|
|
|
|
|
|
private val viewModel by viewModel<MangaCategoriesViewModel> {
|
|
|
|
private val viewModel by viewModel<MangaCategoriesViewModel> {
|
|
|
|
parametersOf(requireNotNull(arguments?.getParcelableArrayList<ParcelableManga>(KEY_MANGA_LIST)).map { it.manga })
|
|
|
|
parametersOf(requireNotNull(arguments?.getParcelableArrayList<ParcelableManga>(KEY_MANGA_LIST)).map { it.manga })
|
|
|
|
@ -41,7 +44,7 @@ class FavouriteCategoriesBottomSheet :
|
|
|
|
adapter = MangaCategoriesAdapter(this)
|
|
|
|
adapter = MangaCategoriesAdapter(this)
|
|
|
|
binding.recyclerViewCategories.adapter = adapter
|
|
|
|
binding.recyclerViewCategories.adapter = adapter
|
|
|
|
binding.buttonDone.setOnClickListener(this)
|
|
|
|
binding.buttonDone.setOnClickListener(this)
|
|
|
|
binding.itemCreate.setOnClickListener(this)
|
|
|
|
binding.toolbar.setOnMenuItemClickListener(this)
|
|
|
|
|
|
|
|
|
|
|
|
viewModel.content.observe(viewLifecycleOwner, this::onContentChanged)
|
|
|
|
viewModel.content.observe(viewLifecycleOwner, this::onContentChanged)
|
|
|
|
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
|
|
|
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
|
|
|
@ -54,11 +57,18 @@ class FavouriteCategoriesBottomSheet :
|
|
|
|
|
|
|
|
|
|
|
|
override fun onClick(v: View) {
|
|
|
|
override fun onClick(v: View) {
|
|
|
|
when (v.id) {
|
|
|
|
when (v.id) {
|
|
|
|
R.id.item_create -> startActivity(FavouritesCategoryEditActivity.newIntent(requireContext()))
|
|
|
|
|
|
|
|
R.id.button_done -> dismiss()
|
|
|
|
R.id.button_done -> dismiss()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
|
|
|
|
|
|
|
when (item.itemId) {
|
|
|
|
|
|
|
|
R.id.action_create -> startActivity(FavouritesCategoryEditActivity.newIntent(requireContext()))
|
|
|
|
|
|
|
|
else -> return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onItemClick(item: MangaCategoryItem, view: View) {
|
|
|
|
override fun onItemClick(item: MangaCategoryItem, view: View) {
|
|
|
|
viewModel.setChecked(item.id, !item.isChecked)
|
|
|
|
viewModel.setChecked(item.id, !item.isChecked)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -81,8 +91,8 @@ class FavouriteCategoriesBottomSheet :
|
|
|
|
fun show(fm: FragmentManager, manga: Collection<Manga>) = FavouriteCategoriesBottomSheet().withArgs(1) {
|
|
|
|
fun show(fm: FragmentManager, manga: Collection<Manga>) = FavouriteCategoriesBottomSheet().withArgs(1) {
|
|
|
|
putParcelableArrayList(
|
|
|
|
putParcelableArrayList(
|
|
|
|
KEY_MANGA_LIST,
|
|
|
|
KEY_MANGA_LIST,
|
|
|
|
manga.mapTo(ArrayList(manga.size)) { ParcelableManga(it, withChapters = false) }
|
|
|
|
manga.mapTo(ArrayList(manga.size)) { ParcelableManga(it, withChapters = false) },
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}.show(fm, TAG)
|
|
|
|
}.show(fm, TAG)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|