mirror of
https://github.com/tateisu/SubwayTooter
synced 2025-02-09 16:48:47 +01:00
リファクタ。あとmisskey v11でミュート一覧を読めなかったバグの修正
This commit is contained in:
parent
75d399f988
commit
f482b3bff1
@ -23,6 +23,10 @@ abstract class ColumnTask(
|
||||
val ctType : ColumnTaskType
|
||||
) : AsyncTask<Void, Void, TootApiResult?>() {
|
||||
|
||||
override fun onCancelled(result : TootApiResult?) {
|
||||
onPostExecute(null)
|
||||
}
|
||||
|
||||
val ctStarted = AtomicBoolean(false)
|
||||
val ctClosed = AtomicBoolean(false)
|
||||
|
||||
|
@ -19,12 +19,141 @@ class ColumnTask_Gap(
|
||||
) : ColumnTask(columnArg, ColumnTaskType.GAP) {
|
||||
|
||||
companion object {
|
||||
private val log = LogCategory("CT_Gap")
|
||||
internal val log = LogCategory("CT_Gap")
|
||||
}
|
||||
|
||||
private var max_id : EntityId? = gap.max_id
|
||||
private var since_id : EntityId? = gap.since_id
|
||||
|
||||
override fun doInBackground(vararg unused : Void) : TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
override val isApiCancelled : Boolean
|
||||
get() = isCancelled || column.is_dispose.get()
|
||||
|
||||
override fun publishApiProgress(s : String) {
|
||||
runOnMainLooper {
|
||||
if(isCancelled) return@runOnMainLooper
|
||||
column.task_progress = s
|
||||
column.fireShowContent(reason = "gap progress", changeList = ArrayList())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
client.account = access_info
|
||||
|
||||
try {
|
||||
return (columnTypeProcMap[column.column_type] ?: columnTypeProcMap[Column.TYPE_HOME])
|
||||
.gap(this, client)
|
||||
|
||||
} finally {
|
||||
try {
|
||||
column.updateRelation(client, list_tmp, column.who_account, parser)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
|
||||
ctClosed.set(true)
|
||||
runOnMainLooperDelayed(333L) {
|
||||
if(! isCancelled) column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostExecute(result : TootApiResult?) {
|
||||
if(column.is_dispose.get()) return
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
column.lastTask = null
|
||||
column.bRefreshLoading = false
|
||||
|
||||
val error = result.error
|
||||
if(error != null) {
|
||||
column.mRefreshLoadingError = error
|
||||
column.fireShowContent(reason = "gap error", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
val list_tmp = this.list_tmp
|
||||
if(list_tmp == null) {
|
||||
column.fireShowContent(reason = "gap list_tmp is null", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_tmp)
|
||||
// 0個でもギャップを消すために以下の処理を続ける
|
||||
|
||||
val changeList = ArrayList<AdapterChange>()
|
||||
|
||||
column.replaceConversationSummary(changeList, list_new, column.list_data)
|
||||
|
||||
val added = list_new.size // may 0
|
||||
|
||||
val position = column.list_data.indexOf(gap)
|
||||
if(position == - 1) {
|
||||
log.d("gap not found..")
|
||||
column.fireShowContent(reason = "gap not found", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
// idx番目の要素がListViewのtopから何ピクセル下にあるか
|
||||
var restore_idx = position + 1
|
||||
var restore_y = 0
|
||||
val holder = column.viewHolder
|
||||
if(holder != null) {
|
||||
try {
|
||||
restore_y = holder.getListItemOffset(restore_idx)
|
||||
} catch(ex : IndexOutOfBoundsException) {
|
||||
restore_idx = position
|
||||
try {
|
||||
restore_y = holder.getListItemOffset(restore_idx)
|
||||
} catch(ex2 : IndexOutOfBoundsException) {
|
||||
restore_idx = - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column.list_data.removeAt(position)
|
||||
column.list_data.addAll(position, list_new)
|
||||
|
||||
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, position))
|
||||
if(added > 0) {
|
||||
changeList.add(
|
||||
AdapterChange(
|
||||
AdapterChangeType.RangeInsert,
|
||||
position,
|
||||
added
|
||||
)
|
||||
)
|
||||
}
|
||||
column.fireShowContent(reason = "gap updated", changeList = changeList)
|
||||
|
||||
if(holder != null) {
|
||||
if(restore_idx >= 0) {
|
||||
// ギャップが画面内にあるなら
|
||||
holder.setListItemTop(restore_idx + added - 1, restore_y)
|
||||
} else {
|
||||
// ギャップが画面内にない場合、何もしない
|
||||
}
|
||||
} else {
|
||||
val scroll_save = column.scroll_save
|
||||
if(scroll_save != null) {
|
||||
scroll_save.adapterIndex += added - 1
|
||||
}
|
||||
}
|
||||
|
||||
column.updateMisskeyCapture()
|
||||
} finally {
|
||||
column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun getAccountList(
|
||||
client : TootApiClient,
|
||||
path_base : String,
|
||||
@ -640,136 +769,4 @@ class ColumnTask_Gap(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun doInBackground(vararg unused : Void) : TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
override val isApiCancelled : Boolean
|
||||
get() = isCancelled || column.is_dispose.get()
|
||||
|
||||
override fun publishApiProgress(s : String) {
|
||||
runOnMainLooper {
|
||||
if(isCancelled) return@runOnMainLooper
|
||||
column.task_progress = s
|
||||
column.fireShowContent(reason = "gap progress", changeList = ArrayList())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
client.account = access_info
|
||||
|
||||
try {
|
||||
return (columnTypeProcMap[column.column_type]?:columnTypeProcMap[Column.TYPE_HOME])
|
||||
.procGap(this,client)
|
||||
|
||||
} finally {
|
||||
try {
|
||||
column.updateRelation(client, list_tmp, column.who_account, parser)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
|
||||
ctClosed.set(true)
|
||||
runOnMainLooperDelayed(333L) {
|
||||
if(! isCancelled) column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancelled(result : TootApiResult?) {
|
||||
onPostExecute(null)
|
||||
}
|
||||
|
||||
override fun onPostExecute(result : TootApiResult?) {
|
||||
if(column.is_dispose.get()) return
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
column.lastTask = null
|
||||
column.bRefreshLoading = false
|
||||
|
||||
val error = result.error
|
||||
if(error != null) {
|
||||
column.mRefreshLoadingError = error
|
||||
column.fireShowContent(reason = "gap error", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
val list_tmp = this.list_tmp
|
||||
if(list_tmp == null) {
|
||||
column.fireShowContent(reason = "gap list_tmp is null", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_tmp)
|
||||
// 0個でもギャップを消すために以下の処理を続ける
|
||||
|
||||
val changeList = ArrayList<AdapterChange>()
|
||||
|
||||
column.replaceConversationSummary(changeList, list_new, column.list_data)
|
||||
|
||||
val added = list_new.size // may 0
|
||||
|
||||
val position = column.list_data.indexOf(gap)
|
||||
if(position == - 1) {
|
||||
log.d("gap not found..")
|
||||
column.fireShowContent(reason = "gap not found", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
// idx番目の要素がListViewのtopから何ピクセル下にあるか
|
||||
var restore_idx = position + 1
|
||||
var restore_y = 0
|
||||
val holder = column.viewHolder
|
||||
if(holder != null) {
|
||||
try {
|
||||
restore_y = holder.getListItemOffset(restore_idx)
|
||||
} catch(ex : IndexOutOfBoundsException) {
|
||||
restore_idx = position
|
||||
try {
|
||||
restore_y = holder.getListItemOffset(restore_idx)
|
||||
} catch(ex2 : IndexOutOfBoundsException) {
|
||||
restore_idx = - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column.list_data.removeAt(position)
|
||||
column.list_data.addAll(position, list_new)
|
||||
|
||||
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, position))
|
||||
if(added > 0) {
|
||||
changeList.add(
|
||||
AdapterChange(
|
||||
AdapterChangeType.RangeInsert,
|
||||
position,
|
||||
added
|
||||
)
|
||||
)
|
||||
}
|
||||
column.fireShowContent(reason = "gap updated", changeList = changeList)
|
||||
|
||||
if(holder != null) {
|
||||
if(restore_idx >= 0) {
|
||||
// ギャップが画面内にあるなら
|
||||
holder.setListItemTop(restore_idx + added - 1, restore_y)
|
||||
} else {
|
||||
// ギャップが画面内にない場合、何もしない
|
||||
}
|
||||
} else {
|
||||
val scroll_save = column.scroll_save
|
||||
if(scroll_save != null) {
|
||||
scroll_save.adapterIndex += added - 1
|
||||
}
|
||||
}
|
||||
|
||||
column.updateMisskeyCapture()
|
||||
} finally {
|
||||
column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package jp.juggler.subwaytooter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.SystemClock
|
||||
import android.view.Gravity
|
||||
import jp.juggler.subwaytooter.api.TootApiCallback
|
||||
import jp.juggler.subwaytooter.api.TootApiClient
|
||||
import jp.juggler.subwaytooter.api.TootApiResult
|
||||
@ -15,19 +13,98 @@ import org.json.JSONObject
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
class ColumnTask_Loading(
|
||||
columnArg : Column
|
||||
) : ColumnTask(columnArg, ColumnTaskType.LOADING) {
|
||||
|
||||
companion object {
|
||||
val log = LogCategory("CT_Loading")
|
||||
internal val log = LogCategory("CT_Loading")
|
||||
}
|
||||
|
||||
internal var instance_tmp : TootInstance? = null
|
||||
|
||||
internal var list_pinned : ArrayList<TimelineItem>? = null
|
||||
|
||||
override fun doInBackground(vararg unused : Void) : TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
if(Pref.bpInstanceTicker(pref)) {
|
||||
InstanceTicker.load()
|
||||
}
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
override val isApiCancelled : Boolean
|
||||
get() = isCancelled || column.is_dispose.get()
|
||||
|
||||
override fun publishApiProgress(s : String) {
|
||||
runOnMainLooper {
|
||||
if(isCancelled) return@runOnMainLooper
|
||||
column.task_progress = s
|
||||
column.fireShowContent(reason = "loading progress", changeList = ArrayList())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
client.account = access_info
|
||||
|
||||
try {
|
||||
val result : TootApiResult? = access_info.checkConfirmed(context, client)
|
||||
if(result == null || result.error != null) return result
|
||||
|
||||
column.muted_word2 = column.encodeFilterTree(column.loadFilter2(client))
|
||||
|
||||
return (columnTypeProcMap[column.column_type] ?: columnTypeProcMap[Column.TYPE_HOME])
|
||||
.loading(this, client)
|
||||
|
||||
} finally {
|
||||
try {
|
||||
column.updateRelation(client, list_tmp, column.who_account, parser)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
ctClosed.set(true)
|
||||
runOnMainLooperDelayed(333L) {
|
||||
if(! isCancelled) column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostExecute(result : TootApiResult?) {
|
||||
if(column.is_dispose.get()) return
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
return
|
||||
}
|
||||
|
||||
column.bInitialLoading = false
|
||||
column.lastTask = null
|
||||
|
||||
if(result.error != null) {
|
||||
column.mInitialLoadingError = result.error ?: ""
|
||||
} else {
|
||||
column.duplicate_map.clear()
|
||||
column.list_data.clear()
|
||||
val list_tmp = this.list_tmp
|
||||
if(list_tmp != null) {
|
||||
val list_pinned = this.list_pinned
|
||||
if(list_pinned?.isNotEmpty() == true) {
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_pinned)
|
||||
column.list_data.addAll(list_new)
|
||||
}
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_tmp)
|
||||
column.list_data.addAll(list_new)
|
||||
}
|
||||
|
||||
column.resumeStreaming(false)
|
||||
}
|
||||
column.fireShowContent(reason = "loading updated", reset = true)
|
||||
|
||||
// 初期ロードの直後は先頭に移動する
|
||||
column.viewHolder?.scrollToTop()
|
||||
|
||||
column.updateMisskeyCapture()
|
||||
}
|
||||
|
||||
internal fun getInstanceInformation(
|
||||
client : TootApiClient,
|
||||
instance_name : String?
|
||||
@ -62,7 +139,7 @@ class ColumnTask_Loading(
|
||||
log.d("getStatusesPinned: list size=%s", list_pinned?.size ?: - 1)
|
||||
}
|
||||
|
||||
internal fun getStatuses(
|
||||
internal fun getStatusList(
|
||||
client : TootApiClient,
|
||||
path_base : String?,
|
||||
aroundMin : Boolean = false,
|
||||
@ -403,7 +480,7 @@ class ColumnTask_Loading(
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun parseAccountList(
|
||||
internal fun getAccountList(
|
||||
client : TootApiClient,
|
||||
path_base : String,
|
||||
emptyMessage : String? = null,
|
||||
@ -480,7 +557,7 @@ class ColumnTask_Loading(
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun parseDomainList(
|
||||
internal fun getDomainList(
|
||||
client : TootApiClient,
|
||||
path_base : String
|
||||
) : TootApiResult? {
|
||||
@ -493,7 +570,7 @@ class ColumnTask_Loading(
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun parseReports(client : TootApiClient, path_base : String) : TootApiResult? {
|
||||
internal fun getReportList(client : TootApiClient, path_base : String) : TootApiResult? {
|
||||
val result = client.request(path_base)
|
||||
if(result != null) {
|
||||
val src = parseList(::TootReport, result.jsonArray)
|
||||
@ -522,7 +599,7 @@ class ColumnTask_Loading(
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun parseNotifications(
|
||||
internal fun getNotificationList(
|
||||
client : TootApiClient,
|
||||
fromAcct : String? = null
|
||||
) : TootApiResult? {
|
||||
@ -606,7 +683,10 @@ class ColumnTask_Loading(
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun getPublicAroundStatuses(client : TootApiClient, url : String) : TootApiResult? {
|
||||
internal fun getPublicAroundStatuses(
|
||||
client : TootApiClient,
|
||||
url : String
|
||||
) : TootApiResult? {
|
||||
// (Mastodonのみ対応)
|
||||
|
||||
var instance = access_info.instance
|
||||
@ -633,14 +713,14 @@ class ColumnTask_Loading(
|
||||
var bInstanceTooOld = false
|
||||
if(instance?.versionGE(TootInstance.VERSION_2_6_0) == true) {
|
||||
// 指定より新しいトゥート
|
||||
result = getStatuses(client, url, aroundMin = true)
|
||||
result = getStatusList(client, url, aroundMin = true)
|
||||
if(result == null || result.error != null) return result
|
||||
} else {
|
||||
bInstanceTooOld = true
|
||||
}
|
||||
|
||||
// 指定位置より古いトゥート
|
||||
result = getStatuses(client, url, aroundMax = true)
|
||||
result = getStatusList(client, url, aroundMax = true)
|
||||
if(result == null || result.error != null) return result
|
||||
|
||||
list_tmp?.sortBy { it.getOrderId() }
|
||||
@ -685,14 +765,14 @@ class ColumnTask_Loading(
|
||||
var bInstanceTooOld = false
|
||||
if(instance?.versionGE(TootInstance.VERSION_2_6_0) == true) {
|
||||
// 指定より新しいトゥート
|
||||
result = getStatuses(client, path, aroundMin = true)
|
||||
result = getStatusList(client, path, aroundMin = true)
|
||||
if(result == null || result.error != null) return result
|
||||
} else {
|
||||
bInstanceTooOld = true
|
||||
}
|
||||
|
||||
// 指定位置より古いトゥート
|
||||
result = getStatuses(client, path, aroundMax = true)
|
||||
result = getStatusList(client, path, aroundMax = true)
|
||||
if(result == null || result.error != null) return result
|
||||
|
||||
list_tmp?.sortBy { it.getOrderId() }
|
||||
@ -718,88 +798,5 @@ class ColumnTask_Loading(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun doInBackground(vararg unused : Void) : TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
if(Pref.bpInstanceTicker(pref)) {
|
||||
InstanceTicker.load()
|
||||
}
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
override val isApiCancelled : Boolean
|
||||
get() = isCancelled || column.is_dispose.get()
|
||||
|
||||
override fun publishApiProgress(s : String) {
|
||||
runOnMainLooper {
|
||||
if(isCancelled) return@runOnMainLooper
|
||||
column.task_progress = s
|
||||
column.fireShowContent(reason = "loading progress", changeList = ArrayList())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
client.account = access_info
|
||||
|
||||
|
||||
try {
|
||||
val result : TootApiResult? = access_info.checkConfirmed(context, client)
|
||||
if(result == null || result.error != null) return result
|
||||
|
||||
column.muted_word2 = column.encodeFilterTree(column.loadFilter2(client))
|
||||
|
||||
return (columnTypeProcMap[column.column_type]?:columnTypeProcMap[Column.TYPE_HOME])
|
||||
.procLoading(this,client)
|
||||
|
||||
} finally {
|
||||
try {
|
||||
column.updateRelation(client, list_tmp, column.who_account, parser)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
ctClosed.set(true)
|
||||
runOnMainLooperDelayed(333L) {
|
||||
if(! isCancelled) column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancelled(result : TootApiResult?) {
|
||||
onPostExecute(null)
|
||||
}
|
||||
|
||||
override fun onPostExecute(result : TootApiResult?) {
|
||||
if(column.is_dispose.get()) return
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
return
|
||||
}
|
||||
|
||||
column.bInitialLoading = false
|
||||
column.lastTask = null
|
||||
|
||||
if(result.error != null) {
|
||||
column.mInitialLoadingError = result.error ?: ""
|
||||
} else {
|
||||
column.duplicate_map.clear()
|
||||
column.list_data.clear()
|
||||
val list_tmp = this.list_tmp
|
||||
if(list_tmp != null) {
|
||||
val list_pinned = this.list_pinned
|
||||
if(list_pinned?.isNotEmpty() == true) {
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_pinned)
|
||||
column.list_data.addAll(list_new)
|
||||
}
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_tmp)
|
||||
column.list_data.addAll(list_new)
|
||||
}
|
||||
|
||||
column.resumeStreaming(false)
|
||||
}
|
||||
column.fireShowContent(reason = "loading updated", reset = true)
|
||||
|
||||
// 初期ロードの直後は先頭に移動する
|
||||
column.viewHolder?.scrollToTop()
|
||||
|
||||
column.updateMisskeyCapture()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package jp.juggler.subwaytooter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.SystemClock
|
||||
import jp.juggler.subwaytooter.api.TootApiCallback
|
||||
import jp.juggler.subwaytooter.api.TootApiClient
|
||||
@ -12,10 +11,9 @@ import jp.juggler.util.*
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
class ColumnTask_Refresh(
|
||||
columnArg : Column,
|
||||
internal val bSilent : Boolean,
|
||||
private val bSilent : Boolean,
|
||||
internal val bBottom : Boolean,
|
||||
internal val posted_status_id : EntityId? = null,
|
||||
internal val refresh_after_toot : Int = - 1
|
||||
@ -25,7 +23,183 @@ class ColumnTask_Refresh(
|
||||
) {
|
||||
|
||||
companion object {
|
||||
val log = LogCategory("CT_Refresh")
|
||||
internal val log = LogCategory("CT_Refresh")
|
||||
}
|
||||
|
||||
private var filterUpdated = false
|
||||
|
||||
override fun doInBackground(vararg unused : Void) : TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
override val isApiCancelled : Boolean
|
||||
get() = isCancelled || column.is_dispose.get()
|
||||
|
||||
override fun publishApiProgress(s : String) {
|
||||
runOnMainLooper {
|
||||
if(isCancelled) return@runOnMainLooper
|
||||
column.task_progress = s
|
||||
column.fireShowContent(reason = "refresh progress", changeList = ArrayList())
|
||||
}
|
||||
}
|
||||
})
|
||||
client.account = access_info
|
||||
try {
|
||||
|
||||
if(! bBottom) {
|
||||
val filterList = column.loadFilter2(client)
|
||||
if(filterList != null) {
|
||||
column.muted_word2 = column.encodeFilterTree(filterList)
|
||||
filterUpdated = true
|
||||
}
|
||||
}
|
||||
|
||||
return (columnTypeProcMap[column.column_type] ?: columnTypeProcMap[Column.TYPE_HOME])
|
||||
.refresh(this, client)
|
||||
} finally {
|
||||
try {
|
||||
column.updateRelation(client, list_tmp, column.who_account, parser)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
ctClosed.set(true)
|
||||
runOnMainLooperDelayed(333L) {
|
||||
if(! isCancelled) column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostExecute(result : TootApiResult?) {
|
||||
if(column.is_dispose.get()) return
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
column.lastTask = null
|
||||
column.bRefreshLoading = false
|
||||
|
||||
if(filterUpdated) {
|
||||
column.checkFiltersForListData(column.muted_word2)
|
||||
}
|
||||
|
||||
val error = result.error
|
||||
if(error != null) {
|
||||
column.mRefreshLoadingError = error
|
||||
column.mRefreshLoadingErrorTime = SystemClock.elapsedRealtime()
|
||||
column.fireShowContent(reason = "refresh error", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_tmp)
|
||||
if(list_new.isEmpty()) {
|
||||
column.fireShowContent(
|
||||
reason = "refresh list_new is empty",
|
||||
changeList = ArrayList()
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// 事前にスクロール位置を覚えておく
|
||||
var sp : ScrollPosition? = null
|
||||
val holder = column.viewHolder
|
||||
if(holder != null) {
|
||||
sp = holder.scrollPosition
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bBottom) {
|
||||
val changeList = listOf(
|
||||
AdapterChange(
|
||||
AdapterChangeType.RangeInsert,
|
||||
column.list_data.size,
|
||||
list_new.size
|
||||
)
|
||||
)
|
||||
column.list_data.addAll(list_new)
|
||||
column.fireShowContent(reason = "refresh updated bottom", changeList = changeList)
|
||||
|
||||
// 新着が少しだけ見えるようにスクロール位置を移動する
|
||||
if(sp != null) {
|
||||
holder?.setScrollPosition(sp, 20f)
|
||||
}
|
||||
} else {
|
||||
|
||||
val changeList = ArrayList<AdapterChange>()
|
||||
|
||||
if(column.list_data.isNotEmpty() && column.list_data[0] is TootGap) {
|
||||
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, 0, 1))
|
||||
column.list_data.removeAt(0)
|
||||
}
|
||||
|
||||
for(o in list_new) {
|
||||
if(o is TootStatus) {
|
||||
val highlight_sound = o.highlight_sound
|
||||
if(highlight_sound != null) {
|
||||
App1.sound(highlight_sound)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column.replaceConversationSummary(changeList, list_new, column.list_data)
|
||||
|
||||
val added = list_new.size // may 0
|
||||
|
||||
// 投稿後のリフレッシュなら当該投稿の位置を探す
|
||||
var status_index = - 1
|
||||
for(i in 0 until added) {
|
||||
val o = list_new[i]
|
||||
if(o is TootStatus && o.id == posted_status_id) {
|
||||
status_index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
changeList.add(AdapterChange(AdapterChangeType.RangeInsert, 0, added))
|
||||
column.list_data.addAll(0, list_new)
|
||||
column.fireShowContent(reason = "refresh updated head", changeList = changeList)
|
||||
|
||||
if(status_index >= 0 && refresh_after_toot == Pref.RAT_REFRESH_SCROLL) {
|
||||
// 投稿後にその投稿にスクロールする
|
||||
if(holder != null) {
|
||||
holder.setScrollPosition(
|
||||
ScrollPosition(column.toAdapterIndex(status_index)),
|
||||
0f
|
||||
)
|
||||
} else {
|
||||
column.scroll_save = ScrollPosition(column.toAdapterIndex(status_index))
|
||||
}
|
||||
} else {
|
||||
//
|
||||
val scroll_save = column.scroll_save
|
||||
when {
|
||||
// ViewHolderがある場合は増加件数分+deltaの位置にスクロールする
|
||||
sp != null -> {
|
||||
sp.adapterIndex += added
|
||||
val delta = if(bSilent) 0f else - 20f
|
||||
holder?.setScrollPosition(sp, delta)
|
||||
}
|
||||
// ViewHolderがなくて保存中の位置がある場合、増加件数分ずらす。deltaは難しいので反映しない
|
||||
scroll_save != null -> scroll_save.adapterIndex += added
|
||||
// 保存中の位置がない場合、保存中の位置を新しく作る
|
||||
else -> column.scroll_save =
|
||||
ScrollPosition(column.toAdapterIndex(added))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column.updateMisskeyCapture()
|
||||
|
||||
} finally {
|
||||
column.fireShowColumnStatus()
|
||||
|
||||
if(! bBottom) {
|
||||
column.bRefreshingTop = false
|
||||
column.resumeStreaming(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun getAccountList(
|
||||
@ -406,7 +580,7 @@ class ColumnTask_Refresh(
|
||||
var result = if(isMisskey) {
|
||||
client.request(
|
||||
path_base,
|
||||
params.addRangeMisskey( bBottom).toPostRequestBuilder()
|
||||
params.addRangeMisskey(bBottom).toPostRequestBuilder()
|
||||
)
|
||||
} else {
|
||||
client.request(column.addRange(bBottom, path_base))
|
||||
@ -624,7 +798,7 @@ class ColumnTask_Refresh(
|
||||
var result = when {
|
||||
isMisskey -> client.request(
|
||||
path_base,
|
||||
params.addRangeMisskey( bBottom).toPostRequestBuilder()
|
||||
params.addRangeMisskey(bBottom).toPostRequestBuilder()
|
||||
)
|
||||
|
||||
aroundMin -> client.request(column.addRangeMin(path_base))
|
||||
@ -895,7 +1069,7 @@ class ColumnTask_Refresh(
|
||||
var result = when {
|
||||
isMisskey -> client.request(
|
||||
path_base,
|
||||
params.addRangeMisskey( bBottom).toPostRequestBuilder()
|
||||
params.addRangeMisskey(bBottom).toPostRequestBuilder()
|
||||
)
|
||||
|
||||
aroundMin -> client.request(column.addRangeMin(path_base))
|
||||
@ -1135,183 +1309,4 @@ class ColumnTask_Refresh(
|
||||
return firstResult
|
||||
}
|
||||
|
||||
private var filterUpdated = false
|
||||
|
||||
override fun doInBackground(vararg unused : Void) : TootApiResult? {
|
||||
ctStarted.set(true)
|
||||
|
||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||
override val isApiCancelled : Boolean
|
||||
get() = isCancelled || column.is_dispose.get()
|
||||
|
||||
override fun publishApiProgress(s : String) {
|
||||
runOnMainLooper {
|
||||
if(isCancelled) return@runOnMainLooper
|
||||
column.task_progress = s
|
||||
column.fireShowContent(reason = "refresh progress", changeList = ArrayList())
|
||||
}
|
||||
}
|
||||
})
|
||||
client.account = access_info
|
||||
try {
|
||||
|
||||
if(! bBottom) {
|
||||
val filterList = column.loadFilter2(client)
|
||||
if(filterList != null) {
|
||||
column.muted_word2 = column.encodeFilterTree(filterList)
|
||||
filterUpdated = true
|
||||
}
|
||||
}
|
||||
|
||||
return (columnTypeProcMap[column.column_type]?:columnTypeProcMap[Column.TYPE_HOME])
|
||||
.procRefresh(this,client)
|
||||
} finally {
|
||||
try {
|
||||
column.updateRelation(client, list_tmp, column.who_account, parser)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
ctClosed.set(true)
|
||||
runOnMainLooperDelayed(333L) {
|
||||
if(! isCancelled) column.fireShowColumnStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancelled(result : TootApiResult?) {
|
||||
onPostExecute(null)
|
||||
}
|
||||
|
||||
override fun onPostExecute(result : TootApiResult?) {
|
||||
if(column.is_dispose.get()) return
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
column.lastTask = null
|
||||
column.bRefreshLoading = false
|
||||
|
||||
if(filterUpdated) {
|
||||
column.checkFiltersForListData(column.muted_word2)
|
||||
}
|
||||
|
||||
val error = result.error
|
||||
if(error != null) {
|
||||
column.mRefreshLoadingError = error
|
||||
column.mRefreshLoadingErrorTime = SystemClock.elapsedRealtime()
|
||||
column.fireShowContent(reason = "refresh error", changeList = ArrayList())
|
||||
return
|
||||
}
|
||||
|
||||
val list_new = column.duplicate_map.filterDuplicate(list_tmp)
|
||||
if(list_new.isEmpty()) {
|
||||
column.fireShowContent(
|
||||
reason = "refresh list_new is empty",
|
||||
changeList = ArrayList()
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// 事前にスクロール位置を覚えておく
|
||||
var sp : ScrollPosition? = null
|
||||
val holder = column.viewHolder
|
||||
if(holder != null) {
|
||||
sp = holder.scrollPosition
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bBottom) {
|
||||
val changeList = listOf(
|
||||
AdapterChange(
|
||||
AdapterChangeType.RangeInsert,
|
||||
column.list_data.size,
|
||||
list_new.size
|
||||
)
|
||||
)
|
||||
column.list_data.addAll(list_new)
|
||||
column.fireShowContent(reason = "refresh updated bottom", changeList = changeList)
|
||||
|
||||
// 新着が少しだけ見えるようにスクロール位置を移動する
|
||||
if(sp != null) {
|
||||
holder?.setScrollPosition(sp, 20f)
|
||||
}
|
||||
} else {
|
||||
|
||||
val changeList = ArrayList<AdapterChange>()
|
||||
|
||||
if(column.list_data.isNotEmpty() && column.list_data[0] is TootGap) {
|
||||
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, 0, 1))
|
||||
column.list_data.removeAt(0)
|
||||
}
|
||||
|
||||
for(o in list_new) {
|
||||
if(o is TootStatus) {
|
||||
val highlight_sound = o.highlight_sound
|
||||
if(highlight_sound != null) {
|
||||
App1.sound(highlight_sound)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column.replaceConversationSummary(changeList, list_new, column.list_data)
|
||||
|
||||
val added = list_new.size // may 0
|
||||
|
||||
// 投稿後のリフレッシュなら当該投稿の位置を探す
|
||||
var status_index = - 1
|
||||
for(i in 0 until added) {
|
||||
val o = list_new[i]
|
||||
if(o is TootStatus && o.id == posted_status_id) {
|
||||
status_index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
changeList.add(AdapterChange(AdapterChangeType.RangeInsert, 0, added))
|
||||
column.list_data.addAll(0, list_new)
|
||||
column.fireShowContent(reason = "refresh updated head", changeList = changeList)
|
||||
|
||||
if(status_index >= 0 && refresh_after_toot == Pref.RAT_REFRESH_SCROLL) {
|
||||
// 投稿後にその投稿にスクロールする
|
||||
if(holder != null) {
|
||||
holder.setScrollPosition(
|
||||
ScrollPosition(column.toAdapterIndex(status_index)),
|
||||
0f
|
||||
)
|
||||
} else {
|
||||
column.scroll_save = ScrollPosition(column.toAdapterIndex(status_index))
|
||||
}
|
||||
} else {
|
||||
//
|
||||
val scroll_save = column.scroll_save
|
||||
when {
|
||||
// ViewHolderがある場合は増加件数分+deltaの位置にスクロールする
|
||||
sp != null -> {
|
||||
sp.adapterIndex += added
|
||||
val delta = if(bSilent) 0f else - 20f
|
||||
holder?.setScrollPosition(sp, delta)
|
||||
}
|
||||
// ViewHolderがなくて保存中の位置がある場合、増加件数分ずらす。deltaは難しいので反映しない
|
||||
scroll_save != null -> scroll_save.adapterIndex += added
|
||||
// 保存中の位置がない場合、保存中の位置を新しく作る
|
||||
else -> column.scroll_save =
|
||||
ScrollPosition(column.toAdapterIndex(added))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column.updateMisskeyCapture()
|
||||
|
||||
} finally {
|
||||
column.fireShowColumnStatus()
|
||||
|
||||
if(! bBottom) {
|
||||
column.bRefreshingTop = false
|
||||
column.resumeStreaming(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -350,6 +350,25 @@ internal val misskeyCustomParserFollowRequest =
|
||||
dst
|
||||
}
|
||||
|
||||
internal val misskeyCustomParserMutes =
|
||||
{ parser : TootParser, jsonArray : JSONArray ->
|
||||
val dst = ArrayList<TootAccountRef>()
|
||||
for(i in 0 until jsonArray.length()) {
|
||||
val src = jsonArray.optJSONObject(i) ?: continue
|
||||
|
||||
val accountRef = TootAccountRef.mayNull(
|
||||
parser,
|
||||
parser.account(src.optJSONObject("mutee"))
|
||||
) ?: continue
|
||||
|
||||
val requestId = EntityId.mayNull(src.parseString("id")) ?: continue
|
||||
|
||||
accountRef._orderId = requestId
|
||||
|
||||
dst.add(accountRef)
|
||||
}
|
||||
dst
|
||||
}
|
||||
internal val misskeyCustomParserBlocks =
|
||||
{ parser : TootParser, jsonArray : JSONArray ->
|
||||
val dst = ArrayList<TootAccountRef>()
|
||||
@ -369,7 +388,6 @@ internal val misskeyCustomParserBlocks =
|
||||
}
|
||||
dst
|
||||
}
|
||||
|
||||
internal val misskeyCustomParserFavorites =
|
||||
{ parser : TootParser, jsonArray : JSONArray ->
|
||||
val dst = ArrayList<TootStatus>()
|
||||
|
Loading…
x
Reference in New Issue
Block a user