Skip to content

Commit

Permalink
Minor refacotrs
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm committed Dec 6, 2023
1 parent e41726d commit f6139b7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class NotesRepoHelper @Inject constructor(
Log.d("notes-repo", "resource renamed to ${resourcePath.name} successfully")
}

fun readProperties(id: ResourceId): UserNoteProperties {
fun readProperties(id: ResourceId, defaultTitle: String): UserNoteProperties {
val title = propertiesStorage.getProperties(id).titles.let {
if (it.isNotEmpty()) it.elementAt(0) else throw NoteTitlesException()
if (it.isNotEmpty()) it.elementAt(0) else defaultTitle
}
val description = propertiesStorage.getProperties(id).descriptions.let {
if (it.isNotEmpty()) it.elementAt(0) else ""
Expand All @@ -78,6 +78,4 @@ class NotesRepoHelper @Inject constructor(
data class UserNoteProperties(
val title: String,
val description: String
)

class NoteTitlesException: Exception("note resource missing at least one title")
)
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class GraphicNotesRepo @Inject constructor(
modified = path.getLastModifiedTime()
)

val userNoteProperties = helper.readProperties(id)
val userNoteProperties = helper.readProperties(id, "")

GraphicNote(
title = userNoteProperties.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ class TextNotesRepo @Inject constructor(
modified = path.getLastModifiedTime()
)

val userNoteProperties = helper.readProperties(id)

path.readLines { data ->
val userNoteProperties = helper.readProperties(
id,
data.substringBefore("\n")
)

TextNote(
title = userNoteProperties.title,
description = userNoteProperties.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
}
}
}

}

if (memoPreferences.getPath().isEmpty()) {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/dev/arkbuilders/arkmemo/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ fun Fragment.observeSaveResult(result: LiveData<SaveNoteResult>) {
if (!isResumed) return@observe

if (it == SaveNoteResult.SUCCESS) {
toast(requireContext(), getString(R.string.ark_memo_note_saved))
activity?.onBackPressedDispatcher?.onBackPressed()
context?.let { ctx ->
toast(ctx, getString(R.string.ark_memo_note_saved))
activity?.onBackPressedDispatcher?.onBackPressed()
}
} else {
context?.let { ctx -> toast(ctx, getString(R.string.ark_memo_note_existing)) }
}
Expand Down

0 comments on commit f6139b7

Please sign in to comment.