|
@@ -14,8 +14,6 @@ import android.support.v7.widget.SearchView
|
|
import android.view.*
|
|
import android.view.*
|
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
|
import com.bluelinelabs.conductor.ControllerChangeType
|
|
import com.bluelinelabs.conductor.ControllerChangeType
|
|
-import com.bluelinelabs.conductor.RouterTransaction
|
|
|
|
-import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
|
|
|
import com.f2prateek.rx.preferences.Preference
|
|
import com.f2prateek.rx.preferences.Preference
|
|
import com.jakewharton.rxbinding.support.v4.view.pageSelections
|
|
import com.jakewharton.rxbinding.support.v4.view.pageSelections
|
|
import com.jakewharton.rxbinding.support.v7.widget.queryTextChanges
|
|
import com.jakewharton.rxbinding.support.v7.widget.queryTextChanges
|
|
@@ -30,13 +28,14 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault
|
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
|
import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController
|
|
import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController
|
|
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
|
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
|
|
|
+import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
|
import eu.kanade.tachiyomi.ui.category.CategoryController
|
|
import eu.kanade.tachiyomi.ui.category.CategoryController
|
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
|
import eu.kanade.tachiyomi.util.inflate
|
|
import eu.kanade.tachiyomi.util.inflate
|
|
import eu.kanade.tachiyomi.util.toast
|
|
import eu.kanade.tachiyomi.util.toast
|
|
import eu.kanade.tachiyomi.widget.DrawerSwipeCloseListener
|
|
import eu.kanade.tachiyomi.widget.DrawerSwipeCloseListener
|
|
-import kotlinx.android.synthetic.main.library_controller.view.*
|
|
|
|
|
|
+import kotlinx.android.synthetic.main.library_controller.*
|
|
import kotlinx.android.synthetic.main.main_activity.*
|
|
import kotlinx.android.synthetic.main.main_activity.*
|
|
import rx.Subscription
|
|
import rx.Subscription
|
|
import timber.log.Timber
|
|
import timber.log.Timber
|
|
@@ -100,14 +99,8 @@ class LibraryController(
|
|
private set
|
|
private set
|
|
|
|
|
|
/**
|
|
/**
|
|
- * TabLayout of the categories.
|
|
|
|
|
|
+ * Adapter of the view pager.
|
|
*/
|
|
*/
|
|
- private val tabs: TabLayout?
|
|
|
|
- get() = activity?.tabs
|
|
|
|
-
|
|
|
|
- private val drawer: DrawerLayout?
|
|
|
|
- get() = activity?.drawer
|
|
|
|
-
|
|
|
|
private var adapter: LibraryAdapter? = null
|
|
private var adapter: LibraryAdapter? = null
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -141,43 +134,41 @@ class LibraryController(
|
|
return inflater.inflate(R.layout.library_controller, container, false)
|
|
return inflater.inflate(R.layout.library_controller, container, false)
|
|
}
|
|
}
|
|
|
|
|
|
- override fun onViewCreated(view: View, savedViewState: Bundle?) {
|
|
|
|
- super.onViewCreated(view, savedViewState)
|
|
|
|
|
|
+ override fun onViewCreated(view: View) {
|
|
|
|
+ super.onViewCreated(view)
|
|
|
|
|
|
adapter = LibraryAdapter(this)
|
|
adapter = LibraryAdapter(this)
|
|
- with(view) {
|
|
|
|
- view_pager.adapter = adapter
|
|
|
|
- view_pager.pageSelections().skip(1).subscribeUntilDestroy {
|
|
|
|
- preferences.lastUsedCategory().set(it)
|
|
|
|
- activeCategory = it
|
|
|
|
- }
|
|
|
|
|
|
+ view_pager.adapter = adapter
|
|
|
|
+ view_pager.pageSelections().skip(1).subscribeUntilDestroy {
|
|
|
|
+ preferences.lastUsedCategory().set(it)
|
|
|
|
+ activeCategory = it
|
|
|
|
+ }
|
|
|
|
|
|
- getColumnsPreferenceForCurrentOrientation().asObservable()
|
|
|
|
- .doOnNext { mangaPerRow = it }
|
|
|
|
- .skip(1)
|
|
|
|
- // Set again the adapter to recalculate the covers height
|
|
|
|
- .subscribeUntilDestroy { reattachAdapter() }
|
|
|
|
|
|
+ getColumnsPreferenceForCurrentOrientation().asObservable()
|
|
|
|
+ .doOnNext { mangaPerRow = it }
|
|
|
|
+ .skip(1)
|
|
|
|
+ // Set again the adapter to recalculate the covers height
|
|
|
|
+ .subscribeUntilDestroy { reattachAdapter() }
|
|
|
|
|
|
- if (selectedMangas.isNotEmpty()) {
|
|
|
|
- createActionModeIfNeeded()
|
|
|
|
- }
|
|
|
|
|
|
+ if (selectedMangas.isNotEmpty()) {
|
|
|
|
+ createActionModeIfNeeded()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
|
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
|
super.onChangeStarted(handler, type)
|
|
super.onChangeStarted(handler, type)
|
|
if (type.isEnter) {
|
|
if (type.isEnter) {
|
|
- activity?.tabs?.setupWithViewPager(view?.view_pager)
|
|
|
|
|
|
+ activity?.tabs?.setupWithViewPager(view_pager)
|
|
presenter.subscribeLibrary()
|
|
presenter.subscribeLibrary()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
override fun onDestroyView(view: View) {
|
|
override fun onDestroyView(view: View) {
|
|
- super.onDestroyView(view)
|
|
|
|
adapter = null
|
|
adapter = null
|
|
actionMode = null
|
|
actionMode = null
|
|
tabsVisibilitySubscription?.unsubscribe()
|
|
tabsVisibilitySubscription?.unsubscribe()
|
|
tabsVisibilitySubscription = null
|
|
tabsVisibilitySubscription = null
|
|
|
|
+ super.onDestroyView(view)
|
|
}
|
|
}
|
|
|
|
|
|
override fun createSecondaryDrawer(drawer: DrawerLayout): ViewGroup {
|
|
override fun createSecondaryDrawer(drawer: DrawerLayout): ViewGroup {
|
|
@@ -233,14 +224,14 @@ class LibraryController(
|
|
|
|
|
|
// Show empty view if needed
|
|
// Show empty view if needed
|
|
if (mangaMap.isNotEmpty()) {
|
|
if (mangaMap.isNotEmpty()) {
|
|
- view.empty_view.hide()
|
|
|
|
|
|
+ empty_view.hide()
|
|
} else {
|
|
} else {
|
|
- view.empty_view.show(R.drawable.ic_book_black_128dp, R.string.information_empty_library)
|
|
|
|
|
|
+ empty_view.show(R.drawable.ic_book_black_128dp, R.string.information_empty_library)
|
|
}
|
|
}
|
|
|
|
|
|
// Get the current active category.
|
|
// Get the current active category.
|
|
val activeCat = if (adapter.categories.isNotEmpty())
|
|
val activeCat = if (adapter.categories.isNotEmpty())
|
|
- view.view_pager.currentItem
|
|
|
|
|
|
+ view_pager.currentItem
|
|
else
|
|
else
|
|
activeCategory
|
|
activeCategory
|
|
|
|
|
|
@@ -248,14 +239,14 @@ class LibraryController(
|
|
adapter.categories = categories
|
|
adapter.categories = categories
|
|
|
|
|
|
// Restore active category.
|
|
// Restore active category.
|
|
- view.view_pager.setCurrentItem(activeCat, false)
|
|
|
|
|
|
+ view_pager.setCurrentItem(activeCat, false)
|
|
|
|
|
|
tabsVisibilityRelay.call(categories.size > 1)
|
|
tabsVisibilityRelay.call(categories.size > 1)
|
|
|
|
|
|
// Delay the scroll position to allow the view to be properly measured.
|
|
// Delay the scroll position to allow the view to be properly measured.
|
|
view.post {
|
|
view.post {
|
|
if (isAttached) {
|
|
if (isAttached) {
|
|
- tabs?.setScrollPosition(view.view_pager.currentItem, 0f, true)
|
|
|
|
|
|
+ activity?.tabs?.setScrollPosition(view_pager.currentItem, 0f, true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -298,14 +289,13 @@ class LibraryController(
|
|
* Reattaches the adapter to the view pager to recreate fragments
|
|
* Reattaches the adapter to the view pager to recreate fragments
|
|
*/
|
|
*/
|
|
private fun reattachAdapter() {
|
|
private fun reattachAdapter() {
|
|
- val pager = view?.view_pager ?: return
|
|
|
|
val adapter = adapter ?: return
|
|
val adapter = adapter ?: return
|
|
|
|
|
|
- val position = pager.currentItem
|
|
|
|
|
|
+ val position = view_pager.currentItem
|
|
|
|
|
|
adapter.recycle = false
|
|
adapter.recycle = false
|
|
- pager.adapter = adapter
|
|
|
|
- pager.currentItem = position
|
|
|
|
|
|
+ view_pager.adapter = adapter
|
|
|
|
+ view_pager.currentItem = position
|
|
adapter.recycle = true
|
|
adapter.recycle = true
|
|
}
|
|
}
|
|
|
|
|
|
@@ -331,7 +321,7 @@ class LibraryController(
|
|
val searchItem = menu.findItem(R.id.action_search)
|
|
val searchItem = menu.findItem(R.id.action_search)
|
|
val searchView = searchItem.actionView as SearchView
|
|
val searchView = searchItem.actionView as SearchView
|
|
|
|
|
|
- if (!query.isNullOrEmpty()) {
|
|
|
|
|
|
+ if (!query.isEmpty()) {
|
|
searchItem.expandActionView()
|
|
searchItem.expandActionView()
|
|
searchView.setQuery(query, true)
|
|
searchView.setQuery(query, true)
|
|
searchView.clearFocus()
|
|
searchView.clearFocus()
|
|
@@ -361,15 +351,13 @@ class LibraryController(
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
when (item.itemId) {
|
|
when (item.itemId) {
|
|
R.id.action_filter -> {
|
|
R.id.action_filter -> {
|
|
- navView?.let { drawer?.openDrawer(Gravity.END) }
|
|
|
|
|
|
+ navView?.let { activity?.drawer?.openDrawer(Gravity.END) }
|
|
}
|
|
}
|
|
R.id.action_update_library -> {
|
|
R.id.action_update_library -> {
|
|
activity?.let { LibraryUpdateService.start(it) }
|
|
activity?.let { LibraryUpdateService.start(it) }
|
|
}
|
|
}
|
|
R.id.action_edit_categories -> {
|
|
R.id.action_edit_categories -> {
|
|
- router.pushController(RouterTransaction.with(CategoryController())
|
|
|
|
- .pushChangeHandler(FadeChangeHandler())
|
|
|
|
- .popChangeHandler(FadeChangeHandler()))
|
|
|
|
|
|
+ router.pushController(CategoryController().withFadeTransaction())
|
|
}
|
|
}
|
|
else -> return super.onOptionsItemSelected(item)
|
|
else -> return super.onOptionsItemSelected(item)
|
|
}
|
|
}
|
|
@@ -425,9 +413,7 @@ class LibraryController(
|
|
// Notify the presenter a manga is being opened.
|
|
// Notify the presenter a manga is being opened.
|
|
presenter.onOpenManga()
|
|
presenter.onOpenManga()
|
|
|
|
|
|
- router.pushController(RouterTransaction.with(MangaController(manga))
|
|
|
|
- .pushChangeHandler(FadeChangeHandler())
|
|
|
|
- .popChangeHandler(FadeChangeHandler()))
|
|
|
|
|
|
+ router.pushController(MangaController(manga).withFadeTransaction())
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -462,11 +448,11 @@ class LibraryController(
|
|
.toTypedArray()
|
|
.toTypedArray()
|
|
|
|
|
|
ChangeMangaCategoriesDialog(this, mangas, categories, commonCategoriesIndexes)
|
|
ChangeMangaCategoriesDialog(this, mangas, categories, commonCategoriesIndexes)
|
|
- .showDialog(router, null)
|
|
|
|
|
|
+ .showDialog(router)
|
|
}
|
|
}
|
|
|
|
|
|
private fun showDeleteMangaDialog() {
|
|
private fun showDeleteMangaDialog() {
|
|
- DeleteLibraryMangasDialog(this, selectedMangas.toList()).showDialog(router, null)
|
|
|
|
|
|
+ DeleteLibraryMangasDialog(this, selectedMangas.toList()).showDialog(router)
|
|
}
|
|
}
|
|
|
|
|
|
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
|
|
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
|
|
@@ -481,8 +467,6 @@ class LibraryController(
|
|
|
|
|
|
/**
|
|
/**
|
|
* Changes the cover for the selected manga.
|
|
* Changes the cover for the selected manga.
|
|
- *
|
|
|
|
- * @param mangas a list of selected manga.
|
|
|
|
*/
|
|
*/
|
|
private fun changeSelectedCover() {
|
|
private fun changeSelectedCover() {
|
|
val manga = selectedMangas.firstOrNull() ?: return
|
|
val manga = selectedMangas.firstOrNull() ?: return
|