mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-24 01:48:24 +01:00
Recycle view holders in library. Format fixes
This commit is contained in:
parent
31b1b83606
commit
fbd2235a51
@ -85,10 +85,9 @@ class LibraryCategoryAdapter(val fragment: LibraryCategoryFragment) :
|
||||
*/
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LibraryHolder {
|
||||
//depending on preferences, display a list or display a grid
|
||||
if(parent.id == R.id.library_list) {
|
||||
if (parent.id == R.id.library_list) {
|
||||
val view = parent.inflate(R.layout.item_library_list)
|
||||
return LibraryListHolder(view, this, fragment)
|
||||
|
||||
} else {
|
||||
val view = parent.inflate(R.layout.item_catalogue_grid).apply {
|
||||
card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight)
|
||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
@ -91,8 +92,6 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_library_category, container, false)
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
@ -100,14 +99,16 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||
|
||||
//set up grid
|
||||
recycler.setHasFixedSize(true)
|
||||
(recycler.layoutManager as GridLayoutManager).recycleChildrenOnDetach = true
|
||||
recycler.recycledViewPool = libraryFragment.pool
|
||||
recycler.adapter = adapter
|
||||
|
||||
//set up list
|
||||
library_list.setHasFixedSize(true)
|
||||
library_list.adapter = adapter
|
||||
library_list.layoutManager = LinearLayoutManager(activity)
|
||||
|
||||
|
||||
library_list.recycledViewPool = libraryFragment.pool
|
||||
(library_list.layoutManager as LinearLayoutManager).recycleChildrenOnDetach = true
|
||||
library_list.adapter = adapter
|
||||
|
||||
if (libraryFragment.actionMode != null) {
|
||||
setSelectionMode(FlexibleAdapter.MODE_MULTI)
|
||||
@ -119,19 +120,19 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||
// Set again the adapter to recalculate the covers height
|
||||
.subscribe { recycler.adapter = adapter }
|
||||
|
||||
searchSubscription = libraryPresenter.searchSubject?.subscribe { text ->
|
||||
searchSubscription = libraryPresenter.searchSubject.subscribe { text ->
|
||||
adapter.searchText = text
|
||||
adapter.updateDataSet()
|
||||
}
|
||||
|
||||
toggleViewSubscription = preferences.libraryAsList().asObservable().subscribe {onViewModeChange(it)}
|
||||
toggleViewSubscription = preferences.libraryAsList().asObservable()
|
||||
.subscribe { onViewModeChange(it) }
|
||||
|
||||
if(libraryPresenter.displayAsList != displayAsList) {
|
||||
if (libraryPresenter.displayAsList != displayAsList) {
|
||||
library_switcher.showNext()
|
||||
displayAsList = libraryPresenter.displayAsList
|
||||
}
|
||||
|
||||
|
||||
library_switcher.inAnimation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_in)
|
||||
library_switcher.outAnimation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_out)
|
||||
|
||||
@ -176,11 +177,8 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
|
||||
libraryMangaSubscription = libraryPresenter.libraryMangaSubject
|
||||
?.subscribe { onNextLibraryManga(it) }
|
||||
|
||||
.subscribe { onNextLibraryManga(it) }
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -310,7 +308,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||
|
||||
fun onViewModeChange(isList: Boolean) {
|
||||
//do nothing if the display does not need to change
|
||||
if(isList == displayAsList) return
|
||||
if (isList == displayAsList) return
|
||||
|
||||
//else change view and display mode
|
||||
library_switcher.showNext()
|
||||
|
@ -6,6 +6,7 @@ import android.os.Bundle
|
||||
import android.support.design.widget.TabLayout
|
||||
import android.support.v4.view.ViewPager
|
||||
import android.support.v7.view.ActionMode
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.support.v7.widget.SearchView
|
||||
import android.view.*
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
@ -86,6 +87,11 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
*/
|
||||
var isFilterUnread = false
|
||||
|
||||
/**
|
||||
* A pool to share view holders between all the registered categories (fragments).
|
||||
*/
|
||||
val pool = RecyclerView.RecycledViewPool()
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Key to change the cover of a manga in [onActivityResult].
|
||||
@ -138,7 +144,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
if (savedState != null) {
|
||||
activeCategory = savedState.getInt(CATEGORY_KEY)
|
||||
query = savedState.getString(QUERY_KEY)
|
||||
presenter.searchSubject?.onNext(query)
|
||||
presenter.searchSubject.onNext(query)
|
||||
} else {
|
||||
activeCategory = presenter.preferences.lastUsedCategory().getOrDefault()
|
||||
}
|
||||
@ -311,7 +317,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
view_pager.post { if (isAdded) tabs.setScrollPosition(view_pager.currentItem, 0f, true) }
|
||||
|
||||
// Send the manga map to child fragments after the adapter is updated.
|
||||
presenter.libraryMangaSubject?.onNext(LibraryMangaEvent(mangaMap))
|
||||
presenter.libraryMangaSubject.onNext(LibraryMangaEvent(mangaMap))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,8 @@ import kotlinx.android.synthetic.main.item_library_list.view.*
|
||||
*/
|
||||
|
||||
class LibraryListHolder(private val view: View,
|
||||
private val adapter: LibraryCategoryAdapter,
|
||||
listener: FlexibleViewHolder.OnListItemClickListener)
|
||||
private val adapter: LibraryCategoryAdapter,
|
||||
listener: FlexibleViewHolder.OnListItemClickListener)
|
||||
: LibraryHolder(view, adapter, listener) {
|
||||
|
||||
/**
|
||||
|
@ -39,12 +39,12 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
/**
|
||||
* Search query of the library.
|
||||
*/
|
||||
val searchSubject: BehaviorSubject<String>? = BehaviorSubject.create<String>()
|
||||
val searchSubject: BehaviorSubject<String> = BehaviorSubject.create<String>()
|
||||
|
||||
/**
|
||||
* Subject to notify the library's viewpager for updates.
|
||||
*/
|
||||
val libraryMangaSubject: BehaviorSubject<LibraryMangaEvent>? = BehaviorSubject.create<LibraryMangaEvent>()
|
||||
val libraryMangaSubject: BehaviorSubject<LibraryMangaEvent> = BehaviorSubject.create<LibraryMangaEvent>()
|
||||
|
||||
/**
|
||||
* Database.
|
||||
@ -95,9 +95,7 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
start(GET_LIBRARY)
|
||||
}
|
||||
|
||||
|
||||
add(preferences.libraryAsList().asObservable().subscribe{setDisplayMode(it)})
|
||||
|
||||
add(preferences.libraryAsList().asObservable().subscribe { setDisplayMode(it) })
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user