update commons to 3.12.6

This commit is contained in:
tibbi 2018-02-19 20:24:32 +01:00
parent df1494d684
commit fb493459de
18 changed files with 130 additions and 120 deletions

View File

@ -46,7 +46,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.11.15'
implementation 'com.simplemobiletools:commons:3.12.6'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.google.code.gson:gson:2.8.2'

View File

@ -12,6 +12,7 @@ import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.dialogs.ResizeDialog
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
@ -191,7 +192,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
try {
Thread {
val file = File(path)
getFileOutputStream(file) {
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
getFileOutputStream(fileDirItem) {
if (it != null) {
saveBitmap(file, bitmap, it)
} else {
@ -227,7 +229,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
}
private fun editWith() {
openEditor(uri)
openEditor(uri.toString())
isEditingWithThirdParty = true
}

View File

@ -20,6 +20,7 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.commons.views.MyGridLayoutManager
@ -233,7 +234,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val newFolder = File(config.tempFolderPath)
if (newFolder.exists() && newFolder.isDirectory) {
if (newFolder.list()?.isEmpty() == true) {
deleteFile(newFolder, true)
deleteFile(newFolder.toFileDirItem(applicationContext), true)
}
}
config.tempFolderPath = ""
@ -352,7 +353,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
override fun deleteFolders(folders: ArrayList<File>) {
deleteFolders(folders) {
val fileDirItems = folders.map { FileDirItem(it.absolutePath, it.name, true) } as ArrayList<FileDirItem>
deleteFolders(fileDirItems) {
runOnUiThread {
refreshItems()
}
@ -522,7 +524,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun fillIntentPath(resultData: Intent, resultIntent: Intent) {
val path = resultData.data.path
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
val type = path.getMimeTypeFromPath()
val type = path.getMimeType()
resultIntent.setDataAndTypeAndNormalize(uri, type)
resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

View File

@ -26,6 +26,7 @@ import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.commons.views.MyRecyclerView
@ -442,9 +443,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
private fun deleteDirectoryIfEmpty() {
val file = File(mPath)
if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.list()?.isEmpty() == true) {
deleteFile(file, true)
val fileDirItem = FileDirItem(mPath, mPath.getFilenameFromPath())
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(applicationContext, true) == 0) {
deleteFile(fileDirItem, true)
}
}
@ -610,10 +611,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
finish()
} else {
val file = File(path)
val isVideo = file.isVideoFast()
val isVideo = path.isVideoFast()
if (isVideo) {
openFile(Uri.fromFile(file), false)
openPath(path, false)
} else {
Intent(this, ViewPagerActivity::class.java).apply {
putExtra(PATH, path)
@ -666,8 +666,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
}
override fun deleteFiles(files: ArrayList<File>) {
val filtered = files.filter { it.isImageVideoGif() } as ArrayList
override fun deleteFiles(fileDirItems: ArrayList<FileDirItem>) {
val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList
deleteFiles(filtered) {
if (!it) {
toast(R.string.unknown_error_occurred)

View File

@ -59,7 +59,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
private fun checkIntent(savedInstanceState: Bundle? = null) {
mUri = intent.data ?: return
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
mUri = intent.extras.get(REAL_FILE_PATH) as Uri
mUri = Uri.parse(intent.extras.get(REAL_FILE_PATH) as String)
}
mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false)
@ -131,14 +131,15 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (mMedium == null)
if (mMedium == null) {
return true
}
when (item.itemId) {
R.id.menu_set_as -> setAs(mUri!!)
R.id.menu_open_with -> openFile(mUri!!, true)
R.id.menu_share -> shareUri(mUri!!)
R.id.menu_edit -> openEditor(mUri!!)
R.id.menu_set_as -> setAs(mUri!!.toString())
R.id.menu_open_with -> openPath(mUri!!.toString(), true)
R.id.menu_share -> sharePath(mUri!!.toString())
R.id.menu_edit -> openEditor(mUri!!.toString())
R.id.menu_properties -> showProperties()
else -> return super.onOptionsItemSelected(item)
}

View File

@ -33,6 +33,7 @@ import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
import com.simplemobiletools.commons.helpers.REQUEST_SET_AS
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.adapters.MyPagerAdapter
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
@ -180,10 +181,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return
}
val file = File(mPath)
if (!file.exists() && file.length() == 0L) {
if (!getDoesFilePathExist(mPath)) {
Thread {
deleteFromMediaStore(file)
deleteFromMediaStore(mPath)
}.start()
finish()
return
@ -201,7 +201,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
showSystemUI()
mDirectory = file.parent
mDirectory = mPath.getParentPath().trimEnd('/')
supportActionBar?.title = mPath.getFilenameFromPath()
view_pager.onGlobalLayout {
@ -272,18 +272,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return true
when (item.itemId) {
R.id.menu_set_as -> setAs(Uri.fromFile(getCurrentFile()))
R.id.menu_set_as -> setAs(getCurrentPath())
R.id.menu_slideshow -> initSlideshow()
R.id.menu_copy_to -> copyMoveTo(true)
R.id.menu_move_to -> copyMoveTo(false)
R.id.menu_open_with -> openFile(Uri.fromFile(getCurrentFile()), true)
R.id.menu_open_with -> openPath(getCurrentPath(), true)
R.id.menu_hide -> toggleFileVisibility(true)
R.id.menu_unhide -> toggleFileVisibility(false)
R.id.menu_share_1 -> shareMedium(getCurrentMedium()!!)
R.id.menu_share_2 -> shareMedium(getCurrentMedium()!!)
R.id.menu_delete -> checkDeleteConfirmation()
R.id.menu_rename -> renameFile()
R.id.menu_edit -> openEditor(Uri.fromFile(getCurrentFile()))
R.id.menu_edit -> openEditor(getCurrentPath())
R.id.menu_properties -> showProperties()
R.id.menu_show_on_map -> showOnMap()
R.id.menu_rotate_right -> rotateImage(90)
@ -462,8 +462,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun copyMoveTo(isCopyOperation: Boolean) {
val files = ArrayList<File>(1).apply { add(getCurrentFile()) }
tryCopyMoveFilesTo(files, isCopyOperation) {
val currPath = getCurrentPath()
val fileDirItems = arrayListOf(FileDirItem(currPath, currPath.getFilenameFromPath()))
tryCopyMoveFilesTo(fileDirItems, isCopyOperation) {
config.tempFolderPath = ""
if (!isCopyOperation) {
refreshViewPager()
@ -472,13 +473,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun toggleFileVisibility(hide: Boolean) {
toggleFileVisibility(getCurrentFile(), hide) {
val newFileName = it.absolutePath.getFilenameFromPath()
toggleFileVisibility(getCurrentPath(), hide) {
val newFileName = it.getFilenameFromPath()
supportActionBar?.title = newFileName
getCurrentMedium()!!.apply {
name = newFileName
path = it.absolutePath
path = it
getCurrentMedia()[mPos] = this
}
invalidateOptionsMenu()
@ -508,8 +509,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun saveImageAs() {
val currPath = getCurrentPath()
SaveAsDialog(this, currPath, false) {
val selectedFile = File(it)
handleSAFDialog(selectedFile) {
handleSAFDialog(it) {
Thread {
saveImageToFile(currPath, it)
}.start()
@ -523,7 +523,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}")
try {
val bitmap = BitmapFactory.decodeFile(oldPath)
getFileOutputStream(tmpFile) {
getFileOutputStream(tmpFile.toFileDirItem(applicationContext)) {
if (it == null) {
toast(R.string.unknown_error_occurred)
return@getFileOutputStream
@ -536,16 +536,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
saveFile(tmpFile, bitmap, it as FileOutputStream)
}
if (tmpFile.length() > 0 && newFile.exists()) {
deleteFile(newFile)
if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) {
deleteFile(FileDirItem(newPath, newPath.getFilenameFromPath()))
}
copyFile(tmpFile, newFile)
scanFile(newFile)
scanPath(newPath)
toast(R.string.file_saved)
if (config.keepLastModified) {
newFile.setLastModified(oldLastModified)
updateLastModified(newFile, oldLastModified)
updateLastModified(newPath, oldLastModified)
}
it.flush()
@ -565,7 +565,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} catch (e: Exception) {
showErrorToast(e)
} finally {
deleteFile(tmpFile)
deleteFile(FileDirItem(newPath, newPath.getFilenameFromPath()))
}
}
@ -573,7 +573,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
var inputStream: InputStream? = null
var out: OutputStream? = null
try {
val fileDocument = if (isPathOnSD(destination.absolutePath)) getFileDocument(destination.parent) else null
val fileDocument = if (isPathOnSD(destination.absolutePath)) getDocumentFile(destination.parent) else null
out = getFileOutputStreamSync(destination.absolutePath, source.getMimeType(), fileDocument)
inputStream = FileInputStream(source)
inputStream.copyTo(out!!)
@ -735,7 +735,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun deleteConfirmed() {
deleteFile(File(getCurrentMedia()[mPos].path)) {
val path = getCurrentMedia()[mPos].path
deleteFile(FileDirItem(path, path.getFilenameFromPath())) {
refreshViewPager()
}
}
@ -811,9 +812,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun deleteDirectoryIfEmpty() {
val file = File(mDirectory)
if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.list()?.isEmpty() == true) {
deleteFile(file, true)
val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), getIsPathDirectory(mDirectory))
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(applicationContext, true) == 0) {
deleteFile(fileDirItem, true)
}
scanPath(mDirectory)
@ -821,7 +822,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun checkOrientation() {
if (!mIsOrientationLocked && config.screenRotation == ROTATE_BY_ASPECT_RATIO) {
val res = getCurrentFile().getResolution()
val res = getCurrentPath().getResolution() ?: return
if (res.x > res.y) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
} else if (res.x < res.y) {

View File

@ -11,6 +11,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.dialogs.RenameItemDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.gallery.R
@ -76,6 +77,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
}
override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) {
return
}
when (id) {
R.id.cab_properties -> showProperties()
R.id.cab_rename -> renameDir()
@ -213,16 +218,14 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
}
private fun copyMoveTo(isCopyOperation: Boolean) {
if (selectedPositions.isEmpty())
return
val files = ArrayList<File>()
val paths = ArrayList<String>()
selectedPositions.forEach {
val dir = File(dirs[it].path)
files.addAll(dir.listFiles().filter { it.isFile && it.isImageVideoGif() })
paths.addAll(dir.list().filter { !activity.getIsPathDirectory(it) && it.isImageVideoGif() })
}
activity.tryCopyMoveFilesTo(files, isCopyOperation) {
val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList<FileDirItem>
activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) {
config.tempFolderPath = ""
listener?.refreshItems()
finishActMode()
@ -236,10 +239,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
}
private fun deleteFiles() {
if (selectedPositions.isEmpty()) {
return
}
val folders = ArrayList<File>(selectedPositions.size)
val removeFolders = ArrayList<Directory>(selectedPositions.size)
@ -253,7 +252,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
}
}
activity.handleSAFDialog(File(SAFPath)) {
activity.handleSAFDialog(SAFPath) {
selectedPositions.sortedDescending().forEach {
val directory = dirs[it]
folders.add(File(directory.path))

View File

@ -12,7 +12,6 @@ import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.removeNoMedia
import kotlinx.android.synthetic.main.item_manage_folder.view.*
import java.io.File
import java.util.*
class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<String>, val listener: RefreshRecyclerViewListener?,
@ -70,7 +69,7 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra
}
if (sdCardPaths.isNotEmpty()) {
activity.handleSAFDialog(File(sdCardPaths.first())) {
activity.handleSAFDialog(sdCardPaths.first()) {
unhideFolders(removeFolders)
}
} else {

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery.adapters
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.view.Menu
@ -13,7 +12,9 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.dialogs.RenameItemDialog
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getFilenameFromPath
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.gallery.R
@ -23,7 +24,6 @@ import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.photo_video_item_grid.view.*
import java.io.File
import java.util.*
class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null,
@ -86,6 +86,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
}
override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) {
return
}
when (id) {
R.id.cab_confirm_selection -> confirmSelection()
R.id.cab_properties -> showProperties()
@ -97,8 +101,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
R.id.cab_copy_to -> copyMoveTo(true)
R.id.cab_move_to -> copyMoveTo(false)
R.id.cab_select_all -> selectAll()
R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile()), true)
R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile()))
R.id.cab_open_with -> activity.openPath(getCurrentPath(), true)
R.id.cab_set_as -> activity.setAs(getCurrentPath())
R.id.cab_delete -> checkDeleteConfirmation()
}
}
@ -145,7 +149,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
}
private fun renameFile() {
RenameItemDialog(activity, getCurrentFile().absolutePath) {
RenameItemDialog(activity, getCurrentPath()) {
activity.runOnUiThread {
listener?.refreshItems()
finishActMode()
@ -154,15 +158,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
}
private fun editFile() {
activity.openEditor(Uri.fromFile(getCurrentFile()))
activity.openEditor(getCurrentPath())
finishActMode()
}
private fun toggleFileVisibility(hide: Boolean) {
Thread {
getSelectedMedia().forEach {
val oldFile = File(it.path)
activity.toggleFileVisibility(oldFile, hide)
activity.toggleFileVisibility(it.path, hide)
}
activity.runOnUiThread {
listener?.refreshItems()
@ -180,10 +183,11 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
}
private fun copyMoveTo(isCopyOperation: Boolean) {
val files = ArrayList<File>()
selectedPositions.forEach { files.add(File(media[it].path)) }
val paths = ArrayList<String>()
selectedPositions.forEach { paths.add(media[it].path) }
activity.tryCopyMoveFilesTo(files, isCopyOperation) {
val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList
activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) {
config.tempFolderPath = ""
if (!isCopyOperation) {
listener?.refreshItems()
@ -211,14 +215,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
deleteFiles()
}
private fun getCurrentFile() = File(media[selectedPositions.first()].path)
private fun getCurrentPath() = media[selectedPositions.first()].path
private fun getCurrentFile() = File(getCurrentPath())
private fun deleteFiles() {
if (selectedPositions.isEmpty()) {
return
}
val files = ArrayList<File>(selectedPositions.size)
val fileDirItems = ArrayList<FileDirItem>(selectedPositions.size)
val removeMedia = ArrayList<Medium>(selectedPositions.size)
if (media.size <= selectedPositions.first()) {
@ -227,15 +229,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
}
val SAFPath = media[selectedPositions.first()].path
activity.handleSAFDialog(File(SAFPath)) {
activity.handleSAFDialog(SAFPath) {
selectedPositions.sortedDescending().forEach {
val medium = media[it]
files.add(File(medium.path))
fileDirItems.add(FileDirItem(medium.path, medium.name))
removeMedia.add(medium)
}
media.removeAll(removeMedia)
listener?.deleteFiles(files)
listener?.deleteFiles(fileDirItems)
removeSelectedItems()
}
}
@ -314,7 +316,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
interface MediaOperationsListener {
fun refreshItems()
fun deleteFiles(files: ArrayList<File>)
fun deleteFiles(fileDirItems: ArrayList<FileDirItem>)
fun selectedPaths(paths: ArrayList<String>)
}

View File

@ -81,7 +81,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti
config.saveFileSorting(path, sorting)
} else {
config.removeFileSorting(path)
config.fileSorting = sorting
config.sorting = sorting
}
}
callback()

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.extensions
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.provider.MediaStore
import android.support.v7.app.AppCompatActivity
import android.view.View
@ -17,6 +16,7 @@ import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.BuildConfig
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
@ -32,34 +32,33 @@ import pl.droidsonroids.gif.GifDrawable
import java.io.File
import java.util.*
fun Activity.shareUri(uri: Uri) {
shareUri(uri, BuildConfig.APPLICATION_ID)
fun Activity.sharePath(path: String) {
sharePathIntent(path, BuildConfig.APPLICATION_ID)
}
fun Activity.shareUris(uris: ArrayList<Uri>) {
shareUris(uris, BuildConfig.APPLICATION_ID)
fun Activity.sharePaths(paths: ArrayList<String>) {
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
}
fun Activity.shareMedium(medium: Medium) {
val file = File(medium.path)
shareUri(Uri.fromFile(file))
sharePath(medium.path)
}
fun Activity.shareMedia(media: List<Medium>) {
val uris = media.map { Uri.fromFile(File(it.path)) } as ArrayList
shareUris(uris)
val paths = media.map { it.path } as ArrayList
sharePaths(paths)
}
fun Activity.setAs(uri: Uri) {
setAs(uri, BuildConfig.APPLICATION_ID)
fun Activity.setAs(path: String) {
setAsIntent(path, BuildConfig.APPLICATION_ID)
}
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.openEditor(uri: Uri) {
openEditor(uri, BuildConfig.APPLICATION_ID)
fun Activity.openEditor(path: String) {
openEditorIntent(path, BuildConfig.APPLICATION_ID)
}
fun Activity.launchCamera() {
@ -100,8 +99,8 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
return
if (needsStupidWritePermissions(path)) {
handleSAFDialog(file) {
val fileDocument = getFileDocument(path)
handleSAFDialog(file.absolutePath) {
val fileDocument = getDocumentFile(path)
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
fileDocument.createFile("", NOMEDIA)
} else {
@ -123,22 +122,23 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
val file = File(path, NOMEDIA)
deleteFile(file) {
deleteFile(file.toFileDirItem(applicationContext)) {
callback?.invoke()
}
}
fun BaseSimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: ((newFile: File) -> Unit)? = null) {
val path = oldFile.parent
var filename = oldFile.name
fun BaseSimpleActivity.toggleFileVisibility(oldPath: String, hide: Boolean, callback: ((newPath: String) -> Unit)? = null) {
val path = oldPath.getParentPath()
var filename = oldPath.getFilenameFromPath()
filename = if (hide) {
".${filename.trimStart('.')}"
} else {
filename.substring(1, filename.length)
}
val newFile = File(path, filename)
renameFile(oldFile, newFile) {
callback?.invoke(newFile)
val newPath = "$path/$filename"
renameFile(oldPath, newPath) {
callback?.invoke(newPath)
}
}
@ -169,15 +169,15 @@ fun Activity.loadImage(type: Int, path: String, target: MySquareImageView, horiz
}
}
fun BaseSimpleActivity.tryCopyMoveFilesTo(files: ArrayList<File>, isCopyOperation: Boolean, callback: () -> Unit) {
if (files.isEmpty()) {
fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList<FileDirItem>, isCopyOperation: Boolean, callback: () -> Unit) {
if (fileDirItems.isEmpty()) {
toast(R.string.unknown_error_occurred)
return
}
val source = if (files[0].isFile) files[0].parent else files[0].absolutePath
val source = fileDirItems[0].getParentPath()
PickDirectoryDialog(this, source) {
copyMoveFilesTo(files, source.trimEnd('/'), it, isCopyOperation, true, config.shouldShowHidden, callback)
copyMoveFilesTo(fileDirItems, source.trimEnd('/'), it, isCopyOperation, true, config.shouldShowHidden, callback)
}
}

View File

@ -0,0 +1,6 @@
package com.simplemobiletools.gallery.extensions
import android.os.Environment
import com.simplemobiletools.commons.models.FileDirItem
fun FileDirItem.isDownloadsFolder() = path == Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()

View File

@ -45,7 +45,7 @@ abstract class ViewPagerFragment : Fragment() {
}
if (detailsFlag and EXT_RESOLUTION != 0) {
file.getResolution().formatAsResolution().let { if (it.isNotEmpty()) details.appendln(it) }
file.absolutePath.getResolution()?.formatAsResolution().let { if (it?.isNotEmpty() == true) details.appendln(it) }
}
if (detailsFlag and EXT_LAST_MODIFIED != 0) {

View File

@ -16,23 +16,19 @@ class Config(context: Context) : BaseConfig(context) {
fun newInstance(context: Context) = Config(context)
}
var fileSorting: Int
get() = prefs.getInt(SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
set(order) = prefs.edit().putInt(SORT_ORDER, order).apply()
var directorySorting: Int
get() = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
set(order) = prefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply()
fun saveFileSorting(path: String, value: Int) {
if (path.isEmpty()) {
fileSorting = value
sorting = value
} else {
prefs.edit().putInt(SORT_FOLDER_PREFIX + path.toLowerCase(), value).apply()
}
}
fun getFileSorting(path: String) = prefs.getInt(SORT_FOLDER_PREFIX + path.toLowerCase(), fileSorting)
fun getFileSorting(path: String) = prefs.getInt(SORT_FOLDER_PREFIX + path.toLowerCase(), sorting)
fun removeFileSorting(path: String) {
prefs.edit().remove(SORT_FOLDER_PREFIX + path.toLowerCase()).apply()

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.gallery.helpers
// shared preferences
const val SORT_ORDER = "sort_order"
const val DIRECTORY_SORT_ORDER = "directory_sort_order"
const val SORT_FOLDER_PREFIX = "sort_folder_"
const val SHOW_HIDDEN_MEDIA = "show_hidden_media"

View File

@ -138,8 +138,9 @@ class MediaFetcher(val context: Context) {
if (cur.moveToFirst()) {
do {
try {
if (shouldStop)
if (shouldStop) {
break
}
val path = cur.getStringValue(MediaStore.Images.Media.DATA).trim()
var filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)?.trim() ?: ""

View File

@ -2,7 +2,7 @@ package com.simplemobiletools.gallery.models
import com.simplemobiletools.commons.extensions.formatDate
import com.simplemobiletools.commons.extensions.formatSize
import com.simplemobiletools.commons.extensions.getMimeTypeFromPath
import com.simplemobiletools.commons.extensions.getMimeType
import com.simplemobiletools.commons.extensions.isDng
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.gallery.helpers.TYPE_GIF
@ -24,7 +24,7 @@ data class Medium(var name: String, var path: String, val modified: Long, val ta
fun isDng() = path.isDng()
fun getMimeType() = path.getMimeTypeFromPath()
fun getMimeType() = path.getMimeType()
override fun compareTo(other: Medium): Int {
var result: Int

View File

@ -3,4 +3,6 @@
<integer name="directory_columns_horizontal_scroll">3</integer>
<integer name="media_columns_vertical_scroll">3</integer>
<integer name="media_columns_horizontal_scroll">4</integer>
<integer name="default_sorting">1026</integer>
</resources>