添付メディアアップロード用スレッドの待機時間を変更

This commit is contained in:
tateisu 2018-12-01 05:58:13 +09:00
parent ad620c95a6
commit 5ff7561dd5
2 changed files with 18 additions and 13 deletions

View File

@ -1658,7 +1658,11 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
// 投稿画面ごとに1スレッドだけ作成してバックグラウンド処理を行う
attachment_queue.add(AttachmentRequest(account, pa, uri, mime_type, onUploadEnd))
val oldWorker = attachment_worker
if(oldWorker == null || ! oldWorker.isAlive || oldWorker.isInterrupted) {
if(oldWorker == null
|| ! oldWorker.isAlive
|| oldWorker.isInterrupted
|| oldWorker.isCancelled.get()
) {
oldWorker?.cancel()
attachment_worker = AttachmentWorker().apply { start() }
} else {
@ -1668,7 +1672,8 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
inner class AttachmentWorker : WorkerBase() {
private val isCancelled = AtomicBoolean(false)
internal val isCancelled = AtomicBoolean(false)
override fun cancel() {
isCancelled.set(true)
notifyEx()
@ -1679,7 +1684,7 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
while(! isCancelled.get()) {
val item = attachment_queue.poll()
if(item == null) {
waitEx(86400)
waitEx(86400000L)
continue
}
val result = item.upload()

View File

@ -48,16 +48,16 @@ class CharacterGroup {
// 空白とみなす文字なら真
fun isWhitespace(cp : Int) : Boolean = mapWhitespace.get(cp,false)
internal val reWhitespace :Pattern by lazy {
val sb = StringBuilder()
sb.append("[\\s\\t\\x0d\\x0a")
for(i in 0 until mapWhitespace.size()){
val k = mapWhitespace.keyAt(i)
if( k > 0x20 ) sb.append(k.toChar())
}
sb.append("]+")
Pattern.compile(sb.toString())
}
internal val reWhitespace =Pattern.compile(
StringBuilder().apply{
append("[\\s\\t\\x0d\\x0a")
for(i in 0 until mapWhitespace.size()){
val k = mapWhitespace.keyAt(i)
if( k > 0x20 ) append(k.toChar())
}
append("]+")
}.toString()
)
// 文字列のリストからグループIDを決定する