diff --git a/app/src/main/java/com/vanced/manager/core/fragments/Home.kt b/app/src/main/java/com/vanced/manager/core/fragments/Home.kt index f7084f76..998c9e9e 100644 --- a/app/src/main/java/com/vanced/manager/core/fragments/Home.kt +++ b/app/src/main/java/com/vanced/manager/core/fragments/Home.kt @@ -9,6 +9,7 @@ import android.widget.* import androidx.navigation.findNavController import androidx.preference.PreferenceManager.getDefaultSharedPreferences import com.google.android.material.button.MaterialButton +import com.google.android.material.switchmaterial.SwitchMaterial import com.topjohnwu.superuser.Shell import com.vanced.manager.R import com.vanced.manager.core.base.BaseFragment @@ -20,7 +21,7 @@ import com.vanced.manager.ui.dialogs.DialogContainer.secondMiuiDialog import com.vanced.manager.utils.MiuiHelper import com.vanced.manager.utils.PackageHelper.uninstallApk -open class Home : BaseFragment(), View.OnClickListener, AdapterView.OnItemSelectedListener { +open class Home : BaseFragment(), View.OnClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -30,36 +31,32 @@ open class Home : BaseFragment(), View.OnClickListener, AdapterView.OnItemSelect val signaturebtn = view.findViewById(R.id.signature_button) val microguninstallbtn = view.findViewById(R.id.microg_uninstallbtn) val vanceduninstallbtn = view.findViewById(R.id.vanced_uninstallbtn) - val spinner: Spinner = view.findViewById(R.id.home_variant_selector) + val switch: SwitchMaterial = view.findViewById(R.id.variant_switcher) val variantPref = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot") - activity?.let { - ArrayAdapter.createFromResource(it, - R.array.vanced_variant, - android.R.layout.simple_spinner_item).also { arrayAdapter -> - arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) - spinner.adapter = arrayAdapter - } - } - vancedinstallbtn.setOnClickListener(this) microginstallbtn.setOnClickListener(this) signaturebtn.setOnClickListener(this) microguninstallbtn.setOnClickListener(this) vanceduninstallbtn.setOnClickListener(this) - - when (variantPref) { - "nonroot" -> spinner.setSelection(0) - "root" -> { + switch.setOnCheckedChangeListener { _, isChecked -> + if (isChecked) { if (Shell.rootAccess()) - spinner.setSelection(1) + writeToVariantPref("root") else - spinner.setSelection(0) + writeToVariantPref("nonroot") + } else { + writeToVariantPref("nonroot") } } - spinner.onItemSelectedListener = this + when (variantPref) { + "nonroot" -> switch.isChecked = false + "root" -> { + switch.isChecked = Shell.rootAccess() + } + } } @@ -140,22 +137,6 @@ open class Home : BaseFragment(), View.OnClickListener, AdapterView.OnItemSelect } } - override fun onNothingSelected(parent: AdapterView<*>?) { - TODO("Ehh we don't need it") - } - - override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - when (position) { - 0 -> writeToVariantPref("nonroot") - 1 -> { - if (Shell.rootAccess()) - writeToVariantPref("root") - else - writeToVariantPref("nonroot") - } - } - } - private fun writeToVariantPref(variant: String) { val prefs = getDefaultSharedPreferences(activity) if (prefs.getString("vanced_variant", "nonroot") != variant) { diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt index 7394ec31..2338a61c 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt @@ -1,5 +1,6 @@ package com.vanced.manager.ui.fragments +import android.animation.LayoutTransition import android.annotation.SuppressLint import android.content.BroadcastReceiver import android.content.Context @@ -10,7 +11,6 @@ import android.graphics.Color import android.os.Bundle import android.util.Log import android.view.* -import android.view.animation.AccelerateDecelerateInterpolator import android.view.animation.Animation import android.view.animation.RotateAnimation import android.widget.* @@ -72,6 +72,7 @@ class HomeFragment : Home() { } } + view.findViewById(R.id.changelog_card).layoutTransition.enableTransitionType(LayoutTransition.CHANGING) view.findViewById(R.id.changelog_button).setOnClickListener { cardExpandCollapse() } diff --git a/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt b/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt index 15adb912..9626b4c8 100644 --- a/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt +++ b/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt @@ -34,6 +34,8 @@ class HomeViewModel(application: Application): AndroidViewModel(application) { private val pm = application.packageManager + val variantSwitchTxt = "Variant: $variant" + val microgInstalled: Boolean = isPackageInstalled("com.mgoogle.android.gms", application.packageManager) val vancedInstalled: Boolean = isPackageInstalled(vancedPkgName, application.packageManager) diff --git a/app/src/main/res/drawable/arrow_down.xml b/app/src/main/res/drawable/arrow_down.xml new file mode 100644 index 00000000..ad33063c --- /dev/null +++ b/app/src/main/res/drawable/arrow_down.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 08e6368b..2ce23c7d 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -27,13 +27,11 @@ android:layout_marginTop="4dp" android:orientation="vertical"> - + android:text="@{viewModel.variantSwitchTxt}"/> + android:background="@android:color/transparent" /> @@ -41,13 +41,17 @@ app:tabIndicatorColor="?colorPrimary" app:tabSelectedTextColor="?colorPrimary" app:tabTextColor="?colorPrimary" - app:layout_constraintTop_toBottomOf="parent" /> + app:layout_constraintTop_toBottomOf="parent" + android:visibility="gone" + tools:visibility="visible"/> + android:layout_weight="1" + android:visibility="gone" + tools:visibility="visible"/>