Delete scheduled post after editing (#1947)
* Delete scheduled post after editing This ensures that editing a scheduled toot will not duplicate it. Fixes #1924 * Fix scheduled toot editing * Convert isEditingScheduledToot to property * Replace MediatorLiveData with combineLiveData * Remove dead code * Fix observer emission * Fix "Finish media upload" appearing for split second
This commit is contained in:
parent
21b28f1bbb
commit
af44b25c29
4 changed files with 28 additions and 4 deletions
|
@ -164,6 +164,7 @@ public final class SavedTootActivity extends BaseActivity implements SavedTootAd
|
||||||
List<String> descriptions = gson.fromJson(item.getDescriptions(), stringListType);
|
List<String> descriptions = gson.fromJson(item.getDescriptions(), stringListType);
|
||||||
|
|
||||||
ComposeOptions composeOptions = new ComposeOptions(
|
ComposeOptions composeOptions = new ComposeOptions(
|
||||||
|
/*scheduledTootUid*/null,
|
||||||
item.getUid(),
|
item.getUid(),
|
||||||
item.getText(),
|
item.getText(),
|
||||||
jsonUrls,
|
jsonUrls,
|
||||||
|
|
|
@ -744,9 +744,11 @@ class ComposeActivity : BaseActivity(),
|
||||||
composeEditField.error = getString(R.string.error_empty)
|
composeEditField.error = getString(R.string.error_empty)
|
||||||
enableButtons(true)
|
enableButtons(true)
|
||||||
} else if (characterCount <= maximumTootCharacters) {
|
} else if (characterCount <= maximumTootCharacters) {
|
||||||
finishingUploadDialog = ProgressDialog.show(
|
if (viewModel.media.value!!.isNotEmpty()) {
|
||||||
this, getString(R.string.dialog_title_finishing_media_upload),
|
finishingUploadDialog = ProgressDialog.show(
|
||||||
getString(R.string.dialog_message_uploading_media), true, true)
|
this, getString(R.string.dialog_title_finishing_media_upload),
|
||||||
|
getString(R.string.dialog_message_uploading_media), true, true)
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.sendStatus(contentText, spoilerText).observe(this, {
|
viewModel.sendStatus(contentText, spoilerText).observe(this, {
|
||||||
finishingUploadDialog?.dismiss()
|
finishingUploadDialog?.dismiss()
|
||||||
|
@ -1001,6 +1003,7 @@ class ComposeActivity : BaseActivity(),
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class ComposeOptions(
|
data class ComposeOptions(
|
||||||
// Let's keep fields var until all consumers are Kotlin
|
// Let's keep fields var until all consumers are Kotlin
|
||||||
|
var scheduledTootUid: String? = null,
|
||||||
var savedTootUid: Int? = null,
|
var savedTootUid: Int? = null,
|
||||||
var tootText: String? = null,
|
var tootText: String? = null,
|
||||||
var mediaUrls: List<String>? = null,
|
var mediaUrls: List<String>? = null,
|
||||||
|
|
|
@ -19,8 +19,10 @@ import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MediatorLiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.work.impl.utils.LiveDataUtils
|
||||||
import com.keylesspalace.tusky.adapter.ComposeAutoCompleteAdapter
|
import com.keylesspalace.tusky.adapter.ComposeAutoCompleteAdapter
|
||||||
import com.keylesspalace.tusky.components.compose.ComposeActivity.QueuedMedia
|
import com.keylesspalace.tusky.components.compose.ComposeActivity.QueuedMedia
|
||||||
import com.keylesspalace.tusky.components.search.SearchType
|
import com.keylesspalace.tusky.components.search.SearchType
|
||||||
|
@ -33,6 +35,8 @@ import com.keylesspalace.tusky.network.MastodonApi
|
||||||
import com.keylesspalace.tusky.service.ServiceClient
|
import com.keylesspalace.tusky.service.ServiceClient
|
||||||
import com.keylesspalace.tusky.service.TootToSend
|
import com.keylesspalace.tusky.service.TootToSend
|
||||||
import com.keylesspalace.tusky.util.*
|
import com.keylesspalace.tusky.util.*
|
||||||
|
import io.reactivex.Observable.empty
|
||||||
|
import io.reactivex.Observable.just
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.rxkotlin.Singles
|
import io.reactivex.rxkotlin.Singles
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -58,6 +62,7 @@ class ComposeViewModel
|
||||||
private var replyingStatusContent: String? = null
|
private var replyingStatusContent: String? = null
|
||||||
internal var startingText: String? = null
|
internal var startingText: String? = null
|
||||||
private var savedTootUid: Int = 0
|
private var savedTootUid: Int = 0
|
||||||
|
private var scheduledTootUid: String? = null
|
||||||
private var startingContentWarning: String = ""
|
private var startingContentWarning: String = ""
|
||||||
private var inReplyToId: String? = null
|
private var inReplyToId: String? = null
|
||||||
private var startingVisibility: Status.Visibility = Status.Visibility.UNKNOWN
|
private var startingVisibility: Status.Visibility = Status.Visibility.UNKNOWN
|
||||||
|
@ -94,6 +99,7 @@ class ComposeViewModel
|
||||||
|
|
||||||
private val mediaToDisposable = mutableMapOf<Long, Disposable>()
|
private val mediaToDisposable = mutableMapOf<Long, Disposable>()
|
||||||
|
|
||||||
|
private val isEditingScheduledToot get() = !scheduledTootUid.isNullOrEmpty()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
|
@ -241,7 +247,14 @@ class ComposeViewModel
|
||||||
content: String,
|
content: String,
|
||||||
spoilerText: String
|
spoilerText: String
|
||||||
): LiveData<Unit> {
|
): LiveData<Unit> {
|
||||||
return media
|
|
||||||
|
val deletionObservable = if (isEditingScheduledToot) {
|
||||||
|
api.deleteScheduledStatus(scheduledTootUid.toString()).toObservable().map { Unit }
|
||||||
|
} else {
|
||||||
|
just(Unit)
|
||||||
|
}.toLiveData()
|
||||||
|
|
||||||
|
val sendObservable = media
|
||||||
.filter { items -> items.all { it.uploadPercent == -1 } }
|
.filter { items -> items.all { it.uploadPercent == -1 } }
|
||||||
.map {
|
.map {
|
||||||
val mediaIds = ArrayList<String>()
|
val mediaIds = ArrayList<String>()
|
||||||
|
@ -272,8 +285,13 @@ class ComposeViewModel
|
||||||
idempotencyKey = randomAlphanumericString(16),
|
idempotencyKey = randomAlphanumericString(16),
|
||||||
retries = 0
|
retries = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
serviceClient.sendToot(tootToSend)
|
serviceClient.sendToot(tootToSend)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return combineLiveData(deletionObservable, sendObservable) { _, _ -> Unit }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateDescription(localId: Long, description: String): LiveData<Boolean> {
|
fun updateDescription(localId: Long, description: String): LiveData<Boolean> {
|
||||||
|
@ -406,6 +424,7 @@ class ComposeViewModel
|
||||||
|
|
||||||
|
|
||||||
savedTootUid = composeOptions?.savedTootUid ?: 0
|
savedTootUid = composeOptions?.savedTootUid ?: 0
|
||||||
|
scheduledTootUid = composeOptions?.scheduledTootUid
|
||||||
startingText = composeOptions?.tootText
|
startingText = composeOptions?.tootText
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ class ScheduledTootActivity : BaseActivity(), ScheduledTootActionListener, Injec
|
||||||
|
|
||||||
override fun edit(item: ScheduledStatus) {
|
override fun edit(item: ScheduledStatus) {
|
||||||
val intent = ComposeActivity.startIntent(this, ComposeActivity.ComposeOptions(
|
val intent = ComposeActivity.startIntent(this, ComposeActivity.ComposeOptions(
|
||||||
|
scheduledTootUid = item.id,
|
||||||
tootText = item.params.text,
|
tootText = item.params.text,
|
||||||
contentWarning = item.params.spoilerText,
|
contentWarning = item.params.spoilerText,
|
||||||
mediaAttachments = item.mediaAttachments,
|
mediaAttachments = item.mediaAttachments,
|
||||||
|
|
Loading…
Reference in a new issue