mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-07 15:08:40 +01:00
show a Save as dialog at selecting "Save as file"
This commit is contained in:
parent
524b439d91
commit
6e67949f0a
@ -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"
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
48
app/src/main/res/layout/dialog_save_as.xml
Normal file
48
app/src/main/res/layout/dialog_save_as.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/save_as_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/file_path_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/path"
|
||||
android:textSize="@dimen/smaller_text_size"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/file_path"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/small_margin"
|
||||
android:paddingTop="@dimen/small_margin"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/file_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:singleLine="true"
|
||||
android:textCursorDrawable="@null"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/file_extension_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/extension"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/file_extension"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:singleLine="true"
|
||||
android:textCursorDrawable="@null"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user