toggle undo/redo menu button visibility as required

This commit is contained in:
tibbi
2018-07-17 21:23:37 +02:00
parent 2c3a6937a7
commit d47226edf2
2 changed files with 28 additions and 4 deletions

View File

@ -46,6 +46,8 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private var wasInit = false
private var storedEnableLineWrap = true
private var showSaveButton = false
private var showUndoButton = false
private var showRedoButton = false
private var saveNoteButton: MenuItem? = null
override fun onCreate(savedInstanceState: Bundle?) {
@ -105,6 +107,11 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu, menu)
menu.apply {
findItem(R.id.undo).isVisible = showUndoButton
findItem(R.id.redo).isVisible = showRedoButton
}
return true
}
@ -573,13 +580,28 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
config.currentNoteId = mCurrentNote.id
}
fun currentNoteTextChanged(newText: String) {
fun currentNoteTextChanged(newText: String, showUndo: Boolean, showRedo: Boolean) {
var shouldRecreateMenu = false
if (showUndo != showUndoButton) {
showUndoButton = showUndo
shouldRecreateMenu = true
}
if (showRedo != showRedoButton) {
showRedoButton = showRedo
shouldRecreateMenu = true
}
if (!config.autosaveNotes) {
showSaveButton = newText != mCurrentNote.value
if (showSaveButton != saveNoteButton?.isVisible) {
invalidateOptionsMenu()
shouldRecreateMenu = true
}
}
if (shouldRecreateMenu) {
invalidateOptionsMenu()
}
}
private fun checkWhatsNewDialog() {