(Re)Added animations and shortcut endpoints
Fixed first backpress closing the app instead of showing default fragment
This commit is contained in:
parent
f3cd9a096a
commit
d52210dd90
@ -79,4 +79,6 @@ class MagiskAnimBuilder {
|
|||||||
@AnimRes
|
@AnimRes
|
||||||
@AnimatorRes
|
@AnimatorRes
|
||||||
var popExit = 0
|
var popExit = 0
|
||||||
|
|
||||||
|
val anySet: Boolean get() = enter != 0 || exit != 0 || popEnter != 0 || popExit != 0
|
||||||
}
|
}
|
@ -40,6 +40,16 @@ object Navigation {
|
|||||||
navDirections { destination = SettingsFragment::class }
|
navDirections { destination = SettingsFragment::class }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun fromSection(section: String) = when (section) {
|
||||||
|
"superuser" -> superuser()
|
||||||
|
"modules" -> modules()
|
||||||
|
"downloads" -> repos()
|
||||||
|
"magiskhide" -> hide()
|
||||||
|
"log" -> log()
|
||||||
|
"settings" -> settings()
|
||||||
|
else -> home()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
object Main {
|
object Main {
|
||||||
const val OPEN_NAV = 1
|
const val OPEN_NAV = 1
|
||||||
|
@ -6,6 +6,7 @@ import androidx.core.view.GravityCompat
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.topjohnwu.magisk.ClassMap
|
import com.topjohnwu.magisk.ClassMap
|
||||||
import com.topjohnwu.magisk.Config
|
import com.topjohnwu.magisk.Config
|
||||||
|
import com.topjohnwu.magisk.Const.Key.OPEN_SECTION
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.databinding.ActivityMainBinding
|
import com.topjohnwu.magisk.databinding.ActivityMainBinding
|
||||||
import com.topjohnwu.magisk.model.navigation.Navigation
|
import com.topjohnwu.magisk.model.navigation.Navigation
|
||||||
@ -23,6 +24,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import com.topjohnwu.magisk.ui.home.MagiskFragment as HomeFragment
|
import com.topjohnwu.magisk.ui.home.MagiskFragment as HomeFragment
|
||||||
|
|
||||||
|
|
||||||
open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
|
open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
|
||||||
|
|
||||||
override val layoutRes: Int = R.layout.activity_main
|
override val layoutRes: Int = R.layout.activity_main
|
||||||
@ -54,6 +56,11 @@ open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
|
|||||||
checkHideSection()
|
checkHideSection()
|
||||||
setSupportActionBar(binding.mainInclude.mainToolbar)
|
setSupportActionBar(binding.mainInclude.mainToolbar)
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
intent.getStringExtra(OPEN_SECTION)?.let {
|
||||||
|
onEventDispatched(Navigation.fromSection(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setTitle(title: CharSequence?) {
|
override fun setTitle(title: CharSequence?) {
|
||||||
|
@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatDelegate
|
|||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.databinding.ViewDataBinding
|
import androidx.databinding.ViewDataBinding
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.FragmentTransaction
|
||||||
import com.karumi.dexter.Dexter
|
import com.karumi.dexter.Dexter
|
||||||
import com.karumi.dexter.MultiplePermissionsReport
|
import com.karumi.dexter.MultiplePermissionsReport
|
||||||
import com.karumi.dexter.PermissionToken
|
import com.karumi.dexter.PermissionToken
|
||||||
@ -146,7 +147,15 @@ abstract class MagiskActivity<ViewModel : MagiskViewModel, Binding : ViewDataBin
|
|||||||
try {
|
try {
|
||||||
navigationController?.popFragment() ?: throw UnsupportedOperationException()
|
navigationController?.popFragment() ?: throw UnsupportedOperationException()
|
||||||
} catch (e: UnsupportedOperationException) {
|
} catch (e: UnsupportedOperationException) {
|
||||||
super.onBackPressed()
|
when {
|
||||||
|
navigationController?.currentStackIndex != defaultPosition -> {
|
||||||
|
val options = FragNavTransactionOptions.newBuilder()
|
||||||
|
.transition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
|
||||||
|
.build()
|
||||||
|
navigationController?.switchTab(defaultPosition, options)
|
||||||
|
}
|
||||||
|
else -> super.onBackPressed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +182,10 @@ abstract class MagiskActivity<ViewModel : MagiskViewModel, Binding : ViewDataBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun FragNavTransactionOptions.Builder.customAnimations(options: MagiskAnimBuilder) =
|
private fun FragNavTransactionOptions.Builder.customAnimations(options: MagiskAnimBuilder) =
|
||||||
customAnimations(options.enter, options.exit, options.popEnter, options.popExit)
|
customAnimations(options.enter, options.exit, options.popEnter, options.popExit).apply {
|
||||||
|
if (!options.anySet) {
|
||||||
|
transition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user