Add "Grid mode" option to explore options menu
This commit is contained in:
@@ -36,6 +36,7 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
||||||
|
import org.koitharu.kotatsu.utils.ext.addMenuProvider
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ class ExploreFragment :
|
|||||||
val spacing = resources.getDimensionPixelOffset(R.dimen.list_spacing)
|
val spacing = resources.getDimensionPixelOffset(R.dimen.list_spacing)
|
||||||
paddingHorizontal = spacing
|
paddingHorizontal = spacing
|
||||||
}
|
}
|
||||||
|
addMenuProvider(ExploreMenuProvider(view.context, viewModel))
|
||||||
viewModel.content.observe(viewLifecycleOwner) {
|
viewModel.content.observe(viewLifecycleOwner) {
|
||||||
exploreAdapter?.items = it
|
exploreAdapter?.items = it
|
||||||
}
|
}
|
||||||
@@ -162,6 +164,7 @@ class ExploreFragment :
|
|||||||
} else {
|
} else {
|
||||||
LinearLayoutManager(requireContext())
|
LinearLayoutManager(requireContext())
|
||||||
}
|
}
|
||||||
|
activity?.invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class SourceMenuListener(
|
private inner class SourceMenuListener(
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.koitharu.kotatsu.explore.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class ExploreMenuProvider(
|
||||||
|
private val context: Context,
|
||||||
|
private val viewModel: ExploreViewModel,
|
||||||
|
) : MenuProvider {
|
||||||
|
|
||||||
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
|
menuInflater.inflate(R.menu.opt_explore, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
|
return when (menuItem.itemId) {
|
||||||
|
R.id.action_grid -> {
|
||||||
|
viewModel.setGridMode(!menuItem.isChecked)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
|
super.onPrepareMenu(menu)
|
||||||
|
menu.findItem(R.id.action_grid)?.isChecked = viewModel.isGrid.value == true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,6 +69,10 @@ class ExploreViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setGridMode(value: Boolean) {
|
||||||
|
settings.isSourcesGridMode = value
|
||||||
|
}
|
||||||
|
|
||||||
private fun createContentFlow() = settings.observe()
|
private fun createContentFlow() = settings.observe()
|
||||||
.filter {
|
.filter {
|
||||||
it == AppSettings.KEY_SOURCES_HIDDEN ||
|
it == AppSettings.KEY_SOURCES_HIDDEN ||
|
||||||
|
|||||||
11
app/src/main/res/menu/opt_explore.xml
Normal file
11
app/src/main/res/menu/opt_explore.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_grid"
|
||||||
|
android:checkable="true"
|
||||||
|
android:title="@string/show_in_grid_view"
|
||||||
|
android:titleCondensed="@string/grid" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
Reference in New Issue
Block a user