mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
appending package name with .pro
This commit is contained in:
@ -0,0 +1,36 @@
|
||||
package com.simplemobiletools.notes.pro.dialogs
|
||||
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.extensions.beVisible
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_delete_note.view.*
|
||||
|
||||
class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callback: (deleteFile: Boolean) -> Unit) {
|
||||
var dialog: AlertDialog? = null
|
||||
|
||||
init {
|
||||
val message = String.format(activity.getString(R.string.delete_note_prompt_message), note.title)
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_delete_note, null).apply {
|
||||
if (note.path.isNotEmpty()) {
|
||||
delete_note_checkbox.text = String.format(activity.getString(R.string.delete_file_itself), note.path)
|
||||
delete_note_checkbox.beVisible()
|
||||
}
|
||||
delete_note_description.text = message
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed(view.delete_note_checkbox.isChecked) }
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun dialogConfirmed(deleteFile: Boolean) {
|
||||
callback(deleteFile && note.path.isNotEmpty())
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.simplemobiletools.notes.pro.dialogs
|
||||
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
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
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_export_file.view.*
|
||||
import java.io.File
|
||||
|
||||
class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callback: (exportPath: String) -> Unit) {
|
||||
|
||||
init {
|
||||
var realPath = File(note.path).parent ?: activity.config.lastUsedSavePath
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_export_file, null).apply {
|
||||
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, true) {
|
||||
file_path.text = activity.humanizePath(it)
|
||||
realPath = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
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.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_export_files.view.*
|
||||
|
||||
class ExportFilesDialog(val activity: SimpleActivity, val notes: ArrayList<Note>, val callback: (parent: String, extension: String) -> Unit) {
|
||||
init {
|
||||
var realPath = activity.config.lastUsedSavePath
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_export_files, null).apply {
|
||||
folder_path.text = activity.humanizePath(realPath)
|
||||
|
||||
file_extension.setText(activity.config.lastUsedExtension)
|
||||
folder_path.setOnClickListener {
|
||||
FilePickerDialog(activity, realPath, false, false, true, true) {
|
||||
folder_path.text = activity.humanizePath(it)
|
||||
realPath = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
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.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.notes.pro.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_import_folder.view.*
|
||||
import java.io.File
|
||||
|
||||
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: (id: Int) -> Unit) : AlertDialog.Builder(activity) {
|
||||
private var dialog: AlertDialog
|
||||
|
||||
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
|
||||
saveFolder(updateFilesOnEdit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveFolder(updateFilesOnEdit: Boolean) {
|
||||
val folder = File(path)
|
||||
var lastSavedNoteId = -1
|
||||
folder.listFiles { file ->
|
||||
val filename = file.path.getFilenameFromPath()
|
||||
when {
|
||||
file.isDirectory -> false
|
||||
filename.isMediaFile() -> false
|
||||
file.length() > 10 * 1000 * 1000 -> false
|
||||
activity.dbHelper.doesNoteTitleExist(filename) -> false
|
||||
else -> true
|
||||
}
|
||||
}.forEach {
|
||||
val storePath = if (updateFilesOnEdit) it.absolutePath else ""
|
||||
val title = it.absolutePath.getFilenameFromPath()
|
||||
val value = if (updateFilesOnEdit) "" else it.readText()
|
||||
|
||||
if (updateFilesOnEdit) {
|
||||
activity.handleSAFDialog(path) {
|
||||
lastSavedNoteId = saveNote(title, value, storePath)
|
||||
}
|
||||
} else {
|
||||
lastSavedNoteId = saveNote(title, value, storePath)
|
||||
}
|
||||
}
|
||||
|
||||
if (lastSavedNoteId != -1) {
|
||||
callback(lastSavedNoteId)
|
||||
}
|
||||
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
private fun saveNote(title: String, value: String, path: String): Int {
|
||||
val note = Note(0, title, value, TYPE_NOTE, path)
|
||||
return activity.dbHelper.insertNote(note)
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
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.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.helpers.DBHelper
|
||||
import kotlinx.android.synthetic.main.dialog_new_note.view.*
|
||||
|
||||
class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title: String) -> Unit) {
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null)
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.new_note) {
|
||||
showKeyboard(view.note_name)
|
||||
getButton(BUTTON_POSITIVE).setOnClickListener {
|
||||
val title = view.note_name.value
|
||||
when {
|
||||
title.isEmpty() -> activity.toast(R.string.no_title)
|
||||
db.doesNoteTitleExist(title) -> activity.toast(R.string.title_taken)
|
||||
else -> {
|
||||
callback(title)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
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.setupDialogStuff
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.helpers.TYPE_NOTE
|
||||
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
|
||||
|
||||
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()
|
||||
|
||||
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(0, filename, storeContent, TYPE_NOTE, storePath)
|
||||
callback(note)
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.simplemobiletools.notes.pro.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RadioGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.extensions.config
|
||||
import com.simplemobiletools.notes.pro.extensions.dbHelper
|
||||
import kotlinx.android.synthetic.main.dialog_open_note.view.*
|
||||
import kotlinx.android.synthetic.main.open_note_item.view.*
|
||||
|
||||
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> Unit) {
|
||||
lateinit var dialog: AlertDialog
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_open_note, null)
|
||||
val textColor = activity.config.textColor
|
||||
val notes = activity.dbHelper.getNotes()
|
||||
notes.forEach {
|
||||
activity.layoutInflater.inflate(R.layout.open_note_item, null).apply {
|
||||
val note = it
|
||||
open_note_item_radio_button.apply {
|
||||
text = note.title
|
||||
isChecked = note.id == activity.config.currentNoteId
|
||||
id = note.id
|
||||
|
||||
setOnClickListener {
|
||||
callback(id)
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
open_note_item_icon.apply {
|
||||
beVisibleIf(note.path.isNotEmpty())
|
||||
applyColorFilter(textColor)
|
||||
setOnClickListener {
|
||||
activity.toast(note.path)
|
||||
}
|
||||
}
|
||||
view.dialog_open_note_linear.addView(this, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
}
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.pick_a_note)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.simplemobiletools.notes.pro.dialogs
|
||||
|
||||
import android.content.DialogInterface.BUTTON_POSITIVE
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_new_note.view.*
|
||||
import java.io.File
|
||||
|
||||
class RenameNoteDialog(val activity: SimpleActivity, val note: Note, callback: (note: Note) -> Unit) {
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_note, null)
|
||||
view.note_name.setText(note.title)
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.rename_note) {
|
||||
showKeyboard(view.note_name)
|
||||
getButton(BUTTON_POSITIVE).setOnClickListener {
|
||||
val title = view.note_name.value
|
||||
when {
|
||||
title.isEmpty() -> activity.toast(R.string.no_title)
|
||||
activity.dbHelper.doesNoteTitleExist(title) -> activity.toast(R.string.title_taken)
|
||||
else -> {
|
||||
note.title = title
|
||||
val path = note.path
|
||||
if (path.isNotEmpty()) {
|
||||
if (title.isEmpty()) {
|
||||
activity.toast(R.string.filename_cannot_be_empty)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
val file = File(path)
|
||||
val newFile = File(file.parent, title)
|
||||
if (!newFile.name.isAValidFilename()) {
|
||||
activity.toast(R.string.invalid_name)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
activity.renameFile(file.absolutePath, newFile.absolutePath) {
|
||||
if (it) {
|
||||
note.path = newFile.absolutePath
|
||||
activity.dbHelper.updateNotePath(note)
|
||||
} else {
|
||||
activity.toast(R.string.rename_file_error)
|
||||
return@renameFile
|
||||
}
|
||||
}
|
||||
}
|
||||
activity.dbHelper.updateNoteTitle(note)
|
||||
dismiss()
|
||||
callback(note)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user