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) {
if (download.state == Download.STATE_COMPLETED) {
download.getMetadata()?.let { info ->
adapter.downloads.withIndex().associate { it.value to it.index }.filter { it.key.id == info.id }.toList().getOrNull(0)?.let { match ->
download.getMetadata()?.let { info ->
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) {
adapter.downloads[match.second] = info.apply {
this.download = download

View File

@ -52,9 +52,14 @@ class DownloadsAdapter(private val context: Context, private val listener: OnDow
false -> {
holder.progress.visibility = View.VISIBLE
holder.toggle.visibility = View.VISIBLE
holder.progress.isIndeterminate = false
holder.progress.progress = state.percentDownloaded.toInt()
when (state.state) {
Download.STATE_QUEUED -> {
holder.progress.isIndeterminate = true
}
Download.STATE_REMOVING -> {
holder.progress.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 {
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 -> {
Track(download.id, download.title, Artist(0, download.artist, listOf()),Album(0, Album.Artist(""), "", Covers("")), 0, listOf(Track.Upload(download.contentId, 0, 0))).also {