update commons to 3.12.3

This commit is contained in:
tibbi 2018-02-17 11:24:29 +01:00
parent f6b6d4a872
commit f4f2a2ccbb
6 changed files with 37 additions and 43 deletions

View File

@ -45,7 +45,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.11.52'
implementation 'com.simplemobiletools:commons:3.12.3'
implementation files('../libs/RootTools.jar')

View File

@ -300,7 +300,7 @@ class MainActivity : SimpleActivity() {
fun pickedPath(path: String) {
val resultIntent = Intent()
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
val type = path.getMimeTypeFromPath()
val type = path.getMimeType()
resultIntent.setDataAndType(uri, type)
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
setResult(Activity.RESULT_OK, resultIntent)
@ -310,7 +310,7 @@ class MainActivity : SimpleActivity() {
fun pickedRingtone(path: String) {
val resultIntent = Intent()
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
val type = path.getMimeTypeFromPath()
val type = path.getMimeType()
resultIntent.setDataAndType(uri, type)
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, uri)
@ -319,10 +319,10 @@ class MainActivity : SimpleActivity() {
}
fun pickedPaths(paths: ArrayList<String>) {
val uris = paths.map { getFilePublicUri(File(it), BuildConfig.APPLICATION_ID) } as ArrayList
val clipData = ClipData("Attachment", arrayOf(uris.getMimeType()), ClipData.Item(uris.removeAt(0)))
val newPaths = paths.map { getFilePublicUri(File(it), BuildConfig.APPLICATION_ID).toString() } as ArrayList
val clipData = ClipData("Attachment", arrayOf(newPaths.getMimeType()), ClipData.Item(newPaths.removeAt(0)))
uris.forEach {
newPaths.forEach {
clipData.addItem(ClipData.Item(it))
}

View File

@ -9,12 +9,12 @@ import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.dialogs.SaveAsDialog
import com.simplemobiletools.filemanager.extensions.config
import com.simplemobiletools.filemanager.extensions.openFile
import com.simplemobiletools.filemanager.extensions.openPath
import kotlinx.android.synthetic.main.activity_read_text.*
import java.io.File
class ReadTextActivity : SimpleActivity() {
var filePath = ""
private var filePath = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -39,7 +39,7 @@ class ReadTextActivity : SimpleActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_save -> saveText()
R.id.menu_open_with -> openFile(intent.data, true)
R.id.menu_open_with -> openPath(intent.dataString, true)
else -> return super.onOptionsItemSelected(item)
}
return true

View File

@ -5,7 +5,6 @@ import android.content.ClipboardManager
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.net.Uri
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@ -142,21 +141,27 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
private fun shareFiles() {
val selectedItems = getSelectedMedia()
val uris = ArrayList<Uri>(selectedItems.size)
val paths = ArrayList<String>(selectedItems.size)
selectedItems.forEach {
addFileUris(File(it.path), uris)
addFileUris(it.path, paths)
}
activity.shareUris(uris)
activity.sharePaths(paths)
}
private fun addFileUris(file: File, uris: ArrayList<Uri>) {
if (file.isDirectory) {
private fun addFileUris(path: String, paths: ArrayList<String>) {
if (activity.getIsPathDirectory(path)) {
val shouldShowHidden = activity.config.shouldShowHidden
file.listFiles()?.filter { if (shouldShowHidden) true else !it.isHidden }?.forEach {
addFileUris(it, uris)
if (activity.isPathOnOTG(path)) {
activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name.startsWith(".") }?.forEach {
addFileUris(it.uri.toString(), paths)
}
} else {
uris.add(Uri.fromFile(file))
File(path).listFiles()?.filter { if (shouldShowHidden) true else !it.isHidden }?.forEach {
addFileUris(it.absolutePath, paths)
}
}
} else {
paths.add(path)
}
}
@ -169,13 +174,11 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
}
private fun setAs() {
val file = File(getSelectedMedia().first().path)
activity.setAs(Uri.fromFile(file))
activity.setAs(getSelectedMedia().first().path)
}
private fun openWith() {
val file = File(getSelectedMedia().first().path)
activity.openFile(file, true)
activity.tryOpenPathIntent(getSelectedMedia().first().path, true)
}
private fun copyMoveTo(isCopyOperation: Boolean) {

View File

@ -2,25 +2,17 @@ package com.simplemobiletools.filemanager.extensions
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.support.v4.content.FileProvider
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.BuildConfig
import java.io.File
import java.util.*
fun Activity.shareUris(uris: ArrayList<Uri>) {
shareUris(uris, BuildConfig.APPLICATION_ID)
}
fun Activity.openFile(file: File, forceChooser: Boolean) {
if (!forceChooser && file.absolutePath.endsWith(".apk", true)) {
val uri = if (isNougatPlus()) {
FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", file)
} else {
Uri.fromFile(file)
fun Activity.sharePaths(paths: ArrayList<String>) {
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
}
fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean) {
if (!forceChooser && path.endsWith(".apk", true)) {
val uri = getFinalUriFromPath(path, BuildConfig.APPLICATION_ID) ?: return
Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(uri, getMimeTypeFromUri(uri))
@ -28,14 +20,14 @@ fun Activity.openFile(file: File, forceChooser: Boolean) {
startActivity(this)
}
} else {
openFile(Uri.fromFile(file), forceChooser)
openPath(path, forceChooser)
}
}
fun Activity.openFile(uri: Uri, forceChooser: Boolean) {
openFile(uri, forceChooser, BuildConfig.APPLICATION_ID)
fun Activity.openPath(path: String, forceChooser: Boolean) {
openPathIntent(path, forceChooser, BuildConfig.APPLICATION_ID)
}
fun Activity.setAs(uri: Uri) {
setAs(uri, BuildConfig.APPLICATION_ID)
fun Activity.setAs(path: String) {
setAsIntent(path, BuildConfig.APPLICATION_ID)
}

View File

@ -21,7 +21,7 @@ import com.simplemobiletools.filemanager.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
import com.simplemobiletools.filemanager.extensions.config
import com.simplemobiletools.filemanager.extensions.isPathOnRoot
import com.simplemobiletools.filemanager.extensions.openFile
import com.simplemobiletools.filemanager.extensions.tryOpenPathIntent
import com.simplemobiletools.filemanager.helpers.PATH
import com.simplemobiletools.filemanager.helpers.RootHelpers
import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener
@ -227,8 +227,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
activity?.toast(R.string.select_audio_file)
}
} else {
val file = File(path)
activity!!.openFile(file, false)
activity!!.tryOpenPathIntent(path, false)
}
}
}