0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-23 19:55:11 +00:00
This commit is contained in:
X1nto 2020-06-30 12:09:01 +04:00
parent 925f47034c
commit 2dacfb0616
5 changed files with 15 additions and 12 deletions

View file

@ -9,8 +9,9 @@ import com.downloader.PRDownloader
class DownloadBroadcastReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
PRDownloader.cancel(intent?.getStringExtra("dwnldId"))
Log.d("VMNotification", "Canceled ${intent?.getStringExtra("dwnldId")} download")
val tag: Int? = intent?.getIntExtra("dwnldId", 0)
PRDownloader.cancel(tag)
Log.d("VMNotification", "Canceled ${intent?.getIntExtra("dwnldId", 0)} download")
}
}

View file

@ -37,7 +37,7 @@ class MicrogDownloadService: Service() {
val dwnldUrl = apkUrl.get("url").asString
val channel = 420
PRDownloader.download(dwnldUrl, filesDir.path, "microg.apk")
.setTag("MicrogDownload")
.setTag(55)
.build()
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply() } }
.setOnProgressListener { progress ->
@ -46,7 +46,7 @@ class MicrogDownloadService: Service() {
channel,
mProgress.toInt(),
getFileNameFromUrl(dwnldUrl),
"MicrogDownload",
55,
this
)
}

View file

@ -62,14 +62,14 @@ class VancedDownloadService: Service() {
}
val channel = 69
PRDownloader.download(url, cacheDir.path, getFileNameFromUrl(url))
.setTag("VancedDownload")
PRDownloader
.download(url, cacheDir.path, getFileNameFromUrl(url))
.setTag(66)
.build()
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply() } }
.setOnProgressListener { progress ->
val mProgress = progress.currentBytes * 100 / progress.totalBytes
displayDownloadNotif(channel, mProgress.toInt(), getFileNameFromUrl(url), "VancedDownload", this)
displayDownloadNotif(channel, mProgress.toInt(), getFileNameFromUrl(url), 66, this)
}
.setOnCancelListener { OnCancelListener {
cancelNotif(channel, this)

View file

@ -7,7 +7,9 @@ import java.io.InputStreamReader
object MiuiHelper {
fun isMiui(): Boolean = !TextUtils.isEmpty(getSystemProps("ro.miui.system.version.name"))
fun isMiui(): Boolean {
return !TextUtils.isEmpty(getSystemProps("ro.miui.system.version.name"))
}
private fun getSystemProps(propname: String): String? {
val line: String

View file

@ -24,7 +24,7 @@ object NotificationHelper {
}
}
fun displayDownloadNotif(channel: Int, progress:Int, filename: String, downTag: String, context: Context) {
fun displayDownloadNotif(channel: Int, progress:Int, filename: String, downId: Int, context: Context) {
val notifBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(context, channel.toString()).setChannelId("69420")
@ -32,7 +32,7 @@ object NotificationHelper {
Notification.Builder(context).setPriority(Notification.PRIORITY_LOW)
val cancelDownload = Intent(context, DownloadBroadcastReceiver::class.java).apply {
putExtra("dwnldId", downTag)
putExtra("dwnldId", downId)
}
val cancelPendingIntent = PendingIntent.getBroadcast(context, 0, cancelDownload, PendingIntent.FLAG_UPDATE_CURRENT)
@ -43,7 +43,7 @@ object NotificationHelper {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
addAction(Notification.Action.Builder(null, context.getString(R.string.cancel), cancelPendingIntent).build())
else
addAction(0, context.getString(R.string.cancel), cancelPendingIntent )
addAction(0, context.getString(R.string.cancel), cancelPendingIntent)
}
val notif = notifBuilder.build()