From 5419bb4b48b4a0fd3dad2044f385ea52b3f482ec Mon Sep 17 00:00:00 2001 From: Shubert Munthali Date: Sun, 11 Aug 2024 17:05:30 +0200 Subject: [PATCH] Refactor NoteExt to enhance readability. --- .../dev/arkbuilders/arkmemo/utils/NoteExt.kt | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/utils/NoteExt.kt b/app/src/main/java/dev/arkbuilders/arkmemo/utils/NoteExt.kt index cc686754..07662da0 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/utils/NoteExt.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/utils/NoteExt.kt @@ -8,20 +8,31 @@ import dev.arkbuilders.arkmemo.models.TextNote import dev.arkbuilders.arkmemo.models.VoiceNote fun Note.getAutoTitle(context: Context? = null): String { + return if (context != null) { + when (this) { + is TextNote -> { + title.ifEmpty { text.take(20) }.ifEmpty { + context.getString(R.string.ark_memo_default_text_note_title) + } + } - return if (this is TextNote) { - this.title.ifEmpty { this.text.take(20) }.ifEmpty { - context?.getString(R.string.ark_memo_default_text_note_title) ?: "" - } - } else if (this is GraphicNote && context != null) { - this.title.ifEmpty { - String.format(context.getString(R.string.ark_memo_graphic_note), this.resource?.id) - } - } else if (this is VoiceNote && context != null) { - this.title.ifEmpty { - String.format(context.getString(R.string.ark_memo_voice_note), this.resource?.id) + is GraphicNote -> { + title.ifEmpty { + String.format( + context.getString(R.string.ark_memo_graphic_note), resource?.id + ) + } + } + + is VoiceNote -> { + title.ifEmpty { + String.format( + context.getString(R.string.ark_memo_voice_note), resource?.id + ) + } + } + + else -> { "" } } - } else { - "" - } + } else { "" } } \ No newline at end of file