updating commons with some material elements

This commit is contained in:
tibbi
2022-07-11 23:28:40 +02:00
parent 09e7ee0987
commit 797ac60d56
21 changed files with 742 additions and 656 deletions

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
@ -24,10 +25,10 @@ class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callbac
delete_note_description.text = message
}
AlertDialog.Builder(activity)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed(view.delete_note_checkbox.isChecked) }
.setNegativeButton(R.string.cancel, null)
.create().apply {
.apply {
activity.setupDialogStuff(view, this)
}
}

View File

@ -27,33 +27,33 @@ class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callbac
}
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.export_as_file) {
showKeyboard(view.file_name)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.file_name.value
val extension = view.file_extension.value
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog ->
alertDialog.showKeyboard(view.file_name)
alertDialog.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 fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
if (!fullFilename.isAValidFilename()) {
activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename)))
return@setOnClickListener
}
activity.config.lastUsedExtension = extension
activity.config.lastUsedSavePath = realPath
callback("$realPath/$fullFilename")
dismiss()
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
}
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
if (!fullFilename.isAValidFilename()) {
activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename)))
return@setOnClickListener
}
activity.config.lastUsedExtension = extension
activity.config.lastUsedSavePath = realPath
callback("$realPath/$fullFilename")
alertDialog.dismiss()
}
}
}
}
}

View File

@ -2,10 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.extensions.config
@ -27,22 +24,22 @@ class ExportFilesDialog(val activity: SimpleActivity, val notes: ArrayList<Note>
}
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.export_as_file) {
showKeyboard(view.file_extension)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
activity.handleSAFDialog(realPath) {
val extension = view.file_extension.value
activity.config.lastUsedExtension = extension
activity.config.lastUsedSavePath = realPath
callback(realPath, extension)
dismiss()
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog ->
alertDialog.showKeyboard(view.file_extension)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
activity.handleSAFDialog(realPath) {
val extension = view.file_extension.value
activity.config.lastUsedExtension = extension
activity.config.lastUsedSavePath = realPath
callback(realPath, extension)
alertDialog.dismiss()
}
}
}
}
}
}

View File

@ -2,10 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.getFilenameFromPath
import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.isMediaFile
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R
@ -19,26 +16,27 @@ import kotlinx.android.synthetic.main.dialog_import_folder.view.*
import java.io.File
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
private var dialog: AlertDialog
private var dialog: AlertDialog? = null
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_folder, null) as ViewGroup).apply {
open_file_filename.text = activity.humanizePath(path)
}
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.import_folder) {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val updateFilesOnEdit = view.open_file_type.checkedRadioButtonId == R.id.open_file_update_file
ensureBackgroundThread {
saveFolder(updateFilesOnEdit)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.import_folder) { alertDialog ->
dialog = alertDialog
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val updateFilesOnEdit = view.open_file_type.checkedRadioButtonId == R.id.open_file_update_file
ensureBackgroundThread {
saveFolder(updateFilesOnEdit)
}
}
}
}
}
private fun saveFolder(updateFilesOnEdit: Boolean) {
@ -73,7 +71,7 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
activity.runOnUiThread {
callback()
dialog.dismiss()
dialog?.dismiss()
}
}

View File

@ -6,15 +6,14 @@ import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatEditText
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
import kotlinx.android.synthetic.main.item_add_checklist.view.*
class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayList<String>) -> Unit) {
private val titles = mutableListOf<EditText>()
private val titles = mutableListOf<AppCompatEditText>()
private val textColor = activity.getProperTextColor()
private val view: ViewGroup = activity.layoutInflater.inflate(R.layout.dialog_new_checklist_item, null) as ViewGroup
@ -28,19 +27,19 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
}
}
AlertDialog.Builder(activity)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) {
showKeyboard(titles.first())
getButton(BUTTON_POSITIVE).setOnClickListener {
.apply {
activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) { alertDialog ->
alertDialog.showKeyboard(titles.first())
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
when {
titles.all { it.text.isEmpty() } -> activity.toast(R.string.empty_name)
titles.all { it.text!!.isEmpty() } -> activity.toast(R.string.empty_name)
else -> {
val titles = titles.map { it.text.toString() }.filter { it.isNotEmpty() }.toMutableList() as ArrayList<String>
callback(titles)
dismiss()
alertDialog.dismiss()
}
}
}

View File

@ -2,11 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
import android.app.Activity
import android.content.DialogInterface.BUTTON_POSITIVE
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R
@ -30,24 +26,29 @@ class NewNoteDialog(val activity: Activity, title: String? = null, val setCheckl
view.note_title.setText(title)
AlertDialog.Builder(activity)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.new_note) {
showKeyboard(view.note_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_title.value
.apply {
activity.setupDialogStuff(view, this, R.string.new_note) { alertDialog ->
alertDialog.showKeyboard(view.note_title)
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.note_title.value
ensureBackgroundThread {
when {
title.isEmpty() -> activity.toast(R.string.no_title)
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
newTitle.isEmpty() -> activity.toast(R.string.no_title)
activity.notesDB.getNoteIdWithTitle(newTitle) != null -> activity.toast(R.string.title_taken)
else -> {
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) {
NoteType.TYPE_CHECKLIST.value
} else {
NoteType.TYPE_TEXT.value
}
activity.config.lastCreatedNoteType = type
val newNote = Note(null, title, "", type, "", PROTECTION_NONE, "")
val newNote = Note(null, newTitle, "", type, "", PROTECTION_NONE, "")
callback(newNote)
dismiss()
alertDialog.dismiss()
}
}
}

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.getFilenameFromPath
import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.setupDialogStuff
@ -10,44 +11,44 @@ import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_open_file.*
import kotlinx.android.synthetic.main.dialog_open_file.view.*
import java.io.File
class OpenFileDialog(val activity: SimpleActivity, val path: String, val callback: (note: Note) -> Unit) : AlertDialog.Builder(activity) {
private var dialog: AlertDialog
private var dialog: AlertDialog? = null
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_open_file, null) as ViewGroup).apply {
open_file_filename.text = activity.humanizePath(path)
}
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.open_file) {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == open_file_update_file.id
val storePath = if (updateFileOnEdit) path else ""
val storeContent = if (updateFileOnEdit) "" else File(path).readText()
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.open_file) { alertDialog ->
dialog = alertDialog
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == view.open_file_update_file.id
val storePath = if (updateFileOnEdit) path else ""
val storeContent = if (updateFileOnEdit) "" else File(path).readText()
if (updateFileOnEdit) {
activity.handleSAFDialog(path) {
saveNote(storeContent, storePath)
}
} else {
if (updateFileOnEdit) {
activity.handleSAFDialog(path) {
saveNote(storeContent, storePath)
}
} else {
saveNote(storeContent, storePath)
}
}
}
}
}
private fun saveNote(storeContent: String, storePath: String) {
val filename = path.getFilenameFromPath()
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath, PROTECTION_NONE, "")
callback(note)
dialog.dismiss()
dialog?.dismiss()
}
}

View File

@ -57,9 +57,10 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long, new
}
}
dialog = AlertDialog.Builder(activity)
.create().apply {
activity.setupDialogStuff(view, this, R.string.open_note)
activity.getAlertDialogBuilder().apply {
activity.setupDialogStuff(view, this, R.string.open_note) { alertDialog ->
dialog = alertDialog
}
}
}
}

View File

@ -2,11 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
import android.app.Activity
import android.content.DialogInterface.BUTTON_POSITIVE
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import kotlinx.android.synthetic.main.dialog_rename_checklist_item.view.*
@ -16,23 +12,23 @@ class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, ca
checklist_item_title.setText(oldTitle)
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this) {
showKeyboard(view.checklist_item_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.checklist_item_title.value
when {
newTitle.isEmpty() -> activity.toast(R.string.empty_name)
else -> {
callback(newTitle)
dismiss()
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
alertDialog.showKeyboard(view.checklist_item_title)
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.checklist_item_title.value
when {
newTitle.isEmpty() -> activity.toast(R.string.empty_name)
else -> {
callback(newTitle)
alertDialog.dismiss()
}
}
}
}
}
}
}

View File

@ -20,16 +20,16 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val current
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_note, null)
view.note_title.setText(note.title)
AlertDialog.Builder(activity)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.rename_note) {
showKeyboard(view.note_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
.apply {
activity.setupDialogStuff(view, this, R.string.rename_note) { alertDialog ->
alertDialog.showKeyboard(view.note_title)
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_title.value
ensureBackgroundThread {
newTitleConfirmed(title, this)
newTitleConfirmed(title, alertDialog)
}
}
}

View File

@ -1,7 +1,7 @@
package com.simplemobiletools.notes.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.beGoneIf
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_CREATED
@ -21,10 +21,11 @@ class SortChecklistDialog(private val activity: SimpleActivity, private val call
setupSortRadio()
setupOrderRadio()
setupMoveUndoneChecklistItems()
AlertDialog.Builder(activity)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.create().apply {
.apply {
activity.setupDialogStuff(view, this, R.string.sort_by)
}
}