Download state change would not be reflected in the list.

This commit is contained in:
Antoine POPINEAU 2020-06-14 21:15:13 +02:00
parent abff279df9
commit 098048ac49
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
2 changed files with 9 additions and 4 deletions

View File

@ -64,9 +64,9 @@ class DownloadsActivity : AppCompatActivity() {
} }
private suspend fun refreshTrack(download: Download) { private suspend fun refreshTrack(download: Download) {
if (download.state == Download.STATE_COMPLETED) { download.getMetadata()?.let { info ->
download.getMetadata()?.let { info -> adapter.downloads.withIndex().associate { it.value to it.index }.filter { it.key.id == info.id }.toList().getOrNull(0)?.let { match ->
adapter.downloads.withIndex().associate { it.value to it.index }.filter { it.key.id == info.id }.toList().getOrNull(0)?.let { match -> if (download.state != info.download?.state) {
withContext(Main) { withContext(Main) {
adapter.downloads[match.second] = info.apply { adapter.downloads[match.second] = info.apply {
this.download = download this.download = download

View File

@ -52,9 +52,14 @@ class DownloadsAdapter(private val context: Context, private val listener: OnDow
false -> { false -> {
holder.progress.visibility = View.VISIBLE holder.progress.visibility = View.VISIBLE
holder.toggle.visibility = View.VISIBLE holder.toggle.visibility = View.VISIBLE
holder.progress.isIndeterminate = false
holder.progress.progress = state.percentDownloaded.toInt() holder.progress.progress = state.percentDownloaded.toInt()
when (state.state) { when (state.state) {
Download.STATE_QUEUED -> {
holder.progress.isIndeterminate = true
}
Download.STATE_REMOVING -> { Download.STATE_REMOVING -> {
holder.progress.visibility = View.GONE holder.progress.visibility = View.GONE
holder.toggle.visibility = View.GONE holder.toggle.visibility = View.GONE
@ -69,7 +74,7 @@ class DownloadsAdapter(private val context: Context, private val listener: OnDow
holder.toggle.setOnClickListener { holder.toggle.setOnClickListener {
when (state.state) { when (state.state) {
Download.STATE_DOWNLOADING -> DownloadService.sendSetStopReason(context, PinService::class.java, download.contentId, 1, false) Download.STATE_QUEUED, Download.STATE_DOWNLOADING -> DownloadService.sendSetStopReason(context, PinService::class.java, download.contentId, 1, false)
Download.STATE_FAILED -> { Download.STATE_FAILED -> {
Track(download.id, download.title, Artist(0, download.artist, listOf()),Album(0, Album.Artist(""), "", Covers("")), 0, listOf(Track.Upload(download.contentId, 0, 0))).also { Track(download.id, download.title, Artist(0, download.artist, listOf()),Album(0, Album.Artist(""), "", Covers("")), 0, listOf(Track.Upload(download.contentId, 0, 0))).also {