Skip to content

Commit

Permalink
Refactor NoteExt
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm committed Aug 11, 2024
1 parent 0b0f6ff commit dcc8a2f
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions app/src/main/java/dev/arkbuilders/arkmemo/utils/NoteExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 { this.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 { "" }
}

0 comments on commit dcc8a2f

Please sign in to comment.