From 80edf02089958d5f116f09a4bfd99ce877c9c050 Mon Sep 17 00:00:00 2001 From: Nikola Trubitsyn Date: Sun, 18 Jun 2017 02:05:33 +0300 Subject: [PATCH] Implement appending text received from external application --- .../notes/activities/MainActivity.kt | 23 ++++++++++++++++++- .../notes/adapters/NotesPagerAdapter.kt | 6 +++++ .../notes/fragments/NoteFragment.kt | 2 ++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-es/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-hu/strings.xml | 2 ++ app/src/main/res/values-it/strings.xml | 2 ++ app/src/main/res/values-ja/strings.xml | 2 ++ app/src/main/res/values-lt/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-pt/strings.xml | 2 ++ app/src/main/res/values-ru/strings.xml | 2 ++ app/src/main/res/values-sv/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 15 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index fd0eca55..c7642644 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -11,10 +11,12 @@ import android.text.method.LinkMovementMethod import android.util.TypedValue import android.view.* import com.simplemobiletools.commons.dialogs.FilePickerDialog +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN import com.simplemobiletools.commons.helpers.LICENSE_RTL import com.simplemobiletools.commons.helpers.LICENSE_STETHO +import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.views.MyEditText import com.simplemobiletools.notes.BuildConfig @@ -59,13 +61,30 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { intent.apply { if (action == Intent.ACTION_SEND && type == MIME_TEXT_PLAIN) { getStringExtra(Intent.EXTRA_TEXT)?.let { - displayNewNoteDialog(it) + handleText(it) intent.removeExtra(Intent.EXTRA_TEXT) } } } } + private fun handleText(text: String) { + val notes = DBHelper.newInstance(this@MainActivity).getNotes() + val list = arrayListOf().apply { + add(RadioItem(0, getString(R.string.create_new_note))) + notes.forEachIndexed { index, note -> add(RadioItem(index + 1, note.title)) } + } + + RadioGroupDialog(this@MainActivity, list, -1, R.string.add_to_note, { + if (it as Int == 0) { + displayNewNoteDialog(text) + } else { + updateSelectedNote(notes[it - 1].id) + addTextToCurrentNote(if (mCurrentNote.value.isEmpty()) text else "\n$text") + } + }).create() + } + private fun initViewPager() { mNotes = mDb.getNotes() mCurrentNote = mNotes[0] @@ -269,6 +288,8 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { private fun getCurrentNoteText() = (view_pager.adapter as NotesPagerAdapter).getCurrentNoteViewText(view_pager.currentItem) + private fun addTextToCurrentNote(text: String) = (view_pager.adapter as NotesPagerAdapter).appendText(view_pager.currentItem, text) + private fun saveCurrentNote() = (view_pager.adapter as NotesPagerAdapter).saveCurrentNote(view_pager.currentItem) private fun displayDeleteNotePrompt() { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt index 8c466385..c0eab44c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt @@ -36,6 +36,12 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List, val activity fun getCurrentNoteViewText(position: Int) = fragments[position]?.getCurrentNoteViewText() + fun appendText(position: Int, text: String) { + val fragment = fragments[position] + val finalText = fragment?.getCurrentNoteViewText() + text + fragment?.getNotesView()?.setText(finalText) + } + fun saveCurrentNote(position: Int) = fragments[position]?.saveText() fun showKeyboard(position: Int) = fragments[position]?.showKeyboard() diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt index 51545005..a184c781 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt @@ -54,6 +54,8 @@ class NoteFragment : Fragment() { saveText() } + fun getNotesView() = view.notes_view + fun saveText() { if (note.path.isNotEmpty() && !File(note.path).exists()) return diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 94dd2ee5..9d083be2 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -14,6 +14,8 @@ Notiz auswählen Notiz umbenennen Hauptnotiz + Create a new note + Add to note Datei öffnen diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index ee840fc3..ca4eded6 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -14,6 +14,8 @@ Seleccione una nota Renombrar nota Nota principal + Create a new note + Add to note Open file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2a575c04..80b5c826 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -14,6 +14,8 @@ Choisir une note Renomme la note Note générale + Create a new note + Add to note Ouvrir le fichier diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 120f6e91..802c4260 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -14,6 +14,8 @@ Jegyzetválasztás Jegyzet átnevezése Alapértelmezett jegyzet + Create a new note + Add to note Fájl megnyitása diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 40848ef8..48618ea7 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -14,6 +14,8 @@ Pick a note Rename note General note + Create a new note + Add to note Open file diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index ce7228fe..18dce88f 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -14,6 +14,8 @@ メモを選択 メモの名前を変更 全般メモ + Create a new note + Add to note Open file diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index 625fbe5e..ce74e307 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -14,6 +14,8 @@ Pick a note Rename note General note + Create a new note + Add to note Open file diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 00545d43..170cd691 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -15,6 +15,8 @@ Renomear nota Nota geral Abrir arquivo + Create a new note + Add to note Exportar como arquivo diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 6a6202e8..7a180c54 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -15,6 +15,8 @@ Renomear nota Nota genérica Abrir ficheiro + Create a new note + Add to note Exportar como ficheiro diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 7ea44e20..194f98ad 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -14,6 +14,8 @@ Выберите заметку Переименовать заметку Общая заметка + Новая заметка + Добавить к заметке Открыть файл diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index d96e344f..5f0bfdaf 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -15,6 +15,8 @@ Rename note General note Open file + Create a new note + Add to note Export as file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 625fbe5e..ce74e307 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,6 +14,8 @@ Pick a note Rename note General note + Create a new note + Add to note Open file