From 97ef0ff9415bc04708056be1fa1200ca3c9df3e3 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Wed, 8 Nov 2017 11:10:56 +0800 Subject: [PATCH] fixed #1012 --- .../twidere/task/compose/AbsAddMediaTask.kt | 103 ------------------ .../src/main/res/layout/list_item_status.xml | 8 +- 2 files changed, 7 insertions(+), 104 deletions(-) delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt deleted file mode 100644 index 4a135f6cc..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.task.compose - -import android.content.Context -import android.net.Uri -import android.webkit.MimeTypeMap -import org.mariotaku.abstask.library.AbstractTask -import org.mariotaku.commons.io.StreamUtils -import org.mariotaku.twidere.model.ParcelableMedia -import org.mariotaku.twidere.model.ParcelableMediaUpdate -import org.mariotaku.twidere.util.DebugLog -import org.mariotaku.twidere.util.Utils -import java.io.* -import java.lang.ref.WeakReference - -open class AbsAddMediaTask( - context: Context, - val sources: Array, - val types: IntArray?, - val copySrc: Boolean = false, - val deleteSrc: Boolean = false -) : AbstractTask?, Callback>() { - - private val contextRef = WeakReference(context) - val context: Context? get() = contextRef.get() - - override fun doLongOperation(params: Unit?): List? { - val context = contextRef.get() ?: return null - val resolver = context.contentResolver - return sources.mapIndexedNotNull { index, source -> - var st: InputStream? = null - var os: OutputStream? = null - try { - val mimeTypeMap = MimeTypeMap.getSingleton() - val sourceMimeType = resolver.getType(source) ?: mimeTypeMap.getMimeTypeFromExtension( - source.lastPathSegment.substringAfterLast('.', "tmp")) - val mediaType = types?.get(index) ?: sourceMimeType?.let { - return@let inferMediaType(it) - } ?: ParcelableMedia.Type.IMAGE - val extension = sourceMimeType?.let { mimeType -> - mimeTypeMap.getExtensionFromMimeType(mimeType) - } ?: "tmp" - st = resolver.openInputStream(source) ?: throw FileNotFoundException("Unable to open $source") - val destination: Uri - if (copySrc) { - destination = createTempImageUri(context, index, extension) - os = resolver.openOutputStream(destination) ?: throw FileNotFoundException("Unable to open $destination") - StreamUtils.copy(st, os, null, null) - if (deleteSrc) { - Utils.deleteMedia(context, source) - } - } else { - destination = source - } - // File is copied locally, so delete on success - return@mapIndexedNotNull ParcelableMediaUpdate(destination.toString(), mediaType).apply { - delete_on_success = true - } - } catch (e: IOException) { - DebugLog.w(tr = e) - return@mapIndexedNotNull null - } finally { - os?.close() - st?.close() - } - } - } - - - private fun createTempImageUri(context: Context, extraNum: Int, ext: String): Uri { - val file = File(context.cacheDir, "tmp_media_${System.currentTimeMillis()}_$extraNum.$ext") - return Uri.fromFile(file) - } - - companion object { - fun inferMediaType(mimeType: String, def: Int = ParcelableMedia.Type.IMAGE): Int { - return when { - mimeType == "image/gif" -> ParcelableMedia.Type.ANIMATED_GIF - mimeType.startsWith("video/") -> ParcelableMedia.Type.VIDEO - mimeType.startsWith("image/") -> ParcelableMedia.Type.IMAGE - else -> def - } - } - } -} \ No newline at end of file diff --git a/twidere/src/main/res/layout/list_item_status.xml b/twidere/src/main/res/layout/list_item_status.xml index 88f101a05..fd5aae274 100644 --- a/twidere/src/main/res/layout/list_item_status.xml +++ b/twidere/src/main/res/layout/list_item_status.xml @@ -121,13 +121,19 @@ android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" + android:layout_marginEnd="@dimen/element_spacing_small" + android:layout_marginRight="@dimen/element_spacing_small" android:layout_toLeftOf="@+id/time" android:layout_toStartOf="@+id/time" android:ellipsize="end" android:maxLines="1" + app:tltvPrimaryTextAppearance="?android:textAppearanceSmall" app:tltvPrimaryTextColor="?android:textColorPrimary" app:tltvPrimaryTextStyle="bold" - app:tltvSecondaryTextColor="?android:textColorSecondary"/> + app:tltvSecondaryTextAppearance="?android:textAppearanceSmall" + app:tltvSecondaryTextColor="?android:textColorSecondary" + tools:tltvPrimaryText="Name" + tools:tltvSecondaryText="\@screenname"/>