Changed undo/redo visibility behavior (#427)

This commit is contained in:
Agnieszka C 2021-09-26 19:15:34 +02:00
parent dd70cfe9a9
commit ed1603afad
1 changed files with 13 additions and 2 deletions

View File

@ -136,8 +136,17 @@ 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 == NoteType.TYPE_TEXT.value val areButtonsVisible = (showRedoButton || showUndoButton) && mCurrentNote.type == NoteType.TYPE_TEXT.value
findItem(R.id.redo).isVisible = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value findItem(R.id.undo).apply {
isVisible = areButtonsVisible
isEnabled = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
icon.alpha = if (isEnabled) 255 else 127
}
findItem(R.id.redo).apply {
isVisible = areButtonsVisible
isEnabled = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
icon.alpha = if (isEnabled) 255 else 127
}
} }
updateMenuItemColors(menu) updateMenuItemColors(menu)
@ -505,6 +514,8 @@ class MainActivity : SimpleActivity() {
NotesHelper(this).insertOrUpdateNote(note) { NotesHelper(this).insertOrUpdateNote(note) {
val newNoteId = it val newNoteId = it
showSaveButton = false showSaveButton = false
showUndoButton = false
showRedoButton = false
initViewPager(newNoteId) initViewPager(newNoteId)
updateSelectedNote(newNoteId) updateSelectedNote(newNoteId)
view_pager.onGlobalLayout { view_pager.onGlobalLayout {