Skip to content

Commit 80edf02

Browse files
committed
Implement appending text received from external application
1 parent 58eee25 commit 80edf02

File tree

15 files changed

+54
-1
lines changed

15 files changed

+54
-1
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import android.text.method.LinkMovementMethod
1111
import android.util.TypedValue
1212
import android.view.*
1313
import com.simplemobiletools.commons.dialogs.FilePickerDialog
14+
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
1415
import com.simplemobiletools.commons.extensions.*
1516
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
1617
import com.simplemobiletools.commons.helpers.LICENSE_RTL
1718
import com.simplemobiletools.commons.helpers.LICENSE_STETHO
19+
import com.simplemobiletools.commons.models.RadioItem
1820
import com.simplemobiletools.commons.models.Release
1921
import com.simplemobiletools.commons.views.MyEditText
2022
import com.simplemobiletools.notes.BuildConfig
@@ -59,13 +61,30 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
5961
intent.apply {
6062
if (action == Intent.ACTION_SEND && type == MIME_TEXT_PLAIN) {
6163
getStringExtra(Intent.EXTRA_TEXT)?.let {
62-
displayNewNoteDialog(it)
64+
handleText(it)
6365
intent.removeExtra(Intent.EXTRA_TEXT)
6466
}
6567
}
6668
}
6769
}
6870

71+
private fun handleText(text: String) {
72+
val notes = DBHelper.newInstance(this@MainActivity).getNotes()
73+
val list = arrayListOf<RadioItem>().apply {
74+
add(RadioItem(0, getString(R.string.create_new_note)))
75+
notes.forEachIndexed { index, note -> add(RadioItem(index + 1, note.title)) }
76+
}
77+
78+
RadioGroupDialog(this@MainActivity, list, -1, R.string.add_to_note, {
79+
if (it as Int == 0) {
80+
displayNewNoteDialog(text)
81+
} else {
82+
updateSelectedNote(notes[it - 1].id)
83+
addTextToCurrentNote(if (mCurrentNote.value.isEmpty()) text else "\n$text")
84+
}
85+
}).create()
86+
}
87+
6988
private fun initViewPager() {
7089
mNotes = mDb.getNotes()
7190
mCurrentNote = mNotes[0]
@@ -269,6 +288,8 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
269288

270289
private fun getCurrentNoteText() = (view_pager.adapter as NotesPagerAdapter).getCurrentNoteViewText(view_pager.currentItem)
271290

291+
private fun addTextToCurrentNote(text: String) = (view_pager.adapter as NotesPagerAdapter).appendText(view_pager.currentItem, text)
292+
272293
private fun saveCurrentNote() = (view_pager.adapter as NotesPagerAdapter).saveCurrentNote(view_pager.currentItem)
273294

274295
private fun displayDeleteNotePrompt() {

app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
3636

3737
fun getCurrentNoteViewText(position: Int) = fragments[position]?.getCurrentNoteViewText()
3838

39+
fun appendText(position: Int, text: String) {
40+
val fragment = fragments[position]
41+
val finalText = fragment?.getCurrentNoteViewText() + text
42+
fragment?.getNotesView()?.setText(finalText)
43+
}
44+
3945
fun saveCurrentNote(position: Int) = fragments[position]?.saveText()
4046

4147
fun showKeyboard(position: Int) = fragments[position]?.showKeyboard()

app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class NoteFragment : Fragment() {
5454
saveText()
5555
}
5656

57+
fun getNotesView() = view.notes_view
58+
5759
fun saveText() {
5860
if (note.path.isNotEmpty() && !File(note.path).exists())
5961
return

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Notiz auswählen</string>
1515
<string name="rename_note">Notiz umbenennen</string>
1616
<string name="general_note">Hauptnotiz</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Datei öffnen</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Seleccione una nota</string>
1515
<string name="rename_note">Renombrar nota</string>
1616
<string name="general_note">Nota principal</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Open file</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Choisir une note</string>
1515
<string name="rename_note">Renomme la note</string>
1616
<string name="general_note">Note générale</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Ouvrir le fichier</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Jegyzetválasztás</string>
1515
<string name="rename_note">Jegyzet átnevezése</string>
1616
<string name="general_note">Alapértelmezett jegyzet</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Fájl megnyitása</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Pick a note</string>
1515
<string name="rename_note">Rename note</string>
1616
<string name="general_note">General note</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Open file</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">メモを選択</string>
1515
<string name="rename_note">メモの名前を変更</string>
1616
<string name="general_note">全般メモ</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Open file</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Pick a note</string>
1515
<string name="rename_note">Rename note</string>
1616
<string name="general_note">General note</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Open file</string>

app/src/main/res/values-pt-rBR/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<string name="rename_note">Renomear nota</string>
1616
<string name="general_note">Nota geral</string>
1717
<string name="open_file">Abrir arquivo</string>
18+
<string name="create_new_note">Create a new note</string>
19+
<string name="add_to_note">Add to note</string>
1820

1921
<!-- File notes -->
2022
<string name="export_as_file">Exportar como arquivo</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<string name="rename_note">Renomear nota</string>
1616
<string name="general_note">Nota genérica</string>
1717
<string name="open_file">Abrir ficheiro</string>
18+
<string name="create_new_note">Create a new note</string>
19+
<string name="add_to_note">Add to note</string>
1820

1921
<!-- File notes -->
2022
<string name="export_as_file">Exportar como ficheiro</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Выберите заметку</string>
1515
<string name="rename_note">Переименовать заметку</string>
1616
<string name="general_note">Общая заметка</string>
17+
<string name="create_new_note">Новая заметка</string>
18+
<string name="add_to_note">Добавить к заметке</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Открыть файл</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<string name="rename_note">Rename note</string>
1616
<string name="general_note">General note</string>
1717
<string name="open_file">Open file</string>
18+
<string name="create_new_note">Create a new note</string>
19+
<string name="add_to_note">Add to note</string>
1820

1921
<!-- File notes -->
2022
<string name="export_as_file">Export as file</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="pick_a_note">Pick a note</string>
1515
<string name="rename_note">Rename note</string>
1616
<string name="general_note">General note</string>
17+
<string name="create_new_note">Create a new note</string>
18+
<string name="add_to_note">Add to note</string>
1719

1820
<!-- File notes -->
1921
<string name="open_file">Open file</string>

0 commit comments

Comments
 (0)