mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-12 14:40:07 +01:00
fix #219, show a dialog about unsaved changes at exiting when appropriate
This commit is contained in:
parent
24797f1c41
commit
4612ce53ec
@ -11,6 +11,7 @@ import android.view.ActionMode
|
||||
import android.view.Gravity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
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() {
|
||||
config.apply {
|
||||
storedEnableLineWrap = enableLineWrap
|
||||
|
@ -42,6 +42,10 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
||||
|
||||
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 redo(position: Int) = fragments[position]?.redo()
|
||||
|
@ -155,6 +155,8 @@ class NoteFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
fun hasUnsavedChanges() = getCurrentNoteViewText() != note.getNoteStoredValue()
|
||||
|
||||
fun focusEditText() {
|
||||
view.notes_view.requestFocus()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user