diff --git a/app/build.gradle b/app/build.gradle index 1455a7bd..a0ed7e18 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.9.0' + compile 'com.simplemobiletools:commons:2.9.1' compile 'com.facebook.stetho:stetho:1.4.1' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } 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 79ab620c..ef54e372 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -24,6 +24,7 @@ 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.extensions.config import com.simplemobiletools.notes.extensions.getTextSize import com.simplemobiletools.notes.helpers.DBHelper @@ -186,7 +187,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { } private fun saveAsFile() { + SaveAsDialog(this, mCurrentNote.title) { + } } private fun displayDeleteNotePrompt() { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/SaveAsDialog.kt new file mode 100644 index 00000000..8c0d2c87 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/SaveAsDialog.kt @@ -0,0 +1,67 @@ +package com.simplemobiletools.notes.dialogs + +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import com.simplemobiletools.commons.dialogs.FilePickerDialog +import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.notes.R +import com.simplemobiletools.notes.activities.SimpleActivity +import kotlinx.android.synthetic.main.dialog_save_as.view.* +import java.io.File + +class SaveAsDialog(val activity: SimpleActivity, val noteTitle: String, val callback: (savePath: String) -> Unit) { + + init { + var realPath = activity.internalStoragePath + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null).apply { + file_path.text = activity.humanizePath(realPath) + + val fullName = noteTitle + val dotAt = fullName.lastIndexOf(".") + var name = fullName + + if (dotAt > 0) { + name = fullName.substring(0, dotAt) + val extension = fullName.substring(dotAt + 1) + file_extension.setText(extension) + } + + file_name.setText(name) + file_path.setOnClickListener { + FilePickerDialog(activity, realPath, false, false, true) { + file_path.text = activity.humanizePath(it) + realPath = it + } + } + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.save_as) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ + val filename = view.file_name.value + val extension = view.file_extension.value + + if (filename.isEmpty()) { + context.toast(R.string.filename_cannot_be_empty) + return@setOnClickListener + } + + var fullFileName = filename + if (extension.trim().isNotEmpty()) + fullFileName += ".$extension" + + val newFile = File(realPath, fullFileName) + if (!newFile.name.isAValidFilename()) { + context.toast(R.string.filename_invalid_characters) + return@setOnClickListener + } + + callback.invoke(newFile.absolutePath) + dismiss() + }) + } + } +} diff --git a/app/src/main/res/layout/dialog_save_as.xml b/app/src/main/res/layout/dialog_save_as.xml new file mode 100644 index 00000000..828459a7 --- /dev/null +++ b/app/src/main/res/layout/dialog_save_as.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + +