|
|
|
@ -1,14 +1,17 @@
|
|
|
|
package org.koitharu.kotatsu.main.ui
|
|
|
|
package org.koitharu.kotatsu.main.ui
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.MenuItem
|
|
|
|
import androidx.activity.OnBackPressedCallback
|
|
|
|
import androidx.activity.OnBackPressedCallback
|
|
|
|
import androidx.annotation.IdRes
|
|
|
|
import androidx.annotation.IdRes
|
|
|
|
|
|
|
|
import androidx.core.view.isEmpty
|
|
|
|
import androidx.core.view.iterator
|
|
|
|
import androidx.core.view.iterator
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
import com.google.android.material.navigation.NavigationBarView
|
|
|
|
import com.google.android.material.navigation.NavigationBarView
|
|
|
|
import com.google.android.material.transition.MaterialFadeThrough
|
|
|
|
import com.google.android.material.transition.MaterialFadeThrough
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
|
|
|
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
|
|
|
@ -23,7 +26,10 @@ private const val TAG_PRIMARY = "primary"
|
|
|
|
class MainNavigationDelegate(
|
|
|
|
class MainNavigationDelegate(
|
|
|
|
private val navBar: NavigationBarView,
|
|
|
|
private val navBar: NavigationBarView,
|
|
|
|
private val fragmentManager: FragmentManager,
|
|
|
|
private val fragmentManager: FragmentManager,
|
|
|
|
) : OnBackPressedCallback(false), NavigationBarView.OnItemSelectedListener, NavigationBarView.OnItemReselectedListener {
|
|
|
|
private val settings: AppSettings,
|
|
|
|
|
|
|
|
) : OnBackPressedCallback(false),
|
|
|
|
|
|
|
|
NavigationBarView.OnItemSelectedListener,
|
|
|
|
|
|
|
|
NavigationBarView.OnItemReselectedListener {
|
|
|
|
|
|
|
|
|
|
|
|
private val listeners = LinkedList<OnFragmentChangedListener>()
|
|
|
|
private val listeners = LinkedList<OnFragmentChangedListener>()
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,14 +62,26 @@ class MainNavigationDelegate(
|
|
|
|
navBar.selectedItemId = R.id.nav_history
|
|
|
|
navBar.selectedItemId = R.id.nav_history
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun onCreate() {
|
|
|
|
fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
primaryFragment?.let {
|
|
|
|
if (navBar.menu.isEmpty()) {
|
|
|
|
onFragmentChanged(it, fromUser = false)
|
|
|
|
val menuRes = if (settings.isFavoritesNavItemFirst) R.menu.nav_bottom_alt else R.menu.nav_bottom
|
|
|
|
val itemId = getItemId(it)
|
|
|
|
navBar.inflateMenu(menuRes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
val fragment = primaryFragment
|
|
|
|
|
|
|
|
if (fragment != null) {
|
|
|
|
|
|
|
|
onFragmentChanged(fragment, fromUser = false)
|
|
|
|
|
|
|
|
val itemId = getItemId(fragment)
|
|
|
|
if (navBar.selectedItemId != itemId) {
|
|
|
|
if (navBar.selectedItemId != itemId) {
|
|
|
|
navBar.selectedItemId = itemId
|
|
|
|
navBar.selectedItemId = itemId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} ?: onNavigationItemSelected(navBar.selectedItemId)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
val itemId = if (savedInstanceState == null) {
|
|
|
|
|
|
|
|
firstItem()?.itemId ?: navBar.selectedItemId
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
navBar.selectedItemId
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
onNavigationItemSelected(itemId)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun setCounterAt(position: Int, counter: Int) {
|
|
|
|
fun setCounterAt(position: Int, counter: Int) {
|
|
|
|
|