0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-26 21:13:01 +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.navigation.findNavController
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.switchmaterial.SwitchMaterial
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.base.BaseFragment 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.MiuiHelper
import com.vanced.manager.utils.PackageHelper.uninstallApk 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?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -30,37 +31,33 @@ open class Home : BaseFragment(), View.OnClickListener, AdapterView.OnItemSelect
val signaturebtn = view.findViewById<MaterialButton>(R.id.signature_button) val signaturebtn = view.findViewById<MaterialButton>(R.id.signature_button)
val microguninstallbtn = view.findViewById<ImageView>(R.id.microg_uninstallbtn) val microguninstallbtn = view.findViewById<ImageView>(R.id.microg_uninstallbtn)
val vanceduninstallbtn = view.findViewById<ImageView>(R.id.vanced_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") 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) vancedinstallbtn.setOnClickListener(this)
microginstallbtn.setOnClickListener(this) microginstallbtn.setOnClickListener(this)
signaturebtn.setOnClickListener(this) signaturebtn.setOnClickListener(this)
microguninstallbtn.setOnClickListener(this) microguninstallbtn.setOnClickListener(this)
vanceduninstallbtn.setOnClickListener(this) vanceduninstallbtn.setOnClickListener(this)
switch.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
if (Shell.rootAccess())
writeToVariantPref("root")
else
writeToVariantPref("nonroot")
} else {
writeToVariantPref("nonroot")
}
}
when (variantPref) { when (variantPref) {
"nonroot" -> spinner.setSelection(0) "nonroot" -> switch.isChecked = false
"root" -> { "root" -> {
if (Shell.rootAccess()) switch.isChecked = Shell.rootAccess()
spinner.setSelection(1)
else
spinner.setSelection(0)
} }
} }
spinner.onItemSelectedListener = this
} }
override fun onResume() { override fun onResume() {
@ -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) { private fun writeToVariantPref(variant: String) {
val prefs = getDefaultSharedPreferences(activity) val prefs = getDefaultSharedPreferences(activity)
if (prefs.getString("vanced_variant", "nonroot") != variant) { if (prefs.getString("vanced_variant", "nonroot") != variant) {

View file

@ -1,5 +1,6 @@
package com.vanced.manager.ui.fragments package com.vanced.manager.ui.fragments
import android.animation.LayoutTransition
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
@ -10,7 +11,6 @@ import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.* import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.Animation import android.view.animation.Animation
import android.view.animation.RotateAnimation import android.view.animation.RotateAnimation
import android.widget.* 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 { view.findViewById<ImageButton>(R.id.changelog_button).setOnClickListener {
cardExpandCollapse() cardExpandCollapse()
} }

View file

@ -34,6 +34,8 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
private val pm = application.packageManager private val pm = application.packageManager
val variantSwitchTxt = "Variant: $variant"
val microgInstalled: Boolean = isPackageInstalled("com.mgoogle.android.gms", application.packageManager) val microgInstalled: Boolean = isPackageInstalled("com.mgoogle.android.gms", application.packageManager)
val vancedInstalled: Boolean = isPackageInstalled(vancedPkgName, 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:layout_marginTop="4dp"
android:orientation="vertical"> android:orientation="vertical">
<Spinner <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/home_variant_selector" android:id="@+id/variant_switcher"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:text="@{viewModel.variantSwitchTxt}"/>
android:layout_marginTop="@dimen/eightdp"
android:layout_marginEnd="@dimen/stdp" />
<include <include
layout="@layout/include_vanced" layout="@layout/include_vanced"

View file

@ -29,7 +29,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/arrow_down" android:src="@drawable/arrow_down"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:background="@android:color/transparent"/> android:background="@android:color/transparent" />
</RelativeLayout> </RelativeLayout>
@ -41,13 +41,17 @@
app:tabIndicatorColor="?colorPrimary" app:tabIndicatorColor="?colorPrimary"
app:tabSelectedTextColor="?colorPrimary" app:tabSelectedTextColor="?colorPrimary"
app:tabTextColor="?colorPrimary" app:tabTextColor="?colorPrimary"
app:layout_constraintTop_toBottomOf="parent" /> app:layout_constraintTop_toBottomOf="parent"
android:visibility="gone"
tools:visibility="visible"/>
<androidx.viewpager2.widget.ViewPager2 <androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager" android:id="@+id/viewpager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"/> android:layout_weight="1"
android:visibility="gone"
tools:visibility="visible"/>
</LinearLayout> </LinearLayout>