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-08-03 19:29:20 +00:00
|
|
|
import android.content.Intent
|
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-03 19:29:20 +00:00
|
|
|
import com.vanced.manager.core.downloader.VancedDownloadService
|
2020-08-02 16:16:55 +00:00
|
|
|
import com.vanced.manager.utils.InternetTools.baseUrl
|
2020-08-04 10:02:36 +00:00
|
|
|
import com.vanced.manager.utils.InternetTools.getArrayFromJson
|
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-03 11:39:26 +00:00
|
|
|
@ExperimentalStdlibApi
|
2020-08-02 16:16:55 +00:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2020-08-09 15:28:56 +00:00
|
|
|
CoroutineScope(Dispatchers.IO).launch {
|
2020-08-08 10:59:56 +00:00
|
|
|
langs = getArrayFromJson("${PreferenceManager.getDefaultSharedPreferences(requireActivity()).getString("install_url", baseUrl)}/vanced.json", "langs")
|
|
|
|
}
|
2020-08-09 15:28:56 +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 11:39:26 +00:00
|
|
|
if (!langs.contains("null"))
|
2020-08-04 10:02:36 +00:00
|
|
|
langs.forEach { lang ->
|
2020-08-03 11:39:26 +00:00
|
|
|
if (view.findViewWithTag<MaterialCheckBox>(lang).isChecked) {
|
|
|
|
chosenLangs.add(lang)
|
|
|
|
}
|
2020-08-02 16:16:55 +00:00
|
|
|
}
|
2020-08-08 10:59:56 +00:00
|
|
|
with(requireActivity()) {
|
|
|
|
getSharedPreferences("installPrefs", Context.MODE_PRIVATE)?.edit()?.apply {
|
2020-08-25 09:05:20 +00:00
|
|
|
putString("lang", chosenLangs.joinToString())?.apply()
|
|
|
|
putBoolean("valuesModified", true).apply()
|
2020-08-04 10:02:36 +00:00
|
|
|
}
|
2020-08-08 10:59:56 +00:00
|
|
|
startService(Intent(this, VancedDownloadService::class.java))
|
2020-08-02 16:16:55 +00:00
|
|
|
}
|
2020-08-08 10:59:56 +00:00
|
|
|
view.findNavController().navigate(R.id.action_installTo_homeFragment)
|
2020-08-02 16:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 15:28:56 +00:00
|
|
|
@ExperimentalStdlibApi
|
|
|
|
private fun loadBoxes(ll: LinearLayout) {
|
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
|
|
|
if (this@VancedLanguageSelectionFragment::langs.isInitialized) {
|
|
|
|
if (!langs.contains("null")) {
|
|
|
|
langs.forEach { lang ->
|
|
|
|
val loc = Locale(lang)
|
|
|
|
val box: MaterialCheckBox = MaterialCheckBox(requireActivity()).apply {
|
|
|
|
tag = lang
|
|
|
|
text = loc.getDisplayLanguage(loc).capitalize(Locale.ROOT)
|
|
|
|
textSize = 18F
|
|
|
|
typeface = ResourcesCompat.getFont(requireActivity(), R.font.exo_bold)
|
|
|
|
}
|
|
|
|
ll.addView(box, MATCH_PARENT, WRAP_CONTENT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
loadBoxes(ll)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 17:31:13 +00:00
|
|
|
}
|