Skip to content

Commit b995a4b

Browse files
committed
Remove the much hated button durations and replace with text
Affects: https://ebce-lyrasis.atlassian.net/browse/PP-2560
1 parent 79b5214 commit b995a4b

File tree

5 files changed

+82
-140
lines changed

5 files changed

+82
-140
lines changed

simplified-ui/src/main/java/org/nypl/simplified/ui/catalog/CatalogButtons.kt

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ class CatalogButtons(
4242
return text
4343
}
4444

45-
@UiThread
46-
fun createCenteredTextForButtons(
47-
centeredText: String
48-
): TextView {
49-
return AppCompatTextView(this.context).apply {
50-
gravity = Gravity.CENTER
51-
text = centeredText
52-
}
53-
}
54-
5545
@UiThread
5646
fun createButton(
5747
text: Int,
@@ -73,56 +63,6 @@ class CatalogButtons(
7363
return button
7464
}
7565

76-
@UiThread
77-
fun createReadButtonWithLoanDuration(
78-
loanDuration: String,
79-
onClick: () -> Unit
80-
): View {
81-
return createButtonWithDuration(loanDuration, R.string.catalogRead, onClick)
82-
}
83-
84-
@UiThread
85-
fun createDownloadButtonWithLoanDuration(
86-
loanDuration: String,
87-
onClick: () -> Unit
88-
): View {
89-
return createButtonWithDuration(loanDuration, R.string.catalogDownload, onClick)
90-
}
91-
92-
@UiThread
93-
fun createListenButtonWithLoanDuration(
94-
loanDuration: String,
95-
onClick: () -> Unit
96-
): View {
97-
return createButtonWithDuration(loanDuration, R.string.catalogListen, onClick)
98-
}
99-
100-
@UiThread
101-
fun createButtonWithDuration(
102-
loanDuration: String,
103-
@StringRes res: Int,
104-
onClick: () -> Unit
105-
): View {
106-
val button = MaterialButton(this.context)
107-
button.text = this.context.getString(res)
108-
button.contentDescription = this.context.getString(res)
109-
button.layoutParams = this.buttonLayoutParameters(true)
110-
button.maxLines = 1
111-
button.ellipsize = TextUtils.TruncateAt.END
112-
button.setOnClickListener {
113-
button.isEnabled = false
114-
onClick.invoke()
115-
button.isEnabled = true
116-
}
117-
button.iconSize = this.screenSizeInformation.dpToPixels(24).toInt()
118-
button.icon = CatalogTimedLoanDrawable(
119-
context = this.context,
120-
screenSizeInformation = this.screenSizeInformation,
121-
durationText = loanDuration
122-
)
123-
return button
124-
}
125-
12666
@UiThread
12767
fun createReadButton(
12868
onClick: (Button) -> Unit,
@@ -307,12 +247,4 @@ class CatalogButtons(
307247
buttonLayoutParams.width = 0
308248
return buttonLayoutParams
309249
}
310-
311-
@UiThread
312-
fun wrapContentParameters(): LinearLayout.LayoutParams {
313-
return LinearLayout.LayoutParams(
314-
LinearLayout.LayoutParams.WRAP_CONTENT,
315-
LinearLayout.LayoutParams.WRAP_CONTENT
316-
)
317-
}
318250
}

simplified-ui/src/main/java/org/nypl/simplified/ui/catalog/CatalogFeedPagingDataAdapter.kt

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
1717
import com.google.common.util.concurrent.MoreExecutors
1818
import io.reactivex.disposables.Disposable
1919
import org.joda.time.DateTime
20+
import org.joda.time.format.DateTimeFormat
2021
import org.librarysimplified.ui.R
2122
import org.nypl.simplified.books.api.Book
2223
import org.nypl.simplified.books.api.BookFormat
@@ -64,9 +65,12 @@ class CatalogFeedPagingDataAdapter(
6465
private val onBookViewerOpen: (Book, BookFormat) -> Unit,
6566
private val onBookDelete: (CatalogBookStatus<*>) -> Unit,
6667
private val onShowTaskError: (TaskResult.Failure<*>) -> Unit,
67-
) : PagingDataAdapter<FeedEntry, CatalogFeedPagingDataAdapter.ViewHolder>(diffCallback) {
68+
) : PagingDataAdapter<FeedEntry, CatalogFeedPagingDataAdapter.ViewHolder>(org.nypl.simplified.ui.catalog.CatalogFeedPagingDataAdapter.Companion.diffCallback) {
6869

6970
companion object {
71+
private val loanEndFormatter =
72+
DateTimeFormat.forPattern("MMM d, yyyy")
73+
7074
private val diffCallback =
7175
object : DiffUtil.ItemCallback<FeedEntry>() {
7276
override fun areContentsTheSame(
@@ -110,8 +114,8 @@ class CatalogFeedPagingDataAdapter(
110114
this.view.findViewById<ProgressBar>(R.id.bookCellIdleCoverProgress)
111115
private val idleTitle =
112116
this.idle.findViewById<TextView>(R.id.bookCellIdleTitle)
113-
private val idleMeta =
114-
this.idle.findViewById<TextView>(R.id.bookCellIdleMeta)
117+
private val idleTime =
118+
this.idle.findViewById<TextView>(R.id.bookCellIdleTime)
115119
private val idleAuthor =
116120
this.idle.findViewById<TextView>(R.id.bookCellIdleAuthor)
117121
private val idleButtons =
@@ -182,7 +186,7 @@ class CatalogFeedPagingDataAdapter(
182186
.filter { event -> event.bookId == item.bookID }
183187
.subscribe { event -> this.onStatusChangedForFeedEntry(item) }
184188

185-
for (v in listOf(view, this.idle, this.error, this.corrupt, this.progress)) {
189+
for (v in listOf(this.view, this.idle, this.error, this.corrupt, this.progress)) {
186190
v.setOnClickListener { this@CatalogFeedPagingDataAdapter.onBookSelected(item) }
187191
}
188192

@@ -192,6 +196,7 @@ class CatalogFeedPagingDataAdapter(
192196
this.errorTitle.text = item.feedEntry.title
193197
this.idleTitle.text = item.feedEntry.title
194198
this.idleAuthor.text = item.feedEntry.authorsCommaSeparated
199+
this.idleTime.text = ""
195200

196201
val f =
197202
this@CatalogFeedPagingDataAdapter.covers.loadThumbnailInto(
@@ -587,42 +592,30 @@ class CatalogFeedPagingDataAdapter(
587592
this.setVisible(this.progress, false)
588593

589594
this.idleButtons.removeAllViews()
595+
this.setIdleTime(this.getLoanDuration(book))
590596

591597
when (val format = book.findPreferredFormat()) {
592598
is BookFormat.BookFormatPDF,
593599
is BookFormat.BookFormatEPUB -> {
594-
val loanDuration = getLoanDuration(book)
595600
this.idleButtons.addView(
596-
if (loanDuration.isNotEmpty()) {
597-
this.buttonCreator.createReadButtonWithLoanDuration(loanDuration) {
601+
this.buttonCreator.createReadButton(
602+
onClick = {
598603
this.onBookViewerOpen(book, format)
599-
}
600-
} else {
601-
this.buttonCreator.createReadButton(
602-
onClick = {
603-
this.onBookViewerOpen(book, format)
604-
},
605-
heightMatchParent = true
606-
)
607-
}
604+
},
605+
heightMatchParent = true
606+
)
608607
)
609608
}
610609

611610
is BookFormat.BookFormatAudioBook -> {
612-
val loanDuration = getLoanDuration(book)
611+
val loanDuration = this.getLoanDurationText(book)
613612
this.idleButtons.addView(
614-
if (loanDuration.isNotEmpty()) {
615-
this.buttonCreator.createListenButtonWithLoanDuration(loanDuration) {
613+
this.buttonCreator.createListenButton(
614+
onClick = {
616615
this.onBookViewerOpen(book, format)
617-
}
618-
} else {
619-
this.buttonCreator.createListenButton(
620-
onClick = {
621-
this.onBookViewerOpen(book, format)
622-
},
623-
heightMatchParent = true
624-
)
625-
}
616+
},
617+
heightMatchParent = true
618+
)
626619
)
627620
}
628621

@@ -631,7 +624,7 @@ class CatalogFeedPagingDataAdapter(
631624
}
632625
}
633626

634-
if (isBookReturnable(book)) {
627+
if (this.isBookReturnable(book)) {
635628
this.idleButtons.addView(this.buttonCreator.createButtonSpace())
636629
this.idleButtons.addView(
637630
this.buttonCreator.createRevokeLoanButton(
@@ -641,7 +634,7 @@ class CatalogFeedPagingDataAdapter(
641634
heightMatchParent = true
642635
)
643636
)
644-
} else if (isBookDeletable(book)) {
637+
} else if (this.isBookDeletable(book)) {
645638
this.idleButtons.addView(this.buttonCreator.createButtonSpace())
646639
this.idleButtons.addView(
647640
this.buttonCreator.createRevokeLoanButton(
@@ -654,6 +647,20 @@ class CatalogFeedPagingDataAdapter(
654647
}
655648
}
656649

650+
private fun setIdleTime(
651+
loanDuration: DateTime?
652+
) {
653+
if (loanDuration != null) {
654+
this.idleTime.text =
655+
this.idleTime.resources.getString(
656+
R.string.catalogBookCellBorrowingUntil,
657+
loanEndFormatter.print(loanDuration)
658+
)
659+
} else {
660+
this.idleTime.text = ""
661+
}
662+
}
663+
657664
private fun onBookStatusLoanedNotDownloaded(
658665
book: Book,
659666
status: Loaned.LoanedNotDownloaded
@@ -664,17 +671,10 @@ class CatalogFeedPagingDataAdapter(
664671
this.setVisible(this.progress, false)
665672

666673
this.idleButtons.removeAllViews()
667-
668-
val loanDuration = getLoanDuration(book)
674+
this.setIdleTime(this.getLoanDuration(book))
669675

670676
this.idleButtons.addView(
671677
when {
672-
loanDuration.isNotEmpty() -> {
673-
this.buttonCreator.createDownloadButtonWithLoanDuration(loanDuration) {
674-
this.onBookBorrow(book)
675-
}
676-
}
677-
678678
status.isOpenAccess -> {
679679
this.buttonCreator.createGetButton(
680680
onClick = {
@@ -695,7 +695,7 @@ class CatalogFeedPagingDataAdapter(
695695
}
696696
)
697697

698-
if (isBookReturnable(book)) {
698+
if (this.isBookReturnable(book)) {
699699
this.idleButtons.addView(this.buttonCreator.createButtonSpace())
700700
this.idleButtons.addView(
701701
this.buttonCreator.createRevokeLoanButton(
@@ -705,7 +705,7 @@ class CatalogFeedPagingDataAdapter(
705705
heightMatchParent = true
706706
)
707707
)
708-
} else if (isBookDeletable(book)) {
708+
} else if (this.isBookDeletable(book)) {
709709
this.idleButtons.addView(this.buttonCreator.createButtonSpace())
710710
this.idleButtons.addView(
711711
this.buttonCreator.createRevokeLoanButton(
@@ -788,27 +788,34 @@ class CatalogFeedPagingDataAdapter(
788788
* existing code.
789789
*/
790790

791-
private fun getLoanDuration(book: Book): String {
791+
private fun getLoanDurationText(
792+
book: Book
793+
): String {
794+
val endDate = this.getLoanDuration(book)
795+
return if (endDate != null) {
796+
CatalogBookAvailabilityStrings.intervalStringLoanDuration(
797+
this.view.context.resources,
798+
DateTime.now(),
799+
endDate
800+
)
801+
} else {
802+
""
803+
}
804+
}
805+
806+
private fun getLoanDuration(
807+
book: Book
808+
): DateTime? {
792809
val status = BookStatus.fromBook(book)
793810
return if (status is Loaned.LoanedDownloaded ||
794811
status is Loaned.LoanedNotDownloaded
795812
) {
796813
val endDate = (status as? Loaned.LoanedDownloaded)?.loanExpiryDate
797814
?: (status as? Loaned.LoanedNotDownloaded)?.loanExpiryDate
798815

799-
if (
800-
endDate != null
801-
) {
802-
CatalogBookAvailabilityStrings.intervalStringLoanDuration(
803-
this.view.context.resources,
804-
DateTime.now(),
805-
endDate
806-
)
807-
} else {
808-
""
809-
}
816+
endDate
810817
} else {
811-
""
818+
null
812819
}
813820
}
814821

simplified-ui/src/main/res/layout/book_cell_idle.xml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
android:layout_height="@dimen/catalogFeedCellHeight"
1515
android:layout_marginStart="16dp"
1616
android:contentDescription="@null"
17-
app:layout_constraintBottom_toBottomOf="parent"
1817
app:layout_constraintStart_toStartOf="parent"
1918
app:layout_constraintTop_toTopOf="parent" />
2019

@@ -58,21 +57,6 @@
5857
app:layout_constraintTop_toBottomOf="@id/bookCellIdleTitle"
5958
tools:text="Mary Shelley" />
6059

61-
<TextView
62-
android:id="@+id/bookCellIdleMeta"
63-
android:layout_width="0dp"
64-
android:layout_height="wrap_content"
65-
android:layout_marginStart="16dp"
66-
android:layout_marginEnd="16dp"
67-
android:ellipsize="end"
68-
android:maxLines="1"
69-
android:textSize="12sp"
70-
android:textStyle="italic"
71-
app:layout_constraintEnd_toEndOf="parent"
72-
app:layout_constraintStart_toEndOf="@id/bookCellIdleCover"
73-
app:layout_constraintTop_toBottomOf="@id/bookCellIdleAuthor"
74-
tools:text="eBook - The New York Public Library" />
75-
7660
<LinearLayout
7761
android:id="@+id/bookCellIdleButtons"
7862
android:layout_width="0dp"
@@ -82,7 +66,7 @@
8266
android:layout_marginBottom="8dp"
8367
android:gravity="center_vertical"
8468
android:orientation="horizontal"
85-
app:layout_constraintBottom_toBottomOf="parent"
69+
app:layout_constraintBottom_toTopOf="@id/bookCellIdleTime"
8670
app:layout_constraintEnd_toEndOf="parent"
8771
app:layout_constraintStart_toEndOf="@id/bookCellIdleCover">
8872

@@ -124,4 +108,21 @@
124108
tools:text="@string/catalogRetry"
125109
tools:visibility="visible" />
126110
</LinearLayout>
111+
112+
<TextView
113+
android:id="@+id/bookCellIdleTime"
114+
android:layout_width="0dp"
115+
android:layout_height="wrap_content"
116+
android:layout_marginStart="16dp"
117+
android:layout_marginEnd="16dp"
118+
android:layout_marginBottom="8dp"
119+
android:ellipsize="end"
120+
android:maxLines="1"
121+
android:textSize="12sp"
122+
android:alpha="0.75"
123+
app:layout_constraintEnd_toEndOf="parent"
124+
app:layout_constraintStart_toEndOf="@id/bookCellIdleCover"
125+
app:layout_constraintBottom_toBottomOf="parent"
126+
tools:text="Borrowed until 31st February 1976" />
127+
127128
</androidx.constraintlayout.widget.ConstraintLayout>

simplified-ui/src/main/res/values/dimensions.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<dimen name="catalogFacetTabCornerRadius">8dp</dimen>
1919
<dimen name="catalogFacetTabStandardHeight">36dp</dimen>
2020
<dimen name="catalogFacetTabStroke">4dp</dimen>
21-
<dimen name="catalogFeedCellButtonsHeight">45dp</dimen>
22-
<dimen name="catalogFeedCellHeight">128dp</dimen>
21+
<dimen name="catalogFeedCellButtonsHeight">40dp</dimen>
22+
<dimen name="catalogFeedCellHeight">160dp</dimen>
2323
<dimen name="catalogFeedCellImageWidth">80dp</dimen>
2424
<dimen name="catalogFeedCoversSpace">8dp</dimen>
2525
<dimen name="catalogLaneCoverMaximumWidth">96dp</dimen>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
<string name="catalogSearch">Search</string>
9292
<string name="catalogDurationFormat">%1$s hours, %2$s minutes</string>
9393

94+
<string name="catalogBookCellBorrowingUntil">Borrowed until %1$s</string>
95+
9496
<string name="catalogBookDetailBorrowingFor">Borrowing for</string>
9597
<string name="catalogBookDetailBorrowedUntil">Borrowed until</string>
9698

0 commit comments

Comments
 (0)