mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-21 18:42:35 +01:00
Merge pull request #11629 from Two-Ai/kotlin-getStringSafe
Add null-safe SharedPreferences.getStringSafe
This commit is contained in:
commit
64ad05d813
@ -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
|
||||||
|
}
|
@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.Info
|
|||||||
import org.schabi.newpipe.extractor.NewPipe
|
import org.schabi.newpipe.extractor.NewPipe
|
||||||
import org.schabi.newpipe.extractor.feed.FeedInfo
|
import org.schabi.newpipe.extractor.feed.FeedInfo
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
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.feed.FeedDatabaseManager
|
||||||
import org.schabi.newpipe.local.subscription.SubscriptionManager
|
import org.schabi.newpipe.local.subscription.SubscriptionManager
|
||||||
import org.schabi.newpipe.util.ChannelTabHelper
|
import org.schabi.newpipe.util.ChannelTabHelper
|
||||||
@ -69,11 +70,9 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
val outdatedThreshold = if (ignoreOutdatedThreshold) {
|
val outdatedThreshold = if (ignoreOutdatedThreshold) {
|
||||||
OffsetDateTime.now(ZoneOffset.UTC)
|
OffsetDateTime.now(ZoneOffset.UTC)
|
||||||
} else {
|
} else {
|
||||||
val thresholdOutdatedSeconds = (
|
val thresholdOutdatedSeconds = defaultSharedPreferences.getStringSafe(
|
||||||
defaultSharedPreferences.getString(
|
|
||||||
context.getString(R.string.feed_update_threshold_key),
|
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)
|
||||||
) ?: context.getString(R.string.feed_update_threshold_default_value)
|
|
||||||
).toInt()
|
).toInt()
|
||||||
OffsetDateTime.now(ZoneOffset.UTC).minusSeconds(thresholdOutdatedSeconds.toLong())
|
OffsetDateTime.now(ZoneOffset.UTC).minusSeconds(thresholdOutdatedSeconds.toLong())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user