mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-26 13:12:59 +00:00
removed downloadProgress from livedata
This commit is contained in:
parent
62b540b95c
commit
cb38dedb11
7 changed files with 45 additions and 54 deletions
|
@ -18,14 +18,14 @@ object MicrogDownloader {
|
|||
download(url, "$baseInstallUrl/", folderName, fileName, context, onDownloadComplete = {
|
||||
startMicrogInstall(context)
|
||||
}, onError = {
|
||||
downloadProgress.value?.downloadingFile?.postValue(context.getString(R.string.error_downloading, fileName))
|
||||
downloadProgress.downloadingFile.postValue(context.getString(R.string.error_downloading, fileName))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fun startMicrogInstall(context: Context) {
|
||||
downloadProgress.value?.installing?.postValue(true)
|
||||
downloadProgress.value?.postReset()
|
||||
downloadProgress.installing.postValue(true)
|
||||
downloadProgress.postReset()
|
||||
install("${context.getExternalFilesDir(folderName)}/$fileName", context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ object MusicDownloader {
|
|||
"stock" -> startMusicInstall(context)
|
||||
}
|
||||
}, onError = {
|
||||
downloadProgress.value?.downloadingFile?.postValue(context.getString(R.string.error_downloading, getFileNameFromUrl(url)))
|
||||
downloadProgress.downloadingFile.postValue(context.getString(R.string.error_downloading, getFileNameFromUrl(url)))
|
||||
})
|
||||
}
|
||||
|
||||
fun startMusicInstall(context: Context) {
|
||||
downloadProgress.value?.installing?.postValue(true)
|
||||
downloadProgress.value?.postReset()
|
||||
downloadProgress.installing.postValue(true)
|
||||
downloadProgress.postReset()
|
||||
if (variant == "root")
|
||||
installMusicRoot(context)
|
||||
else
|
||||
|
|
|
@ -59,7 +59,7 @@ object VancedDownloader {
|
|||
downloadSplits(context)
|
||||
} catch (e: Exception) {
|
||||
log("VMDownloader", e.stackTraceToString())
|
||||
downloadProgress.value?.downloadingFile?.postValue(context.getString(R.string.error_downloading, "Vanced"))
|
||||
downloadProgress.downloadingFile.postValue(context.getString(R.string.error_downloading, "Vanced"))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -113,14 +113,14 @@ object VancedDownloader {
|
|||
}
|
||||
|
||||
} else {
|
||||
downloadProgress.value?.downloadingFile?.postValue(context.getString(R.string.error_downloading, getFileNameFromUrl(url)))
|
||||
downloadProgress.downloadingFile.postValue(context.getString(R.string.error_downloading, getFileNameFromUrl(url)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun startVancedInstall(context: Context, variant: String? = this.variant) {
|
||||
downloadProgress.value?.installing?.postValue(true)
|
||||
downloadProgress.value?.postReset()
|
||||
downloadProgress.installing.postValue(true)
|
||||
downloadProgress.postReset()
|
||||
FirebaseAnalytics.getInstance(context).logEvent(FirebaseAnalytics.Event.SELECT_ITEM) {
|
||||
variant?.let { param("vanced_variant", it) }
|
||||
theme?.let { param("vanced_theme", it) }
|
||||
|
|
|
@ -83,27 +83,25 @@ class AppDownloadDialog : BindingDialogFragment<DialogAppDownloadBinding>() {
|
|||
|
||||
private fun DialogAppDownloadBinding.bindDownloadProgress() {
|
||||
with(downloadProgress) {
|
||||
observe(viewLifecycleOwner) { progressModel ->
|
||||
progressModel.downloadProgress.observe(viewLifecycleOwner) {
|
||||
appDownloadProgressbar.progress = it
|
||||
}
|
||||
progressModel.installing.observe(viewLifecycleOwner) { installing ->
|
||||
appDownloadProgressbar.isVisible = !installing
|
||||
appInstallProgressbar.isVisible = installing
|
||||
appDownloadFile.isVisible = !installing
|
||||
appDownloadCancel.isEnabled = !installing
|
||||
appDownloadCancel.setOnClickListener {
|
||||
if (installing) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
progressModel.currentDownload?.cancel()
|
||||
progressModel.downloadProgress.value = 0
|
||||
dismiss()
|
||||
downloadProgress.observe(viewLifecycleOwner) {
|
||||
appDownloadProgressbar.progress = it
|
||||
}
|
||||
installing.observe(viewLifecycleOwner) { installing ->
|
||||
appDownloadProgressbar.isVisible = !installing
|
||||
appInstallProgressbar.isVisible = installing
|
||||
appDownloadFile.isVisible = !installing
|
||||
appDownloadCancel.isEnabled = !installing
|
||||
appDownloadCancel.setOnClickListener {
|
||||
if (installing) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
currentDownload?.cancel()
|
||||
downloadProgress.value = 0
|
||||
dismiss()
|
||||
}
|
||||
progressModel.downloadingFile.observe(viewLifecycleOwner) {
|
||||
appDownloadFile.text = it
|
||||
}
|
||||
}
|
||||
downloadingFile.observe(viewLifecycleOwner) {
|
||||
appDownloadFile.text = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,9 +68,9 @@ class ManagerUpdateDialog : BindingDialogFragment<DialogManagerUpdateBinding>()
|
|||
isCancelable = false
|
||||
managerUpdateProgressbar.applyAccent()
|
||||
managerUpdateCancel.setOnClickListener {
|
||||
with(downloadProgress.value) {
|
||||
this?.downloadProgress?.value = 0
|
||||
this?.currentDownload?.cancel()
|
||||
with(downloadProgress) {
|
||||
downloadProgress.value = 0
|
||||
currentDownload?.cancel()
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
|
@ -80,11 +80,9 @@ class ManagerUpdateDialog : BindingDialogFragment<DialogManagerUpdateBinding>()
|
|||
|
||||
private fun DialogManagerUpdateBinding.bindDownloadProgress() {
|
||||
with(downloadProgress) {
|
||||
observe(viewLifecycleOwner) { progressModel ->
|
||||
progressModel.downloadProgress.observe(viewLifecycleOwner) {
|
||||
managerUpdateProgressbar.progress = it
|
||||
managerUpdateProgressbar.isVisible = it != 0
|
||||
}
|
||||
downloadProgress.observe(viewLifecycleOwner) {
|
||||
managerUpdateProgressbar.progress = it
|
||||
managerUpdateProgressbar.isVisible = it != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ object AppUtils: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
fun sendCloseDialog(context: Context): Job {
|
||||
return launch {
|
||||
delay(700)
|
||||
downloadProgress.value?.installing?.postValue(false)
|
||||
downloadProgress.installing.postValue(false)
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(AppDownloadDialog.CLOSE_DIALOG))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.Intent
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.library.network.providers.createService
|
||||
import com.vanced.manager.model.ProgressModel
|
||||
|
@ -40,13 +39,13 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
fileFolder: String,
|
||||
fileName: String,
|
||||
context: Context,
|
||||
onDownloadComplete: () -> Unit,
|
||||
onError: (error: String) -> Unit
|
||||
onDownloadComplete: () -> Unit = {},
|
||||
onError: (error: String) -> Unit = {}
|
||||
) {
|
||||
downloadProgress.value?.downloadingFile?.postValue(context.getString(R.string.downloading_file, fileName))
|
||||
downloadProgress.downloadingFile.postValue(context.getString(R.string.downloading_file, fileName))
|
||||
val downloadInterface = createService(DownloadHelper::class, baseUrl)
|
||||
val download = downloadInterface.download(url)
|
||||
downloadProgress.value?.currentDownload = download
|
||||
downloadProgress.currentDownload = download
|
||||
download.enqueue(object : Callback<ResponseBody> {
|
||||
override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
|
||||
if (response.isSuccessful) {
|
||||
|
@ -55,13 +54,13 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
onDownloadComplete()
|
||||
} else {
|
||||
onError("Could not save file")
|
||||
downloadProgress.value?.downloadProgress?.postValue(0)
|
||||
downloadProgress.downloadProgress.postValue(0)
|
||||
log("VMDownloader", "Failed to save file: $url")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onError(response.errorBody().toString())
|
||||
downloadProgress.value?.downloadProgress?.postValue(0)
|
||||
downloadProgress.downloadProgress.postValue(0)
|
||||
log("VMDownloader", "Failed to download file: $url")
|
||||
}
|
||||
}
|
||||
|
@ -69,10 +68,10 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
|
||||
if (call.isCanceled) {
|
||||
log("VMDownloader", "Download canceled")
|
||||
downloadProgress.value?.downloadProgress?.postValue(0)
|
||||
downloadProgress.downloadProgress.postValue(0)
|
||||
} else {
|
||||
onError(t.stackTraceToString())
|
||||
downloadProgress.value?.downloadProgress?.postValue(0)
|
||||
downloadProgress.downloadProgress.postValue(0)
|
||||
log("VMDownloader", "Failed to download file: $url")
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +94,7 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
while (inputStream.read(fileReader).also { read = it } != -1) {
|
||||
outputStream.write(fileReader, 0, read)
|
||||
downloadedBytes += read.toLong()
|
||||
downloadProgress.value?.downloadProgress?.postValue((downloadedBytes * 100 / totalBytes).toInt())
|
||||
downloadProgress.downloadProgress.postValue((downloadedBytes * 100 / totalBytes).toInt())
|
||||
}
|
||||
outputStream.flush()
|
||||
true
|
||||
|
@ -110,11 +109,7 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
}
|
||||
}
|
||||
|
||||
val downloadProgress = MutableLiveData<ProgressModel>()
|
||||
|
||||
init {
|
||||
downloadProgress.value = ProgressModel()
|
||||
}
|
||||
val downloadProgress = ProgressModel()
|
||||
|
||||
fun downloadManager(context: Context) {
|
||||
val url = "https://github.com/YTVanced/VancedManager/releases/latest/download/manager.apk"
|
||||
|
@ -138,7 +133,7 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
sendCloseDialog(context)
|
||||
}
|
||||
}, onError = {
|
||||
downloadProgress.value?.downloadingFile?.postValue(
|
||||
downloadProgress.downloadingFile.postValue(
|
||||
context.getString(
|
||||
R.string.error_downloading,
|
||||
"manager.apk"
|
||||
|
|
Loading…
Reference in a new issue