diff --git a/app/src/androidTest/java/org/schabi/newpipe/database/FeedDAOTest.kt b/app/src/androidTest/java/org/schabi/newpipe/database/FeedDAOTest.kt index 893ae82b7..54d2dad9c 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/database/FeedDAOTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/database/FeedDAOTest.kt @@ -22,7 +22,6 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo import org.schabi.newpipe.extractor.stream.StreamType import java.io.IOException import java.time.OffsetDateTime -import kotlin.streams.toList class FeedDAOTest { private lateinit var db: AppDatabase diff --git a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java index 6ccc2437a..041e91396 100644 --- a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java +++ b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java @@ -161,9 +161,7 @@ public final class DownloaderImpl extends Downloader { String responseBodyToReturn = null; try (ResponseBody body = response.body()) { - if (body != null) { - responseBodyToReturn = body.string(); - } + responseBodyToReturn = body.string(); } final String latestUrl = response.request().url().toString(); diff --git a/app/src/main/java/org/schabi/newpipe/database/Migrations.kt b/app/src/main/java/org/schabi/newpipe/database/Migrations.kt index 6566f7e6a..414f74893 100644 --- a/app/src/main/java/org/schabi/newpipe/database/Migrations.kt +++ b/app/src/main/java/org/schabi/newpipe/database/Migrations.kt @@ -8,7 +8,6 @@ package org.schabi.newpipe.database import android.util.Log import androidx.room.migration.Migration -import androidx.sqlite.db.SupportSQLiteDatabase import org.schabi.newpipe.MainActivity object Migrations { diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt index 609fbb336..7ddfeb553 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt @@ -163,7 +163,7 @@ class ErrorInfo private constructor( private fun getServiceName(serviceId: Int?) = // not using getNameOfServiceById since we want to accept a nullable serviceId and we // want to default to SERVICE_NONE - ServiceList.all()?.firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name + ServiceList.all().firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name ?: SERVICE_NONE fun throwableToStringList(throwable: Throwable) = arrayOf(throwable.stackTraceToString()) diff --git a/app/src/main/java/org/schabi/newpipe/ktx/View.kt b/app/src/main/java/org/schabi/newpipe/ktx/View.kt index b781335e1..cf9e4baef 100644 --- a/app/src/main/java/org/schabi/newpipe/ktx/View.kt +++ b/app/src/main/java/org/schabi/newpipe/ktx/View.kt @@ -41,11 +41,7 @@ fun View.animate( execOnEnd: Runnable? = null ) { if (DEBUG) { - val id = try { - resources.getResourceEntryName(id) - } catch (e: Exception) { - id.toString() - } + val id = runCatching { resources.getResourceEntryName(id) }.getOrDefault(id.toString()) val msg = String.format( "%8s → [%s:%s] [%s %s:%s] execOnEnd=%s", enterOrExit, javaClass.simpleName, id, animationType, duration, delay, execOnEnd diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt index aacc6757e..8a1de01c9 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt @@ -85,14 +85,13 @@ class FeedDatabaseManager(context: Context) { items: List, oldestAllowedDate: OffsetDateTime = FEED_OLDEST_ALLOWED_DATE ) { - val itemsToInsert = ArrayList() - loop@ for (streamItem in items) { - val uploadDate = streamItem.uploadDate + val itemsToInsert = items.mapNotNull { stream -> + val uploadDate = stream.uploadDate - itemsToInsert += when { - uploadDate == null && streamItem.streamType == StreamType.LIVE_STREAM -> streamItem - uploadDate != null && uploadDate.offsetDateTime() >= oldestAllowedDate -> streamItem - else -> continue@loop + when { + uploadDate == null && stream.streamType == StreamType.LIVE_STREAM -> stream + uploadDate != null && uploadDate.offsetDateTime() >= oldestAllowedDate -> stream + else -> null } } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt index 646596884..7ce117fcd 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt @@ -15,6 +15,7 @@ import androidx.core.app.NotificationManagerCompat import androidx.core.app.PendingIntentCompat import androidx.core.content.ContextCompat import androidx.core.content.getSystemService +import androidx.core.net.toUri import androidx.preference.PreferenceManager import com.squareup.picasso.Picasso import com.squareup.picasso.Target @@ -181,8 +182,7 @@ class NotificationHelper(val context: Context) { val manager = context.getSystemService()!! val enabled = manager.areNotificationsEnabled() val channel = manager.getNotificationChannel(channelId) - val importance = channel?.importance - enabled && channel != null && importance != NotificationManager.IMPORTANCE_NONE + enabled && channel?.importance != NotificationManager.IMPORTANCE_NONE } else { NotificationManagerCompat.from(context).areNotificationsEnabled() } @@ -212,7 +212,7 @@ class NotificationHelper(val context: Context) { context.startActivity(intent) } else { val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) - intent.data = Uri.parse("package:" + context.packageName) + intent.data = "package:${context.packageName}".toUri() context.startActivity(intent) } } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/ScheduleOptions.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/ScheduleOptions.kt index 37e8fc39e..b1027e21a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/ScheduleOptions.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/ScheduleOptions.kt @@ -3,6 +3,7 @@ package org.schabi.newpipe.local.feed.notifications import android.content.Context import androidx.preference.PreferenceManager import org.schabi.newpipe.R +import org.schabi.newpipe.ktx.getStringSafe import java.util.concurrent.TimeUnit /** @@ -20,11 +21,9 @@ data class ScheduleOptions( val preferences = PreferenceManager.getDefaultSharedPreferences(context) return ScheduleOptions( interval = TimeUnit.SECONDS.toMillis( - preferences.getString( + preferences.getStringSafe( context.getString(R.string.streams_notifications_interval_key), - null - )?.toLongOrNull() ?: context.getString( - R.string.streams_notifications_interval_default + context.getString(R.string.streams_notifications_interval_default) ).toLong() ), isRequireNonMeteredNetwork = preferences.getString( diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/ExportPlaylist.kt b/app/src/main/java/org/schabi/newpipe/local/playlist/ExportPlaylist.kt index 8eb3ab3ae..9c7f1ba09 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/ExportPlaylist.kt +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/ExportPlaylist.kt @@ -65,5 +65,5 @@ private val linkHandler: YoutubeStreamLinkHandlerFactory = YoutubeStreamLinkHand */ private fun getYouTubeId(url: String): String? { - return try { linkHandler.getId(url) } catch (e: ParsingException) { null } + return runCatching { linkHandler.getId(url) }.getOrNull() }