From d52210dd901d2548e2a3092aa01ad6ef3f126ceb Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 27 Apr 2019 12:08:41 +0200 Subject: [PATCH] (Re)Added animations and shortcut endpoints Fixed first backpress closing the app instead of showing default fragment --- .../model/navigation/MagiskNavigationEvent.kt | 2 ++ .../magisk/model/navigation/Navigation.kt | 10 ++++++++++ .../com/topjohnwu/magisk/ui/MainActivity.kt | 7 +++++++ .../topjohnwu/magisk/ui/base/MagiskActivity.kt | 17 +++++++++++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/navigation/MagiskNavigationEvent.kt b/app/src/main/java/com/topjohnwu/magisk/model/navigation/MagiskNavigationEvent.kt index 8cdc0fda3..793c2a4c2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/navigation/MagiskNavigationEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/navigation/MagiskNavigationEvent.kt @@ -79,4 +79,6 @@ class MagiskAnimBuilder { @AnimRes @AnimatorRes var popExit = 0 + + val anySet: Boolean get() = enter != 0 || exit != 0 || popEnter != 0 || popExit != 0 } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt index ea1e6ac98..361c79cb9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt @@ -40,6 +40,16 @@ object Navigation { 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 { const val OPEN_NAV = 1 diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index fa144e0ec..6ab8b1e81 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -6,6 +6,7 @@ import androidx.core.view.GravityCompat import androidx.fragment.app.Fragment import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.Config +import com.topjohnwu.magisk.Const.Key.OPEN_SECTION import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ActivityMainBinding import com.topjohnwu.magisk.model.navigation.Navigation @@ -23,6 +24,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel import kotlin.reflect.KClass import com.topjohnwu.magisk.ui.home.MagiskFragment as HomeFragment + open class MainActivity : MagiskActivity() { override val layoutRes: Int = R.layout.activity_main @@ -54,6 +56,11 @@ open class MainActivity : MagiskActivity() { checkHideSection() setSupportActionBar(binding.mainInclude.mainToolbar) + if (savedInstanceState == null) { + intent.getStringExtra(OPEN_SECTION)?.let { + onEventDispatched(Navigation.fromSection(it)) + } + } } override fun setTitle(title: CharSequence?) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt index c12de4a3e..71f66a7ff 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatDelegate import androidx.core.net.toUri import androidx.databinding.ViewDataBinding import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentTransaction import com.karumi.dexter.Dexter import com.karumi.dexter.MultiplePermissionsReport import com.karumi.dexter.PermissionToken @@ -146,7 +147,15 @@ abstract class MagiskActivity { + val options = FragNavTransactionOptions.newBuilder() + .transition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE) + .build() + navigationController?.switchTab(defaultPosition, options) + } + else -> super.onBackPressed() + } } } @@ -173,6 +182,10 @@ abstract class MagiskActivity