From 287c31f3eb81a691849bfad7e306b51f451d6523 Mon Sep 17 00:00:00 2001 From: birdbird <6892457-tzugen@users.noreply.gitlab.com> Date: Thu, 20 Oct 2022 10:59:28 +0000 Subject: [PATCH] Use Linear layout in Track display --- ultrasonic/lint-baseline.xml | 2 +- .../ultrasonic/adapters/TrackViewBinder.kt | 5 + .../ultrasonic/adapters/TrackViewHolder.kt | 59 ++++-- .../src/main/res/layout/list_item_track.xml | 174 ++++-------------- .../res/layout/list_item_track_details.xml | 102 ++++++++++ 5 files changed, 180 insertions(+), 162 deletions(-) create mode 100644 ultrasonic/src/main/res/layout/list_item_track_details.xml diff --git a/ultrasonic/lint-baseline.xml b/ultrasonic/lint-baseline.xml index 33ca3828..3bd04935 100644 --- a/ultrasonic/lint-baseline.xml +++ b/ultrasonic/lint-baseline.xml @@ -1,5 +1,5 @@ - + 0) { track.text = entryDescription.trackNumber } else { - track.isVisible = false + if (!track.isGone) track.isGone = true } - check.isVisible = (checkable && !song.isVideo) - initChecked(isSelected) - drag.isVisible = draggable + val checkValue = (checkable && !song.isVideo) + if (check.isVisible != checkValue) check.isVisible = checkValue + if (checkValue) initChecked(isSelected) + if (drag.isVisible != draggable) drag.isVisible = draggable if (ActiveServerProvider.isOffline()) { - star.isVisible = false - rating.isVisible = false + star.isGone = true } else { setupStarButtons(song, useFiveStarRating) } - updateStatus(DownloadService.getDownloadState(song), null) + // Instead of blocking the UI thread while looking up the current state, + // launch the request in an IO thread and propagate the result through RX + launch { + val state = DownloadService.getDownloadState(song) + RxBus.trackDownloadStatePublisher.onNext( + RxBus.TrackDownloadState(song.id, state, null) + ) + } if (useFiveStarRating) { setFiveStars(entry?.userRating ?: 0) @@ -103,8 +124,8 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable } if (song.isVideo) { - artist.isVisible = false - progressIndicator.isVisible = false + artist.isGone = true + progressIndicator.isGone = true } // Create new Disposable for the new Subscriptions @@ -117,6 +138,8 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable if (it.id != song.id) return@subscribe updateStatus(it.state, it.progress) } + + Timber.v("Setting song done") } // This is called when the Holder is recycled and receives a new Song @@ -145,13 +168,13 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable private fun setupStarButtons(song: Track, useFiveStarRating: Boolean) { if (useFiveStarRating) { // Hide single star - star.visibility = View.INVISIBLE + star.isGone = true + rating.isVisible = true val rating = if (song.userRating == null) 0 else song.userRating!! setFiveStars(rating) } else { - // Hide five stars - rating.isVisible = false - + star.isVisible = true + rating.isGone = true setSingleStar(song.starred) star.setOnClickListener { val isStarred = song.starred @@ -241,7 +264,7 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable } private fun showStatusImage(image: Int?) { - progressIndicator.isVisible = false + progressIndicator.isGone = true statusImage.isVisible = true if (image != null) { statusImage.setImageResource(image) @@ -251,7 +274,7 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable } private fun showIndefiniteProgress() { - statusImage.isVisible = false + statusImage.isGone = true progressIndicator.isVisible = true progressIndicator.isIndeterminate = true progressIndicator.indicatorDirection = @@ -260,7 +283,7 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable } private fun showProgress() { - statusImage.isVisible = false + statusImage.isGone = true progressIndicator.isVisible = true progressIndicator.isIndeterminate = false progressIndicator.indicatorDirection = diff --git a/ultrasonic/src/main/res/layout/list_item_track.xml b/ultrasonic/src/main/res/layout/list_item_track.xml index 55ebfb86..ab3cce4b 100644 --- a/ultrasonic/src/main/res/layout/list_item_track.xml +++ b/ultrasonic/src/main/res/layout/list_item_track.xml @@ -1,169 +1,45 @@ - + + a:layout_height="?android:attr/listPreferredItemHeight" + a:minHeight="?android:attr/listPreferredItemHeight" + a:orientation="horizontal"> + a:visibility="gone" /> + a:visibility="gone" /> - - - - - - - - - - - - - - - - - - - + + a:visibility="gone" + tools:visibility="visible"> - \ No newline at end of file + + + \ No newline at end of file diff --git a/ultrasonic/src/main/res/layout/list_item_track_details.xml b/ultrasonic/src/main/res/layout/list_item_track_details.xml new file mode 100644 index 00000000..0c73405b --- /dev/null +++ b/ultrasonic/src/main/res/layout/list_item_track_details.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file