mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-12 01:10:43 +01:00
fix #135, add an Extension field at Exporting file
This commit is contained in:
parent
e6fac3aa84
commit
847689539b
@ -8,6 +8,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
|||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.notes.R
|
import com.simplemobiletools.notes.R
|
||||||
import com.simplemobiletools.notes.activities.SimpleActivity
|
import com.simplemobiletools.notes.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.notes.extensions.config
|
||||||
import com.simplemobiletools.notes.models.Note
|
import com.simplemobiletools.notes.models.Note
|
||||||
import kotlinx.android.synthetic.main.dialog_export_as.view.*
|
import kotlinx.android.synthetic.main.dialog_export_as.view.*
|
||||||
import java.io.File
|
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_path.text = activity.humanizePath(realPath)
|
||||||
|
|
||||||
file_name.setText(note.title)
|
file_name.setText(note.title)
|
||||||
|
file_extension.setText(activity.config.lastUsedExtension)
|
||||||
file_path.setOnClickListener {
|
file_path.setOnClickListener {
|
||||||
FilePickerDialog(activity, realPath, false, false, true) {
|
FilePickerDialog(activity, realPath, false, false, true) {
|
||||||
file_path.text = activity.humanizePath(it)
|
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)
|
activity.setupDialogStuff(view, this, R.string.export_as_file)
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||||
val filename = view.file_name.value
|
val filename = view.file_name.value
|
||||||
|
val extension = view.file_extension.value
|
||||||
|
|
||||||
if (filename.isEmpty()) {
|
if (filename.isEmpty()) {
|
||||||
activity.toast(R.string.filename_cannot_be_empty)
|
activity.toast(R.string.filename_cannot_be_empty)
|
||||||
return@setOnClickListener
|
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()) {
|
if (!newFile.name.isAValidFilename()) {
|
||||||
activity.toast(R.string.filename_invalid_characters)
|
activity.toast(R.string.filename_invalid_characters)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
activity.config.lastUsedExtension = extension
|
||||||
callback(newFile.absolutePath)
|
callback(newFile.absolutePath)
|
||||||
dismiss()
|
dismiss()
|
||||||
})
|
})
|
||||||
|
@ -43,4 +43,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var placeCursorToEnd: Boolean
|
var placeCursorToEnd: Boolean
|
||||||
get() = prefs.getBoolean(CURSOR_PLACEMENT, true)
|
get() = prefs.getBoolean(CURSOR_PLACEMENT, true)
|
||||||
set(placement) = prefs.edit().putBoolean(CURSOR_PLACEMENT, placement).apply()
|
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()
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ val SHOW_KEYBOARD = "show_keyboard"
|
|||||||
val FONT_SIZE = "font_size"
|
val FONT_SIZE = "font_size"
|
||||||
val GRAVITY = "gravity"
|
val GRAVITY = "gravity"
|
||||||
val CURSOR_PLACEMENT = "cursor_placement"
|
val CURSOR_PLACEMENT = "cursor_placement"
|
||||||
|
val LAST_USED_EXTENSION = "last_used_extension"
|
||||||
|
|
||||||
// gravity
|
// gravity
|
||||||
val GRAVITY_LEFT = 0
|
val GRAVITY_LEFT = 0
|
||||||
|
@ -23,12 +23,38 @@
|
|||||||
android:paddingRight="@dimen/small_margin"
|
android:paddingRight="@dimen/small_margin"
|
||||||
android:paddingTop="@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
|
<com.simplemobiletools.commons.views.MyEditText
|
||||||
android:id="@+id/file_name"
|
android:id="@+id/file_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="@dimen/activity_margin"
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:inputType="text"
|
||||||
android:singleLine="true"
|
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>
|
</LinearLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user