Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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()
}
Comment on lines +24 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make the toString(imageFormat) converter null-safe
The signature currently requires a non-null ImageFormat, which may lead to NPEs if Room passes null. For symmetry with fromXyz it should accept ImageFormat? and return String?.

-    fun toString(imageFormat: ImageFormat): String {
-        return imageFormat.toString()
-    }
+    fun toString(imageFormat: ImageFormat?): String? {
+        return imageFormat?.toString()
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@JvmStatic
@TypeConverter
fun toString(imageFormat: ImageFormat): String {
return imageFormat.toString()
}
@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()
}
Comment on lines +43 to +45
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Null-safe toString(videoFormat) converter
As with ImageFormat, change VideoFormat converter to accept nullable and return nullable.

-    fun toString(videoFormat: VideoFormat): String {
-        return videoFormat.toString()
-    }
+    fun toString(videoFormat: VideoFormat?): String? {
+        return videoFormat?.toString()
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fun toString(videoFormat: VideoFormat): String {
return videoFormat.toString()
}
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
}
}
Loading