diff --git a/BilingualReader/src/androidTest/java/br/com/fenix/bilingualreader/MainActivityTest.kt b/BilingualReader/src/androidTest/java/br/com/fenix/bilingualreader/MainActivityTest.kt index 25ab704e..22e30089 100644 --- a/BilingualReader/src/androidTest/java/br/com/fenix/bilingualreader/MainActivityTest.kt +++ b/BilingualReader/src/androidTest/java/br/com/fenix/bilingualreader/MainActivityTest.kt @@ -171,15 +171,15 @@ class MainActivityTest { waiter.await(animationTimer, TimeUnit.MILLISECONDS) - onView(withId(R.id.menu_manga_library_grid_type)).perform(click()) + onView(withId(R.id.menu_manga_library_type)).perform(click()) waiter.await(animationTimer, TimeUnit.MILLISECONDS) - onView(withId(R.id.menu_manga_library_grid_type)).perform(click()) + onView(withId(R.id.menu_manga_library_type)).perform(click()) waiter.await(animationTimer, TimeUnit.MILLISECONDS) - onView(withId(R.id.menu_manga_library_grid_type)).perform(click()) + onView(withId(R.id.menu_manga_library_type)).perform(click()) waiter.await(animationTimer, TimeUnit.MILLISECONDS) diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridCardAdapter.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridCardAdapter.kt index aab786a1..50858a46 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridCardAdapter.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridCardAdapter.kt @@ -6,18 +6,18 @@ import android.view.animation.AnimationUtils import androidx.recyclerview.widget.RecyclerView import br.com.fenix.bilingualreader.R import br.com.fenix.bilingualreader.model.entity.Manga +import br.com.fenix.bilingualreader.model.enums.LibraryMangaType import br.com.fenix.bilingualreader.service.listener.MangaCardListener -class MangaGridCardAdapter : RecyclerView.Adapter() { +class MangaGridCardAdapter(var type: LibraryMangaType) : RecyclerView.Adapter() { private lateinit var mListener: MangaCardListener private var mMangaList: MutableList = mutableListOf() var isAnimation: Boolean = true override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MangaGridViewHolder { - val item = - LayoutInflater.from(parent.context).inflate(R.layout.grid_card_manga, parent, false) - return MangaGridViewHolder(item, mListener) + val item = LayoutInflater.from(parent.context).inflate(R.layout.grid_card_manga, parent, false) + return MangaGridViewHolder(type, item, mListener) } override fun onBindViewHolder(holder: MangaGridViewHolder, position: Int) { diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridViewHolder.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridViewHolder.kt index 95e10302..68739618 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridViewHolder.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/adapter/library/MangaGridViewHolder.kt @@ -20,8 +20,7 @@ import br.com.fenix.bilingualreader.view.ui.library.manga.MangaLibraryFragment import com.google.android.material.card.MaterialCardView -class MangaGridViewHolder(itemView: View, private val listener: MangaCardListener) : - RecyclerView.ViewHolder(itemView) { +class MangaGridViewHolder(var type: LibraryMangaType, itemView: View, private val listener: MangaCardListener) : RecyclerView.ViewHolder(itemView) { companion object { var mIsLandscape: Boolean = false @@ -79,7 +78,7 @@ class MangaGridViewHolder(itemView: View, private val listener: MangaCardListene subtitle.visibility = if (manga.hasSubtitle) View.VISIBLE else View.GONE - when (MangaLibraryFragment.mGridType) { + when (type) { LibraryMangaType.GRID_MEDIUM -> if (mIsLandscape) cardView.layoutParams.width = mMangaCardWidthLandscapeMedium else cardView.layoutParams.width = mMangaCardWidthMedium LibraryMangaType.GRID_SMALL -> @@ -112,7 +111,7 @@ class MangaGridViewHolder(itemView: View, private val listener: MangaCardListene mangaImage.setImageBitmap(image) MangaImageCoverController.instance.setImageCoverAsync(itemView.context, manga, mangaImage) - val isSmall = manga.lastAccess != null && manga.bookMark > 0 && MangaLibraryFragment.mGridType != LibraryMangaType.GRID_BIG + val isSmall = manga.lastAccess != null && manga.bookMark > 0 && type != LibraryMangaType.GRID_BIG mangaTitle.text = manga.title mangaFileType.text = Util.getExtensionFromPath(manga.path).uppercase() diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryFragment.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryFragment.kt index 87af91a1..9f87dc65 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryFragment.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryFragment.kt @@ -54,13 +54,11 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.viewpager.widget.ViewPager import br.com.fenix.bilingualreader.R import br.com.fenix.bilingualreader.model.entity.Book -import br.com.fenix.bilingualreader.model.enums.FileType import br.com.fenix.bilingualreader.model.enums.Libraries import br.com.fenix.bilingualreader.model.enums.LibraryBookType import br.com.fenix.bilingualreader.model.enums.ListMode import br.com.fenix.bilingualreader.model.enums.Order import br.com.fenix.bilingualreader.model.enums.ShareMarkType -import br.com.fenix.bilingualreader.model.enums.Type import br.com.fenix.bilingualreader.service.listener.BookCardListener import br.com.fenix.bilingualreader.service.listener.MainListener import br.com.fenix.bilingualreader.service.repository.Storage @@ -106,11 +104,12 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O private lateinit var mListener: BookCardListener private lateinit var mScrollUp: FloatingActionButton private lateinit var mScrollDown: FloatingActionButton - private lateinit var mMenuPopupFilterOrder: FrameLayout - private lateinit var mPopupFilterOrderView: ViewPager - private lateinit var mPopupFilterOrderTab: TabLayout + private lateinit var mMenuPopupLibrary: FrameLayout + private lateinit var mPopupLibraryView: ViewPager + private lateinit var mPopupLibraryTab: TabLayout private lateinit var mPopupFilterFragment: LibraryBookPopupFilter private lateinit var mPopupOrderFragment: LibraryBookPopupOrder + private lateinit var mPopupTypeFragment: LibraryBookPopupType private lateinit var mBottomSheet: BottomSheetBehavior private lateinit var mPopupTag: PopupTags @@ -120,7 +119,6 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O private val mDismissDownButton = Runnable { mScrollDown.hide() } companion object { - var mGridType: LibraryBookType = LibraryBookType.GRID var mSortType: Order = Order.Name var mSortDesc: Boolean = false } @@ -146,7 +144,7 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O inflater.inflate(R.menu.menu_library_book, menu) super.onCreateOptionsMenu(menu, inflater) - miGridType = menu.findItem(R.id.menu_book_library_grid_type) + miGridType = menu.findItem(R.id.menu_book_library_type) miGridOrder = menu.findItem(R.id.menu_book_library_list_order) miSearch = menu.findItem(R.id.menu_book_library_search) @@ -260,12 +258,7 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O enableSearchView(searchView, !mRefreshLayout.isRefreshing) - MenuUtil.longClick(requireActivity(), R.id.menu_book_library_list_order) { - if (!mRefreshLayout.isRefreshing) - onOpenMenuSort() - } - - val iconGrid: Int = when (mGridType) { + val iconGrid: Int = when (mViewModel.libraryType.value) { LibraryBookType.GRID -> R.drawable.ic_type_grid_big else -> R.drawable.ic_type_list } @@ -280,14 +273,16 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O } miGridOrder.setIcon(iconSort) - MenuUtil.longClick(requireActivity(), R.id.menu_manga_library_list_order) { - if (!mRefreshLayout.isRefreshing) - onOpenMenuSort() + MenuUtil.longClick(requireActivity(), R.id.menu_book_library_list_order) { + if (!mRefreshLayout.isRefreshing) { + onOpenMenuLibrary() + } } - miGridOrder.setOnMenuItemClickListener { - onChangeSort() - true + MenuUtil.longClick(requireActivity(), R.id.menu_book_library_type) { + if (!mRefreshLayout.isRefreshing) { + onOpenMenuLibrary() + } } mViewModel.order.observe(viewLifecycleOwner) { @@ -398,15 +393,15 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O override fun onOptionsItemSelected(menuItem: MenuItem): Boolean { when (menuItem.itemId) { - R.id.menu_book_library_grid_type -> onChangeLayout() + R.id.menu_book_library_type -> mViewModel.changeLibraryType() R.id.menu_book_library_list_order -> onChangeSort() } return super.onOptionsItemSelected(menuItem) } - private fun onOpenMenuSort() { + private fun onOpenMenuLibrary() { mBottomSheet.state = BottomSheetBehavior.STATE_EXPANDED - AnimationUtil.animatePopupOpen(requireActivity(), mMenuPopupFilterOrder) + AnimationUtil.animatePopupOpen(requireActivity(), mMenuPopupLibrary) } private fun onChangeSort() { @@ -499,25 +494,23 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O notifyDataSet(0, range) } - private fun onChangeLayout() { - mGridType = when (mGridType) { - LibraryBookType.LINE -> LibraryBookType.GRID - else -> LibraryBookType.LINE - } - + private fun onChangeLayout(type: LibraryBookType) { val sharedPreferences = GeneralConsts.getSharedPreferences(requireContext()) with(sharedPreferences.edit()) { - this!!.putString(GeneralConsts.KEYS.LIBRARY.BOOK_LIBRARY_TYPE, mGridType.toString()) + this!!.putString(GeneralConsts.KEYS.LIBRARY.BOOK_LIBRARY_TYPE, type.toString()) this.commit() } - onChangeIconLayout() - generateLayout() - updateList(mViewModel.listBook.value!!) + onChangeIconLayout(type) + generateLayout(type) + updateList(type, mViewModel.listBook.value!!) } - private fun onChangeIconLayout() { - val icon: Int = when (mGridType) { + private fun onChangeIconLayout(type: LibraryBookType) { + if (!::miGridType.isInitialized) + return + + val icon: Int = when (type) { LibraryBookType.GRID -> R.drawable.ico_animated_type_grid_list_to_gridbig else -> R.drawable.ico_animated_type_grid_gridbig_to_list } @@ -532,10 +525,6 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O ): View? { val root = inflater.inflate(R.layout.fragment_book_library, container, false) val sharedPreferences = GeneralConsts.getSharedPreferences(requireContext()) - mGridType = LibraryBookType.valueOf( - sharedPreferences.getString(GeneralConsts.KEYS.LIBRARY.BOOK_LIBRARY_TYPE, LibraryBookType.GRID.toString()) - .toString() - ) mMapOrder = hashMapOf( Order.Name to getString(R.string.config_option_book_order_name), @@ -552,13 +541,13 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O mScrollUp = root.findViewById(R.id.book_library_scroll_up) mScrollDown = root.findViewById(R.id.book_library_scroll_down) - mMenuPopupFilterOrder = root.findViewById(R.id.book_library_popup_menu_order_filter) - mPopupFilterOrderTab = root.findViewById(R.id.book_library_popup_order_filter_tab) - mPopupFilterOrderView = root.findViewById(R.id.book_library_popup_order_filter_view_pager) + mMenuPopupLibrary = root.findViewById(R.id.book_library_popup_menu_library) + mPopupLibraryTab = root.findViewById(R.id.book_library_popup_library_tab) + mPopupLibraryView = root.findViewById(R.id.book_library_popup_library_view_pager) - root.findViewById(R.id.book_library_popup_menu_order_filter_close) + root.findViewById(R.id.book_library_popup_menu_library_close) .setOnClickListener { - AnimationUtil.animatePopupClose(requireActivity(), mMenuPopupFilterOrder) + AnimationUtil.animatePopupClose(requireActivity(), mMenuPopupLibrary) } ComponentsUtil.setThemeColor(requireContext(), mRefreshLayout) @@ -584,12 +573,13 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O mRecyclerView.smoothScrollToPosition((mRecyclerView.adapter as RecyclerView.Adapter).itemCount) } - mPopupFilterOrderTab.setupWithViewPager(mPopupFilterOrderView) + mPopupLibraryTab.setupWithViewPager(mPopupLibraryView) mPopupFilterFragment = LibraryBookPopupFilter() mPopupOrderFragment = LibraryBookPopupOrder(this) + mPopupTypeFragment = LibraryBookPopupType() - BottomSheetBehavior.from(mMenuPopupFilterOrder).apply { + BottomSheetBehavior.from(mMenuPopupLibrary).apply { peekHeight = 195 this.state = BottomSheetBehavior.STATE_COLLAPSED mBottomSheet = this @@ -613,8 +603,12 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O mPopupOrderFragment, resources.getString(R.string.popup_library_book_tab_item_ordering) ) + viewFilterOrderPagerAdapter.addFragment( + mPopupTypeFragment, + resources.getString(R.string.popup_library_book_tab_item_type) + ) - mPopupFilterOrderView.adapter = viewFilterOrderPagerAdapter + mPopupLibraryView.adapter = viewFilterOrderPagerAdapter mRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { @@ -744,7 +738,7 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O if (!Storage.isPermissionGranted(requireContext())) Storage.takePermission(requireContext(), requireActivity()) - generateLayout() + generateLayout(mViewModel.libraryType.value!!) setIsRefreshing(true) ScannerBook.getInstance(requireContext()).scanLibrary(mViewModel.getLibrary()) @@ -783,22 +777,22 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O bundle.putSerializable(GeneralConsts.KEYS.OBJECT.BOOK, book) intent.putExtras(bundle) - val idText = if (mGridType != LibraryBookType.LINE) + val idText = if (mViewModel.libraryType.value != LibraryBookType.LINE) R.id.book_grid_title else R.id.book_line_title - val idAuthor = if (mGridType != LibraryBookType.LINE) + val idAuthor = if (mViewModel.libraryType.value != LibraryBookType.LINE) R.id.book_grid_sub_title else R.id.book_line_sub_title - val idProgress = if (mGridType != LibraryBookType.LINE) + val idProgress = if (mViewModel.libraryType.value != LibraryBookType.LINE) R.id.book_grid_progress else R.id.book_line_progress - val idCover = if (mGridType != LibraryBookType.LINE) + val idCover = if (mViewModel.libraryType.value != LibraryBookType.LINE) R.id.book_grid_image_cover else R.id.book_line_image_cover @@ -829,13 +823,13 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O ).toString() ) - mGridType = LibraryBookType.valueOf( + val type = LibraryBookType.valueOf( sharedPreferences.getString( GeneralConsts.KEYS.LIBRARY.BOOK_LIBRARY_TYPE, LibraryBookType.LINE.toString() ).toString() ) - + mViewModel.setLibraryType(type) mViewModel.sorted(mSortType) } @@ -850,12 +844,12 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O refresh() } - private fun generateLayout() { - if (mGridType != LibraryBookType.LINE) { + private fun generateLayout(type: LibraryBookType) { + if (type != LibraryBookType.LINE) { val gridAdapter = BookGridCardAdapter() mRecyclerView.adapter = gridAdapter - val columnWidth: Int = when (mGridType) { + val columnWidth: Int = when (type) { LibraryBookType.GRID -> resources.getDimension(R.dimen.book_grid_card_layout_width) .toInt() @@ -876,21 +870,21 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O } private fun setAnimationRecycler(isAnimate: Boolean) { - if (mGridType != LibraryBookType.LINE) + if (mViewModel.libraryType.value != LibraryBookType.LINE) (mRecyclerView.adapter as BookGridCardAdapter).isAnimation = isAnimate else (mRecyclerView.adapter as BookLineCardAdapter).isAnimation = isAnimate } private fun removeList(book: Book) { - if (mGridType != LibraryBookType.LINE) + if (mViewModel.libraryType.value != LibraryBookType.LINE) (mRecyclerView.adapter as BookGridCardAdapter).removeList(book) else (mRecyclerView.adapter as BookLineCardAdapter).removeList(book) } - private fun updateList(list: MutableList) { - if (mGridType != LibraryBookType.LINE) + private fun updateList(type : LibraryBookType, list: MutableList) { + if (type != LibraryBookType.LINE) (mRecyclerView.adapter as BookGridCardAdapter).updateList(list) else (mRecyclerView.adapter as BookLineCardAdapter).updateList(list) @@ -898,7 +892,10 @@ class BookLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout.O private fun observer() { mViewModel.listBook.observe(viewLifecycleOwner) { - updateList(it) + updateList(mViewModel.libraryType.value!!, it) + } + mViewModel.libraryType.observe(viewLifecycleOwner) { + onChangeLayout(it) } } diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryViewModel.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryViewModel.kt index 30556929..6257dc80 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryViewModel.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/BookLibraryViewModel.kt @@ -10,9 +10,9 @@ import androidx.lifecycle.MutableLiveData import br.com.fenix.bilingualreader.R import br.com.fenix.bilingualreader.model.entity.Book import br.com.fenix.bilingualreader.model.entity.Library -import br.com.fenix.bilingualreader.model.entity.Manga import br.com.fenix.bilingualreader.model.entity.Tags import br.com.fenix.bilingualreader.model.enums.FileType +import br.com.fenix.bilingualreader.model.enums.LibraryBookType import br.com.fenix.bilingualreader.model.enums.ListMode import br.com.fenix.bilingualreader.model.enums.Order import br.com.fenix.bilingualreader.model.enums.ShareMarkType @@ -49,6 +49,9 @@ class BookLibraryViewModel(var app: Application) : AndroidViewModel(app), Filter private var mTypeFilter = MutableLiveData(FilterType.None) val typeFilter: LiveData = mTypeFilter + private var mLibraryType = MutableLiveData(LibraryBookType.GRID) + val libraryType: LiveData = mLibraryType + private var mListBookFull = MutableLiveData>(mutableListOf()) private var mListBook = MutableLiveData>(mutableListOf()) val listBook: LiveData> = mListBook @@ -270,6 +273,18 @@ class BookLibraryViewModel(var app: Application) : AndroidViewModel(app), Filter return mTags } + fun changeLibraryType() { + val type = when (mLibraryType.value) { + LibraryBookType.LINE -> LibraryBookType.GRID + else -> LibraryBookType.LINE + } + setLibraryType(type) + } + + fun setLibraryType(type: LibraryBookType) { + mLibraryType.value = type + } + fun isEmpty(): Boolean = mListBook.value == null || mListBook.value!!.isEmpty() fun sorted() { @@ -326,13 +341,15 @@ class BookLibraryViewModel(var app: Application) : AndroidViewModel(app), Filter if (list.isNullOrEmpty()) return + val process = list.stream().toList() + CoroutineScope(newSingleThreadContext("SuggestionThread")).launch { async { val authors = mutableSetOf() val publishers = mutableSetOf() val tags = mutableSetOf() - list.forEach { + process.forEach { authors.add(it.author) publishers.add(it.publisher) } diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupFilter.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupFilter.kt index c306c731..eae510a0 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupFilter.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupFilter.kt @@ -61,24 +61,19 @@ class LibraryBookPopupFilter : Fragment() { mFilterFavorite.setOnCheckedChangeListener { _, isChecked -> removeListener(list) - if (isChecked) { - mFilterReading.isChecked = false + if (isChecked) mViewModel.filterType(Filter.Favorite) - } else + else mViewModel.filterType(Filter.None) - addListener() } mFilterReading.setOnCheckedChangeListener { _, isChecked -> removeListener(list) - mViewModel.filterType(Filter.Reading) - if (isChecked) { - mFilterFavorite.isChecked = false + if (isChecked) mViewModel.filterType(Filter.Reading) - } else + else mViewModel.filterType(Filter.None) - addListener() } } diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupOrder.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupOrder.kt index 34a3ece3..1f931a35 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupOrder.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupOrder.kt @@ -85,10 +85,6 @@ class LibraryBookPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderName.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderName) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderName.state = getNextState(mOrderName) when (mOrderName.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Name, true) @@ -107,10 +103,6 @@ class LibraryBookPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderDate.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderDate) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderDate.state = getNextState(mOrderDate) when (mOrderDate.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Date, true) @@ -129,10 +121,6 @@ class LibraryBookPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderAccess.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderAccess) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderAccess.state = getNextState(mOrderAccess) when (mOrderAccess.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.LastAccess, true) @@ -151,10 +139,6 @@ class LibraryBookPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderFavorite.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderFavorite) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderFavorite.state = getNextState(mOrderFavorite) when (mOrderFavorite.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Favorite, true) @@ -173,10 +157,6 @@ class LibraryBookPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderGenre.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderGenre) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderGenre.state = getNextState(mOrderGenre) when (mOrderGenre.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Genre, true) @@ -195,10 +175,6 @@ class LibraryBookPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderAuthor.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderAuthor) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderAuthor.state = getNextState(mOrderAuthor) when (mOrderAuthor.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Author, true) diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupType.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupType.kt new file mode 100644 index 00000000..f51d8182 --- /dev/null +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/book/LibraryBookPopupType.kt @@ -0,0 +1,98 @@ +package br.com.fenix.bilingualreader.view.ui.library.book + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.CheckBox +import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider +import br.com.fenix.bilingualreader.R +import br.com.fenix.bilingualreader.model.enums.LibraryBookType +import org.slf4j.LoggerFactory + +class LibraryBookPopupType : Fragment() { + + private val mLOGGER = LoggerFactory.getLogger(LibraryBookPopupType::class.java) + + private lateinit var mViewModel: BookLibraryViewModel + + private lateinit var mTypeGrid: CheckBox + private lateinit var mTypeLine: CheckBox + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mViewModel = ViewModelProvider(requireActivity()).get(BookLibraryViewModel::class.java) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val root = inflater.inflate(R.layout.popup_library_type_book, container, false) + + mTypeGrid = root.findViewById(R.id.popup_library_book_type_grid) + mTypeLine = root.findViewById(R.id.popup_library_book_type_line) + + setChecked(getCheckList(), mViewModel.libraryType.value ?: LibraryBookType.GRID) + observer() + addListener() + + return root + } + + private fun setChecked(checkboxes: ArrayList, type: LibraryBookType) { + for (check in checkboxes) + check.isChecked = false + + when (type) { + LibraryBookType.GRID -> mTypeGrid.isChecked = true + LibraryBookType.LINE -> mTypeLine.isChecked = true + else -> {} + } + } + + private fun getCheckList() = arrayListOf(mTypeGrid, mTypeLine) + + private fun addListener() { + val list = getCheckList() + + mTypeGrid.setOnCheckedChangeListener { _, isChecked -> + removeListener(list) + if (isChecked) { + mTypeLine.isChecked = false + mViewModel.setLibraryType(LibraryBookType.GRID) + } else { + mTypeLine.isChecked = true + mViewModel.setLibraryType(LibraryBookType.LINE) + } + + addListener() + } + + mTypeLine.setOnCheckedChangeListener { _, isChecked -> + removeListener(list) + if (isChecked) + mViewModel.setLibraryType(LibraryBookType.LINE) + else + mViewModel.setLibraryType(LibraryBookType.GRID) + + addListener() + } + } + + private fun removeListener(checkboxes : ArrayList) { + for (check in checkboxes) + check.setOnCheckedChangeListener(null) + } + + private fun observer() { + mViewModel.libraryType.observe(viewLifecycleOwner) { + removeListener(getCheckList()) + setChecked(getCheckList(), it) + addListener() + } + } + +} \ No newline at end of file diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupFilter.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupFilter.kt index c22065c1..8485e5f2 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupFilter.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupFilter.kt @@ -60,24 +60,19 @@ class LibraryMangaPopupFilter : Fragment() { mFilterFavorite.setOnCheckedChangeListener { _, isChecked -> removeListener(list) - if (isChecked) { - mFilterReading.isChecked = false + if (isChecked) mViewModel.filterType(Filter.Favorite) - } else + else mViewModel.filterType(Filter.None) - addListener() } mFilterReading.setOnCheckedChangeListener { _, isChecked -> removeListener(list) - mViewModel.filterType(Filter.Reading) - if (isChecked) { - mFilterFavorite.isChecked = false + if (isChecked) mViewModel.filterType(Filter.Reading) - } else + else mViewModel.filterType(Filter.None) - addListener() } } diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupOrder.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupOrder.kt index b3a1ed4d..43b4577d 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupOrder.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupOrder.kt @@ -77,10 +77,6 @@ class LibraryMangaPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderName.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderName) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderName.state = getNextState(mOrderName) when (mOrderName.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Name, true) @@ -99,10 +95,6 @@ class LibraryMangaPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderDate.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderDate) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderDate.state = getNextState(mOrderDate) when (mOrderDate.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Date, true) @@ -121,10 +113,6 @@ class LibraryMangaPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderAccess.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderAccess) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderAccess.state = getNextState(mOrderAccess) when (mOrderAccess.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.LastAccess, true) @@ -143,10 +131,6 @@ class LibraryMangaPopupOrder(var listener: PopupOrderListener) : Fragment() { mOrderFavorite.setOnCheckedChangeListener { _, _ -> removeListener(listCheck) - for (check in listCheck) - if (check != mOrderFavorite) - check.state = TriStateCheckBox.STATE_UNCHECKED - mOrderFavorite.state = getNextState(mOrderFavorite) when (mOrderFavorite.state) { TriStateCheckBox.STATE_INDETERMINATE -> listener.popupSorted(Order.Favorite, true) diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupType.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupType.kt new file mode 100644 index 00000000..8769964f --- /dev/null +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/LibraryMangaPopupType.kt @@ -0,0 +1,122 @@ +package br.com.fenix.bilingualreader.view.ui.library.manga + +import android.content.res.Configuration +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.CheckBox +import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider +import br.com.fenix.bilingualreader.R +import br.com.fenix.bilingualreader.model.enums.Filter +import br.com.fenix.bilingualreader.model.enums.LibraryMangaType +import br.com.fenix.bilingualreader.view.components.TriStateCheckBox +import org.slf4j.LoggerFactory + +class LibraryMangaPopupType : Fragment() { + + private val mLOGGER = LoggerFactory.getLogger(LibraryMangaPopupType::class.java) + + private lateinit var mViewModel: MangaLibraryViewModel + + private lateinit var mTypeGridBig: CheckBox + private lateinit var mTypeGridMedium: CheckBox + private lateinit var mTypeGridSmall: CheckBox + private lateinit var mTypeLine: CheckBox + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mViewModel = ViewModelProvider(requireActivity()).get(MangaLibraryViewModel::class.java) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val root = inflater.inflate(R.layout.popup_library_type_manga, container, false) + + mTypeGridBig = root.findViewById(R.id.popup_library_manga_type_grid_big) + mTypeGridMedium = root.findViewById(R.id.popup_library_manga_type_grid_medium) + mTypeGridSmall = root.findViewById(R.id.popup_library_manga_type_grid_small) + mTypeLine = root.findViewById(R.id.popup_library_manga_type_line) + + mTypeGridSmall.visibility = if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) View.VISIBLE else View.GONE + + setChecked(getCheckList(), mViewModel.libraryType.value ?: LibraryMangaType.GRID_BIG) + observer() + addListener() + + return root + } + + private fun setChecked(checkboxes: ArrayList, type: LibraryMangaType) { + for (check in checkboxes) + check.isChecked = false + + when (type) { + LibraryMangaType.GRID_BIG -> mTypeGridBig.isChecked = true + LibraryMangaType.GRID_MEDIUM -> mTypeGridMedium.isChecked = true + LibraryMangaType.GRID_SMALL -> mTypeGridSmall.isChecked = true + LibraryMangaType.LINE -> mTypeLine.isChecked = true + else -> {} + } + } + + private fun getCheckList() = arrayListOf(mTypeGridBig, mTypeGridMedium, mTypeGridSmall, mTypeLine) + + private fun addListener() { + val list = getCheckList() + + mTypeGridBig.setOnCheckedChangeListener { _, isChecked -> + removeListener(list) + if (isChecked) + mViewModel.setLibraryType(LibraryMangaType.GRID_BIG) + else + mViewModel.setLibraryType(LibraryMangaType.LINE) + addListener() + } + + mTypeGridMedium.setOnCheckedChangeListener { _, isChecked -> + removeListener(list) + if (isChecked) + mViewModel.setLibraryType(LibraryMangaType.GRID_MEDIUM) + else + mViewModel.setLibraryType(LibraryMangaType.GRID_BIG) + addListener() + } + + mTypeGridSmall.setOnCheckedChangeListener { _, isChecked -> + removeListener(list) + if (isChecked) + mViewModel.setLibraryType(LibraryMangaType.GRID_SMALL) + else + mViewModel.setLibraryType(LibraryMangaType.GRID_BIG) + addListener() + } + + mTypeLine.setOnCheckedChangeListener { _, isChecked -> + removeListener(list) + if (isChecked) + mViewModel.setLibraryType(LibraryMangaType.LINE) + else + mViewModel.setLibraryType(LibraryMangaType.GRID_BIG) + addListener() + } + } + + private fun removeListener(checkboxes : ArrayList) { + for (check in checkboxes) + check.setOnCheckedChangeListener(null) + } + + private fun observer() { + mViewModel.libraryType.observe(viewLifecycleOwner) { + removeListener(getCheckList()) + setChecked(getCheckList(), it) + addListener() + } + } + +} \ No newline at end of file diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryFragment.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryFragment.kt index 6619f003..b2c4c62e 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryFragment.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryFragment.kt @@ -53,13 +53,11 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.viewpager.widget.ViewPager import br.com.fenix.bilingualreader.R import br.com.fenix.bilingualreader.model.entity.Manga -import br.com.fenix.bilingualreader.model.enums.FileType import br.com.fenix.bilingualreader.model.enums.Libraries import br.com.fenix.bilingualreader.model.enums.LibraryMangaType import br.com.fenix.bilingualreader.model.enums.ListMode import br.com.fenix.bilingualreader.model.enums.Order import br.com.fenix.bilingualreader.model.enums.ShareMarkType -import br.com.fenix.bilingualreader.model.enums.Type import br.com.fenix.bilingualreader.service.listener.MainListener import br.com.fenix.bilingualreader.service.listener.MangaCardListener import br.com.fenix.bilingualreader.service.repository.Storage @@ -103,11 +101,12 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. private lateinit var mListener: MangaCardListener private lateinit var mScrollUp: FloatingActionButton private lateinit var mScrollDown: FloatingActionButton - private lateinit var mMenuPopupFilterOrder: FrameLayout - private lateinit var mPopupFilterOrderView: ViewPager - private lateinit var mPopupFilterOrderTab: TabLayout + private lateinit var mMenuPopupLibrary: FrameLayout + private lateinit var mPopupLibraryView: ViewPager + private lateinit var mPopupLibraryTab: TabLayout private lateinit var mPopupFilterFragment: LibraryMangaPopupFilter private lateinit var mPopupOrderFragment: LibraryMangaPopupOrder + private lateinit var mPopupTypeFragment: LibraryMangaPopupType private lateinit var mBottomSheet: BottomSheetBehavior private lateinit var mMapOrder: HashMap @@ -116,7 +115,6 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. private val mDismissDownButton = Runnable { mScrollDown.hide() } companion object { - var mGridType: LibraryMangaType = LibraryMangaType.GRID_BIG var mSortType: Order = Order.Name var mSortDesc: Boolean = false } @@ -142,7 +140,7 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. inflater.inflate(R.menu.menu_library_manga, menu) super.onCreateOptionsMenu(menu, inflater) - miGridType = menu.findItem(R.id.menu_manga_library_grid_type) + miGridType = menu.findItem(R.id.menu_manga_library_type) miGridOrder = menu.findItem(R.id.menu_manga_library_list_order) miSearch = menu.findItem(R.id.menu_manga_library_search) @@ -237,7 +235,7 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. }) enableSearchView(searchView, !mRefreshLayout.isRefreshing) - val iconGrid: Int = when (mGridType) { + val iconGrid: Int = when (mViewModel.libraryType.value) { LibraryMangaType.GRID_SMALL -> R.drawable.ic_type_grid_small LibraryMangaType.GRID_BIG -> R.drawable.ic_type_grid_big LibraryMangaType.GRID_MEDIUM -> R.drawable.ic_type_grid_medium @@ -254,13 +252,17 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. miGridOrder.setIcon(iconSort) MenuUtil.longClick(requireActivity(), R.id.menu_manga_library_list_order) { - if (!mRefreshLayout.isRefreshing) - onOpenMenuSort() + if (!mRefreshLayout.isRefreshing) { + mPopupLibraryTab.selectTab(mPopupLibraryTab.getTabAt(1)) + onOpenMenuLibrary() + } } - miGridOrder.setOnMenuItemClickListener { - onChangeSort() - true + MenuUtil.longClick(requireActivity(), R.id.menu_manga_library_type) { + if (!mRefreshLayout.isRefreshing) { + mPopupLibraryTab.selectTab(mPopupLibraryTab.getTabAt(0)) + onOpenMenuLibrary() + } } mViewModel.order.observe(viewLifecycleOwner) { @@ -378,15 +380,15 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. override fun onOptionsItemSelected(menuItem: MenuItem): Boolean { when (menuItem.itemId) { - R.id.menu_manga_library_grid_type -> onChangeLayout() + R.id.menu_manga_library_type -> mViewModel.changeLibraryType() R.id.menu_manga_library_list_order -> onChangeSort() } return super.onOptionsItemSelected(menuItem) } - private fun onOpenMenuSort() { + private fun onOpenMenuLibrary() { mBottomSheet.state = BottomSheetBehavior.STATE_EXPANDED - AnimationUtil.animatePopupOpen(requireActivity(), mMenuPopupFilterOrder) + AnimationUtil.animatePopupOpen(requireActivity(), mMenuPopupLibrary) } private fun onChangeSort() { @@ -470,29 +472,23 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. notifyDataSet(0, range) } - private fun onChangeLayout() { - val isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE - - mGridType = when (mGridType) { - LibraryMangaType.LINE -> LibraryMangaType.GRID_BIG - LibraryMangaType.GRID_BIG -> LibraryMangaType.GRID_MEDIUM - LibraryMangaType.GRID_MEDIUM -> if (isLandscape) LibraryMangaType.GRID_SMALL else LibraryMangaType.LINE - else -> LibraryMangaType.LINE - } - + private fun onChangeLayout(type: LibraryMangaType) { val sharedPreferences = GeneralConsts.getSharedPreferences(requireContext()) with(sharedPreferences.edit()) { - this!!.putString(GeneralConsts.KEYS.LIBRARY.MANGA_LIBRARY_TYPE, mGridType.toString()) + this!!.putString(GeneralConsts.KEYS.LIBRARY.MANGA_LIBRARY_TYPE, type.toString()) this.commit() } - onChangeIconLayout() - generateLayout() - updateList(mViewModel.listMangas.value!!) + onChangeIconLayout(type) + generateLayout(type) + updateList(type, mViewModel.listMangas.value!!) } - private fun onChangeIconLayout() { - val icon: Int = when (mGridType) { + private fun onChangeIconLayout(type: LibraryMangaType) { + if (!::miGridType.isInitialized) + return + + val icon: Int = when (type) { LibraryMangaType.GRID_SMALL -> R.drawable.ico_animated_type_grid_gridmedium_to_gridsmall LibraryMangaType.GRID_BIG -> R.drawable.ico_animated_type_grid_list_to_gridbig LibraryMangaType.GRID_MEDIUM -> R.drawable.ico_animated_type_grid_gridbig_to_gridmedium @@ -525,13 +521,13 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. mScrollUp = root.findViewById(R.id.manga_library_scroll_up) mScrollDown = root.findViewById(R.id.manga_library_scroll_down) - mMenuPopupFilterOrder = root.findViewById(R.id.manga_library_popup_menu_order_filter) - mPopupFilterOrderTab = root.findViewById(R.id.manga_library_popup_order_filter_tab) - mPopupFilterOrderView = root.findViewById(R.id.manga_library_popup_order_filter_view_pager) + mMenuPopupLibrary = root.findViewById(R.id.manga_library_popup_menu_library) + mPopupLibraryTab = root.findViewById(R.id.manga_library_popup_library_tab) + mPopupLibraryView = root.findViewById(R.id.manga_library_popup_library_view_pager) - root.findViewById(R.id.manga_library_popup_menu_order_filter_close) + root.findViewById(R.id.manga_library_popup_menu_library_close) .setOnClickListener { - AnimationUtil.animatePopupClose(requireActivity(), mMenuPopupFilterOrder) + AnimationUtil.animatePopupClose(requireActivity(), mMenuPopupLibrary) } ComponentsUtil.setThemeColor(requireContext(), mRefreshLayout) @@ -557,12 +553,13 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. mRecyclerView.smoothScrollToPosition((mRecyclerView.adapter as RecyclerView.Adapter).itemCount) } - mPopupFilterOrderTab.setupWithViewPager(mPopupFilterOrderView) + mPopupLibraryTab.setupWithViewPager(mPopupLibraryView) mPopupFilterFragment = LibraryMangaPopupFilter() mPopupOrderFragment = LibraryMangaPopupOrder(this) + mPopupTypeFragment = LibraryMangaPopupType() - BottomSheetBehavior.from(mMenuPopupFilterOrder).apply { + BottomSheetBehavior.from(mMenuPopupLibrary).apply { peekHeight = 195 this.state = BottomSheetBehavior.STATE_COLLAPSED mBottomSheet = this @@ -586,8 +583,12 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. mPopupOrderFragment, resources.getString(R.string.popup_library_manga_tab_item_ordering) ) + viewFilterOrderPagerAdapter.addFragment( + mPopupTypeFragment, + resources.getString(R.string.popup_library_manga_tab_item_type) + ) - mPopupFilterOrderView.adapter = viewFilterOrderPagerAdapter + mPopupLibraryView.adapter = viewFilterOrderPagerAdapter mRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { @@ -691,7 +692,7 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. if (!Storage.isPermissionGranted(requireContext())) Storage.takePermission(requireContext(), requireActivity()) - generateLayout() + generateLayout(mViewModel.libraryType.value!!) setIsRefreshing(true) ScannerManga.getInstance(requireContext()).scanLibrary(mViewModel.getLibrary()) @@ -730,17 +731,17 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. bundle.putSerializable(GeneralConsts.KEYS.OBJECT.LIBRARY, mViewModel.getLibrary()) bundle.putSerializable(GeneralConsts.KEYS.OBJECT.MANGA, manga) intent.putExtras(bundle) - val idText = if (mGridType != LibraryMangaType.LINE) + val idText = if (mViewModel.libraryType.value != LibraryMangaType.LINE) R.id.manga_grid_text_title else R.id.manga_line_text_title - val idProgress = if (mGridType != LibraryMangaType.LINE) + val idProgress = if (mViewModel.libraryType.value != LibraryMangaType.LINE) R.id.manga_grid_progress else R.id.manga_line_progress - val idCover = if (mGridType != LibraryMangaType.LINE) + val idCover = if (mViewModel.libraryType.value != LibraryMangaType.LINE) R.id.manga_grid_image_cover else R.id.manga_line_image_cover @@ -781,7 +782,7 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. ).toString() ) - mGridType = LibraryMangaType.valueOf( + val type = LibraryMangaType.valueOf( sharedPreferences.getString( GeneralConsts.KEYS.LIBRARY.MANGA_LIBRARY_TYPE, LibraryMangaType.LINE.toString() @@ -789,6 +790,7 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. .toString() ) + mViewModel.setLibraryType(type) mViewModel.sorted(mSortType) } @@ -805,7 +807,7 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. private fun getGridLayout(): GridLayoutManager { val isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE - val columnWidth: Int = when (mGridType) { + val columnWidth: Int = when (mViewModel.libraryType.value) { LibraryMangaType.GRID_BIG -> resources.getDimension(R.dimen.manga_grid_card_layout_width) .toInt() LibraryMangaType.GRID_MEDIUM -> if (isLandscape) resources.getDimension(R.dimen.manga_grid_card_layout_width_landscape_medium) @@ -821,9 +823,9 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. return GridLayoutManager(requireContext(), spaceCount) } - private fun generateLayout() { - if (mGridType != LibraryMangaType.LINE) { - val gridAdapter = MangaGridCardAdapter() + private fun generateLayout(type: LibraryMangaType) { + if (type != LibraryMangaType.LINE) { + val gridAdapter = MangaGridCardAdapter(type) mRecyclerView.adapter = gridAdapter mRecyclerView.layoutManager = getGridLayout() gridAdapter.attachListener(mListener) @@ -833,27 +835,26 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. mRecyclerView.adapter = lineAdapter mRecyclerView.layoutManager = GridLayoutManager(requireContext(), 1) lineAdapter.attachListener(mListener) - mRecyclerView.layoutAnimation = - AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_library_line) + mRecyclerView.layoutAnimation = AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_library_line) } } private fun setAnimationRecycler(isAnimate: Boolean) { - if (mGridType != LibraryMangaType.LINE) + if (mViewModel.libraryType.value != LibraryMangaType.LINE) (mRecyclerView.adapter as MangaGridCardAdapter).isAnimation = isAnimate else (mRecyclerView.adapter as MangaLineCardAdapter).isAnimation = isAnimate } private fun removeList(manga: Manga) { - if (mGridType != LibraryMangaType.LINE) + if (mViewModel.libraryType.value != LibraryMangaType.LINE) (mRecyclerView.adapter as MangaGridCardAdapter).removeList(manga) else (mRecyclerView.adapter as MangaLineCardAdapter).removeList(manga) } - private fun updateList(list: MutableList) { - if (mGridType != LibraryMangaType.LINE) + private fun updateList(type: LibraryMangaType, list: MutableList) { + if (type != LibraryMangaType.LINE) (mRecyclerView.adapter as MangaGridCardAdapter).updateList(list) else (mRecyclerView.adapter as MangaLineCardAdapter).updateList(list) @@ -861,7 +862,10 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. private fun observer() { mViewModel.listMangas.observe(viewLifecycleOwner) { - updateList(it) + updateList(mViewModel.libraryType.value!!, it) + } + mViewModel.libraryType.observe(viewLifecycleOwner) { + onChangeLayout(it) } } @@ -1058,9 +1062,9 @@ class MangaLibraryFragment : Fragment(), PopupOrderListener, SwipeRefreshLayout. override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE || newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { - if (mGridType != LibraryMangaType.LINE) { - if (mGridType == LibraryMangaType.GRID_SMALL && resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE) - onChangeLayout() + if (mViewModel.libraryType.value != LibraryMangaType.LINE) { + if (mViewModel.libraryType.value == LibraryMangaType.GRID_SMALL && resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE) + mViewModel.changeLibraryType() else mRecyclerView.layoutManager = getGridLayout() } diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryViewModel.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryViewModel.kt index 4e1a452a..f2fbad3d 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryViewModel.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/library/manga/MangaLibraryViewModel.kt @@ -2,8 +2,10 @@ package br.com.fenix.bilingualreader.view.ui.library.manga import android.app.Application import android.content.Context +import android.content.res.Configuration import android.widget.Filter import android.widget.Filterable +import android.widget.GridLayout import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -11,6 +13,8 @@ import br.com.fenix.bilingualreader.R import br.com.fenix.bilingualreader.model.entity.Library import br.com.fenix.bilingualreader.model.entity.Manga import br.com.fenix.bilingualreader.model.enums.FileType +import br.com.fenix.bilingualreader.model.enums.LibraryBookType +import br.com.fenix.bilingualreader.model.enums.LibraryMangaType import br.com.fenix.bilingualreader.model.enums.ListMode import br.com.fenix.bilingualreader.model.enums.Order import br.com.fenix.bilingualreader.model.enums.ShareMarkType @@ -47,6 +51,9 @@ class MangaLibraryViewModel(var app: Application) : AndroidViewModel(app), Filte private var mTypeFilter = MutableLiveData(FilterType.None) val typeFilter: LiveData = mTypeFilter + private var mLibraryType = MutableLiveData(LibraryMangaType.GRID_BIG) + val libraryType: LiveData = mLibraryType + private var mListMangasFull = MutableLiveData>(mutableListOf()) private var mListMangas = MutableLiveData>(mutableListOf()) val listMangas: LiveData> = mListMangas @@ -85,8 +92,7 @@ class MangaLibraryViewModel(var app: Application) : AndroidViewModel(app), Filte fun getLibrary() = mLibrary - fun existStack(id: String): Boolean = - mStackLibrary.contains(id) + fun existStack(id: String): Boolean = mStackLibrary.contains(id) fun restoreLastStackLibrary(id: String) { if (mStackLibrary.contains(id)) { @@ -260,6 +266,21 @@ class MangaLibraryViewModel(var app: Application) : AndroidViewModel(app), Filte refreshComplete(mListMangas.value!!.isNotEmpty()) } + fun changeLibraryType() { + val isLandscape = app.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + val type = when (mLibraryType.value) { + LibraryMangaType.LINE -> LibraryMangaType.GRID_BIG + LibraryMangaType.GRID_BIG -> LibraryMangaType.GRID_MEDIUM + LibraryMangaType.GRID_MEDIUM -> if (isLandscape) LibraryMangaType.GRID_SMALL else LibraryMangaType.LINE + else -> LibraryMangaType.LINE + } + setLibraryType(type) + } + + fun setLibraryType(type: LibraryMangaType) { + mLibraryType.value = type + } + fun isEmpty(): Boolean = mListMangas.value == null || mListMangas.value!!.isEmpty() fun sorted() { @@ -318,6 +339,8 @@ class MangaLibraryViewModel(var app: Application) : AndroidViewModel(app), Filte if (list.isNullOrEmpty()) return + val process = list.stream().toList() + CoroutineScope(newSingleThreadContext("SuggestionThread")).launch { async { val authors = mutableSetOf() @@ -325,7 +348,7 @@ class MangaLibraryViewModel(var app: Application) : AndroidViewModel(app), Filte val series = mutableSetOf() val volumes = mutableSetOf() - list.forEach { + process.forEach { authors.add(it.author) publishers.add(it.publisher) series.add(it.series) diff --git a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/menu/SelectMangaFragment.kt b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/menu/SelectMangaFragment.kt index cb62da62..247ea147 100644 --- a/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/menu/SelectMangaFragment.kt +++ b/BilingualReader/src/main/java/br/com/fenix/bilingualreader/view/ui/menu/SelectMangaFragment.kt @@ -205,13 +205,20 @@ class SelectMangaFragment : Fragment() { } private fun recyclerLayout() { - if (MangaLibraryFragment.mGridType != LibraryMangaType.LINE) { - val gridAdapter = MangaGridCardAdapter() + val type = LibraryMangaType.valueOf( + GeneralConsts.getSharedPreferences(requireContext()).getString( + GeneralConsts.KEYS.LIBRARY.MANGA_LIBRARY_TYPE, + LibraryMangaType.LINE.toString() + ) + .toString() + ) + + if (type != LibraryMangaType.LINE) { + val gridAdapter = MangaGridCardAdapter(type) mRecycler.adapter = gridAdapter - val isLandscape = - resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE - val columnWidth: Int = when (MangaLibraryFragment.mGridType) { + val isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + val columnWidth: Int = when (type) { LibraryMangaType.GRID_BIG -> resources.getDimension(R.dimen.manga_grid_card_layout_width) .toInt() LibraryMangaType.GRID_MEDIUM -> if (isLandscape) resources.getDimension(R.dimen.manga_grid_card_layout_width_landscape_medium) diff --git a/BilingualReader/src/main/res/layout/fragment_book_library.xml b/BilingualReader/src/main/res/layout/fragment_book_library.xml index cdd46a70..05ad9682 100644 --- a/BilingualReader/src/main/res/layout/fragment_book_library.xml +++ b/BilingualReader/src/main/res/layout/fragment_book_library.xml @@ -87,7 +87,7 @@ + + + \ No newline at end of file diff --git a/BilingualReader/src/main/res/layout/fragment_manga_library.xml b/BilingualReader/src/main/res/layout/fragment_manga_library.xml index 0a4b2f91..d50c0bcf 100644 --- a/BilingualReader/src/main/res/layout/fragment_manga_library.xml +++ b/BilingualReader/src/main/res/layout/fragment_manga_library.xml @@ -86,7 +86,7 @@ + + + \ No newline at end of file diff --git a/BilingualReader/src/main/res/layout/popup_book_font.xml b/BilingualReader/src/main/res/layout/popup_book_font.xml index 1edb723c..ff461d0c 100644 --- a/BilingualReader/src/main/res/layout/popup_book_font.xml +++ b/BilingualReader/src/main/res/layout/popup_book_font.xml @@ -2,7 +2,7 @@ diff --git a/BilingualReader/src/main/res/layout/popup_library_order_book.xml b/BilingualReader/src/main/res/layout/popup_library_order_book.xml index 37030b78..e70ca1a0 100644 --- a/BilingualReader/src/main/res/layout/popup_library_order_book.xml +++ b/BilingualReader/src/main/res/layout/popup_library_order_book.xml @@ -1,7 +1,7 @@ diff --git a/BilingualReader/src/main/res/layout/popup_library_order_manga.xml b/BilingualReader/src/main/res/layout/popup_library_order_manga.xml index 6f867db4..9f4f5dfa 100644 --- a/BilingualReader/src/main/res/layout/popup_library_order_manga.xml +++ b/BilingualReader/src/main/res/layout/popup_library_order_manga.xml @@ -1,7 +1,7 @@ diff --git a/BilingualReader/src/main/res/layout/popup_library_type_book.xml b/BilingualReader/src/main/res/layout/popup_library_type_book.xml new file mode 100644 index 00000000..eff44892 --- /dev/null +++ b/BilingualReader/src/main/res/layout/popup_library_type_book.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + diff --git a/BilingualReader/src/main/res/layout/popup_library_type_manga.xml b/BilingualReader/src/main/res/layout/popup_library_type_manga.xml new file mode 100644 index 00000000..79008265 --- /dev/null +++ b/BilingualReader/src/main/res/layout/popup_library_type_manga.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + diff --git a/BilingualReader/src/main/res/layout/popup_manga_color_filter.xml b/BilingualReader/src/main/res/layout/popup_manga_color_filter.xml index c42301e3..85d86908 100644 --- a/BilingualReader/src/main/res/layout/popup_manga_color_filter.xml +++ b/BilingualReader/src/main/res/layout/popup_manga_color_filter.xml @@ -2,7 +2,7 @@ diff --git a/BilingualReader/src/main/res/layout/popup_manga_subtitle_reader.xml b/BilingualReader/src/main/res/layout/popup_manga_subtitle_reader.xml index a2fc0028..319ec69c 100644 --- a/BilingualReader/src/main/res/layout/popup_manga_subtitle_reader.xml +++ b/BilingualReader/src/main/res/layout/popup_manga_subtitle_reader.xml @@ -2,7 +2,7 @@ diff --git a/BilingualReader/src/main/res/menu/menu_library_book.xml b/BilingualReader/src/main/res/menu/menu_library_book.xml index 7eaa2afb..cf40393e 100644 --- a/BilingualReader/src/main/res/menu/menu_library_book.xml +++ b/BilingualReader/src/main/res/menu/menu_library_book.xml @@ -18,10 +18,10 @@ \ No newline at end of file diff --git a/BilingualReader/src/main/res/menu/menu_library_manga.xml b/BilingualReader/src/main/res/menu/menu_library_manga.xml index 39acffce..3a96fd7d 100644 --- a/BilingualReader/src/main/res/menu/menu_library_manga.xml +++ b/BilingualReader/src/main/res/menu/menu_library_manga.xml @@ -18,10 +18,10 @@ \ No newline at end of file diff --git a/BilingualReader/src/main/res/values-en/strings.xml b/BilingualReader/src/main/res/values-en/strings.xml index 07e958ea..a4da46fd 100644 --- a/BilingualReader/src/main/res/values-en/strings.xml +++ b/BilingualReader/src/main/res/values-en/strings.xml @@ -41,8 +41,8 @@ Configuration History Vocabulary - Grid type - Grid type + Grid type + Grid type System @@ -478,6 +478,7 @@ Order Filter + Grid For name For date @@ -487,9 +488,15 @@ Favorite Reading + Grid big + Grid medium + Grid small + Line + Order Filter + Grid For name For date @@ -501,6 +508,9 @@ Favorite Reading + Grid + Line + Favorite Clear history diff --git a/BilingualReader/src/main/res/values-pt-rBR/strings.xml b/BilingualReader/src/main/res/values-pt-rBR/strings.xml index 6c31576c..4132b791 100644 --- a/BilingualReader/src/main/res/values-pt-rBR/strings.xml +++ b/BilingualReader/src/main/res/values-pt-rBR/strings.xml @@ -41,8 +41,8 @@ Configuração Histórico Vocabulário - Tipo da grid - Tipo da grid + Tipo da grid + Tipo da grid Sistema @@ -478,6 +478,7 @@ Ordenação Filtro + Grid Por nome Por data @@ -487,9 +488,15 @@ Favoritos Lendo + Grid grande + Grid média + Grid pequeno + Linha + Ordenação Filtro + Grid Por nome Por data @@ -501,6 +508,9 @@ Favoritos Lendo + Grid + Linha + Favorito Limpar histórico diff --git a/BilingualReader/src/main/res/values/strings.xml b/BilingualReader/src/main/res/values/strings.xml index 7dac5fa8..b132792f 100644 --- a/BilingualReader/src/main/res/values/strings.xml +++ b/BilingualReader/src/main/res/values/strings.xml @@ -40,8 +40,8 @@ Help About Configuration - Grid type - Grid type + Grid type + Grid type System @@ -504,6 +504,7 @@ Order Filter + Grid For name For date @@ -513,9 +514,15 @@ Favorite Reading + Grid big + Grid medium + Grid small + Line + Order Filter + Grid For name For date @@ -527,6 +534,9 @@ Favorite Reading + Grid + Line + Favorite Clear history diff --git a/BilingualReader/src/main/res/values/styles.xml b/BilingualReader/src/main/res/values/styles.xml index 31dc3c15..c86585f0 100644 --- a/BilingualReader/src/main/res/values/styles.xml +++ b/BilingualReader/src/main/res/values/styles.xml @@ -797,6 +797,7 @@