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 ee1976d0..c8b28c8f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -21,10 +21,7 @@ import com.simplemobiletools.commons.models.Release import com.simplemobiletools.notes.BuildConfig import com.simplemobiletools.notes.R import com.simplemobiletools.notes.adapters.NotesPagerAdapter -import com.simplemobiletools.notes.dialogs.NewNoteDialog -import com.simplemobiletools.notes.dialogs.OpenNoteDialog -import com.simplemobiletools.notes.dialogs.RenameNoteDialog -import com.simplemobiletools.notes.dialogs.SaveAsDialog +import com.simplemobiletools.notes.dialogs.* import com.simplemobiletools.notes.extensions.config import com.simplemobiletools.notes.extensions.getTextSize import com.simplemobiletools.notes.helpers.DBHelper @@ -167,19 +164,13 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { val file = File(it) if (file.isImageVideoGif()) { toast(R.string.invalid_file_format) - return@FilePickerDialog - } - - if (file.length() > 10 * 1000 * 1000) { + } else if (file.length() > 10 * 1000 * 1000) { toast(R.string.file_too_large) + } else if (mDb.doesTitleExist(it.getFilenameFromPath())) { + toast(R.string.title_taken) } else { - val filename = it.getFilenameFromPath() - if (mDb.doesTitleExist(filename)) { - toast(R.string.title_taken) - } else { - val content = file.readText() - val note = Note(0, filename, content, TYPE_NOTE, it) - addNewNote(note) + OpenFileDialog(this, it) { + addNewNote(it) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenFileDialog.kt new file mode 100644 index 00000000..79a59fa9 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenFileDialog.kt @@ -0,0 +1,37 @@ +package com.simplemobiletools.notes.dialogs + +import android.app.Activity +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import android.view.ViewGroup +import com.simplemobiletools.commons.extensions.getFilenameFromPath +import com.simplemobiletools.commons.extensions.humanizePath +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.notes.R +import com.simplemobiletools.notes.helpers.TYPE_NOTE +import com.simplemobiletools.notes.models.Note +import kotlinx.android.synthetic.main.dialog_open_file.view.* +import java.io.File + +class OpenFileDialog(val activity: Activity, val path: String, val callback: (note: Note) -> Unit) : AlertDialog.Builder(activity) { + init { + val view = (LayoutInflater.from(activity).inflate(R.layout.dialog_open_file, null) as ViewGroup).apply { + open_file_filename.text = activity.humanizePath(path) + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.open_file) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ + val file = File(path) + val filename = path.getFilenameFromPath() + val content = file.readText() + val note = Note(0, filename, content, TYPE_NOTE, path) + callback.invoke(note) + dismiss() + }) + } + } +} diff --git a/app/src/main/res/layout/dialog_open_file.xml b/app/src/main/res/layout/dialog_open_file.xml new file mode 100644 index 00000000..be44a9b5 --- /dev/null +++ b/app/src/main/res/layout/dialog_open_file.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + +