2020-04-09 17:31:13 +00:00
|
|
|
package com.vanced.manager.ui.fragments
|
|
|
|
|
2020-08-03 09:54:59 +00:00
|
|
|
import android.content.Context
|
2020-04-09 17:31:13 +00:00
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2020-08-02 16:16:55 +00:00
|
|
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.navigation.findNavController
|
|
|
|
import androidx.preference.PreferenceManager
|
|
|
|
import com.google.android.material.button.MaterialButton
|
2020-08-02 19:10:13 +00:00
|
|
|
import com.google.android.material.checkbox.MaterialCheckBox
|
2020-04-09 17:31:13 +00:00
|
|
|
import com.vanced.manager.R
|
2020-08-02 16:16:55 +00:00
|
|
|
import com.vanced.manager.utils.InternetTools.baseUrl
|
2020-08-03 10:25:40 +00:00
|
|
|
import com.vanced.manager.utils.JsonHelper.getJson
|
2020-08-03 09:54:59 +00:00
|
|
|
import kotlinx.coroutines.*
|
2020-08-02 16:16:55 +00:00
|
|
|
import java.util.*
|
2020-04-09 17:31:13 +00:00
|
|
|
|
2020-08-02 16:16:55 +00:00
|
|
|
class VancedLanguageSelectionFragment : Fragment() {
|
2020-04-19 17:21:40 +00:00
|
|
|
|
2020-08-03 10:25:40 +00:00
|
|
|
private lateinit var langs: MutableList<String>
|
2020-08-03 08:11:20 +00:00
|
|
|
|
2020-04-09 17:31:13 +00:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2020-07-03 14:43:36 +00:00
|
|
|
activity?.title = getString(R.string.install)
|
2020-04-09 17:31:13 +00:00
|
|
|
return inflater.inflate(R.layout.fragment_vanced_language_selection, container, false)
|
|
|
|
}
|
|
|
|
|
2020-08-02 16:16:55 +00:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2020-08-03 10:25:40 +00:00
|
|
|
langs = runBlocking { getJson("${PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", baseUrl)}/vanced.json").array<String>("langs")?.value }!!
|
2020-08-03 08:11:20 +00:00
|
|
|
loadBoxes(view.findViewById(R.id.lang_button_ll))
|
2020-08-02 16:16:55 +00:00
|
|
|
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
|
2020-08-03 08:11:20 +00:00
|
|
|
val chosenLangs = mutableListOf("en")
|
2020-08-03 09:01:25 +00:00
|
|
|
for (lang in langs) {
|
|
|
|
if (view.findViewWithTag<MaterialCheckBox>(lang).isChecked) {
|
2020-08-03 10:25:40 +00:00
|
|
|
chosenLangs.add(lang)
|
2020-08-02 16:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-03 09:54:59 +00:00
|
|
|
activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)?.edit()?.putString("lang", chosenLangs.joinToString())?.apply()
|
2020-08-03 08:11:20 +00:00
|
|
|
view.findNavController().navigate(R.id.action_installTo_homeFragment)
|
2020-08-02 16:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 08:11:20 +00:00
|
|
|
private fun loadBoxes(ll: LinearLayout) = CoroutineScope(Dispatchers.Main).launch {
|
2020-08-03 09:01:25 +00:00
|
|
|
for (lang in langs) {
|
2020-08-03 10:25:40 +00:00
|
|
|
val box: MaterialCheckBox = MaterialCheckBox(activity).apply {
|
|
|
|
tag = lang
|
|
|
|
text = Locale(lang).displayLanguage
|
|
|
|
textSize = 16F
|
|
|
|
typeface = activity?.let { ResourcesCompat.getFont(it, R.font.exo_bold) }
|
2020-08-02 16:16:55 +00:00
|
|
|
}
|
2020-08-03 10:25:40 +00:00
|
|
|
ll.addView(box, MATCH_PARENT, WRAP_CONTENT)
|
2020-08-02 16:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 17:31:13 +00:00
|
|
|
}
|