Skip to content

Commit 2e53a99

Browse files
Isira-SeneviratneTobiGr
authored andcommitted
Convert isReleaseApk to lazy value
1 parent bec18e1 commit 2e53a99

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import com.grack.nanojson.JsonParser
2020
import com.grack.nanojson.JsonParserException
2121
import org.schabi.newpipe.extractor.downloader.Response
2222
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
23-
import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry
24-
import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired
25-
import org.schabi.newpipe.util.ReleaseVersionUtil.isReleaseApk
23+
import org.schabi.newpipe.util.ReleaseVersionUtil
2624
import java.io.IOException
2725

2826
class NewVersionWorker(
@@ -84,7 +82,7 @@ class NewVersionWorker(
8482
@Throws(IOException::class, ReCaptchaException::class)
8583
private fun checkNewVersion() {
8684
// Check if the current apk is a github one or not.
87-
if (!isReleaseApk()) {
85+
if (!ReleaseVersionUtil.isReleaseApk) {
8886
return
8987
}
9088

@@ -93,7 +91,7 @@ class NewVersionWorker(
9391
// Check if the last request has happened a certain time ago
9492
// to reduce the number of API requests.
9593
val expiry = prefs.getLong(applicationContext.getString(R.string.update_expiry_key), 0)
96-
if (!isLastUpdateCheckExpired(expiry)) {
94+
if (!ReleaseVersionUtil.isLastUpdateCheckExpired(expiry)) {
9795
return
9896
}
9997
}
@@ -108,7 +106,7 @@ class NewVersionWorker(
108106
try {
109107
// Store a timestamp which needs to be exceeded,
110108
// before a new request to the API is made.
111-
val newExpiry = coerceUpdateCheckExpiry(response.getHeader("expires"))
109+
val newExpiry = ReleaseVersionUtil.coerceUpdateCheckExpiry(response.getHeader("expires"))
112110
prefs.edit {
113111
putLong(applicationContext.getString(R.string.update_expiry_key), newExpiry)
114112
}

app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
2323
setHasOptionsMenu(true); // Otherwise onCreateOptionsMenu is not called
2424

2525
// Check if the app is updatable
26-
if (!ReleaseVersionUtil.isReleaseApk()) {
26+
if (!ReleaseVersionUtil.INSTANCE.isReleaseApk()) {
2727
getPreferenceScreen().removePreference(
2828
findPreference(getString(R.string.update_pref_screen_key)));
2929

app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private void initSearch(
266266
*/
267267
private void ensureSearchRepresentsApplicationState() {
268268
// Check if the update settings are available
269-
if (!ReleaseVersionUtil.isReleaseApk()) {
269+
if (!ReleaseVersionUtil.INSTANCE.isReleaseApk()) {
270270
SettingsResourceRegistry.getInstance()
271271
.getEntryByPreferencesResId(R.xml.update_settings)
272272
.setSearchable(false);

app/src/main/java/org/schabi/newpipe/util/ReleaseVersionUtil.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ object ReleaseVersionUtil {
1515
private const val RELEASE_CERT_PUBLIC_KEY_SHA256 =
1616
"cb84069bd68116bafae5ee4ee5b08a567aa6d898404e7cb12f9e756df5cf5cab"
1717

18-
@JvmStatic
19-
fun isReleaseApk(): Boolean {
18+
val isReleaseApk by lazy {
2019
@Suppress("NewApi")
2120
val certificates = mapOf(
2221
RELEASE_CERT_PUBLIC_KEY_SHA256.toByteArray() to PackageManager.CERT_INPUT_SHA256
2322
)
2423
val app = App.getApp()
25-
return try {
24+
try {
2625
PackageInfoCompat.hasSignatures(app.packageManager, app.packageName, certificates, false)
2726
} catch (e: PackageManager.NameNotFoundException) {
2827
createNotification(

0 commit comments

Comments
 (0)