0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-23 03:35:11 +00:00

changed spinner to switch

This commit is contained in:
X1nto 2020-06-25 21:19:44 +04:00
parent d930b04f20
commit 4e68ad63f2
6 changed files with 38 additions and 43 deletions

View file

@ -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<MaterialButton>(R.id.signature_button)
val microguninstallbtn = view.findViewById<ImageView>(R.id.microg_uninstallbtn)
val vanceduninstallbtn = view.findViewById<ImageView>(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) {

View file

@ -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<ViewGroup>(R.id.changelog_card).layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
view.findViewById<ImageButton>(R.id.changelog_button).setOnClickListener {
cardExpandCollapse()
}

View file

@ -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)

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M7.41,7.84L12,12.42l4.59,-4.58L18,9.25l-6,6 -6,-6z"/>
</vector>

View file

@ -27,13 +27,11 @@
android:layout_marginTop="4dp"
android:orientation="vertical">
<Spinner
android:id="@+id/home_variant_selector"
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/variant_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="@dimen/eightdp"
android:layout_marginEnd="@dimen/stdp" />
android:text="@{viewModel.variantSwitchTxt}"/>
<include
layout="@layout/include_vanced"

View file

@ -29,7 +29,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_down"
android:layout_alignParentEnd="true"
android:background="@android:color/transparent"/>
android:background="@android:color/transparent" />
</RelativeLayout>
@ -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"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
android:layout_weight="1"
android:visibility="gone"
tools:visibility="visible"/>
</LinearLayout>