diff --git a/app/src/main/java/ai/elimu/content_provider/room/db/Converters.java b/app/src/main/java/ai/elimu/content_provider/room/db/Converters.java deleted file mode 100644 index 76e2daca..00000000 --- a/app/src/main/java/ai/elimu/content_provider/room/db/Converters.java +++ /dev/null @@ -1,83 +0,0 @@ -package ai.elimu.content_provider.room.db; - -import android.text.TextUtils; - -import androidx.room.TypeConverter; - -import ai.elimu.model.v2.enums.ReadingLevel; -import ai.elimu.model.v2.enums.content.ImageFormat; -import ai.elimu.model.v2.enums.content.VideoFormat; -import ai.elimu.model.v2.enums.content.WordType; - -/** - * See Referencing complex data using Room - */ -public class Converters { - - @TypeConverter - public static ImageFormat fromImageFormat(String value) { - ImageFormat imageFormat = null; - if (!TextUtils.isEmpty(value)) { - imageFormat = ImageFormat.valueOf(value); - } - return imageFormat; - } - - @TypeConverter - public static String toString(ImageFormat imageFormat) { - return imageFormat.toString(); - } - - - @TypeConverter - public static VideoFormat fromVideoFormat(String value) { - VideoFormat videoFormat = null; - if (!TextUtils.isEmpty(value)) { - videoFormat = VideoFormat.valueOf(value); - } - return videoFormat; - } - - @TypeConverter - public static String toString(VideoFormat videoFormat) { - return videoFormat.toString(); - } - - - @TypeConverter - public static WordType fromWordType(String value) { - WordType wordType = null; - if (!TextUtils.isEmpty(value)) { - wordType = WordType.valueOf(value); - } - return wordType; - } - - @TypeConverter - public static String toString(WordType wordType) { - String value = null; - if (wordType != null) { - value = wordType.toString(); - } - return value; - } - - - @TypeConverter - public static ReadingLevel fromReadingLevel(String value) { - ReadingLevel readingLevel = null; - if (!TextUtils.isEmpty(value)) { - readingLevel = ReadingLevel.valueOf(value); - } - return readingLevel; - } - - @TypeConverter - public static String toString(ReadingLevel readingLevel) { - String value = null; - if (readingLevel != null) { - value = readingLevel.toString(); - } - return value; - } -} diff --git a/app/src/main/java/ai/elimu/content_provider/room/db/Converters.kt b/app/src/main/java/ai/elimu/content_provider/room/db/Converters.kt new file mode 100644 index 00000000..e7c2098b --- /dev/null +++ b/app/src/main/java/ai/elimu/content_provider/room/db/Converters.kt @@ -0,0 +1,88 @@ +package ai.elimu.content_provider.room.db + +import ai.elimu.model.v2.enums.ReadingLevel +import ai.elimu.model.v2.enums.content.ImageFormat +import ai.elimu.model.v2.enums.content.VideoFormat +import ai.elimu.model.v2.enums.content.WordType +import android.text.TextUtils +import androidx.room.TypeConverter + +/** + * See [Referencing complex data using Room](https://developer.android.com/training/data-storage/room/referencing-data) + */ +object Converters { + @JvmStatic + @TypeConverter + fun fromImageFormat(value: String?): ImageFormat? { + var imageFormat: ImageFormat? = null + if (!TextUtils.isEmpty(value)) { + imageFormat = ImageFormat.valueOf(value!!) + } + return imageFormat + } + + @JvmStatic + @TypeConverter + fun toString(imageFormat: ImageFormat): String { + return imageFormat.toString() + } + + + @JvmStatic + @TypeConverter + fun fromVideoFormat(value: String?): VideoFormat? { + var videoFormat: VideoFormat? = null + if (!TextUtils.isEmpty(value)) { + videoFormat = VideoFormat.valueOf(value!!) + } + return videoFormat + } + + @JvmStatic + @TypeConverter + fun toString(videoFormat: VideoFormat): String { + return videoFormat.toString() + } + + + @JvmStatic + @TypeConverter + fun fromWordType(value: String?): WordType? { + var wordType: WordType? = null + if (!TextUtils.isEmpty(value)) { + wordType = WordType.valueOf(value!!) + } + return wordType + } + + @JvmStatic + @TypeConverter + fun toString(wordType: WordType?): String? { + var value: String? = null + if (wordType != null) { + value = wordType.toString() + } + return value + } + + + @JvmStatic + @TypeConverter + fun fromReadingLevel(value: String?): ReadingLevel? { + var readingLevel: ReadingLevel? = null + if (!TextUtils.isEmpty(value)) { + readingLevel = ReadingLevel.valueOf(value!!) + } + return readingLevel + } + + @JvmStatic + @TypeConverter + fun toString(readingLevel: ReadingLevel?): String? { + var value: String? = null + if (readingLevel != null) { + value = readingLevel.toString() + } + return value + } +}