|
@@ -7,17 +7,22 @@ import android.support.v7.widget.RecyclerView
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
+import android.view.animation.AnimationUtils
|
|
|
import com.f2prateek.rx.preferences.Preference
|
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|
|
+import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
|
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment
|
|
|
import eu.kanade.tachiyomi.ui.manga.MangaActivity
|
|
|
import eu.kanade.tachiyomi.util.toast
|
|
|
+import kotlinx.android.synthetic.main.fragment_catalogue.*
|
|
|
+import kotlinx.android.synthetic.main.fragment_library.*
|
|
|
import kotlinx.android.synthetic.main.fragment_library_category.*
|
|
|
import rx.Subscription
|
|
|
+import uy.kohesive.injekt.injectLazy
|
|
|
|
|
|
/**
|
|
|
* Fragment containing the library manga for a certain category.
|
|
@@ -25,6 +30,11 @@ import rx.Subscription
|
|
|
*/
|
|
|
class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemClickListener {
|
|
|
|
|
|
+ /**
|
|
|
+ * Preferences.
|
|
|
+ */
|
|
|
+ val preferences: PreferencesHelper by injectLazy()
|
|
|
+
|
|
|
/**
|
|
|
* Adapter to hold the manga in this category.
|
|
|
*/
|
|
@@ -46,11 +56,21 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
|
*/
|
|
|
private var numColumnsSubscription: Subscription? = null
|
|
|
|
|
|
+ /**
|
|
|
+ * subscription to view toggle
|
|
|
+ */
|
|
|
+ private var toggleViewSubscription: Subscription? = null
|
|
|
+
|
|
|
/**
|
|
|
* Subscription of the library search.
|
|
|
*/
|
|
|
private var searchSubscription: Subscription? = null
|
|
|
|
|
|
+ /**
|
|
|
+ * display mode
|
|
|
+ */
|
|
|
+ private var displayAsList: Boolean = false;
|
|
|
+
|
|
|
companion object {
|
|
|
/**
|
|
|
* Key to save and restore [position] from a [Bundle].
|
|
@@ -66,19 +86,29 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
|
fun newInstance(position: Int): LibraryCategoryFragment {
|
|
|
val fragment = LibraryCategoryFragment()
|
|
|
fragment.position = position
|
|
|
+
|
|
|
return fragment
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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?) {
|
|
|
adapter = LibraryCategoryAdapter(this)
|
|
|
+
|
|
|
+ //set up grid
|
|
|
recycler.setHasFixedSize(true)
|
|
|
recycler.adapter = adapter
|
|
|
|
|
|
+ //set up list
|
|
|
+ library_list.setHasFixedSize(true)
|
|
|
+ library_list.adapter = adapter
|
|
|
+ library_list.layoutManager = LinearLayoutManager(activity)
|
|
|
+
|
|
|
if (libraryFragment.actionMode != null) {
|
|
|
setSelectionMode(FlexibleAdapter.MODE_MULTI)
|
|
|
}
|
|
@@ -94,6 +124,17 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
|
adapter.updateDataSet()
|
|
|
}
|
|
|
|
|
|
+ toggleViewSubscription = preferences.libraryAsList().asObservable().subscribe {onViewModeChange(it)}
|
|
|
+
|
|
|
+ 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)
|
|
|
+
|
|
|
if (savedState != null) {
|
|
|
position = savedState.getInt(POSITION_KEY)
|
|
|
adapter.onRestoreInstanceState(savedState)
|
|
@@ -129,13 +170,17 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
|
override fun onDestroyView() {
|
|
|
numColumnsSubscription?.unsubscribe()
|
|
|
searchSubscription?.unsubscribe()
|
|
|
+ toggleViewSubscription?.unsubscribe()
|
|
|
super.onDestroyView()
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
+
|
|
|
+
|
|
|
libraryMangaSubscription = libraryPresenter.libraryMangaSubject
|
|
|
.subscribe { onNextLibraryManga(it) }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
override fun onPause() {
|
|
@@ -211,6 +256,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
|
startActivity(intent)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* Toggles the selection for a manga.
|
|
|
*
|
|
@@ -262,6 +308,15 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun onViewModeChange(isList: Boolean) {
|
|
|
+ //do nothing if the display does not need to change
|
|
|
+ if(isList == displayAsList) return
|
|
|
+
|
|
|
+ //else change view and display mode
|
|
|
+ library_switcher.showNext()
|
|
|
+ displayAsList = isList
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Property to get the library fragment.
|
|
|
*/
|