@@ -36,14 +36,6 @@ import org.nypl.simplified.feeds.api.FeedEntry
36
36
import org.nypl.simplified.feeds.api.FeedFacet
37
37
import org.nypl.simplified.feeds.api.FeedLoaderType
38
38
import org.nypl.simplified.feeds.api.FeedSearch
39
- import org.nypl.simplified.opds.core.OPDSAvailabilityHeld
40
- import org.nypl.simplified.opds.core.OPDSAvailabilityHeldReady
41
- import org.nypl.simplified.opds.core.OPDSAvailabilityHoldable
42
- import org.nypl.simplified.opds.core.OPDSAvailabilityLoanable
43
- import org.nypl.simplified.opds.core.OPDSAvailabilityLoaned
44
- import org.nypl.simplified.opds.core.OPDSAvailabilityMatcherType
45
- import org.nypl.simplified.opds.core.OPDSAvailabilityOpenAccess
46
- import org.nypl.simplified.opds.core.OPDSAvailabilityRevoked
47
39
import org.nypl.simplified.profiles.controller.api.ProfileFeedRequest
48
40
import org.nypl.simplified.profiles.controller.api.ProfilesControllerType
49
41
import org.nypl.simplified.taskrecorder.api.TaskResult
@@ -84,6 +76,7 @@ import org.thepalaceproject.opds.client.OPDSState.LoadedFeedWithoutGroups
84
76
import org.thepalaceproject.opds.client.OPDSState.Loading
85
77
import java.net.URI
86
78
import java.util.concurrent.TimeUnit
79
+ import java.util.concurrent.atomic.AtomicReference
87
80
88
81
/* *
89
82
* The fragment used for the catalog.
@@ -316,20 +309,21 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
316
309
) {
317
310
val view =
318
311
CatalogFeedViewDetails2 .create(
319
- layoutInflater = this .layoutInflater,
320
- screenSize = this .screenSize,
321
312
container = this .contentContainer,
322
313
covers = this .covers,
323
- onShowErrorDetails = this ::onShowErrorDetails,
324
- onBookBorrowRequested = this ::onBookBorrowRequested,
314
+ layoutInflater = this .layoutInflater,
325
315
onBookBorrowCancelRequested = this ::onBookBorrowCancelRequested,
316
+ onBookBorrowRequested = this ::onBookBorrowRequested,
326
317
onBookCanBeRevoked = this ::onBookCanBeRevoked,
327
318
onBookPreviewOpenRequested = this ::onBookPreviewOpenRequested,
328
319
onBookRevokeRequested = this ::onBookRevokeRequested,
320
+ onBookSAMLDownloadRequested = this ::onBookSAMLDownloadRequested,
321
+ onBookSelected = this ::onBookSelected,
329
322
onBookViewerOpen = this ::onBookViewerOpen,
330
- onToolbarBackPressed = this ::onToolbarBackPressed,
331
323
onFeedSelected = this ::onFeedSelected,
332
- onBookSelected = this ::onBookSelected
324
+ onShowErrorDetails = this ::onShowErrorDetails,
325
+ onToolbarBackPressed = this ::onToolbarBackPressed,
326
+ screenSize = this .screenSize
333
327
)
334
328
335
329
when (val entry = this .opdsClient.entry.get()) {
@@ -373,8 +367,6 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
373
367
}
374
368
}
375
369
376
- this .onStateChangeToDetailsConfigureToolbar(newState, view)
377
-
378
370
/*
379
371
* Subscribe to the entry on the OPDS client. We'll receive the initial
380
372
* entry on subscription.
@@ -478,25 +470,6 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
478
470
}
479
471
}
480
472
481
- private fun onStateChangeToDetailsConfigureToolbar (
482
- newState : LoadedFeedEntry ,
483
- view : CatalogFeedViewDetails2
484
- ) {
485
- try {
486
- val account =
487
- this .profiles.profileCurrent()
488
- .account(newState.request.entry.accountID)
489
-
490
- val title =
491
- when (val e = newState.request.entry) {
492
- is FeedEntry .FeedEntryCorrupt -> " "
493
- is FeedEntry .FeedEntryOPDS -> e.feedEntry.title
494
- }
495
- } catch (e: Throwable ) {
496
- // Nothing sensible we can do about this.
497
- }
498
- }
499
-
500
473
private fun onBookBorrowRequested (
501
474
parameters : CatalogBorrowParameters
502
475
) {
@@ -577,64 +550,6 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
577
550
}
578
551
}
579
552
580
- /* *
581
- * Determine whether or not a book can be "deleted".
582
- *
583
- * A book can be deleted if:
584
- *
585
- * * It is loaned, downloaded, and not revocable (because otherwise, a revocation is needed).
586
- * * It is loanable, but there is a book database entry for it
587
- * * It is open access but there is a book database entry for it
588
- */
589
-
590
- private fun onBookCanBeDeleted (
591
- status : CatalogBookStatus <* >
592
- ): Boolean {
593
- return try {
594
- val services =
595
- Services .serviceDirectory()
596
- val profiles =
597
- services.requireService(ProfilesControllerType ::class .java)
598
- val book =
599
- status.book
600
- val profile =
601
- profiles.profileCurrent()
602
- val account =
603
- profile.account(book.account)
604
-
605
- return if (account.bookDatabase.books().contains(book.id)) {
606
- book.entry.availability.matchAvailability(
607
- object : OPDSAvailabilityMatcherType <Boolean , Exception > {
608
- override fun onHeldReady (availability : OPDSAvailabilityHeldReady ): Boolean =
609
- false
610
-
611
- override fun onHeld (availability : OPDSAvailabilityHeld ): Boolean =
612
- false
613
-
614
- override fun onHoldable (availability : OPDSAvailabilityHoldable ): Boolean =
615
- false
616
-
617
- override fun onLoaned (availability : OPDSAvailabilityLoaned ): Boolean =
618
- availability.revoke.isNone && book.isDownloaded
619
-
620
- override fun onLoanable (availability : OPDSAvailabilityLoanable ): Boolean =
621
- true
622
-
623
- override fun onOpenAccess (availability : OPDSAvailabilityOpenAccess ): Boolean =
624
- true
625
-
626
- override fun onRevoked (availability : OPDSAvailabilityRevoked ): Boolean =
627
- false
628
- })
629
- } else {
630
- false
631
- }
632
- } catch (e: Throwable ) {
633
- this .logger.debug(" could not determine if the book could be deleted: " , e)
634
- false
635
- }
636
- }
637
-
638
553
private fun onBookCanBeRevoked (
639
554
status : CatalogBookStatus <* >
640
555
): Boolean {
@@ -702,12 +617,6 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
702
617
)
703
618
}
704
619
705
- private fun onBookResetStatusInitial (
706
- status : CatalogBookStatus <* >
707
- ) {
708
- // XXX: Unclear what the point of this method ever was...
709
- }
710
-
711
620
private fun onBookViewerOpen (
712
621
book : Book ,
713
622
bookFormat : BookFormat
@@ -725,12 +634,6 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
725
634
)
726
635
}
727
636
728
- private fun onBookReserveRequested (
729
- parameters : CatalogBorrowParameters
730
- ) {
731
- this .onBookBorrowRequested(parameters)
732
- }
733
-
734
637
private fun onStateChangedToGroups (
735
638
newState : LoadedFeedWithGroups
736
639
) {
@@ -860,8 +763,8 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
860
763
) {
861
764
val feedHandle =
862
765
newState.handle
863
- val feedPosition =
864
- feedHandle.scrollPositionGet()
766
+ val feedPositionInitial =
767
+ AtomicReference ( feedHandle.scrollPositionGet() )
865
768
val feed =
866
769
feedHandle.feed()
867
770
@@ -931,7 +834,7 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
931
834
val position =
932
835
linearLayoutManager.findFirstVisibleItemPosition()
933
836
934
- // logger.trace("Saving scroll position {}", position)
837
+ logger.trace(" Saving scroll position {}" , position)
935
838
feedHandle.scrollPositionSave(position)
936
839
}
937
840
})
@@ -995,11 +898,24 @@ sealed class CatalogFragment : Fragment(), MainBackButtonConsumerType {
995
898
this .switchView(view)
996
899
997
900
/*
998
- * Set up a listener to restore the scroll position.
901
+ * Set up a listener to restore the scroll position. This works around multiple pieces of
902
+ * Android brokenness: Restoring the scroll position when we navigate to a book detail page
903
+ * and back again, and also properly handling scrolling when new feed pages come in. With
904
+ * the current RecyclerView, not explicitly storing and restoring the scroll position results
905
+ * in all kinds of scroll issues when new pages are loaded.
999
906
*/
1000
907
1001
908
feedAdapter.addOnPagesUpdatedListener {
1002
- // this.logger.trace("Restoring scroll position {}", feedPosition)
909
+ val feedPosition: Int
910
+ val initial = feedPositionInitial.get()
911
+ if (initial == null ) {
912
+ feedPosition = feedHandle.scrollPositionGet()
913
+ // this.logger.trace("Restoring scroll position {}", feedPosition)
914
+ } else {
915
+ feedPositionInitial.set(null )
916
+ feedPosition = initial
917
+ // this.logger.trace("Restoring scroll position (initial) {}", feedPosition)
918
+ }
1003
919
view.listView.scrollToPosition(feedPosition)
1004
920
}
1005
921
}
0 commit comments