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