mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-26 05:05:15 +00:00
fixed preference getter
This commit is contained in:
parent
e77314c658
commit
355537c6f6
5 changed files with 11 additions and 12 deletions
2
.github/workflows/debug.yml
vendored
2
.github/workflows/debug.yml
vendored
|
@ -24,7 +24,7 @@ jobs:
|
||||||
- name: Build project with Gradle
|
- name: Build project with Gradle
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
|
|
||||||
- name: Build Release APK with Gradle
|
- name: Build Debug APK with Gradle
|
||||||
run: ./gradlew assembleDebug
|
run: ./gradlew assembleDebug
|
||||||
|
|
||||||
- name: Upload to GitHub
|
- name: Upload to GitHub
|
||||||
|
|
|
@ -9,7 +9,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.downloader.Error
|
import com.downloader.Error
|
||||||
import com.downloader.OnDownloadListener
|
import com.downloader.OnDownloadListener
|
||||||
import com.downloader.OnStartOrResumeListener
|
|
||||||
import com.downloader.PRDownloader
|
import com.downloader.PRDownloader
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.core.installer.RootSplitInstallerService
|
import com.vanced.manager.core.installer.RootSplitInstallerService
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.vanced.manager.ui.fragments
|
package com.vanced.manager.ui.fragments
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -16,15 +17,12 @@ import com.google.android.material.checkbox.MaterialCheckBox
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.utils.InternetTools.baseUrl
|
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||||
import com.vanced.manager.utils.JsonHelper.getJsonArray
|
import com.vanced.manager.utils.JsonHelper.getJsonArray
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class VancedLanguageSelectionFragment : Fragment() {
|
class VancedLanguageSelectionFragment : Fragment() {
|
||||||
|
|
||||||
private val langs: MutableList<String?> = runBlocking { getJsonArray("${PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", baseUrl)}/vanced.json").string("langs").value }
|
private lateinit var langs: MutableList<String?>
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
@ -36,6 +34,7 @@ class VancedLanguageSelectionFragment : Fragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
langs = runBlocking { getJsonArray("${PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", baseUrl)}/vanced.json").string("langs").value }
|
||||||
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")
|
||||||
|
@ -46,13 +45,11 @@ class VancedLanguageSelectionFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PreferenceManager.getDefaultSharedPreferences(activity).edit()?.putString("lang", chosenLangs.joinToString())?.apply()
|
activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)?.edit()?.putString("lang", chosenLangs.joinToString())?.apply()
|
||||||
view.findNavController().navigate(R.id.action_installTo_homeFragment)
|
view.findNavController().navigate(R.id.action_installTo_homeFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun loadBoxes(ll: LinearLayout) = CoroutineScope(Dispatchers.Main).launch {
|
private fun loadBoxes(ll: LinearLayout) = CoroutineScope(Dispatchers.Main).launch {
|
||||||
for (lang in langs) {
|
for (lang in langs) {
|
||||||
if (lang != null) {
|
if (lang != null) {
|
||||||
|
|
|
@ -155,7 +155,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||||
|
|
||||||
private fun compareInt(int1: Int, int2: Int, application: Application): String {
|
private fun compareInt(int1: Int, int2: Int, application: Application): String {
|
||||||
return when {
|
return when {
|
||||||
int2 == 0 -> application.getString(R.string.install)
|
int1 == 0 -> application.getString(R.string.install)
|
||||||
int2 > int1 -> application.getString(R.string.update)
|
int2 > int1 -> application.getString(R.string.update)
|
||||||
int2 == int1 -> application.getString(R.string.button_reinstall)
|
int2 == int1 -> application.getString(R.string.button_reinstall)
|
||||||
else -> application.getString(R.string.install)
|
else -> application.getString(R.string.install)
|
||||||
|
@ -165,7 +165,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||||
|
|
||||||
private fun compareIntDrawable(int1: Int, int2: Int, application: Application): Drawable? {
|
private fun compareIntDrawable(int1: Int, int2: Int, application: Application): Drawable? {
|
||||||
return when {
|
return when {
|
||||||
int2 == 0 -> application.getDrawable(R.drawable.ic_download)
|
int1 == 0 -> application.getDrawable(R.drawable.ic_download)
|
||||||
int2 > int1 -> application.getDrawable(R.drawable.ic_update)
|
int2 > int1 -> application.getDrawable(R.drawable.ic_update)
|
||||||
int2 == int1 -> application.getDrawable(R.drawable.ic_done)
|
int2 == int1 -> application.getDrawable(R.drawable.ic_done)
|
||||||
else -> application.getDrawable(R.drawable.ic_download)
|
else -> application.getDrawable(R.drawable.ic_download)
|
||||||
|
|
|
@ -5,6 +5,9 @@ import com.beust.klaxon.JsonObject
|
||||||
import com.beust.klaxon.Parser
|
import com.beust.klaxon.Parser
|
||||||
import com.github.kittinunf.fuel.coroutines.awaitString
|
import com.github.kittinunf.fuel.coroutines.awaitString
|
||||||
import com.github.kittinunf.fuel.httpGet
|
import com.github.kittinunf.fuel.httpGet
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
object JsonHelper {
|
object JsonHelper {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue