Add preview requested changes to comfortable grid
This commit is contained in:
parent
290e912cf0
commit
590eb8cd66
@ -73,7 +73,7 @@ object PreferenceKeys {
|
||||
|
||||
const val lastUsedCategory = "last_used_category"
|
||||
|
||||
const val catalogueViewSetting = "pref_display_catalogue_view_setting"
|
||||
const val catalogueDisplayMode = "pref_display_catalogue_display_mode"
|
||||
|
||||
const val enabledLanguages = "source_languages"
|
||||
|
||||
@ -137,7 +137,7 @@ object PreferenceKeys {
|
||||
|
||||
const val downloadNewCategories = "download_new_categories"
|
||||
|
||||
const val libraryViewSetting = "pref_display_library_view_setting"
|
||||
const val libraryDisplayMode = "pref_display_library_display_mode"
|
||||
|
||||
const val lang = "app_language"
|
||||
|
||||
|
@ -15,4 +15,8 @@ object PreferenceValues {
|
||||
const val THEME_DARK_DEFAULT = "default"
|
||||
const val THEME_DARK_BLUE = "blue"
|
||||
const val THEME_DARK_AMOLED = "amoled"
|
||||
|
||||
const val DISPLAY_COMPACT_GRID = 0
|
||||
const val DISPLAY_LIST = 1
|
||||
const val DISPLAY_COMFORTABLE_GRID = 2
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)
|
||||
|
||||
fun catalogueViewSetting() = rxPrefs.getInteger(Keys.catalogueViewSetting, 0)
|
||||
fun catalogueDisplayMode() = flowPrefs.getInt(Keys.catalogueDisplayMode, 0)
|
||||
|
||||
fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("all", "en", Locale.getDefault().language))
|
||||
|
||||
@ -191,7 +191,7 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun libraryUpdatePrioritization() = flowPrefs.getInt(Keys.libraryUpdatePrioritization, 0)
|
||||
|
||||
fun libraryViewSetting() = flowPrefs.getInt(Keys.libraryViewSetting, 0)
|
||||
fun libraryDisplayMode() = flowPrefs.getInt(Keys.libraryDisplayMode, 0)
|
||||
|
||||
fun downloadBadge() = flowPrefs.getBoolean(Keys.downloadBadge, false)
|
||||
|
||||
|
@ -26,6 +26,9 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMFORTABLE_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMPACT_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_LIST
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.databinding.SourceControllerBinding
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
@ -314,7 +317,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
binding.catalogueView.removeView(oldRecycler)
|
||||
}
|
||||
|
||||
val recycler = if (presenter.mode == 1) {
|
||||
val recycler = if (preferences.catalogueDisplayMode().get() == DISPLAY_LIST) {
|
||||
RecyclerView(view.context).apply {
|
||||
id = R.id.recycler
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
@ -397,15 +400,13 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
}
|
||||
)
|
||||
|
||||
// Show next display mode
|
||||
menu.findItem(R.id.action_display_mode).apply {
|
||||
val icon = if (presenter.mode == 0) {
|
||||
R.drawable.ic_view_list_24dp
|
||||
} else {
|
||||
R.drawable.ic_view_module_24dp
|
||||
}
|
||||
setIcon(icon)
|
||||
val displayItem = when (preferences.catalogueDisplayMode().get()) {
|
||||
DISPLAY_COMPACT_GRID -> R.id.action_compact_grid
|
||||
DISPLAY_LIST -> R.id.action_list
|
||||
DISPLAY_COMFORTABLE_GRID -> R.id.action_comfortable_grid
|
||||
else -> throw NotImplementedError("Unimplemented display")
|
||||
}
|
||||
menu.findItem(displayItem).isChecked = true
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
@ -421,7 +422,9 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_search -> expandActionViewFromInteraction = true
|
||||
R.id.action_display_mode -> swapDisplayMode()
|
||||
R.id.action_compact_grid -> setDisplayMode(DISPLAY_COMPACT_GRID)
|
||||
R.id.action_list -> setDisplayMode(DISPLAY_LIST)
|
||||
R.id.action_comfortable_grid -> setDisplayMode(DISPLAY_COMFORTABLE_GRID)
|
||||
R.id.action_open_in_web_view -> openInWebView()
|
||||
R.id.action_local_source_help -> openLocalSourceHelpGuide()
|
||||
}
|
||||
@ -576,17 +579,19 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps the current display mode.
|
||||
* Sets the current display mode.
|
||||
*
|
||||
* @param mode the mode to change to
|
||||
*/
|
||||
fun swapDisplayMode() {
|
||||
private fun setDisplayMode(mode: Int) {
|
||||
val view = view ?: return
|
||||
val adapter = adapter ?: return
|
||||
|
||||
presenter.swapDisplayMode()
|
||||
val isListMode = presenter.mode == 1
|
||||
preferences.catalogueDisplayMode().set(mode)
|
||||
presenter.refreshDisplayMode()
|
||||
activity?.invalidateOptionsMenu()
|
||||
setupRecycler(view)
|
||||
if (!isListMode || !view.context.connectivityManager.isActiveNetworkMetered) {
|
||||
if (mode == DISPLAY_LIST || !view.context.connectivityManager.isActiveNetworkMetered) {
|
||||
// Initialize mangas if going to grid view or if over wifi when going to list view
|
||||
val mangas = (0 until adapter.itemCount).mapNotNull {
|
||||
(adapter.getItem(it) as? SourceItem)?.manga
|
||||
|
@ -98,12 +98,6 @@ open class BrowseSourcePresenter(
|
||||
*/
|
||||
private val mangaDetailSubject = PublishSubject.create<List<Manga>>()
|
||||
|
||||
/**
|
||||
* Whether the view is in list mode or not.
|
||||
*/
|
||||
var mode: Int = 0
|
||||
private set
|
||||
|
||||
/**
|
||||
* Subscription for the pager.
|
||||
*/
|
||||
@ -130,11 +124,6 @@ open class BrowseSourcePresenter(
|
||||
query = savedState.getString(::query.name, "")
|
||||
}
|
||||
|
||||
add(
|
||||
prefs.catalogueViewSetting().asObservable()
|
||||
.subscribe { setDisplayMode(it) }
|
||||
)
|
||||
|
||||
restartPager()
|
||||
}
|
||||
|
||||
@ -162,7 +151,7 @@ open class BrowseSourcePresenter(
|
||||
|
||||
val sourceId = source.id
|
||||
|
||||
val catalogueViewSetting = prefs.catalogueViewSetting()
|
||||
val catalogueDisplayMode = prefs.catalogueDisplayMode()
|
||||
|
||||
// Prepare the pager.
|
||||
pagerSubscription?.let { remove(it) }
|
||||
@ -170,7 +159,7 @@ open class BrowseSourcePresenter(
|
||||
.observeOn(Schedulers.io())
|
||||
.map { pair -> pair.first to pair.second.map { networkToLocalManga(it, sourceId) } }
|
||||
.doOnNext { initializeMangas(it.second) }
|
||||
.map { pair -> pair.first to pair.second.map { SourceItem(it, catalogueViewSetting) } }
|
||||
.map { pair -> pair.first to pair.second.map { SourceItem(it, catalogueDisplayMode) } }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeReplay(
|
||||
{ view, (page, mangas) ->
|
||||
@ -209,12 +198,9 @@ open class BrowseSourcePresenter(
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display mode.
|
||||
*
|
||||
* @param mode whether the current mode is in list or not.
|
||||
* Refeshes the display mode.
|
||||
*/
|
||||
private fun setDisplayMode(mode: Int) {
|
||||
this.mode = mode
|
||||
fun refreshDisplayMode() {
|
||||
subscribeToMangaInitializer()
|
||||
}
|
||||
|
||||
@ -299,19 +285,6 @@ open class BrowseSourcePresenter(
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the active display mode.
|
||||
*/
|
||||
fun swapDisplayMode() {
|
||||
prefs.catalogueViewSetting().set(
|
||||
when (mode) {
|
||||
0 -> 1
|
||||
1 -> 2
|
||||
else -> 0
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filter states for the current source.
|
||||
*
|
||||
|
@ -21,7 +21,7 @@ import kotlinx.android.synthetic.main.source_comfortable_grid_item.title
|
||||
* @constructor creates a new catalogue holder.
|
||||
*/
|
||||
class SourceComfortableGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
|
||||
SourceHolder(view, adapter) {
|
||||
SourceGridHolder(view, adapter) {
|
||||
|
||||
/**
|
||||
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
|
||||
|
@ -20,7 +20,7 @@ import kotlinx.android.synthetic.main.source_grid_item.title
|
||||
* @param adapter the adapter handling this holder.
|
||||
* @constructor creates a new catalogue holder.
|
||||
*/
|
||||
class SourceGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
|
||||
open class SourceGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
|
||||
SourceHolder(view, adapter) {
|
||||
|
||||
/**
|
||||
|
@ -6,23 +6,25 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.widget.FrameLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.f2prateek.rx.preferences.Preference
|
||||
import com.tfcporciuncula.flow.Preference
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMPACT_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_LIST
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import kotlinx.android.synthetic.main.source_grid_item.view.card
|
||||
import kotlinx.android.synthetic.main.source_grid_item.view.gradient
|
||||
|
||||
class SourceItem(val manga: Manga, private val catalogueViewSetting: Preference<Int>) :
|
||||
class SourceItem(val manga: Manga, private val catalogueDisplayMode: Preference<Int>) :
|
||||
AbstractFlexibleItem<SourceHolder>() {
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return when (catalogueViewSetting.get()) {
|
||||
0 -> R.layout.source_grid_item
|
||||
1 -> R.layout.source_list_item
|
||||
return when (catalogueDisplayMode.get()) {
|
||||
DISPLAY_COMPACT_GRID -> R.layout.source_grid_item
|
||||
DISPLAY_LIST -> R.layout.source_list_item
|
||||
else -> R.layout.source_comfortable_grid_item
|
||||
}
|
||||
}
|
||||
@ -34,7 +36,7 @@ class SourceItem(val manga: Manga, private val catalogueViewSetting: Preference<
|
||||
val parent = adapter.recyclerView
|
||||
return if (parent is AutofitRecyclerView) {
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
if (catalogueViewSetting.get() == 0) {
|
||||
if (catalogueDisplayMode.get() == DISPLAY_COMPACT_GRID) {
|
||||
view.apply {
|
||||
card.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight
|
||||
|
@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_LIST
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.category.CategoryAdapter
|
||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||
@ -93,7 +94,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
fun onCreate(controller: LibraryController) {
|
||||
this.controller = controller
|
||||
|
||||
recycler = if (preferences.libraryViewSetting().get() == 1) {
|
||||
recycler = if (preferences.libraryDisplayMode().get() == DISPLAY_LIST) {
|
||||
(swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import kotlinx.android.synthetic.main.source_comfortable_grid_item.unread_text
|
||||
class LibraryComfortableGridHolder(
|
||||
private val view: View,
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
) : LibraryHolder(view, adapter) {
|
||||
) : LibraryGridHolder(view, adapter) {
|
||||
|
||||
/**
|
||||
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
|
||||
|
@ -25,7 +25,7 @@ import kotlinx.android.synthetic.main.source_grid_item.unread_text
|
||||
* @param listener a listener to react to single tap and long tap events.
|
||||
* @constructor creates a new library holder.
|
||||
*/
|
||||
class LibraryGridHolder(
|
||||
open class LibraryGridHolder(
|
||||
private val view: View,
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
) : LibraryHolder(view, adapter) {
|
||||
|
@ -15,6 +15,8 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||
import eu.kanade.tachiyomi.data.database.models.Track
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMPACT_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_LIST
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
@ -24,7 +26,7 @@ import kotlinx.android.synthetic.main.source_grid_item.view.gradient
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class LibraryItem(val manga: LibraryManga, private val libraryViewSetting: Preference<Int>) :
|
||||
class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Preference<Int>) :
|
||||
AbstractFlexibleItem<LibraryHolder>(), IFilterable<String> {
|
||||
|
||||
private val sourceManager: SourceManager = Injekt.get()
|
||||
@ -35,9 +37,9 @@ class LibraryItem(val manga: LibraryManga, private val libraryViewSetting: Prefe
|
||||
var unreadCount = -1
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return when (libraryViewSetting.get()) {
|
||||
0 -> R.layout.source_grid_item
|
||||
1 -> R.layout.source_list_item
|
||||
return when (libraryDisplayMode.get()) {
|
||||
DISPLAY_COMPACT_GRID -> R.layout.source_grid_item
|
||||
DISPLAY_LIST -> R.layout.source_list_item
|
||||
else -> R.layout.source_comfortable_grid_item
|
||||
}
|
||||
}
|
||||
@ -46,7 +48,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryViewSetting: Prefe
|
||||
val parent = adapter.recyclerView
|
||||
return if (parent is AutofitRecyclerView) {
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
if (libraryViewSetting.get() == 0) {
|
||||
if (libraryDisplayMode.get() == DISPLAY_COMPACT_GRID) {
|
||||
view.apply {
|
||||
card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight)
|
||||
gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
|
@ -301,10 +301,10 @@ class LibraryPresenter(
|
||||
* value.
|
||||
*/
|
||||
private fun getLibraryMangasObservable(): Observable<LibraryMap> {
|
||||
val libraryViewSetting = preferences.libraryViewSetting()
|
||||
val libraryDisplayMode = preferences.libraryDisplayMode()
|
||||
return db.getLibraryMangas().asRxObservable()
|
||||
.map { list ->
|
||||
list.map { LibraryItem(it, libraryViewSetting) }.groupBy { it.manga.category }
|
||||
list.map { LibraryItem(it, libraryDisplayMode) }.groupBy { it.manga.category }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,9 @@ import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMFORTABLE_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMPACT_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_LIST
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.source.model.Filter.TriState.Companion.STATE_EXCLUDE
|
||||
@ -228,10 +231,10 @@ class LibrarySettingsSheet(
|
||||
override val footer = null
|
||||
|
||||
override fun initModels() {
|
||||
val mode = preferences.libraryViewSetting().get()
|
||||
grid.checked = mode == 0
|
||||
list.checked = mode == 1
|
||||
comfortableGrid.checked = mode == 2
|
||||
val mode = preferences.libraryDisplayMode().get()
|
||||
grid.checked = mode == DISPLAY_COMPACT_GRID
|
||||
list.checked = mode == DISPLAY_LIST
|
||||
comfortableGrid.checked = mode == DISPLAY_COMFORTABLE_GRID
|
||||
}
|
||||
|
||||
override fun onItemClicked(item: Item) {
|
||||
@ -241,11 +244,11 @@ class LibrarySettingsSheet(
|
||||
item.group.items.forEach { (it as Item.Radio).checked = false }
|
||||
item.checked = true
|
||||
|
||||
preferences.libraryViewSetting().set(
|
||||
preferences.libraryDisplayMode().set(
|
||||
when (item) {
|
||||
grid -> 0
|
||||
list -> 1
|
||||
else -> 2
|
||||
grid -> DISPLAY_COMPACT_GRID
|
||||
list -> DISPLAY_LIST
|
||||
else -> DISPLAY_COMFORTABLE_GRID
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
android:padding="4dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/outside"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/rounded_rectangle">
|
||||
|
@ -10,11 +10,24 @@
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_display_mode"
|
||||
android:icon="@drawable/ic_view_module_24dp"
|
||||
android:title="@string/action_display_mode"
|
||||
app:iconTint="?attr/colorOnPrimary"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="ifRoom">
|
||||
<menu>
|
||||
<group android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/action_compact_grid"
|
||||
android:title="@string/action_display_grid" />
|
||||
<item
|
||||
android:id="@+id/action_list"
|
||||
android:title="@string/action_display_list" />
|
||||
<item
|
||||
android:id="@+id/action_comfortable_grid"
|
||||
android:title="@string/action_display_comfortable_grid" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_open_in_web_view"
|
||||
|
@ -81,7 +81,7 @@
|
||||
<string name="action_migrate">Migrate</string>
|
||||
<string name="action_display_mode">Display mode</string>
|
||||
<string name="action_display">Display</string>
|
||||
<string name="action_display_grid">Grid</string>
|
||||
<string name="action_display_grid">Compact Grid</string>
|
||||
<string name="action_display_list">List</string>
|
||||
<string name="action_display_download_badge">Download badges</string>
|
||||
<string name="action_display_unread_badge">Unread badges</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user