mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-30 23:48:31 +00:00
Added forced loading per user's demand
Added reselecting action (scroll up real fast)
This commit is contained in:
@@ -72,6 +72,9 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
|
||||
}.dispatchOnSelf()
|
||||
true
|
||||
}
|
||||
binding.mainNavigation.setOnNavigationItemReselectedListener {
|
||||
navigation.onReselected()
|
||||
}
|
||||
|
||||
binding.mainNavigation.viewTreeObserver.addOnGlobalLayoutListener(navObserver)
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.topjohnwu.magisk.redesign
|
||||
|
||||
interface ReselectionTarget {
|
||||
|
||||
fun onReselected()
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.model.navigation.MagiskAnimBuilder
|
||||
import com.topjohnwu.magisk.model.navigation.MagiskNavigationEvent
|
||||
import com.topjohnwu.magisk.model.navigation.Navigator
|
||||
import com.topjohnwu.magisk.redesign.ReselectionTarget
|
||||
import timber.log.Timber
|
||||
|
||||
class CompatNavigationDelegate<out Source>(
|
||||
@@ -44,6 +45,10 @@ class CompatNavigationDelegate<out Source>(
|
||||
fun onSaveInstanceState(outState: Bundle) =
|
||||
controller.onSaveInstanceState(outState)
|
||||
|
||||
fun onReselected() {
|
||||
(controller.currentFrag as? ReselectionTarget)?.onReselected()
|
||||
}
|
||||
|
||||
fun onBackPressed(): Boolean {
|
||||
val fragment = controller.currentFrag as? CompatFragment<*, *>
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.core.view.isVisible
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginEnd
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.circularreveal.CircularRevealCompat
|
||||
import com.google.android.material.circularreveal.CircularRevealWidget
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
@@ -61,8 +62,10 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_focus_up -> binding.hideContent
|
||||
.also { it.scrollToPosition(10) }
|
||||
.also { it.smoothScrollToPosition(0) }
|
||||
.takeIf { (it.layoutManager as? LinearLayoutManager)?.findFirstVisibleItemPosition() ?: 0 > 10 }
|
||||
?.also { it.scrollToPosition(10) }
|
||||
.let { binding.hideContent }
|
||||
.also { it.post { it.smoothScrollToPosition(0) } }
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
@@ -2,17 +2,23 @@ package com.topjohnwu.magisk.redesign.module
|
||||
|
||||
import android.graphics.Insets
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
|
||||
import com.topjohnwu.magisk.redesign.MainActivity
|
||||
import com.topjohnwu.magisk.redesign.ReselectionTarget
|
||||
import com.topjohnwu.magisk.redesign.compat.CompatFragment
|
||||
import com.topjohnwu.magisk.redesign.compat.hideKeyboard
|
||||
import com.topjohnwu.magisk.redesign.hide.MotionRevealHelper
|
||||
import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
|
||||
class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>() {
|
||||
class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>(),
|
||||
ReselectionTarget {
|
||||
|
||||
override val layoutRes = R.layout.fragment_module_md2
|
||||
override val viewModel by viewModel<ModuleViewModel>()
|
||||
@@ -23,6 +29,7 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setHasOptionsMenu(true)
|
||||
activity.title = resources.getString(R.string.section_modules)
|
||||
}
|
||||
|
||||
@@ -50,6 +57,35 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_module_md2, menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_refresh -> viewModel.loadRemoteImplicit()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
override fun onReselected() {
|
||||
binding.moduleRemote
|
||||
.takeIf {
|
||||
(it.layoutManager as? StaggeredGridLayoutManager)?.let {
|
||||
it.findFirstVisibleItemPositions(IntArray(it.spanCount)).min()
|
||||
} ?: 0 > 10
|
||||
}
|
||||
?.also { it.scrollToPosition(10) }
|
||||
.let { binding.moduleRemote }
|
||||
.also { it.post { it.smoothScrollToPosition(0) } }
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
override fun onPreBind(binding: FragmentModuleMd2Binding) = Unit
|
||||
|
||||
private fun setEndlessScroller() {
|
||||
|
||||
@@ -111,6 +111,7 @@ class ModuleViewModel(
|
||||
.map { it.order() }
|
||||
.map { build(active = it) }
|
||||
.map { it to items.calculateDiff(it) }
|
||||
.applyViewModel(this)
|
||||
.subscribeK {
|
||||
items.update(it.first, it.second)
|
||||
if (!items.contains(sectionRemote)) {
|
||||
@@ -119,6 +120,13 @@ class ModuleViewModel(
|
||||
moveToState()
|
||||
}
|
||||
|
||||
fun loadRemoteImplicit() = downloadRepos()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnComplete { items.clear(); itemsSearch.clear() }
|
||||
.applyViewModel(this, false)
|
||||
.subscribeK { refresh(); submitQuery() }
|
||||
.add()
|
||||
|
||||
@Synchronized
|
||||
fun loadRemote() {
|
||||
// check for existing jobs
|
||||
|
||||
Reference in New Issue
Block a user