mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-30 15:03:02 +00:00
replaced all deprecated methods with kotlin coroutines
This commit is contained in:
parent
d8f4246abd
commit
f29af1607e
7 changed files with 46 additions and 30 deletions
|
@ -33,7 +33,6 @@ class MicrogDownloadService: Service() {
|
||||||
private fun downloadMicrog() {
|
private fun downloadMicrog() {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
launch {
|
launch {
|
||||||
getExternalFilesDir("apk")?.delete()
|
|
||||||
val url = getObjectFromJson(
|
val url = getObjectFromJson(
|
||||||
"${PreferenceManager.getDefaultSharedPreferences(this@MicrogDownloadService)
|
"${PreferenceManager.getDefaultSharedPreferences(this@MicrogDownloadService)
|
||||||
.getString("install_url", baseUrl)}/microg.json", "url"
|
.getString("install_url", baseUrl)}/microg.json", "url"
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||||
import com.vanced.manager.utils.InternetTools.getObjectFromJson
|
import com.vanced.manager.utils.InternetTools.getObjectFromJson
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class VancedDownloadService: Service() {
|
class VancedDownloadService: Service() {
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ class VancedDownloadService: Service() {
|
||||||
val context = this
|
val context = this
|
||||||
runBlocking {
|
runBlocking {
|
||||||
launch {
|
launch {
|
||||||
getExternalFilesDir("apks")?.delete()
|
File(getExternalFilesDir("apk")?.path as String).deleteRecursively()
|
||||||
val defPrefs = PreferenceManager.getDefaultSharedPreferences(context)
|
val defPrefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val installUrl = defPrefs.getString("install_url", baseUrl)
|
val installUrl = defPrefs.getString("install_url", baseUrl)
|
||||||
val vancedVer = getObjectFromJson("$installUrl/vanced.json", "version")
|
val vancedVer = getObjectFromJson("$installUrl/vanced.json", "version")
|
||||||
|
|
|
@ -3,11 +3,13 @@ package com.vanced.manager.core.installer
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageInstaller
|
import android.content.pm.PackageInstaller
|
||||||
import android.os.Handler
|
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
import com.vanced.manager.ui.fragments.HomeFragment
|
import com.vanced.manager.ui.fragments.HomeFragment
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
class AppUninstallerService: Service() {
|
class AppUninstallerService: Service() {
|
||||||
|
|
||||||
|
@ -26,16 +28,22 @@ class AppUninstallerService: Service() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PackageInstaller.STATUS_SUCCESS -> {
|
PackageInstaller.STATUS_SUCCESS -> {
|
||||||
Handler().postDelayed({
|
runBlocking {
|
||||||
|
launch {
|
||||||
|
delay(500)
|
||||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
||||||
Log.d("VMpm", "Successfully uninstalled $pkgName")
|
Log.d("VMpm", "Successfully uninstalled $pkgName")
|
||||||
}, 500)
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PackageInstaller.STATUS_FAILURE -> {
|
PackageInstaller.STATUS_FAILURE -> {
|
||||||
Handler().postDelayed({
|
runBlocking {
|
||||||
|
launch {
|
||||||
|
delay(500)
|
||||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
||||||
Log.d("VMpm", "Failed to uninstall $pkgName")
|
Log.d("VMpm", "Failed to uninstall $pkgName")
|
||||||
}, 500)
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stopSelf()
|
stopSelf()
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.vanced.manager.core.installer
|
||||||
|
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.AsyncTask
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -13,6 +12,8 @@ import com.topjohnwu.superuser.Shell
|
||||||
import com.vanced.manager.ui.fragments.HomeFragment
|
import com.vanced.manager.ui.fragments.HomeFragment
|
||||||
import com.vanced.manager.utils.AppUtils.sendFailure
|
import com.vanced.manager.utils.AppUtils.sendFailure
|
||||||
import com.vanced.manager.utils.FileInfo
|
import com.vanced.manager.utils.FileInfo
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -25,7 +26,8 @@ class RootSplitInstallerService: Service() {
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
Shell.getShell {
|
Shell.getShell {
|
||||||
AsyncTask.execute {
|
runBlocking {
|
||||||
|
launch {
|
||||||
val apkFilesPath = getExternalFilesDir("apks")?.path
|
val apkFilesPath = getExternalFilesDir("apks")?.path
|
||||||
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
|
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
|
||||||
if (fileInfoList != null) {
|
if (fileInfoList != null) {
|
||||||
|
@ -33,6 +35,7 @@ class RootSplitInstallerService: Service() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
stopSelf()
|
stopSelf()
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,10 +58,7 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
||||||
includeVancedLayout.vancedUninstallbtn.setOnClickListener(this@HomeFragment)
|
includeVancedLayout.vancedUninstallbtn.setOnClickListener(this@HomeFragment)
|
||||||
includeMicrogLayout.microgInstallbtn.setOnClickListener(this@HomeFragment)
|
includeMicrogLayout.microgInstallbtn.setOnClickListener(this@HomeFragment)
|
||||||
includeMicrogLayout.microgUninstallbtn.setOnClickListener(this@HomeFragment)
|
includeMicrogLayout.microgUninstallbtn.setOnClickListener(this@HomeFragment)
|
||||||
}
|
includeChangelogsLayout.changelogButton.setOnClickListener(this@HomeFragment)
|
||||||
|
|
||||||
binding.includeChangelogsLayout.changelogButton.setOnClickListener {
|
|
||||||
cardExpandCollapse()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.includeVancedLayout.vancedCard.setOnLongClickListener {
|
binding.includeVancedLayout.vancedCard.setOnLongClickListener {
|
||||||
|
@ -148,6 +145,7 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
||||||
writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right)
|
writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right)
|
||||||
Toast.makeText(requireActivity(), activity?.getString(R.string.root_not_granted), Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireActivity(), activity?.getString(R.string.root_not_granted), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
R.id.changelog_button -> cardExpandCollapse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.widget.Toast
|
||||||
import androidx.preference.*
|
import androidx.preference.*
|
||||||
import com.google.firebase.messaging.FirebaseMessaging
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class SettingsFragment : PreferenceFragmentCompat() {
|
class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
|
@ -93,9 +94,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
findPreference<Preference>("clear_files")?.setOnPreferenceClickListener {
|
findPreference<Preference>("clear_files")?.setOnPreferenceClickListener {
|
||||||
with(requireActivity()) {
|
with(requireActivity()) {
|
||||||
getExternalFilesDir("apk")?.delete()
|
listOf("apk", "apks").forEach { dir ->
|
||||||
getExternalFilesDir("apks")?.delete()
|
File(getExternalFilesDir(dir)?.path as String).deleteRecursively()
|
||||||
Toast.makeText(this, getString(R.string.cleared_files), Toast.LENGTH_SHORT)
|
}
|
||||||
|
Toast.makeText(this, getString(R.string.cleared_files), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,14 @@ import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageInstaller
|
import android.content.pm.PackageInstaller
|
||||||
import android.os.Handler
|
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.core.downloader.*
|
import com.vanced.manager.core.downloader.*
|
||||||
import com.vanced.manager.core.installer.*
|
import com.vanced.manager.core.installer.*
|
||||||
import com.vanced.manager.ui.fragments.HomeFragment
|
import com.vanced.manager.ui.fragments.HomeFragment
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
object AppUtils {
|
object AppUtils {
|
||||||
|
|
||||||
|
@ -34,11 +36,14 @@ object AppUtils {
|
||||||
|
|
||||||
fun sendFailure(status: Int, context: Context) {
|
fun sendFailure(status: Int, context: Context) {
|
||||||
//Delay error broadcast until activity (and fragment) get back to the screen
|
//Delay error broadcast until activity (and fragment) get back to the screen
|
||||||
Handler().postDelayed({
|
runBlocking {
|
||||||
|
launch {
|
||||||
|
delay(500)
|
||||||
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
||||||
intent.putExtra("errorMsg", getErrorMessage(status, context))
|
intent.putExtra("errorMsg", getErrorMessage(status, context))
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
||||||
}, 500)
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getErrorMessage(status: Int, context: Context): String {
|
private fun getErrorMessage(status: Int, context: Context): String {
|
||||||
|
|
Loading…
Reference in a new issue