compose code cleanup
This commit is contained in:
parent
0b27aad645
commit
ec8267f8a5
|
@ -21,3 +21,7 @@ fun <T : Any> Array<T>.toNulls(): Array<T?> {
|
|||
fun <T : Any> Array<T>.toStringArray(): Array<String> {
|
||||
return Array(size) { this[it].toString() }
|
||||
}
|
||||
|
||||
inline fun <T : Any, reified R : Any> Array<T>.mapToArray(transform: (T) -> R): Array<R> {
|
||||
return map(transform).toTypedArray()
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -31,9 +31,11 @@ import java.nio.charset.Charset
|
|||
import java.util.*
|
||||
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/7.
|
||||
*/
|
||||
val Draft.filename: String get() = "$unique_id_non_null.eml"
|
||||
|
||||
val Draft.unique_id_non_null: String
|
||||
get() = unique_id ?: UUID.nameUUIDFromBytes(("$_id:$timestamp").toByteArray()).toString()
|
||||
|
||||
fun Draft.writeMimeMessageTo(context: Context, st: OutputStream) {
|
||||
val bodyFactory = StorageBodyFactory()
|
||||
val storageProvider = bodyFactory.storageProvider
|
||||
|
@ -126,10 +128,15 @@ fun Draft.getActionName(context: Context): String? {
|
|||
return null
|
||||
}
|
||||
|
||||
val Draft.filename: String get() = "$unique_id_non_null.eml"
|
||||
|
||||
val Draft.unique_id_non_null: String
|
||||
get() = unique_id ?: UUID.nameUUIDFromBytes(("$_id:$timestamp").toByteArray()).toString()
|
||||
fun Draft.applyUpdateStatus(statusUpdate: ParcelableStatusUpdate) {
|
||||
this.unique_id = statusUpdate.draft_unique_id ?: UUID.randomUUID().toString()
|
||||
this.account_keys = statusUpdate.accounts.map { it.key }.toTypedArray()
|
||||
this.text = statusUpdate.text
|
||||
this.location = statusUpdate.location
|
||||
this.media = statusUpdate.media
|
||||
this.timestamp = System.currentTimeMillis()
|
||||
this.action_extras = statusUpdate.draft_extras
|
||||
}
|
||||
|
||||
private class DraftContentHandler(private val context: Context, private val draft: Draft) : SimpleContentHandler() {
|
||||
private val processingStack = Stack<SimpleContentHandler>()
|
||||
|
|
|
@ -33,10 +33,10 @@ import org.mariotaku.twidere.R
|
|||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
import org.mariotaku.twidere.extension.model.applyUpdateStatus
|
||||
import org.mariotaku.twidere.extension.model.mediaSizeLimit
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.extension.model.textLimit
|
||||
import org.mariotaku.twidere.extension.text.twitter.extractReplyTextAndMentions
|
||||
import org.mariotaku.twidere.extension.text.twitter.getTweetLength
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.account.AccountExtras
|
||||
|
@ -137,31 +137,6 @@ class UpdateStatusTask(
|
|||
return result
|
||||
}
|
||||
|
||||
private fun regulateReplyText(update: ParcelableStatusUpdate, pending: PendingStatusUpdate) {
|
||||
if (update.draft_action != Draft.Action.REPLY) return
|
||||
val inReplyTo = update.in_reply_to_status ?: return
|
||||
for (i in 0 until pending.length) {
|
||||
val details = update.accounts[i]
|
||||
if (details.type != AccountType.TWITTER) continue
|
||||
val (_, replyText, extraMentions, excludedMentions, replyToOriginalUser) =
|
||||
extractor.extractReplyTextAndMentions(pending.overrideTexts[i], inReplyTo)
|
||||
pending.overrideTexts[i] = replyText
|
||||
val excludeReplyUserIds = excludedMentions.mapNotNull { mention ->
|
||||
// Remove account mention that is not appeared in `extraMentions`
|
||||
if (details.key == mention.key && extraMentions.none {
|
||||
it.value.equals(mention.screen_name, ignoreCase = true)
|
||||
}) return@mapNotNull null
|
||||
return@mapNotNull mention.key.id
|
||||
}.toTypedArray()
|
||||
val replyToSelf = details.key == inReplyTo.user_key
|
||||
// Fix status to at least make mentioned user know what status it is
|
||||
if (!replyToOriginalUser && !replyToSelf && update.attachment_url == null) {
|
||||
update.attachment_url = LinkCreator.getTwitterStatusLink(inReplyTo.user_screen_name,
|
||||
inReplyTo.id).toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteOrUpdateDraft(update: ParcelableStatusUpdate, result: UpdateStatusResult,
|
||||
draftId: Long) {
|
||||
val where = Expression.equals(Drafts._ID, draftId).sql
|
||||
|
@ -520,16 +495,11 @@ class UpdateStatusTask(
|
|||
|
||||
private fun saveDraft(statusUpdate: ParcelableStatusUpdate): Long {
|
||||
return saveDraft(context, statusUpdate.draft_action ?: Draft.Action.UPDATE_STATUS) {
|
||||
this.unique_id = statusUpdate.draft_unique_id ?: UUID.randomUUID().toString()
|
||||
this.account_keys = statusUpdate.accounts.map { it.key }.toTypedArray()
|
||||
this.text = statusUpdate.text
|
||||
this.location = statusUpdate.location
|
||||
this.media = statusUpdate.media
|
||||
this.timestamp = System.currentTimeMillis()
|
||||
this.action_extras = statusUpdate.draft_extras
|
||||
applyUpdateStatus(statusUpdate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PendingStatusUpdate internal constructor(val length: Int, defaultText: String) {
|
||||
|
||||
internal constructor(statusUpdate: ParcelableStatusUpdate) : this(statusUpdate.accounts.size,
|
||||
|
@ -996,17 +966,23 @@ class UpdateStatusTask(
|
|||
val deleteAlways: List<MediaDeletionItem>?
|
||||
)
|
||||
|
||||
fun saveDraft(context: Context, @Draft.Action action: String, config: Draft.() -> Unit): Long {
|
||||
inline fun createDraft(@Draft.Action action: String, config: Draft.() -> Unit): Draft {
|
||||
val draft = Draft()
|
||||
draft.action_type = action
|
||||
draft.timestamp = System.currentTimeMillis()
|
||||
config(draft)
|
||||
return draft
|
||||
}
|
||||
|
||||
fun saveDraft(context: Context, @Draft.Action action: String, config: Draft.() -> Unit): Long {
|
||||
val draft = createDraft(action, config)
|
||||
val resolver = context.contentResolver
|
||||
val creator = ObjectCursor.valuesCreatorFrom(Draft::class.java)
|
||||
val draftUri = resolver.insert(Drafts.CONTENT_URI, creator.create(draft)) ?: return -1
|
||||
return draftUri.lastPathSegment.toLongOr(-1)
|
||||
}
|
||||
|
||||
|
||||
fun deleteDraft(context: Context, id: Long) {
|
||||
val where = Expression.equals(Drafts._ID, id).sql
|
||||
context.contentResolver.delete(Drafts.CONTENT_URI, where, null)
|
||||
|
|
Loading…
Reference in New Issue