mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-25 20:55:12 +00:00
ManagerUpdateDialog, AppDownloadDialog view binding migrate ProgressModel to MutableLiveData
This commit is contained in:
parent
41cd02c256
commit
d4f01eb8b3
14 changed files with 304 additions and 263 deletions
|
@ -20,29 +20,29 @@ object MicrogDownloader : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
) = launch {
|
||||
val url = microg.get()?.string("url")
|
||||
|
||||
downloadProgress.get()?.currentDownload = PRDownloader.download(url, context.getExternalFilesDir("microg")?.path, "microg.apk")
|
||||
downloadProgress.value?.currentDownload = PRDownloader.download(url, context.getExternalFilesDir("microg")?.path, "microg.apk")
|
||||
.build()
|
||||
.setOnStartOrResumeListener {
|
||||
downloadProgress.get()?.downloadingFile?.set(context.getString(R.string.downloading_file, url?.let { getFileNameFromUrl(it) }))
|
||||
downloadProgress.value?.downloadingFile?.value = context.getString(R.string.downloading_file, url?.let { getFileNameFromUrl(it) })
|
||||
}
|
||||
.setOnProgressListener { progress ->
|
||||
downloadProgress.get()?.downloadProgress?.set((progress.currentBytes * 100 / progress.totalBytes).toInt())
|
||||
downloadProgress.value?.downloadProgress?.value = (progress.currentBytes * 100 / progress.totalBytes).toInt()
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
startMicrogInstall(context)
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
startMicrogInstall(context)
|
||||
}
|
||||
|
||||
override fun onError(error: Error?) {
|
||||
downloadProgress.get()?.downloadingFile?.set(context.getString(R.string.error_downloading, "microG"))
|
||||
}
|
||||
})
|
||||
override fun onError(error: Error?) {
|
||||
downloadProgress.value?.downloadingFile?.value = context.getString(R.string.error_downloading, "microG")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fun startMicrogInstall(context: Context) {
|
||||
downloadProgress.get()?.installing?.set(true)
|
||||
downloadProgress.get()?.reset()
|
||||
downloadProgress.value?.installing?.value = true
|
||||
downloadProgress.value?.reset()
|
||||
install("${context.getExternalFilesDir("microg")}/microg.apk", context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,13 @@ object MusicDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
launch {
|
||||
val url = if (apk == "stock") "$baseurl/stock/${getArch()}.apk" else "$baseurl/$variant.apk"
|
||||
suspendCoroutine {
|
||||
downloadProgress.get()?.currentDownload = PRDownloader.download(url, downloadPath, getFileNameFromUrl(url))
|
||||
downloadProgress.value?.currentDownload = PRDownloader.download(url, downloadPath, getFileNameFromUrl(url))
|
||||
.build()
|
||||
.setOnStartOrResumeListener {
|
||||
downloadProgress.get()?.downloadingFile?.set(context.getString(R.string.downloading_file, getFileNameFromUrl(url)))
|
||||
downloadProgress.value?.downloadingFile?.value =context.getString(R.string.downloading_file, getFileNameFromUrl(url))
|
||||
}
|
||||
.setOnProgressListener { progress ->
|
||||
downloadProgress.get()?.downloadProgress?.set((progress.currentBytes * 100 / progress.totalBytes).toInt())
|
||||
downloadProgress.value?.downloadProgress?.value = (progress.currentBytes * 100 / progress.totalBytes).toInt()
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
|
@ -90,7 +90,7 @@ object MusicDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
return
|
||||
}
|
||||
|
||||
downloadProgress.get()?.downloadingFile?.set(context.getString(R.string.error_downloading, "Music"))
|
||||
downloadProgress.value?.downloadingFile?.value = context.getString(R.string.error_downloading, "Music")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -99,8 +99,8 @@ object MusicDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
}
|
||||
|
||||
fun startMusicInstall(context: Context) {
|
||||
downloadProgress.get()?.installing?.set(true)
|
||||
downloadProgress.get()?.reset()
|
||||
downloadProgress.value?.installing?.value = true
|
||||
downloadProgress.value?.reset()
|
||||
if (variant == "root")
|
||||
installMusicRoot(context)
|
||||
else
|
||||
|
|
|
@ -86,13 +86,13 @@ object VancedDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?")
|
||||
}
|
||||
|
||||
downloadProgress.get()?.currentDownload = PRDownloader.download(url, downloadPath, getFileNameFromUrl(url))
|
||||
downloadProgress.value?.currentDownload = PRDownloader.download(url, downloadPath, getFileNameFromUrl(url))
|
||||
.build()
|
||||
.setOnStartOrResumeListener {
|
||||
downloadProgress.get()?.downloadingFile?.set(context.getString(R.string.downloading_file, getFileNameFromUrl(url)))
|
||||
downloadProgress.value?.downloadingFile?.value = context.getString(R.string.downloading_file, getFileNameFromUrl(url))
|
||||
}
|
||||
.setOnProgressListener { progress ->
|
||||
downloadProgress.get()?.downloadProgress?.set((progress.currentBytes * 100 / progress.totalBytes).toInt())
|
||||
downloadProgress.value?.downloadProgress?.value = (progress.currentBytes * 100 / progress.totalBytes).toInt()
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
|
@ -143,7 +143,7 @@ object VancedDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
}
|
||||
|
||||
} else {
|
||||
downloadProgress.get()?.downloadingFile?.set(context.getString(R.string.error_downloading, getFileNameFromUrl(url)))
|
||||
downloadProgress.value?.downloadingFile?.value = context.getString(R.string.error_downloading, getFileNameFromUrl(url))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -151,8 +151,8 @@ object VancedDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
}
|
||||
|
||||
fun startVancedInstall(context: Context, variant: String? = this.variant) {
|
||||
downloadProgress.get()?.installing?.set(true)
|
||||
downloadProgress.get()?.reset()
|
||||
downloadProgress.value?.installing?.value = true
|
||||
downloadProgress.value?.reset()
|
||||
FirebaseAnalytics.getInstance(context).logEvent(FirebaseAnalytics.Event.SELECT_ITEM) {
|
||||
variant?.let { param("vanced_variant", it) }
|
||||
theme?.let { param("vanced_theme", it) }
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
package com.vanced.manager.model
|
||||
|
||||
import androidx.databinding.ObservableBoolean
|
||||
import androidx.databinding.ObservableField
|
||||
import androidx.databinding.ObservableInt
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
|
||||
open class ProgressModel {
|
||||
|
||||
val downloadProgress = ObservableInt()
|
||||
val downloadingFile = ObservableField<String>()
|
||||
val installing = ObservableBoolean()
|
||||
|
||||
val downloadProgress = MutableLiveData<Int>()
|
||||
val downloadingFile = MutableLiveData<String>()
|
||||
val installing = MutableLiveData<Boolean>()
|
||||
|
||||
var currentDownload: Int = 0
|
||||
|
||||
fun reset() {
|
||||
downloadProgress.set(0)
|
||||
downloadingFile.set("")
|
||||
downloadProgress.value = 0
|
||||
downloadingFile.value = ""
|
||||
}
|
||||
|
||||
init {
|
||||
installing.set(false)
|
||||
installing.value = false
|
||||
reset()
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
|
@ -19,53 +18,87 @@ import com.vanced.manager.core.downloader.MicrogDownloader.downloadMicrog
|
|||
import com.vanced.manager.core.downloader.MusicDownloader.downloadMusic
|
||||
import com.vanced.manager.core.downloader.VancedDownloader.downloadVanced
|
||||
import com.vanced.manager.databinding.DialogAppDownloadBinding
|
||||
import com.vanced.manager.ui.core.BindingDialogFragment
|
||||
import com.vanced.manager.utils.DownloadHelper.downloadProgress
|
||||
|
||||
class AppDownloadDialog(
|
||||
private val app: String,
|
||||
private val installing: Boolean = false
|
||||
) : DialogFragment() {
|
||||
class AppDownloadDialog : BindingDialogFragment<DialogAppDownloadBinding>() {
|
||||
|
||||
private lateinit var binding: DialogAppDownloadBinding
|
||||
companion object {
|
||||
|
||||
const val CLOSE_DIALOG = "close_dialog"
|
||||
private const val TAG_APP = "TAG_APP"
|
||||
private const val TAG_INSTALLING = "TAG_INSTALLING"
|
||||
|
||||
fun newInstance(
|
||||
app: String,
|
||||
installing: Boolean = false
|
||||
): AppDownloadDialog = AppDownloadDialog().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(TAG_APP, app)
|
||||
putBoolean(TAG_INSTALLING, installing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
|
||||
|
||||
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
when (intent.action) {
|
||||
CLOSE_DIALOG -> dismiss()
|
||||
if (intent.action == CLOSE_DIALOG) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
if (dialog != null && dialog?.window != null) {
|
||||
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
}
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_app_download, container, false)
|
||||
binding.progress = downloadProgress.get()
|
||||
return binding.root
|
||||
) = DialogAppDownloadBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun otherSetups() {
|
||||
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
bindData()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
isCancelable = false
|
||||
binding.appDownloadHeader.text = requireActivity().getString(R.string.installing_app, app)
|
||||
binding.appDownloadCancel.setOnClickListener {
|
||||
if (downloadProgress.get()?.installing?.get() == true)
|
||||
return@setOnClickListener
|
||||
|
||||
PRDownloader.cancel(downloadProgress.get()!!.currentDownload)
|
||||
dismiss()
|
||||
private fun bindData() {
|
||||
with(binding) {
|
||||
isCancelable = false
|
||||
bindDownloadProgress()
|
||||
val app = arguments?.getString(TAG_APP)
|
||||
appDownloadHeader.text = app
|
||||
if (arguments?.getBoolean(TAG_INSTALLING) == false) {
|
||||
when (app) {
|
||||
getString(R.string.vanced) -> downloadVanced(requireContext())
|
||||
getString(R.string.music) -> downloadMusic(requireContext())
|
||||
getString(R.string.microg) -> downloadMicrog(requireContext())
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!installing) {
|
||||
when (app) {
|
||||
requireActivity().getString(R.string.vanced) -> downloadVanced(requireActivity())
|
||||
requireActivity().getString(R.string.music) -> downloadMusic(requireActivity())
|
||||
requireActivity().getString(R.string.microg) -> downloadMicrog(requireActivity())
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
PRDownloader.cancel(downloadProgress.value?.currentDownload)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
progressModel.downloadingFile.observe(viewLifecycleOwner) {
|
||||
appDownloadFile.text = it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,9 +113,4 @@ class AppDownloadDialog(
|
|||
intentFilter.addAction(CLOSE_DIALOG)
|
||||
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CLOSE_DIALOG = "close_dialog"
|
||||
}
|
||||
|
||||
}
|
|
@ -5,8 +5,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import androidx.preference.PreferenceManager.*
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.downloader.MicrogDownloader.startMicrogInstall
|
||||
|
@ -14,7 +13,6 @@ import com.vanced.manager.core.downloader.MusicDownloader.startMusicInstall
|
|||
import com.vanced.manager.core.downloader.VancedDownloader.startVancedInstall
|
||||
import com.vanced.manager.databinding.DialogInstallationFilesDetectedBinding
|
||||
import com.vanced.manager.utils.Extensions.show
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class InstallationFilesDetectedDialog(private val app: String) : BottomSheetDialogFragment() {
|
||||
|
||||
|
@ -39,18 +37,23 @@ class InstallationFilesDetectedDialog(private val app: String) : BottomSheetDial
|
|||
dismiss()
|
||||
if (app == requireActivity().getString(R.string.vanced))
|
||||
VancedPreferencesDialog().show(requireActivity())
|
||||
else
|
||||
AppDownloadDialog(app).show(requireActivity())
|
||||
else {
|
||||
AppDownloadDialog.newInstance(app).show(requireActivity())
|
||||
}
|
||||
}
|
||||
|
||||
binding.installationDetectedInstall.setOnClickListener {
|
||||
dismiss()
|
||||
when (app) {
|
||||
requireActivity().getString(R.string.vanced) -> startVancedInstall(requireActivity(), getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot"))
|
||||
requireActivity().getString(R.string.vanced) -> startVancedInstall(requireActivity(),
|
||||
getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot"))
|
||||
requireActivity().getString(R.string.music) -> startMusicInstall(requireActivity())
|
||||
requireActivity().getString(R.string.microg) -> startMicrogInstall(requireActivity())
|
||||
}
|
||||
AppDownloadDialog(app, true).show(requireActivity())
|
||||
AppDownloadDialog.newInstance(
|
||||
app = app,
|
||||
installing = true
|
||||
).show(requireActivity())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,13 +10,19 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.downloader.MicrogDownloader
|
||||
import com.vanced.manager.core.downloader.MusicDownloader
|
||||
import com.vanced.manager.core.downloader.VancedDownloader
|
||||
import com.vanced.manager.databinding.DialogAppDownloadBinding
|
||||
import com.vanced.manager.databinding.DialogManagerUpdateBinding
|
||||
import com.vanced.manager.ui.core.BindingDialogFragment
|
||||
import com.vanced.manager.utils.DownloadHelper.downloadManager
|
||||
import com.vanced.manager.utils.DownloadHelper.downloadProgress
|
||||
import com.vanced.manager.utils.InternetTools.isUpdateAvailable
|
||||
|
@ -24,9 +30,24 @@ import kotlinx.coroutines.launch
|
|||
|
||||
class ManagerUpdateDialog(
|
||||
private val forceUpdate: Boolean
|
||||
) : DialogFragment() {
|
||||
) : BindingDialogFragment<DialogManagerUpdateBinding>() {
|
||||
|
||||
private lateinit var binding: DialogManagerUpdateBinding
|
||||
companion object {
|
||||
|
||||
const val CLOSE_DIALOG = "close_dialog"
|
||||
private const val TAG_APP = "TAG_APP"
|
||||
private const val TAG_INSTALLING = "TAG_INSTALLING"
|
||||
|
||||
fun newInstance(
|
||||
app: String,
|
||||
installing: Boolean = false
|
||||
): AppDownloadDialog = AppDownloadDialog().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(TAG_APP, app)
|
||||
putBoolean(TAG_INSTALLING, installing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
|
||||
|
||||
|
@ -38,21 +59,15 @@ class ManagerUpdateDialog(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
if (dialog != null && dialog?.window != null) {
|
||||
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
}
|
||||
isCancelable = false
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_manager_update, container, false)
|
||||
binding.progress = downloadProgress.get()
|
||||
return binding.root
|
||||
}
|
||||
) = DialogManagerUpdateBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
override fun otherSetups() {
|
||||
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
bindData()
|
||||
lifecycleScope.launch {
|
||||
if (forceUpdate) {
|
||||
binding.managerUpdatePatient.text = requireActivity().getString(R.string.please_be_patient)
|
||||
|
@ -62,12 +77,30 @@ class ManagerUpdateDialog(
|
|||
}
|
||||
|
||||
binding.managerUpdateCancel.setOnClickListener {
|
||||
PRDownloader.cancel(downloadProgress.get()!!.currentDownload)
|
||||
PRDownloader.cancel(downloadProgress.value?.currentDownload)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindData() {
|
||||
with(binding) {
|
||||
isCancelable = false
|
||||
bindDownloadProgress()
|
||||
}
|
||||
}
|
||||
|
||||
private fun DialogManagerUpdateBinding.bindDownloadProgress() {
|
||||
with(downloadProgress) {
|
||||
observe(viewLifecycleOwner) { progressModel ->
|
||||
progressModel.downloadProgress.observe(viewLifecycleOwner) {
|
||||
managerUpdateProgressbar.progress = it
|
||||
managerUpdateProgressbar.isVisible = it != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
registerReceiver()
|
||||
|
@ -87,9 +120,4 @@ class ManagerUpdateDialog(
|
|||
intentFilter.addAction(CLOSE_DIALOG)
|
||||
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CLOSE_DIALOG = "close_dialog"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,8 +43,9 @@ class MusicPreferencesDialog : BottomSheetDialogFragment() {
|
|||
}
|
||||
binding.musicInstall.setOnClickListener {
|
||||
dismiss()
|
||||
AppDownloadDialog(requireActivity().getString(R.string.music)).show(requireActivity())
|
||||
AppDownloadDialog.newInstance(
|
||||
app = getString(R.string.music)
|
||||
).show(requireActivity())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -68,7 +68,9 @@ class VancedPreferencesDialog : BottomSheetDialogFragment() {
|
|||
|
||||
binding.vancedInstall.setOnClickListener {
|
||||
dismiss()
|
||||
AppDownloadDialog(requireActivity().getString(R.string.vanced)).show(requireActivity())
|
||||
AppDownloadDialog.newInstance(
|
||||
app = getString(R.string.vanced)
|
||||
).show(requireActivity())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
when (app) {
|
||||
activity.getString(R.string.vanced) -> VancedPreferencesDialog().show(activity)
|
||||
activity.getString(R.string.music) -> MusicPreferencesDialog().show(activity)
|
||||
else -> AppDownloadDialog(app).show(activity)
|
||||
else -> AppDownloadDialog.newInstance(app).show(activity)
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -109,18 +109,38 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
when (app) {
|
||||
activity.getString(R.string.vanced) -> {
|
||||
when (variant) {
|
||||
"nonroot" -> if (vancedInstallFilesExist(activity)) InstallationFilesDetectedDialog(app).show(activity) else VancedPreferencesDialog().show(activity)
|
||||
"root" -> VancedPreferencesDialog().show(activity)
|
||||
"nonroot" -> {
|
||||
if (vancedInstallFilesExist(activity)) {
|
||||
InstallationFilesDetectedDialog(app).show(activity)
|
||||
} else {
|
||||
VancedPreferencesDialog().show(activity)
|
||||
}
|
||||
}
|
||||
"root" -> {
|
||||
VancedPreferencesDialog().show(activity)
|
||||
}
|
||||
}
|
||||
}
|
||||
activity.getString(R.string.music) -> {
|
||||
when (variant) {
|
||||
"nonroot" -> if (musicApkExists(activity)) InstallationFilesDetectedDialog(app).show(activity) else MusicPreferencesDialog().show(activity)
|
||||
"root" -> MusicPreferencesDialog().show(activity)
|
||||
"nonroot" -> {
|
||||
if (musicApkExists(activity)) {
|
||||
InstallationFilesDetectedDialog(app).show(activity)
|
||||
} else {
|
||||
MusicPreferencesDialog().show(activity)
|
||||
}
|
||||
}
|
||||
"root" -> {
|
||||
MusicPreferencesDialog().show(activity)
|
||||
}
|
||||
}
|
||||
}
|
||||
activity.getString(R.string.microg) -> {
|
||||
if (apkExist(activity, "microg.apk")) InstallationFilesDetectedDialog(app).show(activity) else AppDownloadDialog(app).show(activity)
|
||||
if (apkExist(activity, "microg.apk")) {
|
||||
InstallationFilesDetectedDialog(app).show(activity)
|
||||
} else {
|
||||
AppDownloadDialog.newInstance(app).show(activity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ object AppUtils: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
}
|
||||
|
||||
fun sendCloseDialog(context: Context): Job {
|
||||
downloadProgress.get()?.installing?.set(false)
|
||||
downloadProgress.value?.installing?.value = false
|
||||
return launch {
|
||||
delay(700)
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(AppDownloadDialog.CLOSE_DIALOG))
|
||||
|
@ -40,7 +40,7 @@ object AppUtils: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
}
|
||||
|
||||
fun sendFailure(status: Int, context: Context): Job {
|
||||
downloadProgress.get()?.installing?.set(false)
|
||||
downloadProgress.value?.installing?.value = false
|
||||
//Delay error broadcast until activity (and fragment) get back to the screen
|
||||
return launch {
|
||||
delay(700)
|
||||
|
@ -51,7 +51,7 @@ object AppUtils: CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
}
|
||||
|
||||
fun sendFailure(error: MutableList<String>, context: Context): Job {
|
||||
downloadProgress.get()?.installing?.set(false)
|
||||
downloadProgress.value?.installing?.value = false
|
||||
return launch {
|
||||
delay(700)
|
||||
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
||||
|
|
|
@ -10,7 +10,7 @@ import android.widget.Toast
|
|||
import androidx.core.content.FileProvider
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.net.toUri
|
||||
import androidx.databinding.ObservableField
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
|
@ -34,23 +34,23 @@ object DownloadHelper {
|
|||
return downloadManager.enqueue(request)
|
||||
}
|
||||
|
||||
val downloadProgress = ObservableField<ProgressModel>()
|
||||
val downloadProgress = MutableLiveData<ProgressModel>()
|
||||
|
||||
init {
|
||||
downloadProgress.set(ProgressModel())
|
||||
downloadProgress.value = ProgressModel()
|
||||
}
|
||||
|
||||
suspend fun downloadManager(context: Context) =
|
||||
withContext(Dispatchers.IO) {
|
||||
val url = "https://github.com/YTVanced/VancedManager/releases/latest/download/manager.apk"
|
||||
downloadProgress.get()?.currentDownload = PRDownloader.download(url, context.getExternalFilesDir("manager")?.path, "manager.apk")
|
||||
downloadProgress.value?.currentDownload = PRDownloader.download(url, context.getExternalFilesDir("manager")?.path, "manager.apk")
|
||||
.build()
|
||||
.setOnProgressListener { progress ->
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
downloadProgress.get()?.downloadProgress?.set(mProgress.toInt())
|
||||
downloadProgress.value?.downloadProgress?.value = mProgress.toInt()
|
||||
}
|
||||
.setOnCancelListener {
|
||||
downloadProgress.get()?.downloadProgress?.set(0)
|
||||
downloadProgress.value?.downloadProgress?.value = 0
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
|
|
|
@ -1,94 +1,72 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".ui.dialogs.AppDownloadDialog"
|
||||
style="@style/DialogCard">
|
||||
|
||||
<data>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<import type="android.view.View" />
|
||||
<TextView
|
||||
android:id="@+id/app_download_header"
|
||||
tools:text="Installing Vanced"
|
||||
style="@style/DialogCardTitle"/>
|
||||
|
||||
<variable
|
||||
name="progress"
|
||||
type="com.vanced.manager.model.ProgressModel" />
|
||||
<TextView
|
||||
android:id="@+id/app_download_patient"
|
||||
android:layout_below="@id/app_download_header"
|
||||
android:text="@string/please_be_patient"
|
||||
style="@style/DialogCardSubtitle"/>
|
||||
|
||||
</data>
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
android:id="@+id/app_download_progressbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/app_download_patient"
|
||||
android:layout_marginTop="24dp"
|
||||
app:indicatorColor="?colorPrimary"
|
||||
app:indicatorCornerRadius="15dp"
|
||||
tools:progress="10"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Determinate"/>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="@style/DialogCard"
|
||||
tools:context=".ui.dialogs.AppDownloadDialog">
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
android:id="@+id/app_install_progressbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/app_download_progressbar"
|
||||
android:layout_marginTop="24dp"
|
||||
android:indeterminate="true"
|
||||
app:indicatorColor="?colorPrimary"
|
||||
app:indicatorCornerRadius="15dp"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Indeterminate"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/app_install_progressbar"
|
||||
android:layout_marginTop="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/app_download_header"
|
||||
style="@style/DialogCardTitle"
|
||||
tools:text="Installing Vanced" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/app_download_patient"
|
||||
style="@style/DialogCardSubtitle"
|
||||
android:layout_below="@id/app_download_header"
|
||||
android:text="@string/please_be_patient" />
|
||||
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
android:id="@+id/app_download_progressbar"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Determinate"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/app_download_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/app_download_patient"
|
||||
android:layout_marginTop="24dp"
|
||||
android:progress="@{progress.downloadProgress}"
|
||||
android:visibility="@{progress.installing ? View.GONE : View.VISIBLE}"
|
||||
app:indicatorColor="?colorPrimary"
|
||||
app:indicatorCornerRadius="15dp"
|
||||
tools:progress="10" />
|
||||
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
android:id="@+id/app_install_progressbar"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Indeterminate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/app_download_progressbar"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toStartOf="@+id/app_download_cancel"
|
||||
android:textSize="15sp"
|
||||
tools:text="Downloading base.apk..."/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/app_download_cancel"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="24dp"
|
||||
android:indeterminate="true"
|
||||
android:visibility="@{progress.installing ? View.VISIBLE : View.GONE}"
|
||||
app:indicatorColor="?colorPrimary"
|
||||
app:indicatorCornerRadius="15dp" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/app_install_progressbar"
|
||||
android:layout_marginTop="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/app_download_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toStartOf="@+id/app_download_cancel"
|
||||
android:text="@{progress.downloadingFile}"
|
||||
android:textSize="15sp"
|
||||
android:visibility="@{progress.installing ? View.GONE : View.VISIBLE}"
|
||||
tools:text="Downloading base.apk..." />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/app_download_cancel"
|
||||
style="@style/OutlinedButtonStyle"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:enabled="@{!progress.installing}"
|
||||
android:text="@string/cancel"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
android:text="@string/cancel"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
style="@style/OutlinedButtonStyle"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</layout>
|
||||
</RelativeLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
|
@ -1,73 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
app:contentPaddingLeft="16dp"
|
||||
app:contentPaddingRight="16dp"
|
||||
tools:context=".ui.dialogs.ManagerUpdateDialog"
|
||||
style="@style/MaterialCard">
|
||||
|
||||
<data>
|
||||
|
||||
<import type="android.view.View" />
|
||||
|
||||
<variable
|
||||
name="progress"
|
||||
type="com.vanced.manager.model.ProgressModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="@style/MaterialCard"
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
app:contentPaddingLeft="16dp"
|
||||
app:contentPaddingRight="16dp"
|
||||
tools:context=".ui.dialogs.ManagerUpdateDialog">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
<TextView
|
||||
android:id="@+id/manager_update_header"
|
||||
android:text="@string/update_center"
|
||||
style="@style/DialogCardTitle"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/manager_update_patient"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/manager_update_header"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/checking_updates"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/manager_update_header"
|
||||
style="@style/DialogCardTitle"
|
||||
android:text="@string/update_center" />
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
android:id="@+id/manager_update_progressbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/manager_update_patient"
|
||||
android:layout_marginTop="32dp"
|
||||
android:paddingBottom="8dp"
|
||||
app:indicatorColor="?colorPrimary"
|
||||
app:indicatorCornerRadius="15dp"
|
||||
tools:progress="10"
|
||||
tools:visibility="visible"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Determinate"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/manager_update_patient"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/manager_update_header"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/checking_updates"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
android:id="@+id/manager_update_progressbar"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Determinate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/manager_update_patient"
|
||||
android:layout_marginTop="32dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:progress="@{progress.downloadProgress}"
|
||||
android:visibility="@{progress.downloadProgress == 0 ? View.GONE : View.VISIBLE}"
|
||||
app:indicatorColor="?colorPrimary"
|
||||
app:indicatorCornerRadius="15dp"
|
||||
tools:progress="10"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/manager_update_cancel"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/manager_update_progressbar"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:text="@string/cancel"
|
||||
app:strokeWidth="2dp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</layout>
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/manager_update_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@id/manager_update_progressbar"
|
||||
android:text="@string/cancel"
|
||||
app:strokeWidth="2dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
|
||||
</RelativeLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
Loading…
Reference in a new issue