0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-22 11:15:10 +00:00

fixed preference getter

This commit is contained in:
X1nto 2020-08-03 13:54:59 +04:00
parent e77314c658
commit 355537c6f6
5 changed files with 11 additions and 12 deletions

View file

@ -24,7 +24,7 @@ jobs:
- name: Build project with Gradle
run: ./gradlew build
- name: Build Release APK with Gradle
- name: Build Debug APK with Gradle
run: ./gradlew assembleDebug
- name: Upload to GitHub

View file

@ -9,7 +9,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import com.downloader.Error
import com.downloader.OnDownloadListener
import com.downloader.OnStartOrResumeListener
import com.downloader.PRDownloader
import com.vanced.manager.R
import com.vanced.manager.core.installer.RootSplitInstallerService

View file

@ -1,5 +1,6 @@
package com.vanced.manager.ui.fragments
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -16,15 +17,12 @@ import com.google.android.material.checkbox.MaterialCheckBox
import com.vanced.manager.R
import com.vanced.manager.utils.InternetTools.baseUrl
import com.vanced.manager.utils.JsonHelper.getJsonArray
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.*
import java.util.*
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(
inflater: LayoutInflater, container: ViewGroup?,
@ -36,6 +34,7 @@ class VancedLanguageSelectionFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
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))
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
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)
}
}
private fun loadBoxes(ll: LinearLayout) = CoroutineScope(Dispatchers.Main).launch {
for (lang in langs) {
if (lang != null) {

View file

@ -155,7 +155,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
private fun compareInt(int1: Int, int2: Int, application: Application): String {
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.button_reinstall)
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? {
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_done)
else -> application.getDrawable(R.drawable.ic_download)

View file

@ -5,6 +5,9 @@ import com.beust.klaxon.JsonObject
import com.beust.klaxon.Parser
import com.github.kittinunf.fuel.coroutines.awaitString
import com.github.kittinunf.fuel.httpGet
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
object JsonHelper {