0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2025-01-06 23:41:00 +00:00

ux improvements

This commit is contained in:
X1nto 2020-08-04 14:02:36 +04:00
parent 9906ea9d0d
commit 6429f32660
9 changed files with 152 additions and 169 deletions

View file

@ -1,48 +0,0 @@
package com.vanced.manager.core.fragments
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.widget.Toast
import androidx.preference.PreferenceManager
import com.vanced.manager.core.base.BaseFragment
open class About : BaseFragment() {
private var count = 0
private var startMillSec: Long = 0
@SuppressLint("ClickableViewAccessibility")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.setOnTouchListener { _, event: MotionEvent ->
val eventAction = event.action
if (eventAction == MotionEvent.ACTION_UP) {
val time = System.currentTimeMillis()
if (startMillSec == 0L || time - startMillSec > 3000) {
startMillSec = time
count = 1
} else {
count++
}
if (count == 5) {
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
val devSettings = prefs.getBoolean("devSettings", false)
if (!devSettings) {
Toast.makeText(requireContext(), "Dev options unlocked!", Toast.LENGTH_SHORT).show()
prefs.edit().putBoolean("devSettings", true).apply()
} else
Toast.makeText(requireContext(), "Dev options already unlocked", Toast.LENGTH_SHORT).show()
}
return@setOnTouchListener true
}
false
}
}
}

View file

@ -1,71 +0,0 @@
package com.vanced.manager.core.fragments
import android.content.Context
import android.content.Intent
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.navigation.findNavController
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.topjohnwu.superuser.Shell
import com.vanced.manager.R
import com.vanced.manager.core.base.BaseFragment
import com.vanced.manager.core.downloader.MicrogDownloadService
import com.vanced.manager.core.downloader.VancedDownloadService
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.PackageHelper.uninstallApk
open class Home : BaseFragment(), View.OnClickListener {
override fun onClick(v: View?) {
val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val variant = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot")
val vancedPkgName =
if (variant == "root") {
"com.google.android.youtube"
} else {
"com.vanced.android.youtube"
}
when (v?.id) {
R.id.vanced_installbtn -> {
if (prefs?.getBoolean("valuesModified", false)!!) {
activity?.startService(
Intent(
activity,
VancedDownloadService::class.java
)
)
} else {
view?.findNavController()?.navigate(R.id.toInstallThemeFragment)
}
}
R.id.microg_installbtn -> {
activity?.startService(Intent(activity, MicrogDownloadService::class.java))
}
R.id.microg_uninstallbtn -> activity?.let { uninstallApk("com.mgoogle.android.gms", it) }
R.id.vanced_uninstallbtn -> activity?.let { uninstallApk(vancedPkgName, it) }
R.id.nonroot_switch -> writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right)
R.id.root_switch ->
if (Shell.rootAccess()) {
writeToVariantPref("root", R.anim.slide_in_right, R.anim.slide_out_left)
} else {
writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right)
Toast.makeText(activity, activity?.getString(R.string.root_not_granted), Toast.LENGTH_SHORT).show()
}
}
}
private fun writeToVariantPref(variant: String, animIn: Int, animOut: Int) {
val prefs = getDefaultSharedPreferences(activity)
if (prefs.getString("vanced_variant", "nonroot") != variant) {
prefs.edit().putString("vanced_variant", variant).apply()
startActivity(Intent(activity, MainActivity::class.java))
activity?.overridePendingTransition(animIn, animOut)
activity?.finish()
} else
Log.d("VMVariant", "$variant is already selected")
}
}

View file

