mirror of
https://github.com/YTVanced/VancedManager
synced 2025-01-05 15:01:01 +00:00
reverted to PRDownload
This commit is contained in:
parent
50e05c4660
commit
ac4cc3ff7a
3 changed files with 75 additions and 69 deletions
|
@ -44,7 +44,7 @@ class VancedDownloadService: Service() {
|
|||
runBlocking {
|
||||
launch {
|
||||
val defPrefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val insallUrl = defPrefs.getString("install_url", baseUrl)
|
||||
val installUrl = defPrefs.getString("install_url", baseUrl)
|
||||
val vancedVer = getObjectFromJson("$installUrl/vanced.json", "version")
|
||||
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
|
@ -70,9 +70,9 @@ class VancedDownloadService: Service() {
|
|||
|
||||
val channel = 69
|
||||
PRDownloader
|
||||
.download(url, cacheDir.path, getFileNameFromUrl(url))
|
||||
.download(url, getExternalFilesDir("apks")?.path, getFileNameFromUrl(url))
|
||||
.build()
|
||||
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply() } }
|
||||
//.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply() } }
|
||||
.setOnProgressListener { progress ->
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
displayDownloadNotif(channel, mProgress.toInt(), getFileNameFromUrl(url), this@VancedDownloadService)
|
||||
|
@ -83,8 +83,8 @@ class VancedDownloadService: Service() {
|
|||
"arch" -> downloadSplits("theme")
|
||||
"theme" -> downloadSplits("lang")
|
||||
"lang" -> {
|
||||
count++
|
||||
if (count < lang?.count()!!) {
|
||||
count++
|
||||
downloadSplits("lang")
|
||||
} else {
|
||||
prepareInstall(variant!!)
|
||||
|
|
|
@ -1,33 +1,28 @@
|
|||
package com.vanced.manager.ui.fragments
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.ui.MainActivity
|
||||
import com.vanced.manager.utils.DownloadHelper.download
|
||||
import com.vanced.manager.utils.InternetTools.getObjectFromJson
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
|
||||
class DevSettingsFragment: PreferenceFragmentCompat() {
|
||||
|
||||
private var downloadId: Long = 0
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.dev_settings, rootKey)
|
||||
activity?.registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
|
||||
|
||||
val ftSwitch: Preference? = findPreference("firststart_switch")
|
||||
|
||||
|
@ -63,8 +58,34 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
|
|||
forceUpdate?.setOnPreferenceClickListener {
|
||||
runBlocking {
|
||||
launch {
|
||||
val url = getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "url")
|
||||
downloadId = activity?.let { download(url, "apk", "manager.apk", it) }!!
|
||||
val url = "https://github.com/YTVanced/VancedManager/releases/latest/download/manager.apk"
|
||||
//downloadId = activity?.let { download(url, "apk", "manager.apk", it) }!!
|
||||
PRDownloader.download(url, activity?.filesDir?.path, "manager.apk")
|
||||
.build()
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
activity?.let {
|
||||
val apk = File("${activity?.filesDir?.path}/manager.apk")
|
||||
val uri =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
FileProvider.getUriForFile(activity!!, "${activity?.packageName}.provider", apk)
|
||||
else
|
||||
Uri.fromFile(apk)
|
||||
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(error: com.downloader.Error?) {
|
||||
Toast.makeText(activity, error.toString(), Toast.LENGTH_SHORT).show()
|
||||
Log.e("VMUpgrade", error.toString())
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
true
|
||||
|
@ -72,26 +93,4 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
|
|||
|
||||
}
|
||||
|
||||
private val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) {
|
||||
activity?.let {
|
||||
val apk = File("${activity?.getExternalFilesDir("apk")}/manager.apk")
|
||||
val uri =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
FileProvider.getUriForFile(activity!!, "${activity?.packageName}.provider", apk)
|
||||
else
|
||||
Uri.fromFile(apk)
|
||||
|
||||
val mIntent = Intent(Intent.ACTION_VIEW)
|
||||
mIntent.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
mIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
startActivity(mIntent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -10,13 +10,18 @@ import android.graphics.drawable.ColorDrawable
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.DownloadHelper.download
|
||||
|
@ -71,44 +76,46 @@ class UpdateCheckFragment : DialogFragment() {
|
|||
private fun upgradeManager() {
|
||||
runBlocking {
|
||||
launch {
|
||||
val url = InternetTools.getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "url")
|
||||
downloadId = activity?.let { download(url, "apk", "manager.apk", it) }!!
|
||||
val loadBar = view?.findViewById<ProgressBar>(R.id.update_center_progressbar)
|
||||
val url = "https://github.com/YTVanced/VancedManager/releases/latest/download/manager.apk"
|
||||
//downloadId = activity?.let { download(url, "apk", "manager.apk", it) }!!
|
||||
PRDownloader.download(url, activity?.filesDir?.path, "manager.apk")
|
||||
.build()
|
||||
.setOnProgressListener { progress ->
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
loadBar?.visibility = View.VISIBLE
|
||||
loadBar?.progress = mProgress.toInt()
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
activity?.let {
|
||||
val apk = File("${activity?.filesDir?.path}/manager.apk")
|
||||
val uri =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
FileProvider.getUriForFile(activity!!, "${activity?.packageName}.provider", apk)
|
||||
else
|
||||
Uri.fromFile(apk)
|
||||
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(error: com.downloader.Error?) {
|
||||
Toast.makeText(activity, error.toString(), Toast.LENGTH_SHORT).show()
|
||||
Log.e("VMUpgrade", error.toString())
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
PRDownloader.download(dwnldUrl, activity?.filesDir?.path, "manager.apk")
|
||||
.build()
|
||||
.setOnProgressListener { progress ->
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
loadBar?.visibility = View.VISIBLE
|
||||
loadBar?.progress = mProgress.toInt()
|
||||
|
||||
}
|
||||
.start(object : OnDownloadListener{
|
||||
override fun onDownloadComplete() {
|
||||
activity?.let {
|
||||
val apk = File("${activity?.filesDir?.path}/manager.apk")
|
||||
val uri =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
FileProvider.getUriForFile(activity!!, "${activity?.packageName}.provider", apk)
|
||||
else
|
||||
Uri.fromFile(apk)
|
||||
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(error: Error?) {
|
||||
Toast.makeText(activity, error.toString(), Toast.LENGTH_SHORT).show()
|
||||
Log.e("VMUpgrade", error.toString())
|
||||
}
|
||||
})
|
||||
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in a new issue