Skip to content

Commit 6614539

Browse files
committed
Added ExportNotesDialog
1 parent 5e0d4a5 commit 6614539

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.simplemobiletools.commons.extensions.*
1010
import com.simplemobiletools.commons.helpers.*
1111
import com.simplemobiletools.commons.models.RadioItem
1212
import com.simplemobiletools.notes.pro.R
13+
import com.simplemobiletools.notes.pro.dialogs.ExportNotesDialog
1314
import com.simplemobiletools.notes.pro.extensions.config
1415
import com.simplemobiletools.notes.pro.extensions.requestUnlockNotes
1516
import com.simplemobiletools.notes.pro.extensions.updateWidgets
@@ -290,8 +291,9 @@ class SettingsActivity : SimpleActivity() {
290291

291292
private fun setupNotesExport() {
292293
settings_export_notes_holder.setOnClickListener {
293-
val fileName = "${getString(R.string.notes)}_${getCurrentFormattedDateTime()}"
294-
saveDocument.launch(fileName)
294+
ExportNotesDialog(this) { filename ->
295+
saveDocument.launch(filename)
296+
}
295297
}
296298
}
297299

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.simplemobiletools.notes.pro.dialogs
2+
3+
import android.view.ViewGroup
4+
import androidx.appcompat.app.AlertDialog
5+
import com.simplemobiletools.commons.extensions.*
6+
import com.simplemobiletools.notes.pro.R
7+
import com.simplemobiletools.notes.pro.activities.SimpleActivity
8+
import kotlinx.android.synthetic.main.dialog_export_notes.view.export_notes_filename
9+
10+
class ExportNotesDialog(val activity: SimpleActivity, callback: (filename: String) -> Unit) {
11+
12+
init {
13+
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_notes, null) as ViewGroup).apply {
14+
export_notes_filename.setText(
15+
buildString {
16+
append(context.getString(R.string.notes))
17+
append("_")
18+
append(context.getCurrentFormattedDateTime())
19+
}
20+
)
21+
}
22+
23+
activity.getAlertDialogBuilder().setPositiveButton(R.string.ok, null).setNegativeButton(R.string.cancel, null).apply {
24+
activity.setupDialogStuff(view, this, R.string.export_notes) { alertDialog ->
25+
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
26+
27+
val filename = view.export_notes_filename.value
28+
when {
29+
filename.isEmpty() -> activity.toast(R.string.empty_name)
30+
filename.isAValidFilename() -> {
31+
callback(filename)
32+
alertDialog.dismiss()
33+
}
34+
35+
else -> activity.toast(R.string.invalid_name)
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/export_notes_scrollview"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content">
6+
7+
<LinearLayout
8+
android:id="@+id/export_notes_holder"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:orientation="vertical"
12+
android:paddingTop="@dimen/activity_margin">
13+
14+
<com.simplemobiletools.commons.views.MyTextInputLayout
15+
android:id="@+id/export_notes_filename_hint"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:layout_marginBottom="@dimen/medium_margin"
19+
android:hint="@string/filename_without_json"
20+
android:paddingStart="@dimen/activity_margin"
21+
android:paddingEnd="@dimen/activity_margin">
22+
23+
<com.google.android.material.textfield.TextInputEditText
24+
android:id="@+id/export_notes_filename"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:singleLine="true"
28+
android:textCursorDrawable="@null"
29+
android:textSize="@dimen/bigger_text_size" />
30+
31+
</com.simplemobiletools.commons.views.MyTextInputLayout>
32+
33+
</LinearLayout>
34+
</ScrollView>

0 commit comments

Comments
 (0)