@ -1,11 +1,15 @@
package com.vanced.manager.ui.fragments package com.vanced.manager.ui.fragments
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.preference.PreferenceManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.fragments.About import com.vanced.manager.core.fragments.About
import com.vanced.manager.databinding.FragmentAboutBinding import com.vanced.manager.databinding.FragmentAboutBinding
@ -14,6 +18,8 @@ import com.vanced.manager.ui.viewmodels.AboutViewModel
class AboutFragment : About() { class AboutFragment : About() {
private lateinit var binding: FragmentAboutBinding private lateinit var binding: FragmentAboutBinding
private var count = 0
private var startMillSec: Long = 0
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
@ -24,11 +30,39 @@ class AboutFragment : About() {
return binding.root return binding.root
} }
@SuppressLint("ClickableViewAccessibility")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val viewModel: AboutViewModel by viewModels() val viewModel: AboutViewModel by viewModels()
binding.viewModel = viewModel binding.viewModel = viewModel
}
view.setOnTouchListener { _, event: MotionEvent ->
val eventAction = event.action
if (eventAction == MotionEvent.ACTION_UP) {
val time = System.currentTimeMillis()
if (startMillSec == 0L || time - startMillSec > 3000) {
startMillSec = time
count = 1
} else {
count++
}
if (count == 5) {
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
val devSettings = prefs.getBoolean("devSettings", false)
if (!devSettings) {
Toast.makeText(requireContext(), "Dev options unlocked!", Toast.LENGTH_SHORT).show()
prefs.edit().putBoolean("devSettings", true).apply()
} else
Toast.makeText(requireContext(), "Dev options already unlocked", Toast.LENGTH_SHORT).show()
}
return@setOnTouchListener true
}
false
}
}
} }

View file

@ -7,17 +7,24 @@ import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.Toast import android.widget.Toast
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.findNavController
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.topjohnwu.superuser.Shell
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.adapter.* import com.vanced.manager.adapter.*
import com.vanced.manager.core.fragments.Home import com.vanced.manager.core.downloader.MicrogDownloadService
import com.vanced.manager.core.downloader.VancedDownloadService
import com.vanced.manager.databinding.FragmentHomeBinding import com.vanced.manager.databinding.FragmentHomeBinding
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
import com.vanced.manager.utils.PackageHelper
class HomeFragment : Home(), View.OnClickListener { class HomeFragment : Fragment(), View.OnClickListener {
private lateinit var binding: FragmentHomeBinding private lateinit var binding: FragmentHomeBinding
private var isExpanded: Boolean = false private var isExpanded: Boolean = false
@ -64,21 +71,15 @@ class HomeFragment : Home(), View.OnClickListener {
} }
binding.includeVancedLayout.vancedCard.setOnLongClickListener { binding.includeVancedLayout.vancedCard.setOnLongClickListener {
val clip = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager versionToast("Vanced", viewModel.vancedInstalledVersion.get())
clip.setPrimaryClip(ClipData.newPlainText("vanced", viewModel.vancedInstalledVersion.get()))
versionToast("Vanced")
true true
} }
binding.includeMicrogLayout.microgCard.setOnLongClickListener { binding.includeMicrogLayout.microgCard.setOnLongClickListener {
val clip = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager versionToast("MicroG", viewModel.microgInstalledVersion.get())
clip.setPrimaryClip(ClipData.newPlainText("microg", viewModel.microgInstalledVersion.get()))
versionToast("MicroG")
true true
} }
viewModel.fetchData()
with(binding.includeChangelogsLayout) { with(binding.includeChangelogsLayout) {
viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment) viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
TabLayoutMediator(tablayout, viewpager) { tab, position -> TabLayoutMediator(tablayout, viewpager) { tab, position ->
@ -96,9 +97,79 @@ class HomeFragment : Home(), View.OnClickListener {
}.attach() }.attach()
} }
viewModel.fetchData()
} }
private fun versionToast(name: String) { override fun onClick(v: View?) {
val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val variant = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot")
val vancedPkgName =
if (variant == "root") {
"com.google.android.youtube"
} else {
"com.vanced.android.youtube"
}
when (v?.id) {
R.id.vanced_installbtn -> {
if (viewModel.microgInstalled.get()!!) {
if (prefs?.getBoolean("valuesModified", false)!!) {
activity?.startService(
Intent(
activity,
VancedDownloadService::class.java
)
)
} else {
view?.findNavController()?.navigate(R.id.toInstallThemeFragment)
}
} else
Snackbar.make(binding.homeRefresh, R.string.no_microg, Snackbar.LENGTH_LONG)
.setAction(R.string.install) {
activity?.startService(Intent(activity, MicrogDownloadService::class.java))
}
}
R.id.microg_installbtn -> {
activity?.startService(Intent(activity, MicrogDownloadService::class.java))
}
R.id.microg_uninstallbtn -> activity?.let {
PackageHelper.uninstallApk(
"com.mgoogle.android.gms",
it
)
}
R.id.vanced_uninstallbtn -> activity?.let {
PackageHelper.uninstallApk(
vancedPkgName,
it
)
}
R.id.nonroot_switch -> writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right)
R.id.root_switch ->
if (Shell.rootAccess()) {
writeToVariantPref("root", R.anim.slide_in_right, R.anim.slide_out_left)
} else {
writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right)
Toast.makeText(activity, activity?.getString(R.string.root_not_granted), Toast.LENGTH_SHORT).show()
}
}
}
private fun writeToVariantPref(variant: String, animIn: Int, animOut: Int) {
val prefs = getDefaultSharedPreferences(activity)
if (prefs.getString("vanced_variant", "nonroot") != variant) {
prefs.edit().putString("vanced_variant", variant).apply()
startActivity(Intent(activity, MainActivity::class.java))
activity?.overridePendingTransition(animIn, animOut)
activity?.finish()
} else
Log.d("VMVariant", "$variant is already selected")
}
private fun versionToast(name: String, app: String?) {
val clip = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clip.setPrimaryClip(ClipData.newPlainText(name, app))
Toast.makeText(activity, getString(R.string.version_toast, name), Toast.LENGTH_LONG).show() Toast.makeText(activity, getString(R.string.version_toast, name), Toast.LENGTH_LONG).show()
} }

View file

@ -18,7 +18,7 @@ import com.google.android.material.checkbox.MaterialCheckBox
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.downloader.VancedDownloadService import com.vanced.manager.core.downloader.VancedDownloadService
import com.vanced.manager.utils.InternetTools.baseUrl import com.vanced.manager.utils.InternetTools.baseUrl
import com.vanced.manager.utils.JsonHelper.getJson import com.vanced.manager.utils.InternetTools.getArrayFromJson
import kotlinx.coroutines.* import kotlinx.coroutines.*
import java.util.* import java.util.*
@ -37,14 +37,13 @@ class VancedLanguageSelectionFragment : Fragment() {
@ExperimentalStdlibApi @ExperimentalStdlibApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
langs = runBlocking { getJson("${PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", baseUrl)}/vanced.json").array<String>("langs")?.value } ?: mutableListOf("null") langs = runBlocking { getArrayFromJson("${PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", baseUrl)}/vanced.json", "langs") }
if (!langs.contains("null")) loadBoxes(view.findViewById(R.id.lang_button_ll))
loadBoxes(view.findViewById(R.id.lang_button_ll))
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener { view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
val chosenLangs = mutableListOf("en") val chosenLangs = mutableListOf("en")
if (!langs.contains("null")) if (!langs.contains("null"))
for (lang in langs) { langs.forEach { lang ->
if (view.findViewWithTag<MaterialCheckBox>(lang).isChecked) { if (view.findViewWithTag<MaterialCheckBox>(lang).isChecked) {
chosenLangs.add(lang) chosenLangs.add(lang)
} }
@ -57,15 +56,17 @@ class VancedLanguageSelectionFragment : Fragment() {
@ExperimentalStdlibApi @ExperimentalStdlibApi
private fun loadBoxes(ll: LinearLayout) = CoroutineScope(Dispatchers.Main).launch { private fun loadBoxes(ll: LinearLayout) = CoroutineScope(Dispatchers.Main).launch {
for (lang in langs) { if (!langs.contains("null")) {
val loc = Locale(lang) langs.forEach { lang ->
val box: MaterialCheckBox = MaterialCheckBox(activity).apply { val loc = Locale(lang)
tag = lang val box: MaterialCheckBox = MaterialCheckBox(activity).apply {
text = loc.getDisplayLanguage(loc).capitalize(Locale.ROOT) tag = lang
textSize = 18F text = loc.getDisplayLanguage(loc).capitalize(Locale.ROOT)
typeface = activity?.let { ResourcesCompat.getFont(it, R.font.exo_bold) } textSize = 18F
typeface = activity?.let { ResourcesCompat.getFont(it, R.font.exo_bold) }
}
ll.addView(box, MATCH_PARENT, WRAP_CONTENT)
} }
ll.addView(box, MATCH_PARENT, WRAP_CONTENT)
} }
} }

View file

@ -10,6 +10,7 @@ import android.widget.RadioButton
import android.widget.RadioGroup import android.widget.RadioGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.findNavController import androidx.navigation.findNavController
import com.google.android.material.radiobutton.MaterialRadioButton
import com.vanced.manager.R import com.vanced.manager.R
class VancedThemeSelectionFragment : Fragment() { class VancedThemeSelectionFragment : Fragment() {
@ -28,10 +29,10 @@ class VancedThemeSelectionFragment : Fragment() {
val nextButton = view.findViewById<Button>(R.id.vanced_next_to_variant) val nextButton = view.findViewById<Button>(R.id.vanced_next_to_variant)
val themeGroup = view.findViewById<RadioGroup>(R.id.theme_radiogroup) val themeGroup = view.findViewById<RadioGroup>(R.id.theme_radiogroup)
val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE) val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
themeGroup.findViewWithTag<MaterialRadioButton>(prefs?.getString("theme", "dark")).isChecked = true
nextButton.setOnClickListener { nextButton.setOnClickListener {
val selectedThemeId = themeGroup.checkedRadioButtonId val selectedButton = view.findViewById<MaterialRadioButton>(themeGroup.checkedRadioButtonId)
val selectedButton = view.findViewById<RadioButton>(selectedThemeId)
prefs?.edit()?.putString("theme", selectedButton.tag.toString())?.apply() prefs?.edit()?.putString("theme", selectedButton.tag.toString())?.apply()
view.findNavController().navigate(R.id.toInstallLanguageFragment) view.findNavController().navigate(R.id.toInstallLanguageFragment)
} }

View file

@ -78,18 +78,8 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication())) microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication())) microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!) shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
vancedInstallButtonIcon.set( vancedInstallButtonIcon.set(compareIntDrawable(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication()))
if (shouldBeDisabled.get()!!) { vancedInstallButtonTxt.set(compareInt(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication()))
null
} else
compareIntDrawable(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication())
)
vancedInstallButtonTxt.set(
if (shouldBeDisabled.get()!!) {
getApplication<Application>().getString(R.string.no_microg)
} else
compareInt(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication())
)
fetching.set(false) fetching.set(false)
} }
} }
@ -172,9 +162,4 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
} }
} }
init {
//expanded.set(false)
//fetchData()
}
} }

