-
-
Notifications
You must be signed in to change notification settings - Fork 3
Convert Converters class to Kotlin #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Null-safe - fun toString(videoFormat: VideoFormat): String {
- return videoFormat.toString()
- }
+ fun toString(videoFormat: VideoFormat?): String? {
+ return videoFormat?.toString()
+ }📝 Committable suggestion
Suggested change
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @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 | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
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-safeThe signature currently requires a non-null
ImageFormat, which may lead to NPEs if Room passesnull. For symmetry withfromXyzit should acceptImageFormat?and returnString?.📝 Committable suggestion