fix #135, add an Extension field at Exporting file

This commit is contained in:
tibbi 2017-11-10 20:50:26 +01:00
parent e6fac3aa84
commit 847689539b
4 changed files with 38 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.activities.SimpleActivity
import com.simplemobiletools.notes.extensions.config
import com.simplemobiletools.notes.models.Note
import kotlinx.android.synthetic.main.dialog_export_as.view.*
import java.io.File
@ -20,6 +21,7 @@ class ExportAsDialog(val activity: SimpleActivity, val note: Note, val callback:
file_path.text = activity.humanizePath(realPath)
file_name.setText(note.title)
file_extension.setText(activity.config.lastUsedExtension)
file_path.setOnClickListener {
FilePickerDialog(activity, realPath, false, false, true) {
file_path.text = activity.humanizePath(it)
@ -36,18 +38,21 @@ class ExportAsDialog(val activity: SimpleActivity, val note: Note, val callback:
activity.setupDialogStuff(view, this, R.string.export_as_file)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val filename = view.file_name.value
val extension = view.file_extension.value
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
}
val newFile = File(realPath, filename)
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
val newFile = File(realPath, fullFilename)
if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters)
return@setOnClickListener
}
activity.config.lastUsedExtension = extension
callback(newFile.absolutePath)
dismiss()
})

View File

@ -43,4 +43,8 @@ class Config(context: Context) : BaseConfig(context) {
var placeCursorToEnd: Boolean
get() = prefs.getBoolean(CURSOR_PLACEMENT, true)
set(placement) = prefs.edit().putBoolean(CURSOR_PLACEMENT, placement).apply()
var lastUsedExtension: String
get() = prefs.getString(LAST_USED_EXTENSION, "txt")
set(lastUsedExtension) = prefs.edit().putString(LAST_USED_EXTENSION, lastUsedExtension).apply()
}

View File

@ -13,6 +13,7 @@ val SHOW_KEYBOARD = "show_keyboard"
val FONT_SIZE = "font_size"
val GRAVITY = "gravity"
val CURSOR_PLACEMENT = "cursor_placement"
val LAST_USED_EXTENSION = "last_used_extension"
// gravity
val GRAVITY_LEFT = 0

View File

@ -23,12 +23,38 @@
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/small_margin"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/file_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filename"
android:textSize="@dimen/smaller_text_size"/>
<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:inputType="text"
android:singleLine="true"
android:textCursorDrawable="@null"/>
android:textCursorDrawable="@null"
android:textSize="@dimen/normal_text_size"/>
<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"
android:textSize="@dimen/smaller_text_size"/>
<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:inputType="text"
android:singleLine="true"
android:textCursorDrawable="@null"
android:textSize="@dimen/normal_text_size"/>
</LinearLayout>