mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-21 19:10:06 +01:00
commit
4eeaa6fbf3
@ -99,8 +99,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu, menu)
|
menuInflater.inflate(R.menu.menu, menu)
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.undo).isVisible = showUndoButton && mCurrentNote.type == TYPE_TEXT
|
findItem(R.id.undo).isVisible = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
|
||||||
findItem(R.id.redo).isVisible = showRedoButton && mCurrentNote.type == TYPE_TEXT
|
findItem(R.id.redo).isVisible = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMenuItemColors(menu)
|
updateMenuItemColors(menu)
|
||||||
@ -116,7 +116,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
findItem(R.id.export_all_notes).isVisible = shouldBeVisible
|
findItem(R.id.export_all_notes).isVisible = shouldBeVisible
|
||||||
|
|
||||||
saveNoteButton = findItem(R.id.save_note)
|
saveNoteButton = findItem(R.id.save_note)
|
||||||
saveNoteButton!!.isVisible = !config.autosaveNotes && showSaveButton && mCurrentNote.type == TYPE_TEXT
|
saveNoteButton!!.isVisible = !config.autosaveNotes && showSaveButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
|
||||||
}
|
}
|
||||||
|
|
||||||
pager_title_strip.beVisibleIf(shouldBeVisible)
|
pager_title_strip.beVisibleIf(shouldBeVisible)
|
||||||
@ -274,7 +274,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.showKeyboard || mCurrentNote.type == TYPE_CHECKLIST) {
|
if (!config.showKeyboard || mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,7 +361,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
val fileText = it.readText().trim()
|
val fileText = it.readText().trim()
|
||||||
val checklistItems = fileText.parseChecklistItems()
|
val checklistItems = fileText.parseChecklistItems()
|
||||||
if (checklistItems != null) {
|
if (checklistItems != null) {
|
||||||
val note = Note(null, it.absolutePath.getFilenameFromPath().substringBeforeLast('.'), fileText, TYPE_CHECKLIST)
|
val note = Note(null, it.absolutePath.getFilenameFromPath().substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value)
|
||||||
addNewNote(note)
|
addNewNote(note)
|
||||||
} else {
|
} else {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
@ -416,9 +416,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
val fileText = it.readText().trim()
|
val fileText = it.readText().trim()
|
||||||
val checklistItems = fileText.parseChecklistItems()
|
val checklistItems = fileText.parseChecklistItems()
|
||||||
val note = if (checklistItems != null) {
|
val note = if (checklistItems != null) {
|
||||||
Note(null, title.substringBeforeLast('.'), fileText, TYPE_CHECKLIST)
|
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value)
|
||||||
} else {
|
} else {
|
||||||
Note(null, title, "", TYPE_TEXT, path)
|
Note(null, title, "", NoteType.TYPE_TEXT.value, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mNotes.any { it.title.equals(note.title, true) }) {
|
if (mNotes.any { it.title.equals(note.title, true) }) {
|
||||||
@ -464,10 +464,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun exportAsFile() {
|
private fun exportAsFile() {
|
||||||
ExportFileDialog(this, mCurrentNote) {
|
ExportFileDialog(this, mCurrentNote) {
|
||||||
val textToExport = if (mCurrentNote.type == TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
|
val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT.value) getCurrentNoteText() else mCurrentNote.value
|
||||||
if (textToExport == null || textToExport.isEmpty()) {
|
if (textToExport == null || textToExport.isEmpty()) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
} else if (mCurrentNote.type == TYPE_TEXT) {
|
} else if (mCurrentNote.type == NoteType.TYPE_TEXT.value) {
|
||||||
showExportFilePickUpdateDialog(it, textToExport)
|
showExportFilePickUpdateDialog(it, textToExport)
|
||||||
} else {
|
} else {
|
||||||
tryExportNoteValueToFile(it, textToExport, true)
|
tryExportNoteValueToFile(it, textToExport, true)
|
||||||
@ -626,7 +626,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun saveCurrentNote(force: Boolean) {
|
private fun saveCurrentNote(force: Boolean) {
|
||||||
getPagerAdapter().saveCurrentNote(view_pager.currentItem, force)
|
getPagerAdapter().saveCurrentNote(view_pager.currentItem, force)
|
||||||
if (mCurrentNote.type == TYPE_CHECKLIST) {
|
if (mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) {
|
||||||
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
|
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -712,7 +712,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun shareText() {
|
private fun shareText() {
|
||||||
val text = if (mCurrentNote.type == TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
|
val text = if (mCurrentNote.type == NoteType.TYPE_TEXT.value) getCurrentNoteText() else mCurrentNote.value
|
||||||
if (text == null || text.isEmpty()) {
|
if (text == null || text.isEmpty()) {
|
||||||
toast(R.string.cannot_share_empty_text)
|
toast(R.string.cannot_share_empty_text)
|
||||||
return
|
return
|
||||||
|
@ -122,7 +122,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
|||||||
private fun updateCurrentNote(note: Note) {
|
private fun updateCurrentNote(note: Note) {
|
||||||
mCurrentNoteId = note.id!!
|
mCurrentNoteId = note.id!!
|
||||||
notes_picker_value.text = note.title
|
notes_picker_value.text = note.title
|
||||||
if (note.type == TYPE_CHECKLIST) {
|
if (note.type == NoteType.TYPE_CHECKLIST.value) {
|
||||||
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||||
val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1)
|
val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1)
|
||||||
items.apply {
|
items.apply {
|
||||||
|
@ -10,7 +10,7 @@ import com.simplemobiletools.notes.pro.fragments.ChecklistFragment
|
|||||||
import com.simplemobiletools.notes.pro.fragments.NoteFragment
|
import com.simplemobiletools.notes.pro.fragments.NoteFragment
|
||||||
import com.simplemobiletools.notes.pro.fragments.TextFragment
|
import com.simplemobiletools.notes.pro.fragments.TextFragment
|
||||||
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
|
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
|
||||||
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
|
import com.simplemobiletools.notes.pro.helpers.NoteType
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
|
|
||||||
class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity: Activity) : FragmentStatePagerAdapter(fm) {
|
class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity: Activity) : FragmentStatePagerAdapter(fm) {
|
||||||
@ -30,7 +30,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
|||||||
return fragments[position]!!
|
return fragments[position]!!
|
||||||
}
|
}
|
||||||
|
|
||||||
val fragment = if (note.type == TYPE_TEXT) TextFragment() else ChecklistFragment()
|
val fragment = if (note.type == NoteType.TYPE_TEXT.value) TextFragment() else ChecklistFragment()
|
||||||
fragment.arguments = bundle
|
fragment.arguments = bundle
|
||||||
fragments[position] = fragment
|
fragments[position] = fragment
|
||||||
return fragment
|
return fragment
|
||||||
@ -59,7 +59,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
|||||||
|
|
||||||
fun saveAllFragmentTexts() = fragments.values.forEach { (it as? TextFragment)?.saveText(false) }
|
fun saveAllFragmentTexts() = fragments.values.forEach { (it as? TextFragment)?.saveText(false) }
|
||||||
|
|
||||||
fun getNoteChecklistItems(position: Int) = (fragments[position] as? ChecklistFragment)?.getChecklistItems()
|
fun getNoteChecklistItems(position: Int) = (fragments[position] as? ChecklistFragment)?.checklistItems
|
||||||
|
|
||||||
fun undo(position: Int) = (fragments[position] as? TextFragment)?.undo()
|
fun undo(position: Int) = (fragments[position] as? TextFragment)?.undo()
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
|
|||||||
}
|
}
|
||||||
|
|
||||||
val textSize = context.getTextSize() / context.resources.displayMetrics.density
|
val textSize = context.getTextSize() / context.resources.displayMetrics.density
|
||||||
if (note!!.type == TYPE_CHECKLIST) {
|
if (note!!.type == NoteType.TYPE_CHECKLIST.value) {
|
||||||
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
|
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
|
||||||
val checklistItem = checklistItems.getOrNull(position) ?: return@apply
|
val checklistItem = checklistItems.getOrNull(position) ?: return@apply
|
||||||
setText(checklist_title, checklistItem.title)
|
setText(checklist_title, checklistItem.title)
|
||||||
@ -91,7 +91,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
|
|||||||
widgetTextColor = intent.getIntExtra(WIDGET_TEXT_COLOR, DEFAULT_WIDGET_TEXT_COLOR)
|
widgetTextColor = intent.getIntExtra(WIDGET_TEXT_COLOR, DEFAULT_WIDGET_TEXT_COLOR)
|
||||||
val noteId = intent.getLongExtra(NOTE_ID, 0L)
|
val noteId = intent.getLongExtra(NOTE_ID, 0L)
|
||||||
note = context.notesDB.getNoteWithId(noteId)
|
note = context.notesDB.getNoteWithId(noteId)
|
||||||
if (note?.type == TYPE_CHECKLIST) {
|
if (note?.type == NoteType.TYPE_CHECKLIST.value) {
|
||||||
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||||
checklistItems = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.value, checklistItemType) ?: ArrayList(1)
|
checklistItems = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.value, checklistItemType) ?: ArrayList(1)
|
||||||
if (context.config.moveUndoneChecklistItems) {
|
if (context.config.moveUndoneChecklistItems) {
|
||||||
@ -103,7 +103,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
|
|||||||
override fun hasStableIds() = true
|
override fun hasStableIds() = true
|
||||||
|
|
||||||
override fun getCount(): Int {
|
override fun getCount(): Int {
|
||||||
return if (note?.type == TYPE_CHECKLIST) {
|
return if (note?.type == NoteType.TYPE_CHECKLIST.value) {
|
||||||
checklistItems.size
|
checklistItems.size
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
|
@ -9,7 +9,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
import com.simplemobiletools.commons.helpers.DEFAULT_WIDGET_BG_COLOR
|
import com.simplemobiletools.commons.helpers.DEFAULT_WIDGET_BG_COLOR
|
||||||
import com.simplemobiletools.notes.pro.R
|
import com.simplemobiletools.notes.pro.R
|
||||||
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
|
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
|
||||||
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
|
import com.simplemobiletools.notes.pro.helpers.NoteType
|
||||||
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
||||||
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
|
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
@ -53,7 +53,7 @@ abstract class NotesDatabase : RoomDatabase() {
|
|||||||
private fun insertFirstNote(context: Context) {
|
private fun insertFirstNote(context: Context) {
|
||||||
Executors.newSingleThreadScheduledExecutor().execute {
|
Executors.newSingleThreadScheduledExecutor().execute {
|
||||||
val generalNote = context.resources.getString(R.string.general_note)
|
val generalNote = context.resources.getString(R.string.general_note)
|
||||||
val note = Note(null, generalNote, "", TYPE_TEXT)
|
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value)
|
||||||
db!!.NotesDao().insertOrUpdate(note)
|
db!!.NotesDao().insertOrUpdate(note)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,8 @@ import com.simplemobiletools.notes.pro.R
|
|||||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
import com.simplemobiletools.notes.pro.extensions.notesDB
|
||||||
import com.simplemobiletools.notes.pro.extensions.parseChecklistItems
|
import com.simplemobiletools.notes.pro.extensions.parseChecklistItems
|
||||||
|
import com.simplemobiletools.notes.pro.helpers.NoteType
|
||||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||||
import com.simplemobiletools.notes.pro.helpers.TYPE_CHECKLIST
|
|
||||||
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
|
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
import kotlinx.android.synthetic.main.dialog_import_folder.view.*
|
import kotlinx.android.synthetic.main.dialog_import_folder.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -59,14 +58,14 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
|
|||||||
val fileText = it.readText().trim()
|
val fileText = it.readText().trim()
|
||||||
val checklistItems = fileText.parseChecklistItems()
|
val checklistItems = fileText.parseChecklistItems()
|
||||||
if (checklistItems != null) {
|
if (checklistItems != null) {
|
||||||
saveNote(title.substringBeforeLast('.'), fileText, TYPE_CHECKLIST, "")
|
saveNote(title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value, "")
|
||||||
} else {
|
} else {
|
||||||
if (updateFilesOnEdit) {
|
if (updateFilesOnEdit) {
|
||||||
activity.handleSAFDialog(path) {
|
activity.handleSAFDialog(path) {
|
||||||
saveNote(title, value, TYPE_TEXT, storePath)
|
saveNote(title, value, NoteType.TYPE_TEXT.value, storePath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveNote(title, value, TYPE_TEXT, storePath)
|
saveNote(title, value, NoteType.TYPE_TEXT.value, storePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,14 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|||||||
import com.simplemobiletools.notes.pro.R
|
import com.simplemobiletools.notes.pro.R
|
||||||
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.notesDB
|
||||||
import com.simplemobiletools.notes.pro.helpers.TYPE_CHECKLIST
|
import com.simplemobiletools.notes.pro.helpers.NoteType
|
||||||
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
|
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
import kotlinx.android.synthetic.main.dialog_new_note.view.*
|
import kotlinx.android.synthetic.main.dialog_new_note.view.*
|
||||||
|
|
||||||
class NewNoteDialog(val activity: Activity, callback: (note: Note) -> Unit) {
|
class NewNoteDialog(val activity: Activity, callback: (note: Note) -> Unit) {
|
||||||
init {
|
init {
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null).apply {
|
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null).apply {
|
||||||
new_note_type.check(if (activity.config.lastCreatedNoteType == TYPE_TEXT) type_text_note.id else type_checklist.id)
|
new_note_type.check(if (activity.config.lastCreatedNoteType == NoteType.TYPE_TEXT.value) type_text_note.id else type_checklist.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
@ -35,7 +34,7 @@ class NewNoteDialog(val activity: Activity, callback: (note: Note) -> Unit) {
|
|||||||
title.isEmpty() -> activity.toast(R.string.no_title)
|
title.isEmpty() -> activity.toast(R.string.no_title)
|
||||||
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
|
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
|
||||||
else -> {
|
else -> {
|
||||||
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) TYPE_CHECKLIST else TYPE_TEXT
|
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
|
activity.config.lastCreatedNoteType = type
|
||||||
val newNote = Note(null, title, "", type)
|
val newNote = Note(null, title, "", type)
|
||||||
callback(newNote)
|
callback(newNote)
|
||||||
|
@ -7,7 +7,7 @@ import com.simplemobiletools.commons.extensions.humanizePath
|
|||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.notes.pro.R
|
import com.simplemobiletools.notes.pro.R
|
||||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
|
import com.simplemobiletools.notes.pro.helpers.NoteType
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
import kotlinx.android.synthetic.main.dialog_open_file.*
|
import kotlinx.android.synthetic.main.dialog_open_file.*
|
||||||
import kotlinx.android.synthetic.main.dialog_open_file.view.*
|
import kotlinx.android.synthetic.main.dialog_open_file.view.*
|
||||||
@ -45,7 +45,7 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
|
|||||||
|
|
||||||
private fun saveNote(storeContent: String, storePath: String) {
|
private fun saveNote(storeContent: String, storePath: String) {
|
||||||
val filename = path.getFilenameFromPath()
|
val filename = path.getFilenameFromPath()
|
||||||
val note = Note(null, filename, storeContent, TYPE_TEXT, storePath)
|
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath)
|
||||||
callback(note)
|
callback(note)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.simplemobiletools.notes.pro.extensions
|
package com.simplemobiletools.notes.pro.extensions
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.FragmentActivity
|
||||||
import com.simplemobiletools.notes.pro.helpers.Config
|
import com.simplemobiletools.notes.pro.helpers.Config
|
||||||
|
|
||||||
val Fragment.config: Config? get() = if (context != null) Config.newInstance(context!!) else null
|
val Fragment.config: Config? get() = if (context != null) Config.newInstance(context!!) else null
|
||||||
|
|
||||||
|
val Fragment.requiredActivity: FragmentActivity get() = this.activity!!
|
||||||
|
@ -13,9 +13,7 @@ import com.simplemobiletools.notes.pro.R
|
|||||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
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.*
|
||||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
|
||||||
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
|
||||||
import com.simplemobiletools.notes.pro.interfaces.ChecklistItemsListener
|
import com.simplemobiletools.notes.pro.interfaces.ChecklistItemsListener
|
||||||
@ -24,12 +22,15 @@ import com.simplemobiletools.notes.pro.models.Note
|
|||||||
import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
||||||
|
|
||||||
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
||||||
|
|
||||||
private var noteId = 0L
|
private var noteId = 0L
|
||||||
private var note: Note? = null
|
|
||||||
private var items = ArrayList<ChecklistItem>()
|
private var items = ArrayList<ChecklistItem>()
|
||||||
|
private var note: Note? = null
|
||||||
|
|
||||||
lateinit var view: ViewGroup
|
lateinit var view: ViewGroup
|
||||||
|
|
||||||
|
val checklistItems get(): String = Gson().toJson(items)
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
|
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
|
||||||
noteId = arguments!!.getLong(NOTE_ID, 0L)
|
noteId = arguments!!.getLong(NOTE_ID, 0L)
|
||||||
@ -39,78 +40,113 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
NotesHelper(activity!!).getNoteWithId(noteId) {
|
loadNoteById(noteId)
|
||||||
if (it != null && activity?.isDestroyed == false) {
|
|
||||||
note = it
|
|
||||||
|
|
||||||
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
|
||||||
items = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.value, checklistItemType) ?: ArrayList(1)
|
|
||||||
if (config!!.moveUndoneChecklistItems) {
|
|
||||||
items.sortBy { it.isDone }
|
|
||||||
}
|
|
||||||
|
|
||||||
context!!.updateTextColors(view.checklist_holder)
|
|
||||||
setupFragment()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setMenuVisibility(menuVisible: Boolean) {
|
override fun setMenuVisibility(menuVisible: Boolean) {
|
||||||
super.setMenuVisibility(menuVisible)
|
super.setMenuVisibility(menuVisible)
|
||||||
|
|
||||||
if (menuVisible) {
|
if (menuVisible) {
|
||||||
activity?.hideKeyboard()
|
activity?.hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadNoteById(noteId: Long) {
|
||||||
|
NotesHelper(requiredActivity).getNoteWithId(noteId) { storedNote ->
|
||||||
|
if (storedNote != null && activity?.isDestroyed == false) {
|
||||||
|
note = storedNote
|
||||||
|
|
||||||
|
try {
|
||||||
|
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||||
|
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType)
|
||||||
|
?: ArrayList(1)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
migrateCheckListOnFailure(storedNote)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config?.moveUndoneChecklistItems == true) {
|
||||||
|
items.sortBy { it.isDone }
|
||||||
|
}
|
||||||
|
|
||||||
|
requiredActivity.updateTextColors(view.checklist_holder)
|
||||||
|
setupFragment()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun migrateCheckListOnFailure(note: Note) {
|
||||||
|
items.clear()
|
||||||
|
|
||||||
|
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
|
||||||
|
items.add(ChecklistItem(
|
||||||
|
id = index,
|
||||||
|
title = value,
|
||||||
|
isDone = false
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
saveChecklist()
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupFragment() {
|
private fun setupFragment() {
|
||||||
val plusIcon = resources.getColoredDrawableWithColor(R.drawable.ic_plus_vector, if (context!!.isBlackAndWhiteTheme()) Color.BLACK else Color.WHITE)
|
val plusIcon = resources.getColoredDrawableWithColor(R.drawable.ic_plus_vector, if (requiredActivity.isBlackAndWhiteTheme()) Color.BLACK else Color.WHITE)
|
||||||
|
|
||||||
view.apply {
|
view.apply {
|
||||||
checklist_fab.apply {
|
with(checklist_fab) {
|
||||||
setImageDrawable(plusIcon)
|
setImageDrawable(plusIcon)
|
||||||
background.applyColorFilter(context!!.getAdjustedPrimaryColor())
|
background.applyColorFilter(requiredActivity.getAdjustedPrimaryColor())
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
showNewItemDialog()
|
showNewItemDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment_placeholder_2.apply {
|
with(fragment_placeholder_2) {
|
||||||
setTextColor(context!!.getAdjustedPrimaryColor())
|
setTextColor(requiredActivity.getAdjustedPrimaryColor())
|
||||||
underlineText()
|
underlineText()
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
showNewItemDialog()
|
showNewItemDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showNewItemDialog() {
|
private fun showNewItemDialog() {
|
||||||
NewChecklistItemDialog(activity as SimpleActivity) {
|
NewChecklistItemDialog(activity as SimpleActivity) { titles ->
|
||||||
var currentMaxId = items.maxBy { it.id }?.id ?: 0
|
var currentMaxId = items.maxBy { item -> item.id }?.id ?: 0
|
||||||
it.forEach {
|
|
||||||
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
|
titles.forEach { title ->
|
||||||
items.add(checklistItem)
|
title.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEach { row ->
|
||||||
currentMaxId++
|
items.add(ChecklistItem(currentMaxId + 1, row, false))
|
||||||
|
currentMaxId++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveNote()
|
saveNote()
|
||||||
if (items.size == it.size) {
|
setupAdapter()
|
||||||
setupAdapter()
|
|
||||||
} else {
|
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
|
||||||
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAdapter() {
|
private fun setupAdapter() {
|
||||||
view.apply {
|
with(view) {
|
||||||
fragment_placeholder.beVisibleIf(items.isEmpty())
|
fragment_placeholder.beVisibleIf(items.isEmpty())
|
||||||
fragment_placeholder_2.beVisibleIf(items.isEmpty())
|
fragment_placeholder_2.beVisibleIf(items.isEmpty())
|
||||||
checklist_list.beVisibleIf(items.isNotEmpty())
|
checklist_list.beVisibleIf(items.isNotEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
ChecklistAdapter(activity as SimpleActivity, items, this, view.checklist_list, true) {
|
ChecklistAdapter(
|
||||||
val clickedNote = it as ChecklistItem
|
activity = activity as SimpleActivity,
|
||||||
|
items = items,
|
||||||
|
listener = this,
|
||||||
|
recyclerView = view.checklist_list,
|
||||||
|
showIcons = true
|
||||||
|
) { item ->
|
||||||
|
val clickedNote = item as ChecklistItem
|
||||||
clickedNote.isDone = !clickedNote.isDone
|
clickedNote.isDone = !clickedNote.isDone
|
||||||
|
|
||||||
saveNote(items.indexOfFirst { it.id == clickedNote.id })
|
saveNote(items.indexOfFirst { it.id == clickedNote.id })
|
||||||
context?.updateWidgets()
|
context?.updateWidgets()
|
||||||
}.apply {
|
}.apply {
|
||||||
@ -120,22 +156,22 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
|||||||
|
|
||||||
private fun saveNote(refreshIndex: Int = -1) {
|
private fun saveNote(refreshIndex: Int = -1) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
if (note != null && context != null) {
|
context?.let { ctx ->
|
||||||
if (refreshIndex != -1) {
|
note?.let { currentNote ->
|
||||||
view.checklist_list.post {
|
if (refreshIndex != -1) {
|
||||||
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
|
view.checklist_list.post {
|
||||||
|
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
note!!.value = getChecklistItems()
|
currentNote.value = checklistItems
|
||||||
context?.notesDB?.insertOrUpdate(note!!)
|
ctx.notesDB.insertOrUpdate(currentNote)
|
||||||
context?.updateWidgets()
|
ctx.updateWidgets()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getChecklistItems() = Gson().toJson(items)
|
|
||||||
|
|
||||||
override fun saveChecklist() {
|
override fun saveChecklist() {
|
||||||
saveNote()
|
saveNote()
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
set(useIncognitoMode) = prefs.edit().putBoolean(USE_INCOGNITO_MODE, useIncognitoMode).apply()
|
set(useIncognitoMode) = prefs.edit().putBoolean(USE_INCOGNITO_MODE, useIncognitoMode).apply()
|
||||||
|
|
||||||
var lastCreatedNoteType: Int
|
var lastCreatedNoteType: Int
|
||||||
get() = prefs.getInt(LAST_CREATED_NOTE_TYPE, TYPE_TEXT)
|
get() = prefs.getInt(LAST_CREATED_NOTE_TYPE, NoteType.TYPE_TEXT.value)
|
||||||
set(lastCreatedNoteType) = prefs.edit().putInt(LAST_CREATED_NOTE_TYPE, lastCreatedNoteType).apply()
|
set(lastCreatedNoteType) = prefs.edit().putInt(LAST_CREATED_NOTE_TYPE, lastCreatedNoteType).apply()
|
||||||
|
|
||||||
var moveUndoneChecklistItems: Boolean
|
var moveUndoneChecklistItems: Boolean
|
||||||
|
@ -37,8 +37,7 @@ const val GRAVITY_CENTER = 1
|
|||||||
const val GRAVITY_RIGHT = 2
|
const val GRAVITY_RIGHT = 2
|
||||||
|
|
||||||
// note types
|
// note types
|
||||||
const val TYPE_TEXT = 0
|
enum class NoteType(val value: Int) { TYPE_TEXT(0), TYPE_CHECKLIST(1) }
|
||||||
const val TYPE_CHECKLIST = 1
|
|
||||||
|
|
||||||
// mime types
|
// mime types
|
||||||
const val MIME_TEXT_PLAIN = "text/plain"
|
const val MIME_TEXT_PLAIN = "text/plain"
|
||||||
|
@ -32,7 +32,7 @@ class NotesHelper(val context: Context) {
|
|||||||
|
|
||||||
if (notes.isEmpty()) {
|
if (notes.isEmpty()) {
|
||||||
val generalNote = context.resources.getString(R.string.general_note)
|
val generalNote = context.resources.getString(R.string.general_note)
|
||||||
val note = Note(null, generalNote, "", TYPE_TEXT)
|
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value)
|
||||||
context.notesDB.insertOrUpdate(note)
|
context.notesDB.insertOrUpdate(note)
|
||||||
notes.add(note)
|
notes.add(note)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/dialog_holder"
|
android:id="@+id/dialog_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@ -15,8 +14,9 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="@dimen/medium_margin"
|
android:layout_marginBottom="@dimen/medium_margin"
|
||||||
android:inputType="textCapSentences"
|
android:inputType="textCapSentences"
|
||||||
|
android:maxLength="500"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyEditText
|
<com.simplemobiletools.commons.views.MyEditText
|
||||||
android:id="@+id/checklist_item_title_2"
|
android:id="@+id/checklist_item_title_2"
|
||||||
@ -24,8 +24,9 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="@dimen/medium_margin"
|
android:layout_marginBottom="@dimen/medium_margin"
|
||||||
android:inputType="textCapSentences"
|
android:inputType="textCapSentences"
|
||||||
|
android:maxLength="500"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyEditText
|
<com.simplemobiletools.commons.views.MyEditText
|
||||||
android:id="@+id/checklist_item_title_3"
|
android:id="@+id/checklist_item_title_3"
|
||||||
@ -33,7 +34,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="@dimen/medium_margin"
|
android:layout_marginBottom="@dimen/medium_margin"
|
||||||
android:inputType="textCapSentences"
|
android:inputType="textCapSentences"
|
||||||
|
android:maxLength="500"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user