Skip to content

Commit e16e527

Browse files
Add confirmation popups to hold and loan revoke (#195)
1 parent 8e691b9 commit e16e527

File tree

3 files changed

+120
-9
lines changed

3 files changed

+120
-9
lines changed

simplified-ui-catalog/src/main/java/org/librarysimplified/ui/catalog/CatalogBookDetailFragment.kt

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ class CatalogBookDetailFragment : Fragment(R.layout.book_detail) {
539539

540540
when (val status = book.status) {
541541
is BookStatus.Held -> {
542-
this.onBookStatusHeld(status, bookPreviewStatus)
542+
this.onBookStatusHeld(status, bookPreviewStatus, book.book)
543543
}
544544
is BookStatus.Loaned -> {
545545
this.onBookStatusLoaned(status, book.book)
@@ -821,7 +821,8 @@ class CatalogBookDetailFragment : Fragment(R.layout.book_detail) {
821821

822822
private fun onBookStatusHeld(
823823
bookStatus: BookStatus.Held,
824-
bookPreviewStatus: BookPreviewStatus
824+
bookPreviewStatus: BookPreviewStatus,
825+
book: Book
825826
) {
826827
this.buttons.removeAllViews()
827828

@@ -846,7 +847,7 @@ class CatalogBookDetailFragment : Fragment(R.layout.book_detail) {
846847
this.buttons.addView(
847848
this.buttonCreator.createRevokeHoldButton(
848849
onClick = {
849-
this.viewModel.revokeMaybeAuthenticated()
850+
this.revokeHoldPopup(book)
850851
}
851852
)
852853
)
@@ -892,7 +893,7 @@ class CatalogBookDetailFragment : Fragment(R.layout.book_detail) {
892893
this.buttons.addView(
893894
this.buttonCreator.createRevokeHoldButton(
894895
onClick = {
895-
this.viewModel.revokeMaybeAuthenticated()
896+
this.revokeHoldPopup(book)
896897
}
897898
)
898899
)
@@ -970,7 +971,7 @@ class CatalogBookDetailFragment : Fragment(R.layout.book_detail) {
970971
this.buttons.addView(
971972
this.buttonCreator.createRevokeLoanButton(
972973
onClick = {
973-
this.viewModel.revokeMaybeAuthenticated()
974+
this.revokeLoanPopup(book)
974975
}
975976
)
976977
)
@@ -1138,6 +1139,57 @@ class CatalogBookDetailFragment : Fragment(R.layout.book_detail) {
11381139
dialog.show()
11391140

11401141
}
1142+
/**
1143+
* Show user a popup requiring user to confirm a loan revoke
1144+
*/
1145+
private fun revokeLoanPopup(book: Book) {
1146+
//Mark that a popup is currently shown
1147+
popUpShown = true
1148+
logger.debug("Showing loan revoke popup")
1149+
val builder: AlertDialog.Builder = AlertDialog.Builder(this.requireContext())
1150+
builder
1151+
.setTitle(getString(R.string.bookConfirmReturnTitle, book.entry.title))
1152+
.setMessage(R.string.bookConfirmReturnMessage)
1153+
.setPositiveButton(R.string.bookConfirmReturnConfirmButton) { dialog, which ->
1154+
//Set the popup as closed
1155+
//And start revoke
1156+
this.viewModel.revokeMaybeAuthenticated()
1157+
popUpShown = false
1158+
}
1159+
.setNeutralButton(R.string.bookConfirmReturnCancelButton) { dialog, which ->
1160+
//Do nothing, don't revoke the book
1161+
popUpShown = false
1162+
}
1163+
1164+
val dialog: AlertDialog = builder.create()
1165+
dialog.show()
1166+
}
1167+
1168+
/**
1169+
* Show user a popup requiring user to confirm a hold revoke
1170+
*/
1171+
private fun revokeHoldPopup(book: Book) {
1172+
//Mark that a popup is currently shown
1173+
popUpShown = true
1174+
logger.debug("Showing revoke hold popup")
1175+
val builder: AlertDialog.Builder = AlertDialog.Builder(this.requireContext())
1176+
builder
1177+
.setTitle(getString(R.string.bookConfirmRevokeTitle, book.entry.title))
1178+
.setMessage(R.string.bookConfirmRevokeMessage)
1179+
.setPositiveButton(R.string.bookConfirmRevokeConfirmButton) { dialog, which ->
1180+
//Set the popup as closed
1181+
//And start revoke
1182+
this.viewModel.revokeMaybeAuthenticated()
1183+
popUpShown = false
1184+
}
1185+
.setNeutralButton(R.string.bookConfirmReturnCancelButton) { dialog, which ->
1186+
//Do nothing, don't revoke the book
1187+
popUpShown = false
1188+
}
1189+
1190+
val dialog: AlertDialog = builder.create()
1191+
dialog.show()
1192+
}
11411193

11421194
private fun onBookStatusDownloadWaitingForExternalAuthentication() {
11431195
this.buttons.removeAllViews()

simplified-ui-catalog/src/main/java/org/librarysimplified/ui/catalog/CatalogPagedViewHolder.kt

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class CatalogPagedViewHolder(
361361
this.idleButtons.addView(
362362
this.buttonCreator.createRevokeLoanButton(
363363
onClick = {
364-
this.listener.revokeMaybeAuthenticated(book)
364+
this.revokeLoanPopup(book)
365365
}
366366
)
367367
)
@@ -455,7 +455,7 @@ class CatalogPagedViewHolder(
455455
this.idleButtons.addView(
456456
this.buttonCreator.createRevokeHoldButton(
457457
onClick = {
458-
this.listener.revokeMaybeAuthenticated(book)
458+
this.revokeHoldPopup(book)
459459
}
460460
)
461461
)
@@ -483,7 +483,7 @@ class CatalogPagedViewHolder(
483483
this.idleButtons.addView(
484484
this.buttonCreator.createRevokeHoldButton(
485485
onClick = {
486-
this.listener.revokeMaybeAuthenticated(book)
486+
this.revokeHoldPopup(book)
487487
}
488488
)
489489
)
@@ -542,7 +542,8 @@ class CatalogPagedViewHolder(
542542
this.idleButtons.addView(
543543
this.buttonCreator.createRevokeLoanButton(
544544
onClick = {
545-
this.listener.revokeMaybeAuthenticated(book)
545+
//Show popup asking to confirm revoking the book
546+
this.revokeLoanPopup(book)
546547
}
547548
)
548549
)
@@ -559,6 +560,57 @@ class CatalogPagedViewHolder(
559560
this.idleButtons.addView(this.buttonCreator.createButtonSpace())
560561
}
561562
}
563+
/**
564+
* Show user a popup requiring user to confirm a loan return
565+
*/
566+
private fun revokeLoanPopup(book: Book) {
567+
//Mark that a popup is currently shown
568+
popUpShown = true
569+
logger.debug("Showing book return popup")
570+
val builder: AlertDialog.Builder = AlertDialog.Builder(this.context)
571+
builder
572+
.setTitle(context.getString(R.string.bookConfirmReturnTitle, book.entry.title))
573+
.setMessage(R.string.bookConfirmReturnMessage)
574+
.setPositiveButton(R.string.bookConfirmReturnConfirmButton) { dialog, which ->
575+
//Set the popup as closed
576+
//And start revoke
577+
this.listener.revokeMaybeAuthenticated(book)
578+
popUpShown = false
579+
}
580+
.setNeutralButton(R.string.bookConfirmReturnCancelButton) { dialog, which ->
581+
//Do nothing, don't revoke the book
582+
popUpShown = false
583+
}
584+
585+
val dialog: AlertDialog = builder.create()
586+
dialog.show()
587+
}
588+
589+
/**
590+
* Show user a popup requiring user to confirm a hold revoke
591+
*/
592+
private fun revokeHoldPopup(book: Book) {
593+
//Mark that a popup is currently shown
594+
popUpShown = true
595+
logger.debug("Showing revoke hold popup")
596+
val builder: AlertDialog.Builder = AlertDialog.Builder(this.context)
597+
builder
598+
.setTitle(context.getString(R.string.bookConfirmRevokeTitle, book.entry.title))
599+
.setMessage(R.string.bookConfirmRevokeMessage)
600+
.setPositiveButton(R.string.bookConfirmRevokeConfirmButton) { dialog, which ->
601+
//Set the popup as closed
602+
//And start revoke
603+
this.listener.revokeMaybeAuthenticated(book)
604+
popUpShown = false
605+
}
606+
.setNeutralButton(R.string.bookConfirmReturnCancelButton) { dialog, which ->
607+
//Do nothing, don't revoke the book
608+
popUpShown = false
609+
}
610+
611+
val dialog: AlertDialog = builder.create()
612+
dialog.show()
613+
}
562614

563615
@Suppress("UNUSED_PARAMETER")
564616
private fun onBookStatusRevoked(book: BookWithStatus) {

simplified-ui-catalog/src/main/res/values/stringsCatalog.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,11 @@
101101
<string name="bookNotEnoughSpaceTitle">Not enough space!</string>
102102
<string name="bookNotEnoughSpaceMessage">File is too big to store on device. Current free space on device: %1$s. \nFree at least %2$s of space to download the book.</string>
103103
<string name="bookNotEnoughSpaceButton">Close</string>
104+
<string name="bookConfirmReturnTitle">Return \"%1$s\" ?</string>
105+
<string name="bookConfirmReturnMessage">Returning this book removes it from your loans and from your device.</string>
106+
<string name="bookConfirmReturnConfirmButton">Return</string>
107+
<string name="bookConfirmReturnCancelButton">Cancel</string>
108+
<string name="bookConfirmRevokeTitle">Revoke hold for \"%1$s\" ?</string>
109+
<string name="bookConfirmRevokeMessage">If you revoke this hold you lose your place in the queue.</string>
110+
<string name="bookConfirmRevokeConfirmButton">Revoke</string>
104111
</resources>

0 commit comments

Comments
 (0)