replace some functions with filepicker extensions

This commit is contained in:
tibbi 2016-12-08 21:02:40 +01:00
parent 24a1d716e1
commit 5c9c0d4ac9
5 changed files with 5 additions and 34 deletions

View file

@ -18,7 +18,6 @@ import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.adapters.DirectoryAdapter
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
import com.simplemobiletools.gallery.extensions.getImageMimeType
import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.helpers.*
import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Directory
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
@ -265,7 +264,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val path = resultData.data.path val path = resultData.data.path
val uri = Uri.fromFile(File(path)) val uri = Uri.fromFile(File(path))
if (mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsGetAnyContentIntent) { if (mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsGetAnyContentIntent) {
val type = uri.getImageMimeType() val type = File(path).getMimeType("image/jpeg")
setDataAndTypeAndNormalize(uri, type) setDataAndTypeAndNormalize(uri, type)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
} else if (mIsPickImageIntent || mIsPickVideoIntent) { } else if (mIsPickImageIntent || mIsPickVideoIntent) {

View file

@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.activities
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.Activity import android.app.Activity
import android.content.ContentValues
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -10,7 +9,6 @@ import android.provider.MediaStore
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import com.simplemobiletools.filepicker.extensions.isImageSlow
import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.Config
@ -70,13 +68,6 @@ open class SimpleActivity : AppCompatActivity() {
fun isShowingPermDialog(file: File) = isShowingWritePermissions(file, mConfig.treeUri, OPEN_DOCUMENT_TREE) fun isShowingPermDialog(file: File) = isShowingWritePermissions(file, mConfig.treeUri, OPEN_DOCUMENT_TREE)
fun deleteFromMediaStore(file: File): Boolean {
val values = ContentValues()
values.put(MediaStore.MediaColumns.DATA, file.absolutePath)
val uri = if (file.isImageSlow()) MediaStore.Images.Media.EXTERNAL_CONTENT_URI else MediaStore.Video.Media.EXTERNAL_CONTENT_URI
return contentResolver.delete(uri, "${MediaStore.MediaColumns.DATA} = '${file.absolutePath}'", null) == 1
}
fun showSystemUI() { fun showSystemUI() {
supportActionBar?.show() supportActionBar?.show()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or

View file

@ -1,8 +1,6 @@
package com.simplemobiletools.gallery.dialogs package com.simplemobiletools.gallery.dialogs
import android.app.AlertDialog import android.app.AlertDialog
import android.content.ContentValues
import android.provider.MediaStore
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.WindowManager import android.view.WindowManager
import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.filepicker.extensions.*
@ -78,13 +76,7 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val callbac
} }
private fun sendSuccess(oldFile: File, newFile: File) { private fun sendSuccess(oldFile: File, newFile: File) {
val values = ContentValues() if (activity.updateInMediaStore(oldFile, newFile)) {
values.put(MediaStore.MediaColumns.DISPLAY_NAME, newFile.name)
values.put(MediaStore.MediaColumns.TITLE, newFile.name)
val uri = if (oldFile.isImageSlow()) MediaStore.Images.Media.EXTERNAL_CONTENT_URI else MediaStore.Video.Media.EXTERNAL_CONTENT_URI
val updated = activity.contentResolver.update(uri, values, "${MediaStore.MediaColumns.DATA} = '${oldFile.absolutePath}'", null) == 1
if (updated) {
callback.invoke(newFile) callback.invoke(newFile)
} else { } else {
val changedFiles = arrayListOf(oldFile, newFile) val changedFiles = arrayListOf(oldFile, newFile)

View file

@ -8,6 +8,7 @@ import android.util.DisplayMetrics
import android.view.KeyCharacterMap import android.view.KeyCharacterMap
import android.view.KeyEvent import android.view.KeyEvent
import android.view.ViewConfiguration import android.view.ViewConfiguration
import com.simplemobiletools.filepicker.extensions.getMimeType
import com.simplemobiletools.filepicker.extensions.toast import com.simplemobiletools.filepicker.extensions.toast
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE
@ -45,7 +46,7 @@ fun Activity.shareMedia(media: List<Medium>) {
fun Activity.setAsWallpaper(file: File) { fun Activity.setAsWallpaper(file: File) {
val intent = Intent(Intent.ACTION_ATTACH_DATA) val intent = Intent(Intent.ACTION_ATTACH_DATA)
val uri = Uri.fromFile(file) val uri = Uri.fromFile(file)
intent.setDataAndType(uri, uri.getImageMimeType()) intent.setDataAndType(uri, file.getMimeType("image/jpeg"))
val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with)) val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with))
if (intent.resolveActivity(packageManager) != null) { if (intent.resolveActivity(packageManager) != null) {
@ -58,7 +59,7 @@ fun Activity.setAsWallpaper(file: File) {
fun Activity.openWith(file: File) { fun Activity.openWith(file: File) {
val intent = Intent(Intent.ACTION_VIEW) val intent = Intent(Intent.ACTION_VIEW)
val uri = Uri.fromFile(file) val uri = Uri.fromFile(file)
intent.setDataAndType(uri, uri.getImageMimeType()) intent.setDataAndType(uri, file.getMimeType("image/jpeg"))
val chooser = Intent.createChooser(intent, getString(R.string.open_with)) val chooser = Intent.createChooser(intent, getString(R.string.open_with))
if (intent.resolveActivity(packageManager) != null) { if (intent.resolveActivity(packageManager) != null) {

View file

@ -1,12 +0,0 @@
package com.simplemobiletools.gallery.extensions
import android.net.Uri
import com.simplemobiletools.filepicker.extensions.getMimeType
fun Uri.getImageMimeType(): String {
val mimeType = getMimeType(toString())
return if (mimeType.isNotEmpty())
mimeType
else
"image/jpeg"
}