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

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

View File

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