2021-06-28 09:09:00 +02:00
|
|
|
package jp.juggler.subwaytooter.actmain
|
2021-06-23 06:14:25 +02:00
|
|
|
|
|
|
|
import android.content.Intent
|
2021-06-28 09:09:00 +02:00
|
|
|
import jp.juggler.subwaytooter.ActMain
|
|
|
|
import jp.juggler.subwaytooter.ActPost
|
2021-06-23 06:14:25 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.Acct
|
|
|
|
import jp.juggler.subwaytooter.api.entity.EntityId
|
2022-03-15 12:39:37 +01:00
|
|
|
import jp.juggler.subwaytooter.column.*
|
|
|
|
import jp.juggler.subwaytooter.pref.PrefI
|
|
|
|
import jp.juggler.util.decodeJsonObject
|
2021-06-23 06:14:25 +02:00
|
|
|
import jp.juggler.util.isLiveActivity
|
|
|
|
|
|
|
|
// マルチウィンドウモードでは投稿画面から直接呼ばれる
|
|
|
|
// 通常モードでは activityResultHandler 経由で呼ばれる
|
|
|
|
fun ActMain.onCompleteActPost(data: Intent) {
|
|
|
|
if (!isLiveActivity) return
|
2022-03-15 12:39:37 +01:00
|
|
|
|
|
|
|
this.postedAcct = data.getStringExtra(ActPost.EXTRA_POSTED_ACCT)?.let { Acct.parse(it) }
|
2021-06-23 06:14:25 +02:00
|
|
|
if (data.extras?.containsKey(ActPost.EXTRA_POSTED_STATUS_ID) == true) {
|
|
|
|
postedStatusId = EntityId.from(data, ActPost.EXTRA_POSTED_STATUS_ID)
|
|
|
|
postedReplyId = EntityId.from(data, ActPost.EXTRA_POSTED_REPLY_ID)
|
|
|
|
postedRedraftId = EntityId.from(data, ActPost.EXTRA_POSTED_REDRAFT_ID)
|
2022-03-15 12:39:37 +01:00
|
|
|
|
|
|
|
val postedStatusId = postedStatusId
|
|
|
|
val statusJson = data.getStringExtra(ActPost.KEY_EDIT_STATUS)
|
|
|
|
?.decodeJsonObject()
|
|
|
|
if (statusJson != null && postedStatusId != null) {
|
|
|
|
appState.columnList
|
|
|
|
.filter { it.accessInfo.acct == postedAcct }
|
|
|
|
.forEach {
|
|
|
|
it.replaceStatus(postedStatusId, statusJson)
|
|
|
|
}
|
|
|
|
}
|
2021-06-23 06:14:25 +02:00
|
|
|
} else {
|
|
|
|
postedStatusId = null
|
|
|
|
}
|
|
|
|
if (isStartedEx) refreshAfterPost()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 簡易投稿なら直接呼ばれる
|
|
|
|
// ActPost経由なら画面復帰タイミングや onCompleteActPost から呼ばれる
|
|
|
|
fun ActMain.refreshAfterPost() {
|
|
|
|
val postedAcct = this.postedAcct
|
|
|
|
val postedStatusId = this.postedStatusId
|
|
|
|
|
|
|
|
if (postedAcct != null && postedStatusId == null) {
|
|
|
|
// 予約投稿なら予約投稿リストをリロードする
|
|
|
|
appState.columnList.forEach { column ->
|
|
|
|
if (column.type == ColumnType.SCHEDULED_STATUS &&
|
|
|
|
column.accessInfo.acct == postedAcct
|
|
|
|
) {
|
|
|
|
column.startLoading()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (postedAcct != null && postedStatusId != null) {
|
|
|
|
val postedRedraftId = this.postedRedraftId
|
|
|
|
if (postedRedraftId != null) {
|
|
|
|
val host = postedAcct.host
|
|
|
|
if (host != null) {
|
|
|
|
appState.columnList.forEach {
|
|
|
|
it.onStatusRemoved(host, postedRedraftId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.postedRedraftId = null
|
|
|
|
}
|
|
|
|
|
|
|
|
val refreshAfterToot = PrefI.ipRefreshAfterToot(pref)
|
|
|
|
if (refreshAfterToot != PrefI.RAT_DONT_REFRESH) {
|
|
|
|
appState.columnList
|
|
|
|
.filter { it.accessInfo.acct == postedAcct }
|
|
|
|
.forEach {
|
|
|
|
it.startRefreshForPost(
|
|
|
|
refreshAfterToot,
|
|
|
|
postedStatusId,
|
|
|
|
postedReplyId
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.postedAcct = null
|
|
|
|
this.postedStatusId = null
|
|
|
|
}
|