mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +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.helpers.TYPE_NOTE
|
||||||
import com.simplemobiletools.notes.models.Note
|
import com.simplemobiletools.notes.models.Note
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||||
val STORAGE_OPEN_FILE = 1
|
val STORAGE_OPEN_FILE = 1
|
||||||
@ -133,15 +134,19 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
private fun displayNewNoteDialog() {
|
private fun displayNewNoteDialog() {
|
||||||
NewNoteDialog(this, mDb) {
|
NewNoteDialog(this, mDb) {
|
||||||
val newNote = Note(0, it, "", TYPE_NOTE)
|
val newNote = Note(0, it, "", TYPE_NOTE)
|
||||||
val id = mDb.insertNote(newNote)
|
addNewNote(newNote)
|
||||||
mNotes = mDb.getNotes()
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
initViewPager()
|
|
||||||
updateSelectedNote(id)
|
|
||||||
mAdapter.showKeyboard(getNoteIndexWithId(id))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addNewNote(note: Note) {
|
||||||
|
val id = mDb.insertNote(note)
|
||||||
|
mNotes = mDb.getNotes()
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
initViewPager()
|
||||||
|
updateSelectedNote(id)
|
||||||
|
mAdapter.showKeyboard(getNoteIndexWithId(id))
|
||||||
|
}
|
||||||
|
|
||||||
private fun launchAbout() {
|
private fun launchAbout() {
|
||||||
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_STETHO or LICENSE_RTL, BuildConfig.VERSION_NAME)
|
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() {
|
private fun openFile() {
|
||||||
FilePickerDialog(this) {
|
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