2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.util
|
|
|
|
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAttachment
|
2022-01-05 10:39:48 +01:00
|
|
|
import kotlinx.coroutines.Job
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2021-06-20 15:12:25 +02:00
|
|
|
class PostAttachment : Comparable<PostAttachment> {
|
|
|
|
interface Callback {
|
|
|
|
fun onPostAttachmentComplete(pa: PostAttachment)
|
2022-01-05 10:39:48 +01:00
|
|
|
fun onPostAttachmentProgress()
|
2021-06-20 15:12:25 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 06:14:25 +02:00
|
|
|
enum class Status(val id: Int) {
|
|
|
|
Progress(1),
|
|
|
|
Ok(2),
|
|
|
|
Error(3),
|
|
|
|
}
|
2021-06-20 15:12:25 +02:00
|
|
|
|
2022-01-05 10:39:48 +01:00
|
|
|
var isCancelled = false
|
|
|
|
val job = Job()
|
2021-06-23 06:14:25 +02:00
|
|
|
var status: Status
|
|
|
|
var attachment: TootAttachment? = null
|
2021-06-20 15:12:25 +02:00
|
|
|
var callback: Callback? = null
|
2022-03-11 00:11:49 +01:00
|
|
|
var progress = ""
|
|
|
|
set(value) {
|
|
|
|
if (field != value) {
|
2022-01-05 10:39:48 +01:00
|
|
|
field = value
|
|
|
|
callback?.onPostAttachmentProgress()
|
|
|
|
}
|
|
|
|
}
|
2021-06-20 15:12:25 +02:00
|
|
|
|
|
|
|
constructor(callback: Callback) {
|
2021-06-23 06:14:25 +02:00
|
|
|
this.status = Status.Progress
|
2021-06-20 15:12:25 +02:00
|
|
|
this.callback = callback
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(a: TootAttachment) {
|
2021-06-23 06:14:25 +02:00
|
|
|
this.status = Status.Ok
|
2021-06-20 15:12:25 +02:00
|
|
|
this.attachment = a
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun compareTo(other: PostAttachment): Int {
|
|
|
|
val ta = this.attachment
|
|
|
|
val tb = other.attachment
|
|
|
|
return if (ta != null) {
|
|
|
|
if (tb == null) 1 else ta.id.compareTo(tb.id)
|
|
|
|
} else {
|
|
|
|
if (tb == null) 0 else -1
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|