細かい変更
This commit is contained in:
parent
e3522ef2c0
commit
bdce642d0e
|
@ -115,26 +115,26 @@ abstract class ColumnTask(
|
|||
return TootApiResult()
|
||||
}
|
||||
|
||||
|
||||
abstract suspend fun background() : TootApiResult?
|
||||
abstract suspend fun handleResult(result : TootApiResult?)
|
||||
|
||||
fun cancel() {
|
||||
job?.cancel()
|
||||
}
|
||||
|
||||
abstract suspend fun doInBackground() : TootApiResult?
|
||||
abstract suspend fun onPostExecute(result : TootApiResult?)
|
||||
|
||||
|
||||
fun start() {
|
||||
job = GlobalScope.launch(Dispatchers.Main) {
|
||||
val result = try {
|
||||
withContext(Dispatchers.IO) {
|
||||
doInBackground()
|
||||
handleResult(
|
||||
try {
|
||||
withContext(Dispatchers.IO) { background() }
|
||||
} catch(ex : CancellationException) {
|
||||
null // キャンセルされたらresult==nullとする
|
||||
} catch(ex : Throwable) {
|
||||
// その他のエラー
|
||||
TootApiResult(ex.withCaption("error"))
|
||||
}
|
||||
} catch(ex : CancellationException) {
|
||||
null // キャンセルされたらresult==nullとする
|
||||
} catch(ex : Throwable) {
|
||||
// その他のエラー
|
||||
TootApiResult(ex.withCaption("error"))
|
||||
}
|
||||
onPostExecute(result)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class ColumnTask_Gap(
|
|||
private var max_id: EntityId? = (gap as? TootGap)?.max_id
|
||||
private var since_id: EntityId? = (gap as? TootGap)?.since_id
|
||||
|
||||
override suspend fun doInBackground(): TootApiResult? {
|
||||
override suspend fun background(): TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
|
@ -62,7 +62,7 @@ class ColumnTask_Gap(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun onPostExecute(result: TootApiResult?) {
|
||||
override suspend fun handleResult(result: TootApiResult?) {
|
||||
if (column.is_dispose.get()) return
|
||||
|
||||
if (isCancelled || result == null) {
|
||||
|
|
|
@ -19,7 +19,7 @@ class ColumnTask_Loading(
|
|||
|
||||
internal var list_pinned: ArrayList<TimelineItem>? = null
|
||||
|
||||
override suspend fun doInBackground(): TootApiResult? {
|
||||
override suspend fun background(): TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
if (Pref.bpOpenSticker(pref)) {
|
||||
|
@ -72,7 +72,7 @@ class ColumnTask_Loading(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun onPostExecute(result: TootApiResult?) {
|
||||
override suspend fun handleResult(result: TootApiResult?) {
|
||||
if (column.is_dispose.get()) return
|
||||
|
||||
if (isCancelled || result == null) {
|
||||
|
|
|
@ -23,7 +23,7 @@ class ColumnTask_Refresh(
|
|||
|
||||
private var filterUpdated = false
|
||||
|
||||
override suspend fun doInBackground(): TootApiResult? {
|
||||
override suspend fun background(): TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
|
@ -65,7 +65,7 @@ class ColumnTask_Refresh(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun onPostExecute(result: TootApiResult?) {
|
||||
override suspend fun handleResult(result: TootApiResult?) {
|
||||
if (column.is_dispose.get()) return
|
||||
|
||||
if (isCancelled || result == null) {
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.*
|
|||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
/*
|
||||
JobScheduerに登録する & アプリ内部でも保持するジョブのリスト。
|
||||
JobSchedulerに登録する & アプリ内部でも保持するジョブのリスト。
|
||||
アプリ内部で保持するのは主にサービス完了通知のせい
|
||||
* */
|
||||
class JobItem(
|
||||
|
@ -112,13 +112,13 @@ class JobItem(
|
|||
TaskRunner(pollingWorker, this@JobItem, TaskId.Polling, JsonObject()).runTask()
|
||||
}
|
||||
|
||||
log.d("pollingComplete=${bPollingComplete},isJobCancelled=${isJobCancelled},bPollingRequired=${bPollingRequired.get()}")
|
||||
log.w("pollingComplete=${bPollingComplete},isJobCancelled=${isJobCancelled},bPollingRequired=${bPollingRequired.get()}")
|
||||
if (!isJobCancelled && bPollingComplete) {
|
||||
// ポーリングが完了した
|
||||
pollingWorker.onPollingComplete(bPollingRequired.get())
|
||||
}
|
||||
} catch (ex: JobCancelledException) {
|
||||
log.e("job execution cancelled.")
|
||||
log.w("job execution cancelled.")
|
||||
} catch (ex: Throwable) {
|
||||
log.trace(ex)
|
||||
log.e(ex, "job execution failed.")
|
||||
|
|
Loading…
Reference in New Issue