mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-28 22:13:01 +00:00
build fixes
This commit is contained in:
parent
bd356d5292
commit
4bc3a42ab0
8 changed files with 46 additions and 53 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -25,6 +25,18 @@
|
|||
android:text="- Xinto"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="- Koopah"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="- AioiLight"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
|
@ -61,10 +61,10 @@
|
|||
app:constraint_referenced_ids="microg_installbtn" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/microg_remote_latest_version"
|
||||
android:id="@+id/microg_remote_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toTopOf="@id/linearLayout2"
|
||||
app:layout_constraintBottom_toTopOf="@id/microg_installed_container"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/microg_title_buttons_barrier">
|
||||
|
||||
|
@ -80,12 +80,12 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout2"
|
||||
android:id="@+id/microg_installed_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/microg_remote_latest_version">
|
||||
app:layout_constraintTop_toBottomOf="@id/microg_remote_container">
|
||||
|
||||
<TextView
|
||||
style="@style/AppVer"
|
||||
|
|
|
@ -61,10 +61,10 @@
|
|||
app:constraint_referenced_ids="music_installbtn" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/music_remote_latest_version"
|
||||
android:id="@+id/music_remote_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toTopOf="@id/linearLayout2"
|
||||
app:layout_constraintBottom_toTopOf="@id/music_installed_container"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/music_title_buttons_barrier">
|
||||
|
||||
|
@ -80,12 +80,12 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout2"
|
||||
android:id="@+id/music_installed_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/music_remote_latest_version">
|
||||
app:layout_constraintTop_toBottomOf="@id/music_remote_container">
|
||||
|
||||
<TextView
|
||||
style="@style/AppVer"
|
||||
|
@ -94,7 +94,7 @@
|
|||
<TextView
|
||||
android:id="@+id/music_installed_version"
|
||||
style="@style/AppVer.Bold"
|
||||
android:text="@{viewModel.music.installedVersion}" />
|
||||
android:text="@{viewModel.music.installedVersionName}" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -72,10 +72,10 @@
|
|||
app:srcCompat="@drawable/ic_delete_black_24dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/vanced_remote_latest_version"
|
||||
android:id="@+id/vanced_remote_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toTopOf="@id/linearLayout2"
|
||||
app:layout_constraintBottom_toTopOf="@id/vanced_installed_container"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/vanced_title_buttons_barrier">
|
||||
|
||||
|
@ -91,11 +91,11 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout2"
|
||||
android:id="@+id/vanced_installed_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/vanced_remote_latest_version">
|
||||
app:layout_constraintTop_toBottomOf="@id/vanced_remote_container">
|
||||
|
||||
<TextView
|
||||
style="@style/AppVer"
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
<string name="chown_fail">Failed To Chown Apk to system owner, Try Again</string>
|
||||
<string name="error_downloading">Error Downloading %1$s</string>
|
||||
<string name="failed_uninstall">Failed to uninstall package %1$s</string>
|
||||
<string name="Files_Missing_VA">Files are missing, Failed Download?</string>
|
||||
<string name="files_missing_va">Files are missing, Failed Download?</string>
|
||||
<string name="ifile_missing">Dark/Black.apk Cannot Be Read(Did Storage Get Blocked?) or File Missing</string>
|
||||
<string name="installation_aborted">Installation failed because user aborted the installation.</string>
|
||||
<string name="installation_blocked">Installation failed because user blocked the installation.</string>
|
||||
|
@ -108,6 +108,6 @@
|
|||
<string name="installation_signature">Installation failed because apk signature verification is enabled. Disable apk signature verification, then try again.</string>
|
||||
<string name="installation_miui">Installation failed because MIUI Optimization is enabled. Disable MIUI Optimization, then try again.</string>
|
||||
<string name="installation_storage">Installation failed due to a storage error.</string>
|
||||
<string name="modapk_Missing">Black/Dark apk missing from installer, This should not happen, please clear app data of manager</string>
|
||||
<string name="modapk_missing">Black/Dark apk missing from installer, This should not happen, please clear app data of manager</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue