mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-26 05:05:15 +00:00
added isFetching LiveData
This commit is contained in:
parent
d4f1728c09
commit
f637d2eef8
6 changed files with 16 additions and 40 deletions
|
@ -16,8 +16,8 @@ import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
|||
import com.crowdin.platform.Crowdin
|
||||
import com.crowdin.platform.LoadingStateListener
|
||||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
import com.vanced.manager.BuildConfig.VERSION_CODE
|
||||
import com.vanced.manager.BuildConfig.ENABLE_CROWDIN_AUTH
|
||||
import com.vanced.manager.BuildConfig.VERSION_CODE
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.ActivityMainBinding
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer
|
||||
|
|
|
@ -11,8 +11,8 @@ import androidx.lifecycle.lifecycleScope
|
|||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.vanced.manager.core.ui.base.BindingDialogFragment
|
||||
import com.vanced.manager.databinding.DialogCustomUrlBinding
|
||||
import com.vanced.manager.utils.Extensions.fetchData
|
||||
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||
import com.vanced.manager.utils.InternetTools.loadJson
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class URLChangeDialog : BindingDialogFragment<DialogCustomUrlBinding>() {
|
||||
|
@ -60,7 +60,7 @@ class URLChangeDialog : BindingDialogFragment<DialogCustomUrlBinding>() {
|
|||
private fun saveUrl(url: String) {
|
||||
lifecycleScope.launch {
|
||||
getDefaultSharedPreferences(requireActivity()).edit { putString("install_url", url) }
|
||||
requireActivity().fetchData()
|
||||
loadJson(requireActivity())
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.vanced.manager.databinding.FragmentHomeBinding
|
|||
import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModelFactory
|
||||
import com.vanced.manager.utils.InternetTools.isFetching
|
||||
|
||||
open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
|
||||
|
||||
|
@ -59,6 +60,7 @@ open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
|
|||
setHasOptionsMenu(true)
|
||||
with (binding) {
|
||||
homeRefresh.setOnRefreshListener { viewModel.fetchData() }
|
||||
isFetching.observe(viewLifecycleOwner) { homeRefresh.isRefreshing = it }
|
||||
tooltip = ViewTooltip
|
||||
.on(recyclerAppList)
|
||||
.position(ViewTooltip.Position.TOP)
|
||||
|
|
|
@ -27,8 +27,6 @@ import com.vanced.manager.utils.AppUtils.musicPkg
|
|||
import com.vanced.manager.utils.AppUtils.musicRootPkg
|
||||
import com.vanced.manager.utils.AppUtils.vancedPkg
|
||||
import com.vanced.manager.utils.AppUtils.vancedRootPkg
|
||||
import com.vanced.manager.utils.Extensions.fetchData
|
||||
import com.vanced.manager.utils.Extensions.setRefreshing
|
||||
import com.vanced.manager.utils.Extensions.show
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.InternetTools.loadJson
|
||||
|
@ -52,10 +50,8 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
|
||||
fun fetchData() {
|
||||
viewModelScope.launch {
|
||||
activity.setRefreshing(true)
|
||||
loadJson(activity)
|
||||
Crowdin.forceUpdate(activity)
|
||||
activity.setRefreshing(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,20 +130,18 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
|
||||
fun uninstallPackage(pkg: String) {
|
||||
if (prefs.getString("vanced_variant", "nonroot") == "root" && uninstallRootApk(pkg)) {
|
||||
viewModelScope.launch { activity.fetchData() }
|
||||
viewModelScope.launch { loadJson(activity) }
|
||||
} else {
|
||||
uninstallApk(pkg, activity)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
activity.setRefreshing(true)
|
||||
vanced.value = DataModel(InternetTools.vanced, activity, vancedPkg, activity.getString(R.string.vanced), AppCompatResources.getDrawable(activity, R.drawable.ic_vanced))
|
||||
vancedRoot.value = DataModel(InternetTools.vanced, activity, vancedRootPkg, activity.getString(R.string.vanced), AppCompatResources.getDrawable(activity, R.drawable.ic_vanced))
|
||||
music.value = DataModel(InternetTools.music, activity, musicPkg, activity.getString(R.string.music), AppCompatResources.getDrawable(activity, R.drawable.ic_music))
|
||||
musicRoot.value = DataModel(InternetTools.music, activity, musicRootPkg, activity.getString(R.string.music), AppCompatResources.getDrawable(activity, R.drawable.ic_music))
|
||||
microg.value = DataModel(InternetTools.microg, activity, microgPkg, activity.getString(R.string.microg), AppCompatResources.getDrawable(activity, R.drawable.ic_microg))
|
||||
manager.value = DataModel(InternetTools.manager, activity, managerPkg, activity.getString(R.string.app_name), AppCompatResources.getDrawable(activity, R.mipmap.ic_launcher))
|
||||
activity.setRefreshing(false)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.vanced.manager.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.content.DialogInterface
|
||||
|
@ -11,13 +10,11 @@ import androidx.fragment.app.DialogFragment
|
|||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||
import com.vanced.manager.utils.InternetTools.loadJson
|
||||
import com.vanced.manager.utils.ThemeHelper.accentColor
|
||||
import com.vanced.manager.utils.ThemeHelper.defAccentColor
|
||||
import java.util.*
|
||||
|
@ -32,26 +29,6 @@ object Extensions {
|
|||
show(activity.supportFragmentManager, "")
|
||||
}
|
||||
|
||||
suspend fun Activity.fetchData() {
|
||||
val refreshLayout = findViewById<SwipeRefreshLayout>(R.id.home_refresh)
|
||||
setRefreshing(true, refreshLayout)
|
||||
loadJson(this)
|
||||
setRefreshing(false, refreshLayout)
|
||||
}
|
||||
|
||||
fun Activity.setRefreshing(isRefreshing: Boolean) {
|
||||
val refreshLayout = findViewById<SwipeRefreshLayout>(R.id.home_refresh)
|
||||
if (refreshLayout != null) {
|
||||
refreshLayout.isRefreshing = isRefreshing
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.setRefreshing(isRefreshing: Boolean, refreshLayout: SwipeRefreshLayout?) {
|
||||
if (refreshLayout != null) {
|
||||
refreshLayout.isRefreshing = isRefreshing
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getDefaultPrefs(): SharedPreferences = getDefaultSharedPreferences(this)
|
||||
|
||||
//Not sure how much this can affect performance
|
||||
|
|
|
@ -23,13 +23,15 @@ object InternetTools {
|
|||
|
||||
private const val TAG = "VMNetTools"
|
||||
|
||||
var vanced = MutableLiveData<JsonObject?>()
|
||||
var music = MutableLiveData<JsonObject?>()
|
||||
var microg = MutableLiveData<JsonObject?>()
|
||||
var manager = MutableLiveData<JsonObject?>()
|
||||
val vanced = MutableLiveData<JsonObject?>()
|
||||
val music = MutableLiveData<JsonObject?>()
|
||||
val microg = MutableLiveData<JsonObject?>()
|
||||
val manager = MutableLiveData<JsonObject?>()
|
||||
|
||||
var vancedVersions = MutableLiveData<JsonArray<String>>()
|
||||
var musicVersions = MutableLiveData<JsonArray<String>>()
|
||||
val vancedVersions = MutableLiveData<JsonArray<String>>()
|
||||
val musicVersions = MutableLiveData<JsonArray<String>>()
|
||||
|
||||
val isFetching = MutableLiveData<Boolean>()
|
||||
|
||||
//var braveTiers = MutableLiveData<JsonObject?>()
|
||||
|
||||
|
@ -49,6 +51,7 @@ object InternetTools {
|
|||
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/') + 1, url.length)
|
||||
|
||||
suspend fun loadJson(context: Context) = withContext(Dispatchers.IO) {
|
||||
isFetching.postValue(true)
|
||||
val installUrl = context.getDefaultPrefs().getString("install_url", baseUrl)
|
||||
val calendar = Calendar.getInstance()
|
||||
val hour = calendar.get(Calendar.HOUR_OF_DAY)
|
||||
|
@ -68,7 +71,7 @@ object InternetTools {
|
|||
musicVersions.postValue(versions?.array("music"))
|
||||
microg.postValue(latest?.obj("microg"))
|
||||
manager.postValue(latest?.obj("manager"))
|
||||
|
||||
isFetching.postValue(false)
|
||||
}
|
||||
|
||||
private suspend fun getJsonString(file: String, obj: String, context: Context): String {
|
||||
|
|
Loading…
Reference in a new issue