Skip to content

Commit 64ad05d

Browse files
authored
Merge pull request #11629 from Two-Ai/kotlin-getStringSafe
Add null-safe SharedPreferences.getStringSafe
2 parents 94f992a + 734b6e2 commit 64ad05d

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.schabi.newpipe.ktx
2+
3+
import android.content.SharedPreferences
4+
5+
fun SharedPreferences.getStringSafe(key: String, defValue: String): String {
6+
return getString(key, null) ?: defValue
7+
}

app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.Info
1919
import org.schabi.newpipe.extractor.NewPipe
2020
import org.schabi.newpipe.extractor.feed.FeedInfo
2121
import org.schabi.newpipe.extractor.stream.StreamInfoItem
22+
import org.schabi.newpipe.ktx.getStringSafe
2223
import org.schabi.newpipe.local.feed.FeedDatabaseManager
2324
import org.schabi.newpipe.local.subscription.SubscriptionManager
2425
import org.schabi.newpipe.util.ChannelTabHelper
@@ -69,12 +70,10 @@ class FeedLoadManager(private val context: Context) {
6970
val outdatedThreshold = if (ignoreOutdatedThreshold) {
7071
OffsetDateTime.now(ZoneOffset.UTC)
7172
} else {
72-
val thresholdOutdatedSeconds = (
73-
defaultSharedPreferences.getString(
74-
context.getString(R.string.feed_update_threshold_key),
75-
context.getString(R.string.feed_update_threshold_default_value)
76-
) ?: context.getString(R.string.feed_update_threshold_default_value)
77-
).toInt()
73+
val thresholdOutdatedSeconds = defaultSharedPreferences.getStringSafe(
74+
context.getString(R.string.feed_update_threshold_key),
75+
context.getString(R.string.feed_update_threshold_default_value)
76+
).toInt()
7877
OffsetDateTime.now(ZoneOffset.UTC).minusSeconds(thresholdOutdatedSeconds.toLong())
7978
}
8079

0 commit comments

Comments
 (0)