From 512f533a801d535e2dd36e42f1f7277bbb76fb12 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Fri, 18 Oct 2019 17:04:41 +0200 Subject: [PATCH] Added hide fragment for future use --- .../com/topjohnwu/magisk/di/RedesignModule.kt | 2 + .../magisk/model/navigation/Navigation.kt | 8 ++- .../topjohnwu/magisk/redesign/MainActivity.kt | 30 ++++++++- .../magisk/redesign/compat/CompatView.kt | 2 +- .../magisk/redesign/hide/HideFragment.kt | 20 ++++++ .../magisk/redesign/hide/HideViewModel.kt | 5 ++ .../redesign/superuser/SuperuserFragment.kt | 3 + .../redesign/superuser/SuperuserViewModel.kt | 7 ++- app/src/main/res/layout/fragment_hide_md2.xml | 23 +++++++ .../res/layout/fragment_superuser_md2.xml | 62 ++++++++++++++++++- 10 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideFragment.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt create mode 100644 app/src/main/res/layout/fragment_hide_md2.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt index da9203782..1bd14e65e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.di import com.topjohnwu.magisk.redesign.MainViewModel import com.topjohnwu.magisk.redesign.flash.FlashViewModel +import com.topjohnwu.magisk.redesign.hide.HideViewModel import com.topjohnwu.magisk.redesign.home.HomeViewModel import com.topjohnwu.magisk.redesign.log.LogViewModel import com.topjohnwu.magisk.redesign.module.ModuleViewModel @@ -15,6 +16,7 @@ import org.koin.dsl.module val redesignModule = module { viewModel { FlashViewModel() } + viewModel { HideViewModel() } viewModel { HomeViewModel(get()) } viewModel { LogViewModel() } viewModel { ModuleViewModel() } 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 af53b1662..15a03c094 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 @@ -15,6 +15,7 @@ import com.topjohnwu.magisk.ui.module.ReposFragment import com.topjohnwu.magisk.ui.settings.SettingsFragment import com.topjohnwu.magisk.ui.superuser.SuperuserFragment import com.topjohnwu.magisk.redesign.MainActivity as RedesignActivity +import com.topjohnwu.magisk.redesign.hide.HideFragment as RedesignHideFragment import com.topjohnwu.magisk.redesign.home.HomeFragment as RedesignHomeFragment import com.topjohnwu.magisk.redesign.log.LogFragment as RedesignLogFragment import com.topjohnwu.magisk.redesign.module.ModuleFragment as RedesignModulesFragment @@ -61,7 +62,12 @@ object Navigation { } fun hide() = MagiskNavigationEvent { - navDirections { destination = MagiskHideFragment::class } + navDirections { + destination = when { + Config.redesign -> RedesignHideFragment::class + else -> MagiskHideFragment::class + } + } } fun log() = MagiskNavigationEvent { diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt index 37bbbee26..1a0a43521 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt @@ -2,11 +2,15 @@ package com.topjohnwu.magisk.redesign import android.graphics.Insets import android.os.Bundle +import android.view.MenuItem +import android.view.ViewGroup import android.view.ViewTreeObserver import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.view.isVisible import androidx.core.view.setPadding import androidx.core.view.updateLayoutParams import androidx.fragment.app.Fragment +import androidx.interpolator.view.animation.FastOutSlowInInterpolator import com.google.android.material.card.MaterialCardView import com.ncapdevi.fragnav.FragNavController import com.topjohnwu.magisk.Const @@ -92,6 +96,14 @@ open class MainActivity : CompatActivity( super.onDestroy() } + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + android.R.id.home -> onBackPressed() + else -> return super.onOptionsItemSelected(item) + } + return true + } + override fun onTabTransaction(fragment: Fragment?, index: Int) { setDisplayHomeAsUpEnabled(false) } @@ -99,9 +111,21 @@ open class MainActivity : CompatActivity( override fun onFragmentTransaction( fragment: Fragment?, transactionType: FragNavController.TransactionType - ) = when (transactionType) { - FragNavController.TransactionType.PUSH -> setDisplayHomeAsUpEnabled(!navigation.isRoot) - else -> Unit //dunno might be useful + ) { + setDisplayHomeAsUpEnabled(!navigation.isRoot) + + val lapam = binding.mainBottomBar.layoutParams as ViewGroup.MarginLayoutParams + val height = binding.mainBottomBar.measuredHeight + val verticalMargin = lapam.let { it.topMargin + it.bottomMargin } + val maxTranslation = height + verticalMargin + val translation = if (navigation.isRoot) 0 else maxTranslation + + binding.mainBottomBar.animate() + .translationY(translation.toFloat()) + .setInterpolator(FastOutSlowInInterpolator()) + .withStartAction { if (translation == 0) binding.mainBottomBar.isVisible = true } + .withEndAction { if (translation > 0) binding.mainBottomBar.isVisible = false } + .start() } override fun peekSystemWindowInsets(insets: Insets) { diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatView.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatView.kt index 6257716c7..941fadcc6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatView.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatView.kt @@ -10,6 +10,6 @@ internal interface CompatView { val navigation: CompatNavigationDelegate<*>? fun peekSystemWindowInsets(insets: Insets) = Unit - fun consumeSystemWindowInsets(insets: Insets) = Insets.NONE + fun consumeSystemWindowInsets(insets: Insets): Insets? = null } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideFragment.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideFragment.kt new file mode 100644 index 000000000..d6d9459b4 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideFragment.kt @@ -0,0 +1,20 @@ +package com.topjohnwu.magisk.redesign.hide + +import android.content.Context +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.databinding.FragmentHideMd2Binding +import com.topjohnwu.magisk.redesign.compat.CompatFragment +import org.koin.androidx.viewmodel.ext.android.viewModel + +class HideFragment : CompatFragment() { + + override val layoutRes = R.layout.fragment_hide_md2 + override val viewModel by viewModel() + + override fun onAttach(context: Context) { + super.onAttach(context) + + activity.setTitle(R.string.magiskhide) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt new file mode 100644 index 000000000..683d5007d --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt @@ -0,0 +1,5 @@ +package com.topjohnwu.magisk.redesign.hide + +import com.topjohnwu.magisk.redesign.compat.CompatViewModel + +class HideViewModel : CompatViewModel() \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserFragment.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserFragment.kt index cbaa8f459..1e3d3a772 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserFragment.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.redesign.superuser +import android.graphics.Insets import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.FragmentSuperuserMd2Binding import com.topjohnwu.magisk.redesign.compat.CompatFragment @@ -10,6 +11,8 @@ class SuperuserFragment : CompatFragment() + override fun consumeSystemWindowInsets(insets: Insets) = insets + override fun onStart() { super.onStart() diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt index f5f7e57f7..868d200af 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt @@ -1,5 +1,10 @@ package com.topjohnwu.magisk.redesign.superuser +import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.redesign.compat.CompatViewModel -class SuperuserViewModel : CompatViewModel() \ No newline at end of file +class SuperuserViewModel : CompatViewModel() { + + fun hidePressed() = Navigation.hide().publish() + +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_hide_md2.xml b/app/src/main/res/layout/fragment_hide_md2.xml new file mode 100644 index 000000000..30bddc477 --- /dev/null +++ b/app/src/main/res/layout/fragment_hide_md2.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_superuser_md2.xml b/app/src/main/res/layout/fragment_superuser_md2.xml index 9bc1e4587..d8bb7c4c3 100644 --- a/app/src/main/res/layout/fragment_superuser_md2.xml +++ b/app/src/main/res/layout/fragment_superuser_md2.xml @@ -1,5 +1,7 @@ - + @@ -12,11 +14,65 @@ + android:clipToPadding="false" + android:fillViewport="true" + android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l2}" + android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l2}" + tools:layout_marginTop="24dp"> + android:layout_height="wrap_content"> + + + + + + + + + + + + + + + +