moved download/installation messages to notifications for better background experience
This commit is contained in:
parent
588dd1ba4c
commit
356dc095bf
|
@ -0,0 +1,16 @@
|
|||
package com.vanced.manager.core.downloader
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.downloader.PRDownloader
|
||||
|
||||
class DownloadBroadcastReceiver: BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
when (intent?.action) {
|
||||
"cancel" -> PRDownloader.cancel(intent.getStringExtra("dwnldId"))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -11,9 +11,12 @@ import com.downloader.Error
|
|||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.OnStartOrResumeListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.ui.fragments.HomeFragment
|
||||
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||
import com.vanced.manager.utils.NotificationHelper
|
||||
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||
import java.lang.Exception
|
||||
import java.lang.IllegalStateException
|
||||
import java.lang.RuntimeException
|
||||
|
@ -36,52 +39,32 @@ class MicrogDownloadService: Service() {
|
|||
|
||||
private fun downloadMicrog() {
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply()
|
||||
|
||||
val apkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
|
||||
val dwnldUrl = apkUrl.get("url").asString
|
||||
val channel = 420
|
||||
PRDownloader.download(dwnldUrl, filesDir.path, "microg.apk")
|
||||
.setTag("MicrogDownload")
|
||||
.build()
|
||||
.setOnStartOrResumeListener { OnStartOrResumeListener { TODO("Not yet implemented") } }
|
||||
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply() } }
|
||||
.setOnProgressListener { progress ->
|
||||
val intent = Intent(HomeFragment.MICROG_DOWNLOADING)
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
intent.action = HomeFragment.MICROG_DOWNLOADING
|
||||
intent.putExtra("microgProgress", mProgress.toInt())
|
||||
intent.putExtra("fileName", "Downloading ${getFileNameFromUrl(dwnldUrl)}...")
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
NotificationHelper.displayDownloadNotif(
|
||||
channel,
|
||||
maxVal = 0,
|
||||
progress = mProgress.toInt(),
|
||||
filename = getFileNameFromUrl(dwnldUrl),
|
||||
context = this@MicrogDownloadService
|
||||
downTag = "MicrogDownload",
|
||||
context = this
|
||||
)
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
val intent = Intent(HomeFragment.MICROG_DOWNLOADED)
|
||||
intent.action = HomeFragment.MICROG_DOWNLOADED
|
||||
LocalBroadcastManager.getInstance(this@MicrogDownloadService).sendBroadcast(intent)
|
||||
prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply()
|
||||
NotificationHelper.displayDownloadNotif(
|
||||
channel,
|
||||
maxVal = 0,
|
||||
filename = getFileNameFromUrl(dwnldUrl),
|
||||
context = this@MicrogDownloadService
|
||||
)
|
||||
cancelNotif(channel, this@MicrogDownloadService)
|
||||
}
|
||||
override fun onError(error: Error) {
|
||||
val intent = Intent(HomeFragment.DOWNLOAD_ERROR)
|
||||
intent.action = HomeFragment.DOWNLOAD_ERROR
|
||||
intent.putExtra("DownloadError", error.toString())
|
||||
LocalBroadcastManager.getInstance(this@MicrogDownloadService).sendBroadcast(intent)
|
||||
NotificationHelper.displayDownloadNotif(
|
||||
channel,
|
||||
maxVal = 0,
|
||||
filename = getFileNameFromUrl(dwnldUrl),
|
||||
context = this@MicrogDownloadService
|
||||
)
|
||||
prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply()
|
||||
createBasicNotif(getString(R.string.error_downloading, "Microg"), channel, this@MicrogDownloadService)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.vanced.manager.core.downloader
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -10,12 +11,16 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
|||
import androidx.preference.PreferenceManager
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.OnStartOrResumeListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.installer.RootSplitInstallerService
|
||||
import com.vanced.manager.core.installer.SplitInstaller
|
||||
import com.vanced.manager.ui.fragments.HomeFragment
|
||||
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||
import com.vanced.manager.utils.InternetTools.getLatestVancedUrl
|
||||
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||
import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif
|
||||
import java.lang.Exception
|
||||
import java.lang.IllegalStateException
|
||||
|
@ -43,7 +48,6 @@ class VancedDownloadService: Service() {
|
|||
) {
|
||||
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", getLatestVancedUrl(this))
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply()
|
||||
val variant = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getString("vanced_variant", "nonroot")
|
||||
val lang = prefs?.getString("lang", "en")
|
||||
|
@ -66,18 +70,12 @@ class VancedDownloadService: Service() {
|
|||
val channel = 69
|
||||
|
||||
PRDownloader.download(url, cacheDir.path, getFileNameFromUrl(url))
|
||||
.setTag("VancedDownload")
|
||||
.build()
|
||||
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply() } }
|
||||
.setOnProgressListener { progress ->
|
||||
val intent = Intent(HomeFragment.VANCED_DOWNLOADING)
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
intent.action = HomeFragment.VANCED_DOWNLOADING
|
||||
intent.putExtra("vancedProgress", mProgress.toInt())
|
||||
intent.putExtra(
|
||||
"fileName",
|
||||
"Downloading ${getFileNameFromUrl(url)}..."
|
||||
)
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
displayDownloadNotif(channel, mProgress.toInt(), filename = getFileNameFromUrl(url), context = this)
|
||||
displayDownloadNotif(channel, progress = mProgress.toInt(), filename = getFileNameFromUrl(url), downTag = "VancedDownload", context = this)
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
|
@ -87,24 +85,20 @@ class VancedDownloadService: Service() {
|
|||
"lang" -> {
|
||||
if (lang == "en") {
|
||||
prepareInstall(variant!!)
|
||||
displayDownloadNotif(channel, maxVal = 0, filename = getFileNameFromUrl(url), context = this@VancedDownloadService)
|
||||
cancelNotif(channel, this@VancedDownloadService)
|
||||
} else {
|
||||
downloadSplits("enlang")
|
||||
}
|
||||
}
|
||||
"enlang" -> {
|
||||
prepareInstall(variant!!)
|
||||
displayDownloadNotif(channel, maxVal = 0, filename = getFileNameFromUrl(url), context = this@VancedDownloadService)
|
||||
cancelNotif(channel, this@VancedDownloadService)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(error: Error) {
|
||||
val intent = Intent(HomeFragment.DOWNLOAD_ERROR)
|
||||
intent.action = HomeFragment.DOWNLOAD_ERROR
|
||||
intent.putExtra("DownloadError", error.toString())
|
||||
LocalBroadcastManager.getInstance(this@VancedDownloadService)
|
||||
.sendBroadcast(intent)
|
||||
createBasicNotif(getString(R.string.error_downloading, "Vanced"), channel, this@VancedDownloadService)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -114,17 +108,9 @@ class VancedDownloadService: Service() {
|
|||
intent.action = HomeFragment.VANCED_DOWNLOADED
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
if (variant == "root")
|
||||
launchRootInstaller()
|
||||
startService(Intent(this, RootSplitInstallerService::class.java))
|
||||
else
|
||||
launchInstaller()
|
||||
}
|
||||
|
||||
private fun launchInstaller() {
|
||||
SplitInstaller.installSplitApk(this)
|
||||
}
|
||||
|
||||
private fun launchRootInstaller() {
|
||||
startService(Intent(this, RootSplitInstallerService::class.java))
|
||||
SplitInstaller.installSplitApk(this)
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
|
|
|
@ -11,14 +11,22 @@ import androidx.annotation.Nullable
|
|||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.ui.MainActivity
|
||||
import com.vanced.manager.utils.MiuiHelper
|
||||
import com.vanced.manager.utils.NotificationHelper
|
||||
|
||||
class AppInstallerService: Service() {
|
||||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
val notifId = 42
|
||||
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
|
||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
|
||||
Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show()
|
||||
Log.d(TAG, "Requesting user confirmation for installation")
|
||||
NotificationHelper.createBasicNotif(
|
||||
getString(R.string.installing_app, "MicroG"),
|
||||
notifId,
|
||||
this
|
||||
)
|
||||
val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
|
||||
confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
try {
|
||||
|
@ -33,28 +41,47 @@ class AppInstallerService: Service() {
|
|||
mIntent.action = MainActivity.INSTALL_COMPLETED
|
||||
mIntent.putExtra("package", "normal")
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
NotificationHelper.createBasicNotif(
|
||||
getString(
|
||||
R.string.successfully_installed,
|
||||
"Microg"
|
||||
), notifId, this
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
|
||||
NotificationHelper.createBasicNotif(
|
||||
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)),
|
||||
notifId,
|
||||
this
|
||||
)
|
||||
}
|
||||
else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
|
||||
}
|
||||
stopSelf()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
private fun sendFailure(status: Int) {
|
||||
val msg = when (status) {
|
||||
val mIntent = Intent(MainActivity.INSTALL_FAILED)
|
||||
mIntent.action = MainActivity.INSTALL_FAILED
|
||||
mIntent.putExtra("errorMsg", getErrorMessage(status))
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
}
|
||||
|
||||
private fun getErrorMessage(status: Int): String {
|
||||
return when (status) {
|
||||
PackageInstaller.STATUS_FAILURE_ABORTED -> getString(R.string.installation_aborted)
|
||||
PackageInstaller.STATUS_FAILURE_BLOCKED -> getString(R.string.installation_blocked)
|
||||
PackageInstaller.STATUS_FAILURE_STORAGE -> getString(R.string.installation_storage)
|
||||
PackageInstaller.STATUS_FAILURE_INVALID -> getString(R.string.installation_invalid)
|
||||
PackageInstaller.STATUS_FAILURE_INCOMPATIBLE -> getString(R.string.installation_incompatible)
|
||||
PackageInstaller.STATUS_FAILURE_CONFLICT -> getString(R.string.installation_conflict)
|
||||
else -> getString(R.string.installation_failed)
|
||||
else ->
|
||||
if (MiuiHelper.isMiui())
|
||||
getString(R.string.installation_miui)
|
||||
else
|
||||
getString(R.string.installation_failed)
|
||||
}
|
||||
|
||||
val mIntent = Intent(MainActivity.INSTALL_FAILED)
|
||||
mIntent.action = MainActivity.INSTALL_FAILED
|
||||
mIntent.putExtra("errorMsg", msg)
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.topjohnwu.superuser.Shell
|
|||
import com.vanced.manager.R
|
||||
import com.vanced.manager.ui.MainActivity
|
||||
import com.vanced.manager.utils.FileInfo
|
||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||
import java.io.File
|
||||
import java.nio.charset.Charset
|
||||
import java.text.SimpleDateFormat
|
||||
|
@ -40,6 +41,7 @@ class RootSplitInstallerService: Service() {
|
|||
@WorkerThread
|
||||
private fun installSplitApkFiles(apkFiles: ArrayList<FileInfo>) {
|
||||
var sessionId: Int?
|
||||
val notifId = 666
|
||||
Log.d("AppLog", "installing split apk files:$apkFiles")
|
||||
run {
|
||||
val sessionIdResult = Shell.su("pm install-create -r -t").exec().out
|
||||
|
@ -50,6 +52,7 @@ class RootSplitInstallerService: Service() {
|
|||
}
|
||||
for (apkFile in apkFiles) {
|
||||
Log.d("AppLog", "installing APK : ${apkFile.name} ${apkFile.fileSize} ")
|
||||
createBasicNotif(getString(R.string.installing_app, "Vanced"), notifId, this)
|
||||
val command = arrayOf("su", "-c", "pm", "install-write", "-S", "${apkFile.fileSize}", "$sessionId", apkFile.name)
|
||||
val process: Process = Runtime.getRuntime().exec(command)
|
||||
val inputPipe = apkFile.getInputStream()
|
||||
|
@ -78,11 +81,13 @@ class RootSplitInstallerService: Service() {
|
|||
mIntent.action = MainActivity.INSTALL_COMPLETED
|
||||
mIntent.putExtra("package", "split")
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
createBasicNotif(getString(R.string.successfully_installed, "Vanced"), notifId, this)
|
||||
} else {
|
||||
val mIntent = Intent(MainActivity.INSTALL_FAILED)
|
||||
mIntent.action = MainActivity.INSTALL_FAILED
|
||||
mIntent.putExtra("errorMsg", getString(R.string.installation_failed))
|
||||
mIntent.putExtra("errorMsg", getString(R.string.installation_signature))
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
createBasicNotif(getString(R.string.installation_signature), notifId, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,20 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
|||
import com.vanced.manager.R
|
||||
import com.vanced.manager.ui.MainActivity
|
||||
import com.vanced.manager.utils.MiuiHelper.isMiui
|
||||
import com.vanced.manager.utils.NotificationHelper
|
||||
|
||||
class SplitInstallerService: Service() {
|
||||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
val notifId = 666
|
||||
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
|
||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
|
||||
Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show()
|
||||
NotificationHelper.createBasicNotif(
|
||||
getString(R.string.installing_app, "Vanced"),
|
||||
notifId,
|
||||
this
|
||||
)
|
||||
Log.d(TAG, "Requesting user confirmation for installation")
|
||||
val confirmationIntent =
|
||||
intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
|
||||
|
@ -35,15 +42,34 @@ class SplitInstallerService: Service() {
|
|||
mIntent.action = MainActivity.INSTALL_COMPLETED
|
||||
mIntent.putExtra("package", "split")
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
NotificationHelper.createBasicNotif(
|
||||
getString(R.string.successfully_installed, "Vanced"),
|
||||
notifId,
|
||||
this
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
|
||||
NotificationHelper.createBasicNotif(
|
||||
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)),
|
||||
notifId,
|
||||
this
|
||||
)
|
||||
}
|
||||
else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
|
||||
}
|
||||
stopSelf()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
private fun sendFailure(status: Int) {
|
||||
val msg = when (status) {
|
||||
val mIntent = Intent(MainActivity.INSTALL_FAILED)
|
||||
mIntent.action = MainActivity.INSTALL_FAILED
|
||||
mIntent.putExtra("errorMsg", getErrorMessage(status))
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
}
|
||||
|
||||
private fun getErrorMessage(status: Int): String {
|
||||
return when (status) {
|
||||
PackageInstaller.STATUS_FAILURE_ABORTED -> getString(R.string.installation_aborted)
|
||||
PackageInstaller.STATUS_FAILURE_BLOCKED -> getString(R.string.installation_blocked)
|
||||
PackageInstaller.STATUS_FAILURE_STORAGE -> getString(R.string.installation_storage)
|
||||
|
@ -55,13 +81,7 @@ class SplitInstallerService: Service() {
|
|||
getString(R.string.installation_miui)
|
||||
else
|
||||
getString(R.string.installation_failed)
|
||||
|
||||
}
|
||||
|
||||
val mIntent = Intent(MainActivity.INSTALL_FAILED)
|
||||
mIntent.action = MainActivity.INSTALL_FAILED
|
||||
mIntent.putExtra("errorMsg", msg)
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -92,26 +92,6 @@ class HomeFragment : Home() {
|
|||
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
when (intent.action) {
|
||||
MICROG_DOWNLOADING -> {
|
||||
val progress = intent.getIntExtra("microgProgress", 0)
|
||||
val progressbar = view?.findViewById<ProgressBar>(R.id.microg_progress)
|
||||
val downloadTxt = intent.getStringExtra("fileName")
|
||||
val txt = view?.findViewById<TextView>(R.id.microg_downloading)
|
||||
txt?.visibility = View.VISIBLE
|
||||
txt?.text = downloadTxt
|
||||
progressbar?.visibility = View.VISIBLE
|
||||
progressbar?.progress = progress
|
||||
}
|
||||
VANCED_DOWNLOADING -> {
|
||||
val progress = intent.getIntExtra("vancedProgress", 0)
|
||||
val progressbar = view?.findViewById<ProgressBar>(R.id.vanced_progress)
|
||||
val downloadTxt = intent.getStringExtra("fileName")
|
||||
val txt = view?.findViewById<TextView>(R.id.vanced_downloading)
|
||||
txt?.visibility = View.VISIBLE
|
||||
txt?.text = downloadTxt
|
||||
progressbar?.visibility = View.VISIBLE
|
||||
progressbar?.progress = progress
|
||||
}
|
||||
MICROG_DOWNLOADED -> {
|
||||
view?.findViewById<TextView>(R.id.microg_downloading)?.visibility = View.GONE
|
||||
view?.findViewById<ProgressBar>(R.id.microg_progress)?.visibility = View.GONE
|
||||
|
@ -123,19 +103,12 @@ class HomeFragment : Home() {
|
|||
view?.findViewById<ProgressBar>(R.id.vanced_progress)?.visibility = View.GONE
|
||||
view?.findViewById<ProgressBar>(R.id.vanced_installing)?.visibility = View.VISIBLE
|
||||
}
|
||||
DOWNLOAD_ERROR -> {
|
||||
val error = intent.getStringExtra("DownloadError") as String
|
||||
Toast.makeText(activity, error, Toast.LENGTH_SHORT).show()
|
||||
Log.d("VMDwnld", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerReceivers() {
|
||||
val intentFilter = IntentFilter()
|
||||
intentFilter.addAction(VANCED_DOWNLOADING)
|
||||
intentFilter.addAction(MICROG_DOWNLOADING)
|
||||
intentFilter.addAction(VANCED_DOWNLOADED)
|
||||
intentFilter.addAction(MICROG_DOWNLOADED)
|
||||
activity?.let {
|
||||
|
@ -187,11 +160,8 @@ class HomeFragment : Home() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val VANCED_DOWNLOADING = "Vanced downloading"
|
||||
const val MICROG_DOWNLOADING = "MicroG downloading"
|
||||
const val VANCED_DOWNLOADED = "Vanced downloaded"
|
||||
const val MICROG_DOWNLOADED = "MicroG downloaded"
|
||||
const val DOWNLOAD_ERROR = "Error occurred"
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Application
|
|||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
|
@ -111,18 +112,20 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
|||
private fun compareInt(int1: Int, int2: Int, application: Application): String {
|
||||
return if (connected)
|
||||
when {
|
||||
int1 > int2 -> application.getString(R.string.update)
|
||||
int2 == int1 -> application.getString(R.string.button_reinstall)
|
||||
else -> application.getString(R.string.install)
|
||||
int1 > int2 -> application.getString(R.string.update)
|
||||
int2 == int1 -> application.getString(R.string.button_reinstall)
|
||||
int2 == 0 -> application.getString(R.string.install)
|
||||
else -> application.getString(R.string.install)
|
||||
} else application.getString(R.string.install)
|
||||
}
|
||||
|
||||
private fun compareIntDrawable(int1: Int, int2: Int, application: Application): Drawable? {
|
||||
return if (connected)
|
||||
when {
|
||||
int1 > int2 -> application.getDrawable(R.drawable.ic_update)
|
||||
int2 == int1 -> application.getDrawable(R.drawable.ic_done)
|
||||
else -> application.getDrawable(R.drawable.ic_download)
|
||||
int1 > int2 -> application.getDrawable(R.drawable.ic_update)
|
||||
int2 == int1 -> application.getDrawable(R.drawable.ic_done)
|
||||
int2 == 0 -> application.getDrawable(R.drawable.ic_download)
|
||||
else -> application.getDrawable(R.drawable.ic_download)
|
||||
} else application.getDrawable(R.drawable.ic_download)
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.vanced.manager.utils
|
|||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import com.vanced.manager.BuildConfig
|
||||
import com.vanced.manager.R
|
||||
|
@ -22,9 +22,10 @@ object InternetTools {
|
|||
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)
|
||||
|
||||
fun displayJsonString(json: String, obj: String, context: Context): String {
|
||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", getLatestVancedUrl(context))
|
||||
return if (GetJson().isConnected(context)) {
|
||||
try {
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/$json").get(obj).asString
|
||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
|
||||
} catch (e: IllegalStateException) {
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
||||
}
|
||||
|
@ -34,9 +35,10 @@ object InternetTools {
|
|||
}
|
||||
|
||||
fun displayJsonInt(json: String, obj: String, context: Context): Int {
|
||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", getLatestVancedUrl(context))
|
||||
return if (GetJson().isConnected(context)) {
|
||||
try {
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/$json").get(obj).asInt
|
||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
|
||||
} catch (e: IllegalStateException) {
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
|
||||
}
|
||||
|
@ -53,7 +55,7 @@ object InternetTools {
|
|||
fun getLatestVancedUrl(context: Context): String {
|
||||
return if (GetJson().isConnected(context)) {
|
||||
val latestVer = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("version").asString
|
||||
"https://vanced.app/api/v1/apks/$latestVer"
|
||||
"https://vanced.app/api/v1/apks/v$latestVer"
|
||||
} else
|
||||
"https://vanced.app/api/v1/apks/v15.05.54"
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@ package com.vanced.manager.utils
|
|||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.downloader.DownloadBroadcastReceiver
|
||||
|
||||
object NotificationHelper {
|
||||
|
||||
|
@ -21,7 +24,39 @@ object NotificationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
fun displayDownloadNotif(channel: Int, maxVal: Int = 100, progress:Int = 0, filename: String, context: Context) {
|
||||
fun displayDownloadNotif(channel: Int, maxVal: Int = 100, progress:Int = 0, filename: String, downTag: String, context: Context) {
|
||||
val notifBuilder =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
Notification.Builder(context, channel.toString()).setChannelId("69420")
|
||||
else
|
||||
Notification.Builder(context).setPriority(Notification.PRIORITY_DEFAULT)
|
||||
|
||||
val cancelDownload = Intent(context, DownloadBroadcastReceiver::class.java).apply {
|
||||
action = "cancel"
|
||||
putExtra("dwnldId", downTag)
|
||||
}
|
||||
val cancelPendingIntent = PendingIntent.getBroadcast(context, 0, cancelDownload, 0)
|
||||
|
||||
notifBuilder.apply {
|
||||
setContentTitle(context.getString(R.string.app_name))
|
||||
setContentText(context.getString(R.string.downloading_file, filename))
|
||||
setSmallIcon(R.drawable.ic_stat_name)
|
||||
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 )
|
||||
}
|
||||
|
||||
val notif = notifBuilder.build()
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.apply {
|
||||
notifBuilder.setProgress(maxVal, progress, false)
|
||||
notify(channel, notif)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun createBasicNotif(text: String, channel: Int, context: Context) {
|
||||
val notifBuilder =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
Notification.Builder(context, channel.toString()).setChannelId("69420")
|
||||
|
@ -30,17 +65,18 @@ object NotificationHelper {
|
|||
|
||||
notifBuilder.apply {
|
||||
setContentTitle(context.getString(R.string.app_name))
|
||||
setContentText(context.getString(R.string.downloading_file, filename))
|
||||
setContentText(text)
|
||||
setSmallIcon(R.drawable.ic_stat_name)
|
||||
}
|
||||
|
||||
val notif = notifBuilder.build()
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.apply {
|
||||
notifBuilder.setProgress(maxVal, progress, false)
|
||||
notify(channel, notif)
|
||||
}
|
||||
|
||||
notificationManager.notify(channel, notif)
|
||||
}
|
||||
|
||||
fun cancelNotif(id: Int, context: Context) {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.cancel(id)
|
||||
}
|
||||
|
||||
}
|
|
@ -46,7 +46,8 @@
|
|||
bind:strokeWidth="2dp"
|
||||
bind:strokeColor="?colorPrimary"
|
||||
android:textAllCaps="false"
|
||||
android:text="@string/nonroot"/>
|
||||
android:text="@string/nonroot"
|
||||
android:visibility="@{viewModel.nonrootModeSelected ? View.VISIBLE : View.GONE}"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/nonroot_switch"
|
||||
|
@ -70,7 +71,8 @@
|
|||
bind:strokeWidth="2dp"
|
||||
bind:strokeColor="?colorPrimary"
|
||||
android:textAllCaps="false"
|
||||
android:text="@string/root"/>
|
||||
android:text="@string/root"
|
||||
android:visibility="@{viewModel.nonrootModeSelected ? View.GONE : View.VISIBLE}"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/root_switch"
|
||||
|
|
|
@ -126,23 +126,6 @@
|
|||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/microg_downloading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/CardTitle"
|
||||
android:text="Downloading"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/microg_progress"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
|
@ -114,24 +114,6 @@
|
|||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vanced_downloading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/CardTitle"
|
||||
android:text="Downloading"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/vanced_progress"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<string name="close">Close</string>
|
||||
<string name="reset">Reset</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
|
||||
<!-- Main Activity -->
|
||||
<string name="title_about">About</string>
|
||||
|
@ -18,8 +19,10 @@
|
|||
<string name="changelogs">Changelogs</string>
|
||||
<string name="check">Check</string>
|
||||
<string name="downloading_file">Downloading %1$s</string>
|
||||
<string name="failed_uninstall">Failed to uninstall package: </string>
|
||||
<string name="failed_uninstall">Failed to uninstall package %1$s</string>
|
||||
<string name="error_downloading">Error Downloading %1$s</string>
|
||||
<string name="install">Install</string>
|
||||
<string name="installing_app">Installing %1$s</string>
|
||||
<string name="installation_aborted">Operation failed because user aborted installation</string>
|
||||
<string name="installation_blocked">Operation failed because user blocked installation</string>
|
||||
<string name="installation_conflict">Operation failed because app conflicts with already installed app</string>
|
||||
|
@ -34,6 +37,7 @@
|
|||
<string name="latest">Latest:</string>
|
||||
<string name="loading">Loading…</string>
|
||||
<string name="microg_installed">MicroG successfully installed</string>
|
||||
<string name="successfully_installed">Successfully installed %1$s</string>
|
||||
<string name="network_error">Network connection unavailable</string>
|
||||
<string name="no_microg">No Microg!</string>
|
||||
<string name="unable_download">Unable to download %1$s</string>
|
||||
|
|
Loading…
Reference in New Issue