mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
fix #219, show a dialog about unsaved changes at exiting when appropriate
This commit is contained in:
@ -11,6 +11,7 @@ import android.view.ActionMode
|
|||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
@ -177,6 +178,21 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
if (!config.autosaveNotes && mAdapter?.anyHasUnsavedChanges() == true) {
|
||||||
|
ConfirmationAdvancedDialog(this, "", R.string.unsaved_changes_warning, R.string.save, R.string.discard) {
|
||||||
|
if (it) {
|
||||||
|
mAdapter?.saveAllFragmentTexts()
|
||||||
|
super.onBackPressed()
|
||||||
|
} else {
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
private fun storeStateVariables() {
|
||||||
config.apply {
|
config.apply {
|
||||||
storedEnableLineWrap = enableLineWrap
|
storedEnableLineWrap = enableLineWrap
|
||||||
|
@ -42,6 +42,10 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
|||||||
|
|
||||||
fun focusEditText(position: Int) = fragments[position]?.focusEditText()
|
fun focusEditText(position: Int) = fragments[position]?.focusEditText()
|
||||||
|
|
||||||
|
fun anyHasUnsavedChanges() = fragments.values.any { it.hasUnsavedChanges() }
|
||||||
|
|
||||||
|
fun saveAllFragmentTexts() = fragments.values.forEach { it.saveText(false) }
|
||||||
|
|
||||||
fun undo(position: Int) = fragments[position]?.undo()
|
fun undo(position: Int) = fragments[position]?.undo()
|
||||||
|
|
||||||
fun redo(position: Int) = fragments[position]?.redo()
|
fun redo(position: Int) = fragments[position]?.redo()
|
||||||
|
@ -155,6 +155,8 @@ class NoteFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasUnsavedChanges() = getCurrentNoteViewText() != note.getNoteStoredValue()
|
||||||
|
|
||||||
fun focusEditText() {
|
fun focusEditText() {
|
||||||
view.notes_view.requestFocus()
|
view.notes_view.requestFocus()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user