Skip to content

Commit b96c05a

Browse files
committed
Consolidate is(app)Installed methods into one
Signed-off-by: Leonardo Ledda <leonardoledda@gmail.com>
1 parent 1539cb2 commit b96c05a

File tree

2 files changed

+12
-39
lines changed

2 files changed

+12
-39
lines changed

app/src/main/java/it/leddaz/revancedupdater/MainActivity.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ import it.leddaz.revancedupdater.utils.json.UpdaterReleaseJSONObject
3131
import it.leddaz.revancedupdater.utils.misc.AppInstaller
3232
import it.leddaz.revancedupdater.utils.misc.CommonStuff.APP_VERSION
3333
import it.leddaz.revancedupdater.utils.misc.CommonStuff.GMSCORE_PACKAGE
34+
import it.leddaz.revancedupdater.utils.misc.CommonStuff.GMS_PACKAGE
35+
import it.leddaz.revancedupdater.utils.misc.CommonStuff.HMS_PACKAGE
3436
import it.leddaz.revancedupdater.utils.misc.CommonStuff.IS_DEBUG
3537
import it.leddaz.revancedupdater.utils.misc.CommonStuff.LOG_TAG
3638
import it.leddaz.revancedupdater.utils.misc.CommonStuff.MUSIC_PACKAGE
3739
import it.leddaz.revancedupdater.utils.misc.CommonStuff.REVANCED_PACKAGE
3840
import it.leddaz.revancedupdater.utils.misc.CommonStuff.UPDATER_PACKAGE
3941
import it.leddaz.revancedupdater.utils.misc.CommonStuff.X_PACKAGE
40-
import it.leddaz.revancedupdater.utils.misc.CommonStuff.isGmsCoreInstalled
41-
import it.leddaz.revancedupdater.utils.misc.CommonStuff.isGmsInstalled
42-
import it.leddaz.revancedupdater.utils.misc.CommonStuff.isHmsInstalled
42+
import it.leddaz.revancedupdater.utils.misc.CommonStuff.isAppInstalled
4343
import it.leddaz.revancedupdater.utils.misc.CommonStuff.openLink
4444
import it.leddaz.revancedupdater.utils.misc.CommonStuff.requestInstallPermission
4545
import it.leddaz.revancedupdater.utils.misc.Version
@@ -200,7 +200,7 @@ class MainActivity : AppCompatActivity() {
200200
findViewById(R.id.x_download_button)
201201
)
202202

203-
if (isGmsCoreInstalled(this)) {
203+
if (isAppInstalled(this, GMSCORE_PACKAGE)) {
204204
getAppVersion(
205205
REVANCED_PACKAGE,
206206
findViewById(R.id.installed_revanced_version),
@@ -282,7 +282,8 @@ class MainActivity : AppCompatActivity() {
282282
gmsCoreReply =
283283
Gson().fromJson(response, object : TypeToken<GmsCoreJSONObject>() {}.type)
284284
latestGmsCoreVersion = Version(gmsCoreReply.latestGmsCoreVersion.substring(1))
285-
gmsCoreDownloadUrl = if (isHmsInstalled(this) && !isGmsInstalled(this))
285+
gmsCoreDownloadUrl =
286+
if (isAppInstalled(this, HMS_PACKAGE) && !isAppInstalled(this, GMS_PACKAGE))
286287
gmsCoreReply.assets[0].latestGmsCoreUrl
287288
else
288289
gmsCoreReply.assets[1].latestGmsCoreUrl
@@ -314,7 +315,7 @@ class MainActivity : AppCompatActivity() {
314315
findViewById(R.id.x_download_button)
315316
)
316317

317-
if (isGmsCoreInstalled(this)) {
318+
if (isAppInstalled(this, GMSCORE_PACKAGE)) {
318319
compareAppVersion(
319320
REVANCED_PACKAGE, installedReVancedVersion,
320321
latestReVancedVersion, findViewById(R.id.revanced_update_status),
@@ -435,7 +436,7 @@ class MainActivity : AppCompatActivity() {
435436
getString(R.string.installed_app_version, APP_VERSION)
436437
}
437438
} else if (packageName == GMSCORE_PACKAGE) {
438-
if (isHmsInstalled(this) && !isGmsInstalled(this))
439+
if (isAppInstalled(this, HMS_PACKAGE) && !isAppInstalled(this, GMS_PACKAGE))
439440
installedVersion.version =
440441
pInfo.versionName?.substring(0, pInfo.versionName!!.length - 3)
441442
else

app/src/main/java/it/leddaz/revancedupdater/utils/misc/CommonStuff.kt

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,13 @@ object CommonStuff {
3838
}
3939

4040
/**
41-
* Detects if HMS Core is installed.
41+
* Detects if an app is installed.
4242
* @param context The activity's context
43-
* @return HMS Core installation status
43+
* @return true if the app is installed, false otherwise
4444
*/
45-
fun isHmsInstalled(context: Context): Boolean {
45+
fun isAppInstalled(context: Context, packageName: String): Boolean {
4646
try {
47-
context.packageManager.getPackageInfo(HMS_PACKAGE, 0)
48-
} catch (_: PackageManager.NameNotFoundException) {
49-
return false
50-
}
51-
return true
52-
}
53-
54-
/**
55-
* Detects if GMS is installed.
56-
* @param context The activity's context
57-
* @return GMS installation status
58-
*/
59-
fun isGmsInstalled(context: Context): Boolean {
60-
try {
61-
context.packageManager.getPackageInfo(GMS_PACKAGE, 0)
62-
} catch (_: PackageManager.NameNotFoundException) {
63-
return false
64-
}
65-
return true
66-
}
67-
68-
/**
69-
* Detects if ReVanced GmsCore is installed.
70-
* @param context The activity's context
71-
* @return ReVanced GmsCore installation status
72-
*/
73-
fun isGmsCoreInstalled(context: Context): Boolean {
74-
try {
75-
context.packageManager.getPackageInfo(GMSCORE_PACKAGE, 0)
47+
context.packageManager.getPackageInfo(packageName, 0)
7648
} catch (_: PackageManager.NameNotFoundException) {
7749
return false
7850
}

0 commit comments

Comments
 (0)