mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
moving another function in Room
This commit is contained in:
@ -8,7 +8,7 @@ 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.extensions.notesDB
|
||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||
import com.simplemobiletools.notes.pro.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
@ -30,7 +30,9 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
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)
|
||||
Thread {
|
||||
saveFolder(updateFilesOnEdit)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,7 +46,7 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
file.isDirectory -> false
|
||||
filename.isMediaFile() -> false
|
||||
file.length() > 10 * 1000 * 1000 -> false
|
||||
activity.dbHelper.doesNoteTitleExist(filename) -> false
|
||||
activity.notesDB.getNoteIdWithTitle(filename) != null -> false
|
||||
else -> true
|
||||
}
|
||||
}.forEach {
|
||||
@ -61,8 +63,10 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
}
|
||||
}
|
||||
|
||||
callback()
|
||||
dialog.dismiss()
|
||||
activity.runOnUiThread {
|
||||
callback()
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveNote(title: String, value: String, path: String) {
|
||||
|
@ -8,10 +8,10 @@ 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 com.simplemobiletools.notes.pro.extensions.notesDB
|
||||
import kotlinx.android.synthetic.main.dialog_new_note.view.*
|
||||
|
||||
class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title: String) -> Unit) {
|
||||
class NewNoteDialog(val activity: Activity, callback: (title: String) -> Unit) {
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null)
|
||||
|
||||
@ -23,14 +23,16 @@ class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title:
|
||||
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()
|
||||
Thread {
|
||||
when {
|
||||
title.isEmpty() -> activity.toast(R.string.no_title)
|
||||
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
|
||||
else -> {
|
||||
callback(title)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,12 @@ 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.helpers.NotesHelper
|
||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
||||
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) {
|
||||
class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val callback: (note: Note) -> Unit) {
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_note, null)
|
||||
@ -25,47 +24,55 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, callback: (
|
||||
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.isEmpty()) {
|
||||
NotesHelper(activity).insertOrUpdateNote(note) {
|
||||
dismiss()
|
||||
callback(note)
|
||||
}
|
||||
} else {
|
||||
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
|
||||
NotesHelper(activity).insertOrUpdateNote(note) {
|
||||
dismiss()
|
||||
callback(note)
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.rename_file_error)
|
||||
return@renameFile
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread {
|
||||
newTitleConfirmed(title, this)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun newTitleConfirmed(title: String, dialog: AlertDialog) {
|
||||
when {
|
||||
title.isEmpty() -> activity.toast(R.string.no_title)
|
||||
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
|
||||
else -> {
|
||||
note.title = title
|
||||
val path = note.path
|
||||
if (path.isEmpty()) {
|
||||
activity.notesDB.insertOrUpdate(note)
|
||||
activity.runOnUiThread {
|
||||
dialog.dismiss()
|
||||
callback(note)
|
||||
}
|
||||
} else {
|
||||
if (title.isEmpty()) {
|
||||
activity.toast(R.string.filename_cannot_be_empty)
|
||||
return
|
||||
}
|
||||
|
||||
val file = File(path)
|
||||
val newFile = File(file.parent, title)
|
||||
if (!newFile.name.isAValidFilename()) {
|
||||
activity.toast(R.string.invalid_name)
|
||||
return
|
||||
}
|
||||
|
||||
activity.renameFile(file.absolutePath, newFile.absolutePath) {
|
||||
if (it) {
|
||||
note.path = newFile.absolutePath
|
||||
activity.notesDB.insertOrUpdate(note)
|
||||
activity.runOnUiThread {
|
||||
dialog.dismiss()
|
||||
callback(note)
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.rename_file_error)
|
||||
return@renameFile
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user