Browse Source

Download state change would not be reflected in the list.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
098048ac49
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 6
      app/src/main/java/com/github/apognu/otter/activities/DownloadsActivity.kt
  2. 7
      app/src/main/java/com/github/apognu/otter/adapters/DownloadsAdapter.kt

6
app/src/main/java/com/github/apognu/otter/activities/DownloadsActivity.kt

@ -64,9 +64,9 @@ class DownloadsActivity : AppCompatActivity() { @@ -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

7
app/src/main/java/com/github/apognu/otter/adapters/DownloadsAdapter.kt

@ -52,9 +52,14 @@ class DownloadsAdapter(private val context: Context, private val listener: OnDow @@ -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 @@ -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 {

Loading…
Cancel
Save