mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 01:20:29 +05:30
fix: wrong indicated download progress
This commit is contained in:
parent
5a73fd7cdb
commit
2abd184f78
@ -157,7 +157,6 @@ class DownloadService : LifecycleService() {
|
|||||||
* Download file and emit [DownloadStatus] to the collectors of [downloadFlow]
|
* Download file and emit [DownloadStatus] to the collectors of [downloadFlow]
|
||||||
* and notification.
|
* and notification.
|
||||||
*/
|
*/
|
||||||
@Suppress("KotlinConstantConditions")
|
|
||||||
private suspend fun downloadFile(item: DownloadItem) {
|
private suspend fun downloadFile(item: DownloadItem) {
|
||||||
downloadQueue[item.id] = true
|
downloadQueue[item.id] = true
|
||||||
val notificationBuilder = getNotificationBuilder(item)
|
val notificationBuilder = getNotificationBuilder(item)
|
||||||
@ -221,9 +220,11 @@ class DownloadService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (_: CancellationException) {
|
} catch (_: CancellationException) {
|
||||||
|
break
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
toastFromMainThread("${getString(R.string.download)}: ${e.message}")
|
toastFromMainThread("${getString(R.string.download)}: ${e.message}")
|
||||||
_downloadFlow.emit(item.id to DownloadStatus.Error(e.message.toString(), e))
|
_downloadFlow.emit(item.id to DownloadStatus.Error(e.message.toString(), e))
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
@ -233,14 +234,15 @@ class DownloadService : LifecycleService() {
|
|||||||
con.disconnect()
|
con.disconnect()
|
||||||
}
|
}
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val completed = totalRead < item.downloadSize
|
val completed = totalRead < item.downloadSize
|
||||||
if (completed) {
|
if (completed) {
|
||||||
_downloadFlow.emit(item.id to DownloadStatus.Paused)
|
|
||||||
} else {
|
|
||||||
_downloadFlow.emit(item.id to DownloadStatus.Completed)
|
_downloadFlow.emit(item.id to DownloadStatus.Completed)
|
||||||
|
} else {
|
||||||
|
_downloadFlow.emit(item.id to DownloadStatus.Paused)
|
||||||
}
|
}
|
||||||
|
|
||||||
setPauseNotification(notificationBuilder, item, completed)
|
setPauseNotification(notificationBuilder, item, completed)
|
||||||
@ -466,6 +468,18 @@ class DownloadService : LifecycleService() {
|
|||||||
).build()
|
).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getPauseAction(id: Int): NotificationCompat.Action {
|
||||||
|
val intent = Intent(this, NotificationReceiver::class.java)
|
||||||
|
.setAction(ACTION_DOWNLOAD_PAUSE)
|
||||||
|
.putExtra("id", id)
|
||||||
|
|
||||||
|
return NotificationCompat.Action.Builder(
|
||||||
|
R.drawable.ic_pause,
|
||||||
|
getString(R.string.pause),
|
||||||
|
PendingIntentCompat.getBroadcast(this, id, intent, FLAG_UPDATE_CURRENT, false)
|
||||||
|
).build()
|
||||||
|
}
|
||||||
|
|
||||||
private fun getStopAction(id: Int): NotificationCompat.Action {
|
private fun getStopAction(id: Int): NotificationCompat.Action {
|
||||||
val intent = Intent(this, NotificationReceiver::class.java).apply {
|
val intent = Intent(this, NotificationReceiver::class.java).apply {
|
||||||
action = ACTION_DOWNLOAD_STOP
|
action = ACTION_DOWNLOAD_STOP
|
||||||
@ -481,18 +495,6 @@ class DownloadService : LifecycleService() {
|
|||||||
).build()
|
).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPauseAction(id: Int): NotificationCompat.Action {
|
|
||||||
val intent = Intent(this, NotificationReceiver::class.java)
|
|
||||||
.setAction(ACTION_DOWNLOAD_PAUSE)
|
|
||||||
.putExtra("id", id)
|
|
||||||
|
|
||||||
return NotificationCompat.Action.Builder(
|
|
||||||
R.drawable.ic_pause,
|
|
||||||
getString(R.string.pause),
|
|
||||||
PendingIntentCompat.getBroadcast(this, id, intent, FLAG_UPDATE_CURRENT, false)
|
|
||||||
).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a [File] from the corresponding download directory and the file name
|
* Get a [File] from the corresponding download directory and the file name
|
||||||
*/
|
*/
|
||||||
|
@ -7,7 +7,6 @@ import android.text.format.DateUtils
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.time.format.FormatStyle
|
import java.time.format.FormatStyle
|
||||||
|
Loading…
Reference in New Issue
Block a user