Skip to content

Commit c93e7fe

Browse files
committed
ManageAutoBackupsDialog and DateTimePatternInfoDialog added
1 parent 1fb1afe commit c93e7fe

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.simplemobiletools.notes.pro.dialogs
2+
3+
import com.simplemobiletools.commons.activities.BaseSimpleActivity
4+
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
5+
import com.simplemobiletools.commons.extensions.setupDialogStuff
6+
import com.simplemobiletools.notes.pro.R
7+
8+
class DateTimePatternInfoDialog(activity: BaseSimpleActivity) {
9+
10+
init {
11+
val view = activity.layoutInflater.inflate(R.layout.datetime_pattern_info_layout, null)
12+
activity.getAlertDialogBuilder()
13+
.setPositiveButton(R.string.ok) { _, _ -> { } }
14+
.apply {
15+
activity.setupDialogStuff(view, this)
16+
}
17+
}
18+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.simplemobiletools.notes.pro.dialogs
2+
3+
import android.view.ViewGroup
4+
import androidx.appcompat.app.AlertDialog
5+
import com.simplemobiletools.commons.dialogs.FilePickerDialog
6+
import com.simplemobiletools.commons.extensions.*
7+
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
8+
import com.simplemobiletools.notes.pro.R
9+
import com.simplemobiletools.notes.pro.activities.SimpleActivity
10+
import com.simplemobiletools.notes.pro.extensions.config
11+
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_filename
12+
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_filename_hint
13+
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_folder
14+
import java.io.File
15+
16+
class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: () -> Unit) {
17+
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
18+
private val config = activity.config
19+
private var backupFolder = config.autoBackupFolder
20+
21+
init {
22+
view.apply {
23+
backup_notes_folder.setText(activity.humanizePath(backupFolder))
24+
val filename = config.autoBackupFilename.ifEmpty {
25+
"${activity.getString(R.string.notes)}_%Y%M%D_%h%m%s"
26+
}
27+
28+
backup_notes_filename.setText(filename)
29+
backup_notes_filename_hint.setEndIconOnClickListener {
30+
DateTimePatternInfoDialog(activity)
31+
}
32+
33+
backup_notes_filename_hint.setEndIconOnLongClickListener {
34+
DateTimePatternInfoDialog(activity)
35+
true
36+
}
37+
38+
backup_notes_folder.setOnClickListener {
39+
selectBackupFolder()
40+
}
41+
}
42+
43+
activity.getAlertDialogBuilder()
44+
.setPositiveButton(R.string.ok, null)
45+
.setNegativeButton(R.string.cancel, null)
46+
.apply {
47+
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { dialog ->
48+
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
49+
val filename = view.backup_notes_filename.value
50+
when {
51+
filename.isEmpty() -> activity.toast(R.string.empty_name)
52+
filename.isAValidFilename() -> {
53+
val file = File(backupFolder, "$filename.json")
54+
if (file.exists() && !file.canWrite()) {
55+
activity.toast(R.string.name_taken)
56+
return@setOnClickListener
57+
}
58+
59+
ensureBackgroundThread {
60+
config.apply {
61+
autoBackupFolder = backupFolder
62+
autoBackupFilename = filename
63+
}
64+
65+
activity.runOnUiThread {
66+
onSuccess()
67+
}
68+
69+
dialog.dismiss()
70+
}
71+
}
72+
73+
else -> activity.toast(R.string.invalid_name)
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
private fun selectBackupFolder() {
81+
activity.hideKeyboard(view.backup_notes_filename)
82+
FilePickerDialog(activity, backupFolder, false, showFAB = true) { path ->
83+
activity.handleSAFDialog(path) { grantedSAF ->
84+
if (!grantedSAF) {
85+
return@handleSAFDialog
86+
}
87+
88+
activity.handleSAFDialogSdk30(path) { grantedSAF30 ->
89+
if (!grantedSAF30) {
90+
return@handleSAFDialogSdk30
91+
}
92+
93+
backupFolder = path
94+
view.backup_notes_folder.setText(activity.humanizePath(path))
95+
}
96+
}
97+
}
98+
}
99+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.simplemobiletools.commons.views.MyTextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/date_time_pattern_info"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:paddingHorizontal="@dimen/big_margin"
7+
android:paddingTop="@dimen/big_margin"
8+
android:text="@string/date_time_pattern_info"
9+
android:textIsSelectable="true" />
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/backup_notes_scrollview"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content">
7+
8+
<LinearLayout
9+
android:id="@+id/backup_notes_holder"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:orientation="vertical"
13+
android:paddingTop="@dimen/activity_margin">
14+
15+
<com.simplemobiletools.commons.views.MyTextInputLayout
16+
android:id="@+id/backup_notes_folder_hint"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:layout_marginStart="@dimen/activity_margin"
20+
android:layout_marginEnd="@dimen/activity_margin"
21+
android:layout_marginBottom="@dimen/activity_margin"
22+
android:hint="@string/folder">
23+
24+
<com.google.android.material.textfield.TextInputEditText
25+
android:id="@+id/backup_notes_folder"
26+
style="@style/UnclickableEditText"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content" />
29+
30+
</com.simplemobiletools.commons.views.MyTextInputLayout>
31+
32+
<com.simplemobiletools.commons.views.MyTextInputLayout
33+
android:id="@+id/backup_notes_filename_hint"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:layout_marginStart="@dimen/activity_margin"
37+
android:layout_marginEnd="@dimen/activity_margin"
38+
android:hint="@string/filename_without_json"
39+
app:endIconDrawable="@drawable/ic_info_vector"
40+
app:endIconMode="custom">
41+
42+
<com.google.android.material.textfield.TextInputEditText
43+
android:id="@+id/backup_notes_filename"
44+
android:layout_width="match_parent"
45+
android:layout_height="wrap_content"
46+
android:inputType="textCapWords"
47+
android:singleLine="true"
48+
android:textCursorDrawable="@null"
49+
android:textSize="@dimen/bigger_text_size" />
50+
51+
</com.simplemobiletools.commons.views.MyTextInputLayout>
52+
53+
</LinearLayout>
54+
</ScrollView>

0 commit comments

Comments
 (0)