From 624c27ffe01d6ef715d39096272dec2e832ad2e5 Mon Sep 17 00:00:00 2001 From: Asal Mirzaieva Date: Fri, 21 Oct 2022 21:06:42 +0200 Subject: [PATCH] add a pop up window for the notebook menu --- .../orgzly/android/ui/books/BooksFragment.kt | 39 +++++++++++++++++++ .../orgzly/android/ui/books/BooksViewModel.kt | 8 +++- app/src/main/res/menu/books_cab.xml | 6 +++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/orgzly/android/ui/books/BooksFragment.kt b/app/src/main/java/com/orgzly/android/ui/books/BooksFragment.kt index 77a3da87f..6594bfe38 100644 --- a/app/src/main/java/com/orgzly/android/ui/books/BooksFragment.kt +++ b/app/src/main/java/com/orgzly/android/ui/books/BooksFragment.kt @@ -278,6 +278,10 @@ class BooksFragment : Fragment(), DrawerItem, OnViewHolderClickListener { viewModel.deleteBookRequest(bookId) } + + R.id.books_context_menu_show_diff -> { + viewModel.showDiffBookRequest(bookId) + } } viewModel.appBar.toMode(APP_BAR_DEFAULT_MODE) @@ -305,6 +309,35 @@ class BooksFragment : Fragment(), DrawerItem, OnViewHolderClickListener + dialogBinding.deleteLinkedUrl.isEnabled = isChecked + } + + val dialogClickListener = DialogInterface.OnClickListener { _, which -> + when (which) { + DialogInterface.BUTTON_POSITIVE -> { + val deleteLinked = dialogBinding.deleteLinkedCheckbox.isChecked + viewModel.deleteBook(book.book.id, deleteLinked) + } + } + } + + val builder = MaterialAlertDialogBuilder(requireContext()) + .setTitle(getString(R.string.delete_with_quoted_argument, book.book.name)) + .setPositiveButton(R.string.delete, dialogClickListener) + .setNegativeButton(R.string.cancel, dialogClickListener) + + if (book.syncedTo != null) { + dialogBinding.deleteLinkedUrl.text = book.syncedTo.uri.toString() + builder.setView(dialogBinding.root) + } + + dialog = builder.show() + } + private fun deleteBookDialog(book: BookView) { val dialogBinding = DialogBookDeleteBinding.inflate(LayoutInflater.from(context)) @@ -427,6 +460,12 @@ class BooksFragment : Fragment(), DrawerItem, OnViewHolderClickListener + if (bookView != null) { + showDiffDialog(bookView) + } + }) + viewModel.bookToRenameEvent.observeSingle(viewLifecycleOwner, Observer { bookView -> if (bookView != null) { renameBookDialog(bookView) diff --git a/app/src/main/java/com/orgzly/android/ui/books/BooksViewModel.kt b/app/src/main/java/com/orgzly/android/ui/books/BooksViewModel.kt index 7a45cc552..7a34a6e3f 100644 --- a/app/src/main/java/com/orgzly/android/ui/books/BooksViewModel.kt +++ b/app/src/main/java/com/orgzly/android/ui/books/BooksViewModel.kt @@ -30,7 +30,7 @@ class BooksViewModel(private val dataRepository: DataRepository) : CommonViewMod val bookToExportEvent: SingleLiveEvent> = SingleLiveEvent() val bookExportedEvent: SingleLiveEvent = SingleLiveEvent() val setBookLinkRequestEvent: SingleLiveEvent = SingleLiveEvent() - + val showDiffEvent: SingleLiveEvent = SingleLiveEvent() enum class ViewState { LOADING, @@ -70,6 +70,12 @@ class BooksViewModel(private val dataRepository: DataRepository) : CommonViewMod } } + fun showDiffBookRequest(bookId: Long) { + App.EXECUTORS.diskIO().execute { + showDiffEvent.postValue(dataRepository.getBookView(bookId)) + } + } + fun deleteBook(bookId: Long, deleteLinked: Boolean) { App.EXECUTORS.diskIO().execute { catchAndPostError { diff --git a/app/src/main/res/menu/books_cab.xml b/app/src/main/res/menu/books_cab.xml index becae7bdf..f48357c3a 100644 --- a/app/src/main/res/menu/books_cab.xml +++ b/app/src/main/res/menu/books_cab.xml @@ -40,4 +40,10 @@ app:showAsAction="never"> + + +