mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-24 20:40:09 +01:00
Added synchronization to checklist export and import
This commit is contained in:
parent
3ddc03f442
commit
e965c6ec37
@ -643,7 +643,11 @@ class MainActivity : SimpleActivity() {
|
|||||||
if (checklistItems != null) {
|
if (checklistItems != null) {
|
||||||
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
|
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
|
||||||
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
|
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
|
||||||
displayNewNoteDialog(note.value, title = title, setChecklistAsDefault = true)
|
runOnUiThread {
|
||||||
|
OpenFileDialog(this, it.path) {
|
||||||
|
displayNewNoteDialog(note.value, title = it.title, it.path, setChecklistAsDefault = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
OpenFileDialog(this, it.path) {
|
OpenFileDialog(this, it.path) {
|
||||||
@ -740,11 +744,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checklistItems != null) {
|
val noteType = if (checklistItems != null) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
|
||||||
val note = Note(null, noteTitle, content, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
|
if (!canSyncNoteWithFile) {
|
||||||
displayNewNoteDialog(note.value, title = noteTitle, setChecklistAsDefault = true)
|
val note = Note(null, noteTitle, content, noteType, "", PROTECTION_NONE, "")
|
||||||
} else if (!canSyncNoteWithFile) {
|
|
||||||
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
|
|
||||||
displayNewNoteDialog(note.value, title = noteTitle, "")
|
displayNewNoteDialog(note.value, title = noteTitle, "")
|
||||||
} else {
|
} else {
|
||||||
val items = arrayListOf(
|
val items = arrayListOf(
|
||||||
@ -755,7 +757,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
RadioGroupDialog(this, items) {
|
RadioGroupDialog(this, items) {
|
||||||
val syncFile = it as Int == IMPORT_FILE_SYNC
|
val syncFile = it as Int == IMPORT_FILE_SYNC
|
||||||
val path = if (syncFile) uri.toString() else ""
|
val path = if (syncFile) uri.toString() else ""
|
||||||
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
|
val note = Note(null, noteTitle, content, noteType, "", PROTECTION_NONE, "")
|
||||||
displayNewNoteDialog(note.value, title = noteTitle, path)
|
displayNewNoteDialog(note.value, title = noteTitle, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
|||||||
override fun getPageTitle(position: Int) = notes[position].title
|
override fun getPageTitle(position: Int) = notes[position].title
|
||||||
|
|
||||||
fun updateCurrentNoteData(position: Int, path: String, value: String) {
|
fun updateCurrentNoteData(position: Int, path: String, value: String) {
|
||||||
(fragments[position] as? TextFragment)?.apply {
|
(fragments[position])?.apply {
|
||||||
updateNotePath(path)
|
updateNotePath(path)
|
||||||
updateNoteValue(value)
|
updateNoteValue(value)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
|||||||
import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter
|
import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter
|
||||||
import com.simplemobiletools.notes.pro.dialogs.NewChecklistItemDialog
|
import com.simplemobiletools.notes.pro.dialogs.NewChecklistItemDialog
|
||||||
import com.simplemobiletools.notes.pro.extensions.config
|
import com.simplemobiletools.notes.pro.extensions.config
|
||||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
|
||||||
import com.simplemobiletools.notes.pro.extensions.updateWidgets
|
import com.simplemobiletools.notes.pro.extensions.updateWidgets
|
||||||
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
|
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
|
||||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||||
@ -22,6 +21,7 @@ import com.simplemobiletools.notes.pro.interfaces.ChecklistItemsListener
|
|||||||
import com.simplemobiletools.notes.pro.models.ChecklistItem
|
import com.simplemobiletools.notes.pro.models.ChecklistItem
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||||
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType) ?: ArrayList(1)
|
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.getNoteStoredValue(activity!!), checklistItemType) ?: ArrayList(1)
|
||||||
|
|
||||||
// checklist title can be null only because of the glitch in upgrade to 6.6.0, remove this check in the future
|
// checklist title can be null only because of the glitch in upgrade to 6.6.0, remove this check in the future
|
||||||
items = items.filter { it.title != null }.toMutableList() as ArrayList<ChecklistItem>
|
items = items.filter { it.title != null }.toMutableList() as ArrayList<ChecklistItem>
|
||||||
@ -78,7 +78,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
|||||||
private fun migrateCheckListOnFailure(note: Note) {
|
private fun migrateCheckListOnFailure(note: Note) {
|
||||||
items.clear()
|
items.clear()
|
||||||
|
|
||||||
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
|
note.getNoteStoredValue(activity!!)?.split("\n")?.map { it.trim() }?.filter { it.isNotBlank() }?.forEachIndexed { index, value ->
|
||||||
items.add(
|
items.add(
|
||||||
ChecklistItem(
|
ChecklistItem(
|
||||||
id = index,
|
id = index,
|
||||||
@ -180,6 +180,18 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun saveNote(refreshIndex: Int = -1) {
|
private fun saveNote(refreshIndex: Int = -1) {
|
||||||
|
if (note == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (note!!.path.isNotEmpty() && !note!!.path.startsWith("content://") && !File(note!!.path).exists()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context == null || activity == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
note?.let { currentNote ->
|
note?.let { currentNote ->
|
||||||
@ -190,7 +202,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentNote.value = checklistItems
|
currentNote.value = checklistItems
|
||||||
ctx.notesDB.insertOrUpdate(currentNote)
|
saveNoteValue(note!!, currentNote.value)
|
||||||
ctx.updateWidgets()
|
ctx.updateWidgets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,10 @@ import com.simplemobiletools.commons.extensions.beVisibleIf
|
|||||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||||
import com.simplemobiletools.commons.extensions.performSecurityCheck
|
import com.simplemobiletools.commons.extensions.performSecurityCheck
|
||||||
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
||||||
|
import com.simplemobiletools.notes.pro.activities.MainActivity
|
||||||
import com.simplemobiletools.notes.pro.extensions.config
|
import com.simplemobiletools.notes.pro.extensions.config
|
||||||
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
|
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
|
||||||
|
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
||||||
|
|
||||||
@ -33,6 +35,19 @@ abstract class NoteFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun saveNoteValue(note: Note, content: String?) {
|
||||||
|
if (note.path.isEmpty()) {
|
||||||
|
NotesHelper(activity!!).insertOrUpdateNote(note) {
|
||||||
|
(activity as? MainActivity)?.noteSavedSuccessfully(note.title)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (content != null) {
|
||||||
|
val displaySuccess = activity?.config?.displaySuccess ?: false
|
||||||
|
(activity as? MainActivity)?.tryExportNoteValueToFile(note.path, content, displaySuccess)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun handleUnlocking(callback: (() -> Unit)? = null) {
|
fun handleUnlocking(callback: (() -> Unit)? = null) {
|
||||||
if (callback != null && (note!!.protectionType == PROTECTION_NONE || shouldShowLockedContent)) {
|
if (callback != null && (note!!.protectionType == PROTECTION_NONE || shouldShowLockedContent)) {
|
||||||
callback()
|
callback()
|
||||||
@ -50,5 +65,13 @@ abstract class NoteFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateNoteValue(value: String) {
|
||||||
|
note?.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateNotePath(path: String) {
|
||||||
|
note?.path = path
|
||||||
|
}
|
||||||
|
|
||||||
abstract fun checkLockState()
|
abstract fun checkLockState()
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import com.simplemobiletools.notes.pro.extensions.updateWidgets
|
|||||||
import com.simplemobiletools.notes.pro.helpers.MyMovementMethod
|
import com.simplemobiletools.notes.pro.helpers.MyMovementMethod
|
||||||
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
|
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
|
||||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
|
||||||
import com.simplemobiletools.notes.pro.models.TextHistory
|
import com.simplemobiletools.notes.pro.models.TextHistory
|
||||||
import com.simplemobiletools.notes.pro.models.TextHistoryItem
|
import com.simplemobiletools.notes.pro.models.TextHistoryItem
|
||||||
import kotlinx.android.synthetic.main.fragment_text.view.*
|
import kotlinx.android.synthetic.main.fragment_text.view.*
|
||||||
@ -187,14 +186,6 @@ class TextFragment : NoteFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateNoteValue(value: String) {
|
|
||||||
note?.value = value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateNotePath(path: String) {
|
|
||||||
note?.path = path
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getNotesView() = view.text_note_view
|
fun getNotesView() = view.text_note_view
|
||||||
|
|
||||||
fun saveText(force: Boolean) {
|
fun saveText(force: Boolean) {
|
||||||
@ -214,7 +205,7 @@ class TextFragment : NoteFragment() {
|
|||||||
val oldText = note!!.getNoteStoredValue(context!!)
|
val oldText = note!!.getNoteStoredValue(context!!)
|
||||||
if (newText != null && (newText != oldText || force)) {
|
if (newText != null && (newText != oldText || force)) {
|
||||||
note!!.value = newText
|
note!!.value = newText
|
||||||
saveNoteValue(note!!)
|
saveNoteValue(note!!, newText)
|
||||||
context!!.updateWidgets()
|
context!!.updateWidgets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,20 +216,6 @@ class TextFragment : NoteFragment() {
|
|||||||
view.text_note_view.requestFocus()
|
view.text_note_view.requestFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveNoteValue(note: Note) {
|
|
||||||
if (note.path.isEmpty()) {
|
|
||||||
NotesHelper(activity!!).insertOrUpdateNote(note) {
|
|
||||||
(activity as? MainActivity)?.noteSavedSuccessfully(note.title)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val currentText = getCurrentNoteViewText()
|
|
||||||
if (currentText != null) {
|
|
||||||
val displaySuccess = activity?.config?.displaySuccess ?: false
|
|
||||||
(activity as? MainActivity)?.tryExportNoteValueToFile(note.path, currentText, displaySuccess)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCurrentNoteViewText() = view.text_note_view?.text?.toString()
|
fun getCurrentNoteViewText() = view.text_note_view?.text?.toString()
|
||||||
|
|
||||||
private fun setWordCounter(text: String) {
|
private fun setWordCounter(text: String) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user