コード整理

This commit is contained in:
tateisu 2023-11-27 07:33:53 +09:00
parent 5f403695f1
commit f4d014e404
5 changed files with 6 additions and 4 deletions

View File

@ -49,6 +49,7 @@ import kotlin.math.min
private val log = LogCategory("ActPostAttachment") private val log = LogCategory("ActPostAttachment")
// AppStateに保存する // AppStateに保存する
// シャローコピーなので attachmentList を変更する前後のどっちかで呼ばれてれば良い
fun ActPost.saveAttachmentList() { fun ActPost.saveAttachmentList() {
if (!isMultiWindowPost) appState.attachmentList = this.attachmentList if (!isMultiWindowPost) appState.attachmentList = this.attachmentList
} }

View File

@ -346,7 +346,6 @@ fun ActPost.initializeFromRedraftStatus(account: SavedAccount, jsonText: String)
val srcAttachments = baseStatus.media_attachments val srcAttachments = baseStatus.media_attachments
if (srcAttachments?.isNotEmpty() == true) { if (srcAttachments?.isNotEmpty() == true) {
saveAttachmentList()
this.attachmentList.clear() this.attachmentList.clear()
try { try {
for (src in srcAttachments) { for (src in srcAttachments) {
@ -360,6 +359,7 @@ fun ActPost.initializeFromRedraftStatus(account: SavedAccount, jsonText: String)
} catch (ex: Throwable) { } catch (ex: Throwable) {
log.e(ex, "can't initialize attachments from redraft.") log.e(ex, "can't initialize attachments from redraft.")
} }
saveAttachmentList()
} }
views.cbNSFW.isChecked = baseStatus.sensitive == true views.cbNSFW.isChecked = baseStatus.sensitive == true
@ -443,7 +443,6 @@ fun ActPost.initializeFromEditStatus(account: SavedAccount, jsonText: String) {
?.mapNotNull { it as? TootAttachment } ?.mapNotNull { it as? TootAttachment }
?.notEmpty() ?.notEmpty()
?.let { srcAttachments -> ?.let { srcAttachments ->
saveAttachmentList()
this.attachmentList.clear() this.attachmentList.clear()
for (src in srcAttachments) { for (src in srcAttachments) {
try { try {
@ -455,6 +454,7 @@ fun ActPost.initializeFromEditStatus(account: SavedAccount, jsonText: String) {
log.e(ex, "can't initialize attachments from edit status") log.e(ex, "can't initialize attachments from edit status")
} }
} }
saveAttachmentList()
} }
views.cbNSFW.isChecked = baseStatus.sensitive == true views.cbNSFW.isChecked = baseStatus.sensitive == true

View File

@ -274,6 +274,7 @@ fun ActPost.performMore() {
views.etContent.setText("") views.etContent.setText("")
views.etContentWarning.setText("") views.etContentWarning.setText("")
attachmentList.clear() attachmentList.clear()
saveAttachmentList()
showMediaAttachment() showMediaAttachment()
} }

View File

@ -65,9 +65,9 @@ suspend fun ActPost.initializeFromScheduledStatus(account: SavedAccount, jsonTex
} }
?.notEmpty() ?.notEmpty()
?.let { ?.let {
saveAttachmentList()
this.attachmentList.clear() this.attachmentList.clear()
this.attachmentList.addAll(it) this.attachmentList.addAll(it)
saveAttachmentList()
} }
} catch (ex: Throwable) { } catch (ex: Throwable) {
log.e(ex, "initializeFromScheduledStatus failed.") log.e(ex, "initializeFromScheduledStatus failed.")

View File

@ -98,8 +98,8 @@ suspend fun ActPost.restoreState(savedInstanceState: Bundle) {
} else { } else {
// state から復元する // state から復元する
states.attachmentListEncoded?.let { states.attachmentListEncoded?.let {
saveAttachmentList()
decodeAttachments(it) decodeAttachments(it)
saveAttachmentList()
} }
} }
} }