mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-05-31 14:20:22 +02:00
allow creating a note from file
This commit is contained in:
parent
af80a19f80
commit
8d7a6c0c36
@ -30,6 +30,7 @@ import com.simplemobiletools.notes.helpers.DBHelper
|
||||
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.io.File
|
||||
|
||||
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
val STORAGE_OPEN_FILE = 1
|
||||
@ -133,15 +134,19 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
private fun displayNewNoteDialog() {
|
||||
NewNoteDialog(this, mDb) {
|
||||
val newNote = Note(0, it, "", TYPE_NOTE)
|
||||
val id = mDb.insertNote(newNote)
|
||||
mNotes = mDb.getNotes()
|
||||
invalidateOptionsMenu()
|
||||
initViewPager()
|
||||
updateSelectedNote(id)
|
||||
mAdapter.showKeyboard(getNoteIndexWithId(id))
|
||||
addNewNote(newNote)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addNewNote(note: Note) {
|
||||
val id = mDb.insertNote(note)
|
||||
mNotes = mDb.getNotes()
|
||||
invalidateOptionsMenu()
|
||||
initViewPager()
|
||||
updateSelectedNote(id)
|
||||
mAdapter.showKeyboard(getNoteIndexWithId(id))
|
||||
}
|
||||
|
||||
private fun launchAbout() {
|
||||
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_STETHO or LICENSE_RTL, BuildConfig.VERSION_NAME)
|
||||
}
|
||||
@ -156,7 +161,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
|
||||
private fun openFile() {
|
||||
FilePickerDialog(this) {
|
||||
|
||||
val filename = it.getFilenameFromPath()
|
||||
val content = File(it).readText()
|
||||
val note = Note(0, filename, content, TYPE_NOTE)
|
||||
addNewNote(note)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user