View file

@ -36,6 +36,15 @@ object InternetTools {
} }
} }
suspend fun getArrayFromJson(url: String, array: String): MutableList<String> {
return try {
JsonHelper.getJson(url).array<String>(array)?.value ?: mutableListOf("null")
} catch (e: Exception) {
Log.e(TAG, "Error: ", e)
mutableListOf("null")
}
}
suspend fun getJsonInt(file: String, obj: String, context: Context): Int { suspend fun getJsonInt(file: String, obj: String, context: Context): Int {
val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl) val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl)
return try { return try {
@ -57,10 +66,13 @@ object InternetTools {
} }
suspend fun isUpdateAvailable(): Boolean { suspend fun isUpdateAvailable(): Boolean {
val result = JsonHelper.getJson("https://x1nto.github.io/VancedFiles/manager.json") val result = try {
val remoteVersion = result.int("versionCode") ?: 0 JsonHelper.getJson("https://x1nto.github.io/VancedFiles/manager.json").int("versionCode") ?: 0
} catch (e: Exception) {
0
}
return remoteVersion > BuildConfig.VERSION_CODE return result > BuildConfig.VERSION_CODE
} }
const val baseUrl = "https://vanced.app/api/v1" const val baseUrl = "https://vanced.app/api/v1"

View file

@ -21,11 +21,9 @@
<RadioGroup <RadioGroup
android:id="@+id/theme_radiogroup" android:id="@+id/theme_radiogroup"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:checkedButton="@id/dark">
<com.google.android.material.radiobutton.MaterialRadioButton <com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/dark"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="18sp" android:textSize="18sp"