Skip to content

Commit 8c5f818

Browse files
Add copy note functionality
1 parent 9d4413d commit 8c5f818

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class MainActivity : SimpleActivity() {
321321
R.id.remove_done_items -> fragment?.handleUnlocking { removeDoneItems() }
322322
R.id.uncheck_all_items -> fragment?.handleUnlocking { uncheckAllItems() }
323323
R.id.sort_checklist -> fragment?.handleUnlocking { displaySortChecklistDialog() }
324+
R.id.copy_note -> fragment?.handleUnlocking { copyNote() }
324325
else -> return@setOnMenuItemClickListener false
325326
}
326327
return@setOnMenuItemClickListener true
@@ -1593,4 +1594,37 @@ class MainActivity : SimpleActivity() {
15931594
updateWidgets()
15941595
}
15951596
}
1597+
1598+
private fun copyNote() {
1599+
1600+
val text = if (mCurrentNote.type == NoteType.TYPE_TEXT) {
1601+
getCurrentNoteText()
1602+
} else {
1603+
mCurrentNote.value
1604+
}
1605+
1606+
if (text.isNullOrEmpty()) {
1607+
toast(R.string.cannot_copy_empty_text)
1608+
return
1609+
}
1610+
1611+
NotesHelper(this).getNotes {
1612+
val notes = it
1613+
val list = arrayListOf<RadioItem>().apply {
1614+
add(RadioItem(0, getString(R.string.create_new_note)))
1615+
notes.forEachIndexed { index, note ->
1616+
add(RadioItem(index + 1, note.title))
1617+
}
1618+
}
1619+
1620+
RadioGroupDialog(this, list, -1, R.string.add_to_note) {
1621+
if (it as Int == 0) {
1622+
displayNewNoteDialog(text)
1623+
} else {
1624+
updateSelectedNote(notes[it - 1].id!!)
1625+
addTextToCurrentNote(if (mCurrentNote.value.isEmpty()) text else "\n$text")
1626+
}
1627+
}
1628+
}
1629+
}
15961630
}

app/src/main/res/menu/menu.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
android:icon="@drawable/ic_sort_vector"
5050
android:title="@string/sort_by"
5151
app:showAsAction="ifRoom" />
52+
<item
53+
android:id="@+id/copy_note"
54+
android:title="@string/copy_note"
55+
app:showAsAction="ifRoom" />
5256
<item
5357
android:id="@+id/share"
5458
android:icon="@drawable/ic_share_vector"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<string name="app_launcher_name">Notes</string>
44
<string name="widget_config">Thank you for using Fossify Notes.\nFor more apps from Fossify, please visit fossify.org.</string>
55
<string name="cannot_share_empty_text">Cannot share empty text</string>
6+
<string name="cannot_copy_empty_text">Cannot copy empty text</string>
67
<string name="new_note">Add a new note</string>
78
<string name="no_title">Please name your note</string>
89
<string name="title_taken">A note with that title already exists</string>
@@ -14,6 +15,7 @@
1415
<string name="general_note">General note</string>
1516
<string name="create_new_note">Create a new note</string>
1617
<string name="add_to_note">Add to note</string>
18+
<string name="copy_note">Copy note</string>
1719
<string name="unsaved_changes_warning">You have some unsaved changes. What do you want to do with them?</string>
1820
<string name="note_shown_widget">Note shown in the widget:</string>
1921
<string name="show_note_title">Show note title</string>

0 commit comments

Comments
 (0)