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