Merge tag '12.7.1'

pull/2068/head
Alex Baker 2 years ago
commit 8d78a5bfdb

@ -1,15 +1,15 @@
package com.todoroo.astrid.activity
import android.content.ContentResolver
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.google.common.io.Files
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.service.TaskCreator
import com.todoroo.astrid.utility.Constants
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.Strings.isNullOrEmpty
import org.tasks.analytics.Firebase
import org.tasks.data.TaskAttachment
import org.tasks.files.FileHelper
@ -18,7 +18,6 @@ import org.tasks.intents.TaskIntents
import org.tasks.preferences.Preferences
import timber.log.Timber
import javax.inject.Inject
import kotlin.math.min
/**
* @author joshuagross
@ -88,29 +87,24 @@ class ShareLinkActivity : InjectingAppCompatActivity() {
startActivity(intent)
}
private fun copyAttachment(intent: Intent): ArrayList<Uri> {
val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM) ?: return ArrayList()
var filename = FileHelper.getFilename(this, uri)
if (isNullOrEmpty(filename)) {
filename = intent.getStringExtra(Intent.EXTRA_SUBJECT)
?.takeIf { it.isNotBlank() }
?.let { it.substring(0, min(it.length, FileHelper.MAX_FILENAME_LENGTH)) }
?: uri.lastPathSegment
}
val basename = Files.getNameWithoutExtension(filename!!)
return arrayListOf(FileHelper.copyToUri(this, preferences.attachmentsDirectory!!, uri, basename))
}
private fun copyAttachment(intent: Intent): ArrayList<Uri> =
intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
?.let { copyAttachments(listOf(it)) }
?: arrayListOf()
private fun copyMultipleAttachments(intent: Intent): ArrayList<Uri> =
intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
?.let { copyAttachments(it) }
?: arrayListOf()
private fun copyMultipleAttachments(intent: Intent): ArrayList<Uri> {
val result = ArrayList<Uri>()
val uris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
if (uris != null) {
for (uri in uris) {
result.add(FileHelper.copyToUri(this, preferences.attachmentsDirectory!!, uri))
private fun copyAttachments(uris: List<Uri>) =
uris
.filter {
it.scheme == ContentResolver.SCHEME_CONTENT
&& it.authority != Constants.FILE_PROVIDER_AUTHORITY
}
}
return result
}
.map { FileHelper.copyToUri(this, preferences.attachmentsDirectory!!, it) }
.let { ArrayList(it) }
private fun hasAttachments(intent: Intent) =
intent.type?.let { type -> ATTACHMENT_TYPES.any { type.startsWith(it) } } ?: false

@ -26,7 +26,6 @@ import java.io.IOException
import java.util.*
object FileHelper {
const val MAX_FILENAME_LENGTH = 40
fun newFilePickerIntent(activity: Activity?, initial: Uri?, vararg mimeTypes: String?): Intent =
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
putExtra("android.content.extra.SHOW_ADVANCED", true)
@ -178,20 +177,20 @@ object FileHelper {
fun copyToUri(context: Context, destination: Uri, input: Uri): Uri {
val filename = getFilename(context, input)
return copyToUri(context, destination, input, Files.getNameWithoutExtension(filename!!))
}
fun copyToUri(context: Context, destination: Uri, input: Uri, basename: String): Uri = try {
val output = newFile(
val basename = Files.getNameWithoutExtension(filename!!)
try {
val output = newFile(
context,
destination,
getMimeType(context, input),
basename,
getExtension(context, input))
copyStream(context, input, output)
output
} catch (e: IOException) {
throw IllegalStateException(e)
getExtension(context, input)
)
copyStream(context, input, output)
return output
} catch (e: IOException) {
throw IllegalStateException(e)
}
}
fun copyStream(context: Context, input: Uri?, output: Uri?) {

Loading…
Cancel
Save