Skip to content

Commit

Permalink
Merge pull request #11629 from Two-Ai/kotlin-getStringSafe
Browse files Browse the repository at this point in the history
Add null-safe SharedPreferences.getStringSafe
  • Loading branch information
TobiGr authored Oct 27, 2024
2 parents 94f992a + 734b6e2 commit 64ad05d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/org/schabi/newpipe/ktx/SharedPreferences.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.schabi.newpipe.ktx

import android.content.SharedPreferences

fun SharedPreferences.getStringSafe(key: String, defValue: String): String {
return getString(key, null) ?: defValue
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.Info
import org.schabi.newpipe.extractor.NewPipe
import org.schabi.newpipe.extractor.feed.FeedInfo
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.ktx.getStringSafe
import org.schabi.newpipe.local.feed.FeedDatabaseManager
import org.schabi.newpipe.local.subscription.SubscriptionManager
import org.schabi.newpipe.util.ChannelTabHelper
Expand Down Expand Up @@ -69,12 +70,10 @@ class FeedLoadManager(private val context: Context) {
val outdatedThreshold = if (ignoreOutdatedThreshold) {
OffsetDateTime.now(ZoneOffset.UTC)
} else {
val thresholdOutdatedSeconds = (
defaultSharedPreferences.getString(
context.getString(R.string.feed_update_threshold_key),
context.getString(R.string.feed_update_threshold_default_value)
) ?: context.getString(R.string.feed_update_threshold_default_value)
).toInt()
val thresholdOutdatedSeconds = defaultSharedPreferences.getStringSafe(
context.getString(R.string.feed_update_threshold_key),
context.getString(R.string.feed_update_threshold_default_value)
).toInt()
OffsetDateTime.now(ZoneOffset.UTC).minusSeconds(thresholdOutdatedSeconds.toLong())
}

Expand Down

0 comments on commit 64ad05d

Please sign in to comment.