0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-30 06:53:01 +00:00

fixed manager upgrade

This commit is contained in:
X1nto 2020-05-26 22:46:38 +04:00
parent a812f338c3
commit aa7bade5ce

View file

@ -16,7 +16,6 @@ import android.widget.Button
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.dezlum.codelabs.getjson.GetJson import com.dezlum.codelabs.getjson.GetJson
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
@ -29,7 +28,8 @@ import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import zlc.season.rxdownload4.download import zlc.season.rxdownload4.download
import zlc.season.rxdownload4.file import zlc.season.rxdownload4.file
import java.util.jar.Manifest import zlc.season.rxdownload4.task.Task
import zlc.season.rxdownload4.utils.getFileNameFromUrl
class UpdateCheckFragment : DialogFragment() { class UpdateCheckFragment : DialogFragment() {
@ -67,22 +67,7 @@ class UpdateCheckFragment : DialogFragment() {
checkingTxt.text = "Update Found!" checkingTxt.text = "Update Found!"
updatebtn.setOnClickListener { updatebtn.setOnClickListener {
upgradeManager(loadBar)
if (ContextCompat.checkSelfPermission(requireContext(),
android.Manifest.permission.READ_EXTERNAL_STORAGE) +
ContextCompat.checkSelfPermission(requireContext(),
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE),
69)
} else {
upgradeManager(loadBar, checkingTxt)
}
} }
} else { } else {
@ -114,14 +99,23 @@ class UpdateCheckFragment : DialogFragment() {
} }
} }
private fun upgradeManager(loadBar: ProgressBar, checkingTxt: TextView) { private fun upgradeManager(loadBar: ProgressBar) {
val apkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json") val apkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json")
val dwnldUrl = apkUrl.get("url").asString val dwnldUrl = apkUrl.get("url").asString
if (dwnldUrl.file().exists()) val task = activity?.filesDir?.path?.let {
dwnldUrl.file().delete() Task(
url = dwnldUrl,
saveName = getFileNameFromUrl(dwnldUrl),
savePath = it
)
}
disposable = dwnldUrl.download() if (task?.file()?.exists()!!)
task.file().delete()
disposable = task
.download()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeBy( .subscribeBy(
onNext = { progress -> onNext = { progress ->
@ -134,7 +128,7 @@ class UpdateCheckFragment : DialogFragment() {
prefs.edit().putBoolean("isUpgrading", true).apply() prefs.edit().putBoolean("isUpgrading", true).apply()
val pn = activity?.packageName val pn = activity?.packageName
val apk = dwnldUrl.file() val apk = task.file()
val uri = val uri =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
FileProvider.getUriForFile(requireContext(), "$pn.provider", apk) FileProvider.getUriForFile(requireContext(), "$pn.provider", apk)
@ -147,8 +141,8 @@ class UpdateCheckFragment : DialogFragment() {
startActivity(intent) startActivity(intent)
}, },
onError = { throwable -> onError = { throwable ->
checkingTxt.text = throwable.toString() Toast.makeText(activity, throwable.toString(), Toast.LENGTH_SHORT).show()
Log.e("Error", throwable.toString()) Log.e("VMUpgrade", throwable.toString())
} }
) )
} }