From 4bc3a42ab0065db31461f64c061c69bdc068c4e7 Mon Sep 17 00:00:00 2001 From: X1nto Date: Wed, 26 Aug 2020 21:21:37 +0400 Subject: [PATCH] build fixes --- .../com/vanced/manager/model/DataModel.kt | 23 +++++++------- .../manager/ui/fragments/HomeFragment.kt | 30 +++---------------- .../java/com/vanced/manager/utils/AppUtils.kt | 2 +- .../res/layout/include_about_app_devs.xml | 14 ++++++++- app/src/main/res/layout/include_microg.xml | 8 ++--- app/src/main/res/layout/include_music.xml | 10 +++---- app/src/main/res/layout/include_vanced.xml | 8 ++--- app/src/main/res/values/strings.xml | 4 +-- 8 files changed, 46 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/com/vanced/manager/model/DataModel.kt b/app/src/main/java/com/vanced/manager/model/DataModel.kt index 17f86a1f..a6e244a4 100644 --- a/app/src/main/java/com/vanced/manager/model/DataModel.kt +++ b/app/src/main/java/com/vanced/manager/model/DataModel.kt @@ -2,42 +2,45 @@ package com.vanced.manager.model import android.content.Context import android.graphics.drawable.Drawable +import android.os.Build import androidx.preference.PreferenceManager.getDefaultSharedPreferences import com.vanced.manager.utils.InternetTools.getJsonInt import com.vanced.manager.utils.InternetTools.getJsonString import com.vanced.manager.utils.PackageHelper.isPackageInstalled +import com.vanced.manager.R +import kotlinx.coroutines.runBlocking open class DataModel( private val jsonName: String, private val context: Context ) { - private val variant = getDefaultSharedPreferences(context).getString("vanced_variant") + private val variant = getDefaultSharedPreferences(context).getString("vanced_variant", "nonroot") private val appPkg = when (jsonName) { "vanced" -> if (variant == "root") "com.google.android.youtube" else "com.vanced.android.youtube" "microg" -> "com.mgoogle.android.gms" - "music" -> "com.vanced.android.youtube.music" + else -> "com.vanced.android.youtube.music" } open fun isAppInstalled(): Boolean = isPackageInstalled(appPkg, context.packageManager) - open fun getVersionName(): String = getJsonString("$jsonName.json", "version") + open fun getVersionName(): String = runBlocking { getJsonString("$jsonName.json", "version", context) } - open fun getVersionCode(): Int = getJsonInt("$jsonName.json", "versionCode") + open fun getVersionCode(): Int = runBlocking { getJsonInt("$jsonName.json", "versionCode", context) } - open fun getInstalledVersionName(): String = getPkgVersion(isAppInstalled(), pkgPkg) + open fun getInstalledVersionName(): String = getPkgVersion(isAppInstalled(), appPkg) - open fun getInstalledVersionCode(): Int = getJsonInt("$jsonName.json", "versionCode") + open fun getInstalledVersionCode(): Int = runBlocking { getJsonInt("$jsonName.json", "versionCode", context) } open fun getButtonTxt(): String = compareInt(getInstalledVersionCode(), getVersionCode()) - open fun getButtonIcon(): Drawable = compareIntDrawable(getInstalledVersionCode(), getVersionCode()) + open fun getButtonIcon(): Drawable? = compareIntDrawable(getInstalledVersionCode(), getVersionCode()) private fun getPkgVersion(toCheck: Boolean, pkg: String): String { return if (toCheck) { - pm.getPackageInfo(pkg, 0).versionName + context.packageManager.getPackageInfo(pkg, 0).versionName } else { context.getString(R.string.unavailable) } @@ -47,9 +50,9 @@ open class DataModel( private fun getPkgVerCode(toCheck: Boolean, pkg: String): Int { return if (toCheck) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) - pm.getPackageInfo(pkg, 0).longVersionCode.and(0xFFFFFFFF).toInt() + context.packageManager.getPackageInfo(pkg, 0).longVersionCode.and(0xFFFFFFFF).toInt() else - pm.getPackageInfo(pkg, 0).versionCode + context.packageManager.getPackageInfo(pkg, 0).versionCode } else 0 } diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt index cfedaa89..112577f5 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt @@ -49,7 +49,7 @@ class HomeFragment : Fragment(), View.OnClickListener { binding.viewModel = viewModel val arg = "variant" - val variant = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant") + val variant = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot") with(binding) { when (variant) { @@ -63,9 +63,6 @@ class HomeFragment : Fragment(), View.OnClickListener { } with(binding) { - rootSwitch.setOnClickListener(this@HomeFragment) - nonrootSwitch.setOnClickListener(this@HomeFragment) - includeVancedLayout.vancedInstallbtn.setOnClickListener(this@HomeFragment) includeVancedLayout.vancedUninstallbtn.setOnClickListener(this@HomeFragment) includeMicrogLayout.microgInstallbtn.setOnClickListener(this@HomeFragment) @@ -74,12 +71,12 @@ class HomeFragment : Fragment(), View.OnClickListener { } binding.includeVancedLayout.vancedCard.setOnLongClickListener { - versionToast("Vanced", viewModel.vancedInstalledVersion.get()) + versionToast("Vanced", viewModel.vanced.get()?.getInstalledVersionName()!!) true } binding.includeMicrogLayout.microgCard.setOnLongClickListener { - versionToast("MicroG", viewModel.microgInstalledVersion.get()) + versionToast("MicroG", viewModel.microg.get()?.getInstalledVersionName()!!) true } @@ -117,7 +114,7 @@ class HomeFragment : Fragment(), View.OnClickListener { R.id.vanced_installbtn -> { if (!installing) { if (!viewModel.fetching.get()!!) { - if (variant == "nonroot" && !viewModel.microgInstalled.get()!!) { + if (variant == "nonroot" && !viewModel.microg.get()?.isAppInstalled()!!) { Snackbar.make( binding.homeRefresh, R.string.no_microg, @@ -155,29 +152,10 @@ class HomeFragment : Fragment(), View.OnClickListener { } R.id.microg_uninstallbtn -> PackageHelper.uninstallApk("com.mgoogle.android.gms", requireActivity()) R.id.vanced_uninstallbtn -> PackageHelper.uninstallApk(vancedPkgName, requireActivity()) - R.id.nonroot_switch -> writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right) - R.id.root_switch -> - if (Shell.rootAccess()) { - writeToVariantPref("root", R.anim.slide_in_right, R.anim.slide_out_left) - } else { - 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() - } R.id.changelog_button -> cardExpandCollapse() } } - private fun writeToVariantPref(variant: String, animIn: Int, animOut: Int) { - val prefs = getDefaultSharedPreferences(activity) - if (prefs.getString("vanced_variant", "nonroot") != variant) { - prefs.edit().putString("vanced_variant", variant).apply() - startActivity(Intent(activity, MainActivity::class.java)) - activity?.overridePendingTransition(animIn, animOut) - activity?.finish() - } else - Log.d("VMVariant", "$variant is already selected") - } - private fun versionToast(name: String, app: String?) { val clip = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clip.setPrimaryClip(ClipData.newPlainText(name, app)) diff --git a/app/src/main/java/com/vanced/manager/utils/AppUtils.kt b/app/src/main/java/com/vanced/manager/utils/AppUtils.kt index 995755e9..a8717cbf 100644 --- a/app/src/main/java/com/vanced/manager/utils/AppUtils.kt +++ b/app/src/main/java/com/vanced/manager/utils/AppUtils.kt @@ -39,7 +39,7 @@ object AppUtils { status.contains("INSTALL_FAILED_INVALID_APK") -> context.getString(R.string.installation_invalid) status.contains("INSTALL_FAILED_VERSION_DOWNGRADE") -> context.getString(R.string.installation_downgrade) status.contains("INSTALL_PARSE_FAILED_NO_CERTIFICATES") -> context.getString(R.string.installation_signature) - status.contains("Failed_Uninstall") -> context.getString(R.string.Failed_Uninstall) + status.contains("Failed_Uninstall") -> context.getString(R.string.failed_uninstall) status.contains("Chown_Fail") -> context.getString(R.string.chown_fail) status.contains("IFile_Missing") -> context.getString(R.string.ifile_missing) status.contains("ModApk_Missing") -> context.getString(R.string.modapk_missing) diff --git a/app/src/main/res/layout/include_about_app_devs.xml b/app/src/main/res/layout/include_about_app_devs.xml index abfac5c6..cf26f60d 100644 --- a/app/src/main/res/layout/include_about_app_devs.xml +++ b/app/src/main/res/layout/include_about_app_devs.xml @@ -24,7 +24,19 @@ android:layout_height="wrap_content" android:text="- Xinto" android:textSize="18sp" /> + + + + - \ No newline at end of file + diff --git a/app/src/main/res/layout/include_microg.xml b/app/src/main/res/layout/include_microg.xml index 6bcf0d1f..0dd9a7c7 100644 --- a/app/src/main/res/layout/include_microg.xml +++ b/app/src/main/res/layout/include_microg.xml @@ -61,10 +61,10 @@ app:constraint_referenced_ids="microg_installbtn" /> @@ -80,12 +80,12 @@ + app:layout_constraintTop_toBottomOf="@id/microg_remote_container"> @@ -80,12 +80,12 @@ + app:layout_constraintTop_toBottomOf="@id/music_remote_container"> + android:text="@{viewModel.music.installedVersionName}" /> diff --git a/app/src/main/res/layout/include_vanced.xml b/app/src/main/res/layout/include_vanced.xml index 6cf73224..aaa1c4cb 100644 --- a/app/src/main/res/layout/include_vanced.xml +++ b/app/src/main/res/layout/include_vanced.xml @@ -72,10 +72,10 @@ app:srcCompat="@drawable/ic_delete_black_24dp" /> @@ -91,11 +91,11 @@ + app:layout_constraintTop_toBottomOf="@id/vanced_remote_container"> Failed To Chown Apk to system owner, Try Again Error Downloading %1$s Failed to uninstall package %1$s - Files are missing, Failed Download? + Files are missing, Failed Download? Dark/Black.apk Cannot Be Read(Did Storage Get Blocked?) or File Missing Installation failed because user aborted the installation. Installation failed because user blocked the installation. @@ -108,6 +108,6 @@ Installation failed because apk signature verification is enabled. Disable apk signature verification, then try again. Installation failed because MIUI Optimization is enabled. Disable MIUI Optimization, then try again. Installation failed due to a storage error. - Black/Dark apk missing from installer, This should not happen, please clear app data of manager + Black/Dark apk missing from installer, This should not happen, please clear app data of manager