From cd0a87785e16ca7813da2be9ec266c5c07616b3c Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 16 May 2021 11:04:52 +0530 Subject: [PATCH 1/3] Update Room to 2.3.0. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index c9ca07b42..972b4eaaa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,7 +102,7 @@ ext { checkstyleVersion = '8.38' androidxLifecycleVersion = '2.2.0' - androidxRoomVersion = '2.3.0-alpha03' + androidxRoomVersion = '2.3.0' icepickVersion = '3.2.0' exoPlayerVersion = '2.13.3' From e8b83918682a00b9858a72082a76a67c1d16aabc Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 16 May 2021 11:14:15 +0530 Subject: [PATCH 2/3] Rename .java to .kt --- .../schabi/newpipe/database/{Converters.java => Converters.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/org/schabi/newpipe/database/{Converters.java => Converters.kt} (100%) diff --git a/app/src/main/java/org/schabi/newpipe/database/Converters.java b/app/src/main/java/org/schabi/newpipe/database/Converters.kt similarity index 100% rename from app/src/main/java/org/schabi/newpipe/database/Converters.java rename to app/src/main/java/org/schabi/newpipe/database/Converters.kt From 3b1c4b043d7e2fe33f6f0e4b385d6dddc31ee98e Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 16 May 2021 11:14:15 +0530 Subject: [PATCH 3/3] Convert Converters to a Kotlin object. --- .../org/schabi/newpipe/database/Converters.kt | 60 ++++++++----------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/database/Converters.kt b/app/src/main/java/org/schabi/newpipe/database/Converters.kt index c46b5f427..0eafcede1 100644 --- a/app/src/main/java/org/schabi/newpipe/database/Converters.kt +++ b/app/src/main/java/org/schabi/newpipe/database/Converters.kt @@ -1,64 +1,52 @@ -package org.schabi.newpipe.database; +package org.schabi.newpipe.database -import androidx.room.TypeConverter; - -import org.schabi.newpipe.extractor.stream.StreamType; -import org.schabi.newpipe.local.subscription.FeedGroupIcon; - -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; - -public final class Converters { - private Converters() { } +import androidx.room.TypeConverter +import org.schabi.newpipe.extractor.stream.StreamType +import org.schabi.newpipe.local.subscription.FeedGroupIcon +import java.time.Instant +import java.time.OffsetDateTime +import java.time.ZoneOffset +object Converters { /** - * Convert a long value to a {@link OffsetDateTime}. + * Convert a long value to a [OffsetDateTime]. * * @param value the long value - * @return the {@code OffsetDateTime} + * @return the `OffsetDateTime` */ @TypeConverter - public static OffsetDateTime offsetDateTimeFromTimestamp(final Long value) { - return value == null ? null : OffsetDateTime.ofInstant(Instant.ofEpochMilli(value), - ZoneOffset.UTC); + fun offsetDateTimeFromTimestamp(value: Long?): OffsetDateTime? { + return value?.let { OffsetDateTime.ofInstant(Instant.ofEpochMilli(it), ZoneOffset.UTC) } } /** - * Convert a {@link OffsetDateTime} to a long value. + * Convert a [OffsetDateTime] to a long value. * - * @param offsetDateTime the {@code OffsetDateTime} + * @param offsetDateTime the `OffsetDateTime` * @return the long value */ @TypeConverter - public static Long offsetDateTimeToTimestamp(final OffsetDateTime offsetDateTime) { - return offsetDateTime == null ? null : offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC) - .toInstant().toEpochMilli(); + fun offsetDateTimeToTimestamp(offsetDateTime: OffsetDateTime?): Long? { + return offsetDateTime?.withOffsetSameInstant(ZoneOffset.UTC)?.toInstant()?.toEpochMilli() } @TypeConverter - public static StreamType streamTypeOf(final String value) { - return StreamType.valueOf(value); + fun streamTypeOf(value: String): StreamType { + return StreamType.valueOf(value) } @TypeConverter - public static String stringOf(final StreamType streamType) { - return streamType.name(); + fun stringOf(streamType: StreamType): String { + return streamType.name } @TypeConverter - public static Integer integerOf(final FeedGroupIcon feedGroupIcon) { - return feedGroupIcon.getId(); + fun integerOf(feedGroupIcon: FeedGroupIcon): Int { + return feedGroupIcon.id } @TypeConverter - public static FeedGroupIcon feedGroupIconOf(final Integer id) { - for (final FeedGroupIcon icon : FeedGroupIcon.values()) { - if (icon.getId() == id) { - return icon; - } - } - - throw new IllegalArgumentException("There's no feed group icon with the id \"" + id + "\""); + fun feedGroupIconOf(id: Int): FeedGroupIcon { + return FeedGroupIcon.values().first { it.id == id } } }