mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
fixed delete picked media
This commit is contained in:
parent
6fbfb13339
commit
5a095a9178
@ -80,10 +80,11 @@ public class ParcelableMediaUpdate implements Parcelable {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ParcelableMediaUpdate{" +
|
||||
"alt_text='" + alt_text + '\'' +
|
||||
", uri='" + uri + '\'' +
|
||||
"uri='" + uri + '\'' +
|
||||
", type=" + type +
|
||||
", alt_text='" + alt_text + '\'' +
|
||||
", delete_on_success=" + delete_on_success +
|
||||
", delete_always=" + delete_always +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
e9881eb040d94286c884d572947bc39a082c95e0
|
||||
5b6ffb3701c112844efa7cb73251752db335471d
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.extension.mime4j
|
||||
|
||||
import org.apache.james.mime4j.dom.field.ContentTypeField
|
||||
import org.mariotaku.ktextension.toIntOr
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/8/25.
|
||||
*/
|
||||
fun ContentTypeField.getIntParameter(name: String, def: Int): Int {
|
||||
return getParameter(name).toIntOr(def)
|
||||
}
|
||||
|
||||
fun ContentTypeField.getBooleanParameter(name: String): Boolean {
|
||||
return getParameter(name).toBoolean()
|
||||
}
|
@ -17,9 +17,10 @@ import org.apache.james.mime4j.stream.MimeConfig
|
||||
import org.apache.james.mime4j.stream.RawField
|
||||
import org.apache.james.mime4j.util.MimeUtil
|
||||
import org.mariotaku.ktextension.mapToArray
|
||||
import org.mariotaku.ktextension.toIntOr
|
||||
import org.mariotaku.ktextension.toString
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.extension.mime4j.getBooleanParameter
|
||||
import org.mariotaku.twidere.extension.mime4j.getIntParameter
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.Draft.Action
|
||||
import org.mariotaku.twidere.model.draft.SendDirectMessageActionExtras
|
||||
@ -90,6 +91,8 @@ fun Draft.writeMimeMessageTo(context: Context, st: OutputStream) {
|
||||
val parameters = NonEmptyHashMap<String, String?>()
|
||||
parameters["alt_text"] = mediaItem.alt_text
|
||||
parameters["media_type"] = mediaItem.type.toString()
|
||||
parameters["delete_on_success"] = mediaItem.delete_on_success.toString()
|
||||
parameters["delete_always"] = mediaItem.delete_always.toString()
|
||||
val storage = contentResolver.openInputStream(uri).use { storageProvider.store(it) }
|
||||
this.filename = uri.lastPathSegment
|
||||
this.contentTransferEncoding = MimeUtil.ENC_BASE64
|
||||
@ -260,9 +263,15 @@ private class BodyPartHandler(private val context: Context, private val draft: D
|
||||
val filename = contentDisposition.filename ?: return
|
||||
val mediaFile = File(context.filesDir, filename)
|
||||
media = ParcelableMediaUpdate().apply {
|
||||
bd.transferEncoding
|
||||
this.type = contentType?.getParameter("media_type").toIntOr(ParcelableMedia.Type.UNKNOWN)
|
||||
this.alt_text = contentType?.getParameter("alt_text")
|
||||
if (contentType != null) {
|
||||
this.type = contentType.getIntParameter("media_type",
|
||||
ParcelableMedia.Type.UNKNOWN)
|
||||
this.alt_text = contentType.getParameter("alt_text")
|
||||
this.delete_on_success = contentType.getBooleanParameter("delete_on_success")
|
||||
this.delete_always = contentType.getBooleanParameter("delete_always")
|
||||
} else {
|
||||
this.type = ParcelableMedia.Type.UNKNOWN
|
||||
}
|
||||
FileOutputStream(mediaFile).use {
|
||||
st.copyTo(it)
|
||||
it.flush()
|
||||
|
@ -24,7 +24,6 @@ import android.net.Uri
|
||||
import android.webkit.MimeTypeMap
|
||||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.commons.io.StreamUtils
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
import org.mariotaku.twidere.model.ParcelableMediaUpdate
|
||||
import org.mariotaku.twidere.util.DebugLog
|
||||
@ -69,9 +68,12 @@ open class AbsAddMediaTask<Callback>(
|
||||
} else {
|
||||
destination = source
|
||||
}
|
||||
return@mapIndexedNotNull ParcelableMediaUpdate(destination.toString(), mediaType)
|
||||
// File is copied locally, so delete on success
|
||||
return@mapIndexedNotNull ParcelableMediaUpdate(destination.toString(), mediaType).apply {
|
||||
delete_on_success = true
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
DebugLog.w(Constants.LOGTAG, tr = e)
|
||||
DebugLog.w(tr = e)
|
||||
return@mapIndexedNotNull null
|
||||
} finally {
|
||||
os?.close()
|
||||
|
@ -732,7 +732,7 @@ class UpdateStatusTask(
|
||||
}
|
||||
body?.deleteOnSuccess?.addAllTo(deleteOnSuccess)
|
||||
body?.deleteAlways?.addAllTo(deleteAlways)
|
||||
if (media.alt_text?.isNotEmpty() ?: false) {
|
||||
if (media.alt_text?.isNotEmpty() == true) {
|
||||
try {
|
||||
upload.createMetadata(NewMediaMetadata(resp.id, media.alt_text))
|
||||
} catch (e: MicroBlogException) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user