mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-13 07:00:10 +01:00
Merge pull request #96 from trubitsyn/share-append-note
Implement appending text received from external application
This commit is contained in:
commit
63606269de
@ -32,7 +32,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.simplemobiletools:commons:2.20.2'
|
||||
compile 'com.simplemobiletools:commons:2.21.4'
|
||||
compile 'com.facebook.stetho:stetho:1.4.1'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
@ -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<RadioItem>().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() {
|
||||
|
@ -36,6 +36,12 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, 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()
|
||||
|
@ -54,6 +54,8 @@ class NoteFragment : Fragment() {
|
||||
saveText()
|
||||
}
|
||||
|
||||
fun getNotesView() = view.notes_view
|
||||
|
||||
fun saveText() {
|
||||
if (note.path.isNotEmpty() && !File(note.path).exists())
|
||||
return
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Notiz auswählen</string>
|
||||
<string name="rename_note">Notiz umbenennen</string>
|
||||
<string name="general_note">Hauptnotiz</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Datei öffnen</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Seleccione una nota</string>
|
||||
<string name="rename_note">Renombrar nota</string>
|
||||
<string name="general_note">Nota principal</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Open file</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Choisir une note</string>
|
||||
<string name="rename_note">Renomme la note</string>
|
||||
<string name="general_note">Note générale</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Ouvrir le fichier</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Jegyzetválasztás</string>
|
||||
<string name="rename_note">Jegyzet átnevezése</string>
|
||||
<string name="general_note">Alapértelmezett jegyzet</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Fájl megnyitása</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Pick a note</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
<string name="general_note">General note</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Open file</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">メモを選択</string>
|
||||
<string name="rename_note">メモの名前を変更</string>
|
||||
<string name="general_note">全般メモ</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Open file</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Pick a note</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
<string name="general_note">General note</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Open file</string>
|
||||
|
@ -15,6 +15,8 @@
|
||||
<string name="rename_note">Renomear nota</string>
|
||||
<string name="general_note">Nota geral</string>
|
||||
<string name="open_file">Abrir arquivo</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="export_as_file">Exportar como arquivo</string>
|
||||
|
@ -15,6 +15,8 @@
|
||||
<string name="rename_note">Renomear nota</string>
|
||||
<string name="general_note">Nota genérica</string>
|
||||
<string name="open_file">Abrir ficheiro</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="export_as_file">Exportar como ficheiro</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Выберите заметку</string>
|
||||
<string name="rename_note">Переименовать заметку</string>
|
||||
<string name="general_note">Общая заметка</string>
|
||||
<string name="create_new_note">Новая заметка</string>
|
||||
<string name="add_to_note">Добавить к заметке</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Открыть файл</string>
|
||||
|
@ -15,6 +15,8 @@
|
||||
<string name="rename_note">Rename note</string>
|
||||
<string name="general_note">General note</string>
|
||||
<string name="open_file">Open file</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="export_as_file">Export as file</string>
|
||||
|
@ -14,6 +14,8 @@
|
||||
<string name="pick_a_note">Pick a note</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
<string name="general_note">General note</string>
|
||||
<string name="create_new_note">Create a new note</string>
|
||||
<string name="add_to_note">Add to note</string>
|
||||
|
||||
<!-- File notes -->
|
||||
<string name="open_file">Open file</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user