mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-27 05:23:00 +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 {
|
||||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
launch {
|
||||||
Log.d("VMpm", "Successfully uninstalled $pkgName")
|
delay(500)
|
||||||
}, 500)
|
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
||||||
|
Log.d("VMpm", "Successfully uninstalled $pkgName")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PackageInstaller.STATUS_FAILURE -> {
|
PackageInstaller.STATUS_FAILURE -> {
|
||||||
Handler().postDelayed({
|
runBlocking {
|
||||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
launch {
|
||||||
Log.d("VMpm", "Failed to uninstall $pkgName")
|
delay(500)
|
||||||
}, 500)
|
localBroadcastManager.sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
||||||
|
Log.d("VMpm", "Failed to uninstall $pkgName")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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,11 +26,13 @@ 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 {
|
||||||
val apkFilesPath = getExternalFilesDir("apks")?.path
|
launch {
|
||||||
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
|
val apkFilesPath = getExternalFilesDir("apks")?.path
|
||||||
if (fileInfoList != null) {
|
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
|
||||||
installSplitApkFiles(fileInfoList)
|
if (fileInfoList != null) {
|
||||||
|
installSplitApkFiles(fileInfoList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
launch {
|
||||||
intent.putExtra("errorMsg", getErrorMessage(status, context))
|
delay(500)
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
||||||
}, 500)
|
intent.putExtra("errorMsg", getErrorMessage(status, context))
|
||||||
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getErrorMessage(status: Int, context: Context): String {
|
private fun getErrorMessage(status: Int, context: Context): String {
|
||||||
|
|
Loading…
Reference in a new issue