update commons to 3.12.6
This commit is contained in:
parent
df1494d684
commit
fb493459de
18 changed files with 130 additions and 120 deletions
|
@ -46,7 +46,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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.theartofdev.edmodo:android-image-cropper:2.6.0'
|
||||||
implementation 'com.android.support:multidex:1.0.2'
|
implementation 'com.android.support:multidex:1.0.2'
|
||||||
implementation 'com.google.code.gson:gson:2.8.2'
|
implementation 'com.google.code.gson:gson:2.8.2'
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.dialogs.ResizeDialog
|
import com.simplemobiletools.gallery.dialogs.ResizeDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
|
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
|
||||||
|
@ -191,7 +192,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
try {
|
try {
|
||||||
Thread {
|
Thread {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
getFileOutputStream(file) {
|
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
||||||
|
getFileOutputStream(fileDirItem) {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
saveBitmap(file, bitmap, it)
|
saveBitmap(file, bitmap, it)
|
||||||
} else {
|
} else {
|
||||||
|
@ -227,7 +229,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun editWith() {
|
private fun editWith() {
|
||||||
openEditor(uri)
|
openEditor(uri.toString())
|
||||||
isEditingWithThirdParty = true
|
isEditingWithThirdParty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
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_MODIFIED
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
|
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.RadioItem
|
||||||
import com.simplemobiletools.commons.models.Release
|
import com.simplemobiletools.commons.models.Release
|
||||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||||
|
@ -233,7 +234,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
val newFolder = File(config.tempFolderPath)
|
val newFolder = File(config.tempFolderPath)
|
||||||
if (newFolder.exists() && newFolder.isDirectory) {
|
if (newFolder.exists() && newFolder.isDirectory) {
|
||||||
if (newFolder.list()?.isEmpty() == true) {
|
if (newFolder.list()?.isEmpty() == true) {
|
||||||
deleteFile(newFolder, true)
|
deleteFile(newFolder.toFileDirItem(applicationContext), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.tempFolderPath = ""
|
config.tempFolderPath = ""
|
||||||
|
@ -352,7 +353,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteFolders(folders: ArrayList<File>) {
|
override fun deleteFolders(folders: ArrayList<File>) {
|
||||||
deleteFolders(folders) {
|
val fileDirItems = folders.map { FileDirItem(it.absolutePath, it.name, true) } as ArrayList<FileDirItem>
|
||||||
|
deleteFolders(fileDirItems) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
refreshItems()
|
refreshItems()
|
||||||
}
|
}
|
||||||
|
@ -522,7 +524,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
private fun fillIntentPath(resultData: Intent, resultIntent: Intent) {
|
private fun fillIntentPath(resultData: Intent, resultIntent: Intent) {
|
||||||
val path = resultData.data.path
|
val path = resultData.data.path
|
||||||
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
|
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
|
||||||
val type = path.getMimeTypeFromPath()
|
val type = path.getMimeType()
|
||||||
resultIntent.setDataAndTypeAndNormalize(uri, type)
|
resultIntent.setDataAndTypeAndNormalize(uri, type)
|
||||||
resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
|
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
@ -442,9 +443,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteDirectoryIfEmpty() {
|
private fun deleteDirectoryIfEmpty() {
|
||||||
val file = File(mPath)
|
val fileDirItem = FileDirItem(mPath, mPath.getFilenameFromPath())
|
||||||
if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.list()?.isEmpty() == true) {
|
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(applicationContext, true) == 0) {
|
||||||
deleteFile(file, true)
|
deleteFile(fileDirItem, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,10 +611,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}
|
}
|
||||||
finish()
|
finish()
|
||||||
} else {
|
} else {
|
||||||
val file = File(path)
|
val isVideo = path.isVideoFast()
|
||||||
val isVideo = file.isVideoFast()
|
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
openFile(Uri.fromFile(file), false)
|
openPath(path, false)
|
||||||
} else {
|
} else {
|
||||||
Intent(this, ViewPagerActivity::class.java).apply {
|
Intent(this, ViewPagerActivity::class.java).apply {
|
||||||
putExtra(PATH, path)
|
putExtra(PATH, path)
|
||||||
|
@ -666,8 +666,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteFiles(files: ArrayList<File>) {
|
override fun deleteFiles(fileDirItems: ArrayList<FileDirItem>) {
|
||||||
val filtered = files.filter { it.isImageVideoGif() } as ArrayList
|
val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList
|
||||||
deleteFiles(filtered) {
|
deleteFiles(filtered) {
|
||||||
if (!it) {
|
if (!it) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
|
|
|
@ -59,7 +59,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
private fun checkIntent(savedInstanceState: Bundle? = null) {
|
private fun checkIntent(savedInstanceState: Bundle? = null) {
|
||||||
mUri = intent.data ?: return
|
mUri = intent.data ?: return
|
||||||
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
|
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)
|
mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false)
|
||||||
|
@ -131,14 +131,15 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
if (mMedium == null)
|
if (mMedium == null) {
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_set_as -> setAs(mUri!!)
|
R.id.menu_set_as -> setAs(mUri!!.toString())
|
||||||
R.id.menu_open_with -> openFile(mUri!!, true)
|
R.id.menu_open_with -> openPath(mUri!!.toString(), true)
|
||||||
R.id.menu_share -> shareUri(mUri!!)
|
R.id.menu_share -> sharePath(mUri!!.toString())
|
||||||
R.id.menu_edit -> openEditor(mUri!!)
|
R.id.menu_edit -> openEditor(mUri!!.toString())
|
||||||
R.id.menu_properties -> showProperties()
|
R.id.menu_properties -> showProperties()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
|
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
|
||||||
import com.simplemobiletools.commons.helpers.REQUEST_SET_AS
|
import com.simplemobiletools.commons.helpers.REQUEST_SET_AS
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.MyPagerAdapter
|
import com.simplemobiletools.gallery.adapters.MyPagerAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||||
|
@ -180,10 +181,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val file = File(mPath)
|
if (!getDoesFilePathExist(mPath)) {
|
||||||
if (!file.exists() && file.length() == 0L) {
|
|
||||||
Thread {
|
Thread {
|
||||||
deleteFromMediaStore(file)
|
deleteFromMediaStore(mPath)
|
||||||
}.start()
|
}.start()
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
|
@ -201,7 +201,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
showSystemUI()
|
showSystemUI()
|
||||||
|
|
||||||
mDirectory = file.parent
|
mDirectory = mPath.getParentPath().trimEnd('/')
|
||||||
supportActionBar?.title = mPath.getFilenameFromPath()
|
supportActionBar?.title = mPath.getFilenameFromPath()
|
||||||
|
|
||||||
view_pager.onGlobalLayout {
|
view_pager.onGlobalLayout {
|
||||||
|
@ -272,18 +272,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
return true
|
return true
|
||||||
|
|
||||||
when (item.itemId) {
|
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_slideshow -> initSlideshow()
|
||||||
R.id.menu_copy_to -> copyMoveTo(true)
|
R.id.menu_copy_to -> copyMoveTo(true)
|
||||||
R.id.menu_move_to -> copyMoveTo(false)
|
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_hide -> toggleFileVisibility(true)
|
||||||
R.id.menu_unhide -> toggleFileVisibility(false)
|
R.id.menu_unhide -> toggleFileVisibility(false)
|
||||||
R.id.menu_share_1 -> shareMedium(getCurrentMedium()!!)
|
R.id.menu_share_1 -> shareMedium(getCurrentMedium()!!)
|
||||||
R.id.menu_share_2 -> shareMedium(getCurrentMedium()!!)
|
R.id.menu_share_2 -> shareMedium(getCurrentMedium()!!)
|
||||||
R.id.menu_delete -> checkDeleteConfirmation()
|
R.id.menu_delete -> checkDeleteConfirmation()
|
||||||
R.id.menu_rename -> renameFile()
|
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_properties -> showProperties()
|
||||||
R.id.menu_show_on_map -> showOnMap()
|
R.id.menu_show_on_map -> showOnMap()
|
||||||
R.id.menu_rotate_right -> rotateImage(90)
|
R.id.menu_rotate_right -> rotateImage(90)
|
||||||
|
@ -462,8 +462,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||||
val files = ArrayList<File>(1).apply { add(getCurrentFile()) }
|
val currPath = getCurrentPath()
|
||||||
tryCopyMoveFilesTo(files, isCopyOperation) {
|
val fileDirItems = arrayListOf(FileDirItem(currPath, currPath.getFilenameFromPath()))
|
||||||
|
tryCopyMoveFilesTo(fileDirItems, isCopyOperation) {
|
||||||
config.tempFolderPath = ""
|
config.tempFolderPath = ""
|
||||||
if (!isCopyOperation) {
|
if (!isCopyOperation) {
|
||||||
refreshViewPager()
|
refreshViewPager()
|
||||||
|
@ -472,13 +473,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFileVisibility(hide: Boolean) {
|
private fun toggleFileVisibility(hide: Boolean) {
|
||||||
toggleFileVisibility(getCurrentFile(), hide) {
|
toggleFileVisibility(getCurrentPath(), hide) {
|
||||||
val newFileName = it.absolutePath.getFilenameFromPath()
|
val newFileName = it.getFilenameFromPath()
|
||||||
supportActionBar?.title = newFileName
|
supportActionBar?.title = newFileName
|
||||||
|
|
||||||
getCurrentMedium()!!.apply {
|
getCurrentMedium()!!.apply {
|
||||||
name = newFileName
|
name = newFileName
|
||||||
path = it.absolutePath
|
path = it
|
||||||
getCurrentMedia()[mPos] = this
|
getCurrentMedia()[mPos] = this
|
||||||
}
|
}
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
|
@ -508,8 +509,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private fun saveImageAs() {
|
private fun saveImageAs() {
|
||||||
val currPath = getCurrentPath()
|
val currPath = getCurrentPath()
|
||||||
SaveAsDialog(this, currPath, false) {
|
SaveAsDialog(this, currPath, false) {
|
||||||
val selectedFile = File(it)
|
handleSAFDialog(it) {
|
||||||
handleSAFDialog(selectedFile) {
|
|
||||||
Thread {
|
Thread {
|
||||||
saveImageToFile(currPath, it)
|
saveImageToFile(currPath, it)
|
||||||
}.start()
|
}.start()
|
||||||
|
@ -523,7 +523,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}")
|
val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}")
|
||||||
try {
|
try {
|
||||||
val bitmap = BitmapFactory.decodeFile(oldPath)
|
val bitmap = BitmapFactory.decodeFile(oldPath)
|
||||||
getFileOutputStream(tmpFile) {
|
getFileOutputStream(tmpFile.toFileDirItem(applicationContext)) {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
return@getFileOutputStream
|
return@getFileOutputStream
|
||||||
|
@ -536,16 +536,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
saveFile(tmpFile, bitmap, it as FileOutputStream)
|
saveFile(tmpFile, bitmap, it as FileOutputStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmpFile.length() > 0 && newFile.exists()) {
|
if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) {
|
||||||
deleteFile(newFile)
|
deleteFile(FileDirItem(newPath, newPath.getFilenameFromPath()))
|
||||||
}
|
}
|
||||||
copyFile(tmpFile, newFile)
|
copyFile(tmpFile, newFile)
|
||||||
scanFile(newFile)
|
scanPath(newPath)
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
|
|
||||||
if (config.keepLastModified) {
|
if (config.keepLastModified) {
|
||||||
newFile.setLastModified(oldLastModified)
|
newFile.setLastModified(oldLastModified)
|
||||||
updateLastModified(newFile, oldLastModified)
|
updateLastModified(newPath, oldLastModified)
|
||||||
}
|
}
|
||||||
|
|
||||||
it.flush()
|
it.flush()
|
||||||
|
@ -565,7 +565,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
} finally {
|
} finally {
|
||||||
deleteFile(tmpFile)
|
deleteFile(FileDirItem(newPath, newPath.getFilenameFromPath()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +573,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
var inputStream: InputStream? = null
|
var inputStream: InputStream? = null
|
||||||
var out: OutputStream? = null
|
var out: OutputStream? = null
|
||||||
try {
|
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)
|
out = getFileOutputStreamSync(destination.absolutePath, source.getMimeType(), fileDocument)
|
||||||
inputStream = FileInputStream(source)
|
inputStream = FileInputStream(source)
|
||||||
inputStream.copyTo(out!!)
|
inputStream.copyTo(out!!)
|
||||||
|
@ -735,7 +735,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteConfirmed() {
|
private fun deleteConfirmed() {
|
||||||
deleteFile(File(getCurrentMedia()[mPos].path)) {
|
val path = getCurrentMedia()[mPos].path
|
||||||
|
deleteFile(FileDirItem(path, path.getFilenameFromPath())) {
|
||||||
refreshViewPager()
|
refreshViewPager()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,9 +812,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteDirectoryIfEmpty() {
|
private fun deleteDirectoryIfEmpty() {
|
||||||
val file = File(mDirectory)
|
val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), getIsPathDirectory(mDirectory))
|
||||||
if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.list()?.isEmpty() == true) {
|
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(applicationContext, true) == 0) {
|
||||||
deleteFile(file, true)
|
deleteFile(fileDirItem, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
scanPath(mDirectory)
|
scanPath(mDirectory)
|
||||||
|
@ -821,7 +822,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
private fun checkOrientation() {
|
private fun checkOrientation() {
|
||||||
if (!mIsOrientationLocked && config.screenRotation == ROTATE_BY_ASPECT_RATIO) {
|
if (!mIsOrientationLocked && config.screenRotation == ROTATE_BY_ASPECT_RATIO) {
|
||||||
val res = getCurrentFile().getResolution()
|
val res = getCurrentPath().getResolution() ?: return
|
||||||
if (res.x > res.y) {
|
if (res.x > res.y) {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||||
} else if (res.x < res.y) {
|
} else if (res.x < res.y) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.FastScroller
|
import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
|
@ -76,6 +77,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun actionItemPressed(id: Int) {
|
override fun actionItemPressed(id: Int) {
|
||||||
|
if (selectedPositions.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.cab_properties -> showProperties()
|
R.id.cab_properties -> showProperties()
|
||||||
R.id.cab_rename -> renameDir()
|
R.id.cab_rename -> renameDir()
|
||||||
|
@ -213,16 +218,14 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||||
if (selectedPositions.isEmpty())
|
val paths = ArrayList<String>()
|
||||||
return
|
|
||||||
|
|
||||||
val files = ArrayList<File>()
|
|
||||||
selectedPositions.forEach {
|
selectedPositions.forEach {
|
||||||
val dir = File(dirs[it].path)
|
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 = ""
|
config.tempFolderPath = ""
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
|
@ -236,10 +239,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteFiles() {
|
private fun deleteFiles() {
|
||||||
if (selectedPositions.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val folders = ArrayList<File>(selectedPositions.size)
|
val folders = ArrayList<File>(selectedPositions.size)
|
||||||
val removeFolders = ArrayList<Directory>(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 {
|
selectedPositions.sortedDescending().forEach {
|
||||||
val directory = dirs[it]
|
val directory = dirs[it]
|
||||||
folders.add(File(directory.path))
|
folders.add(File(directory.path))
|
||||||
|
|
|
@ -12,7 +12,6 @@ import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.removeNoMedia
|
import com.simplemobiletools.gallery.extensions.removeNoMedia
|
||||||
import kotlinx.android.synthetic.main.item_manage_folder.view.*
|
import kotlinx.android.synthetic.main.item_manage_folder.view.*
|
||||||
import java.io.File
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<String>, val listener: RefreshRecyclerViewListener?,
|
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()) {
|
if (sdCardPaths.isNotEmpty()) {
|
||||||
activity.handleSAFDialog(File(sdCardPaths.first())) {
|
activity.handleSAFDialog(sdCardPaths.first()) {
|
||||||
unhideFolders(removeFolders)
|
unhideFolders(removeFolders)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.simplemobiletools.gallery.adapters
|
package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
@ -13,7 +12,9 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
|
import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||||
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.FastScroller
|
import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
|
@ -23,7 +24,6 @@ import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.photo_video_item_grid.view.*
|
import kotlinx.android.synthetic.main.photo_video_item_grid.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
|
class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
|
||||||
val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null,
|
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) {
|
override fun actionItemPressed(id: Int) {
|
||||||
|
if (selectedPositions.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.cab_confirm_selection -> confirmSelection()
|
R.id.cab_confirm_selection -> confirmSelection()
|
||||||
R.id.cab_properties -> showProperties()
|
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_copy_to -> copyMoveTo(true)
|
||||||
R.id.cab_move_to -> copyMoveTo(false)
|
R.id.cab_move_to -> copyMoveTo(false)
|
||||||
R.id.cab_select_all -> selectAll()
|
R.id.cab_select_all -> selectAll()
|
||||||
R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile()), true)
|
R.id.cab_open_with -> activity.openPath(getCurrentPath(), true)
|
||||||
R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile()))
|
R.id.cab_set_as -> activity.setAs(getCurrentPath())
|
||||||
R.id.cab_delete -> checkDeleteConfirmation()
|
R.id.cab_delete -> checkDeleteConfirmation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +149,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renameFile() {
|
private fun renameFile() {
|
||||||
RenameItemDialog(activity, getCurrentFile().absolutePath) {
|
RenameItemDialog(activity, getCurrentPath()) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
|
@ -154,15 +158,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun editFile() {
|
private fun editFile() {
|
||||||
activity.openEditor(Uri.fromFile(getCurrentFile()))
|
activity.openEditor(getCurrentPath())
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFileVisibility(hide: Boolean) {
|
private fun toggleFileVisibility(hide: Boolean) {
|
||||||
Thread {
|
Thread {
|
||||||
getSelectedMedia().forEach {
|
getSelectedMedia().forEach {
|
||||||
val oldFile = File(it.path)
|
activity.toggleFileVisibility(it.path, hide)
|
||||||
activity.toggleFileVisibility(oldFile, hide)
|
|
||||||
}
|
}
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
|
@ -180,10 +183,11 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||||
val files = ArrayList<File>()
|
val paths = ArrayList<String>()
|
||||||
selectedPositions.forEach { files.add(File(media[it].path)) }
|
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 = ""
|
config.tempFolderPath = ""
|
||||||
if (!isCopyOperation) {
|
if (!isCopyOperation) {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
|
@ -211,14 +215,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
deleteFiles()
|
deleteFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentFile() = File(media[selectedPositions.first()].path)
|
private fun getCurrentPath() = media[selectedPositions.first()].path
|
||||||
|
|
||||||
|
private fun getCurrentFile() = File(getCurrentPath())
|
||||||
|
|
||||||
private fun deleteFiles() {
|
private fun deleteFiles() {
|
||||||
if (selectedPositions.isEmpty()) {
|
val fileDirItems = ArrayList<FileDirItem>(selectedPositions.size)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val files = ArrayList<File>(selectedPositions.size)
|
|
||||||
val removeMedia = ArrayList<Medium>(selectedPositions.size)
|
val removeMedia = ArrayList<Medium>(selectedPositions.size)
|
||||||
|
|
||||||
if (media.size <= selectedPositions.first()) {
|
if (media.size <= selectedPositions.first()) {
|
||||||
|
@ -227,15 +229,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
}
|
}
|
||||||
|
|
||||||
val SAFPath = media[selectedPositions.first()].path
|
val SAFPath = media[selectedPositions.first()].path
|
||||||
activity.handleSAFDialog(File(SAFPath)) {
|
activity.handleSAFDialog(SAFPath) {
|
||||||
selectedPositions.sortedDescending().forEach {
|
selectedPositions.sortedDescending().forEach {
|
||||||
val medium = media[it]
|
val medium = media[it]
|
||||||
files.add(File(medium.path))
|
fileDirItems.add(FileDirItem(medium.path, medium.name))
|
||||||
removeMedia.add(medium)
|
removeMedia.add(medium)
|
||||||
}
|
}
|
||||||
|
|
||||||
media.removeAll(removeMedia)
|
media.removeAll(removeMedia)
|
||||||
listener?.deleteFiles(files)
|
listener?.deleteFiles(fileDirItems)
|
||||||
removeSelectedItems()
|
removeSelectedItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,7 +316,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
interface MediaOperationsListener {
|
interface MediaOperationsListener {
|
||||||
fun refreshItems()
|
fun refreshItems()
|
||||||
|
|
||||||
fun deleteFiles(files: ArrayList<File>)
|
fun deleteFiles(fileDirItems: ArrayList<FileDirItem>)
|
||||||
|
|
||||||
fun selectedPaths(paths: ArrayList<String>)
|
fun selectedPaths(paths: ArrayList<String>)
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti
|
||||||
config.saveFileSorting(path, sorting)
|
config.saveFileSorting(path, sorting)
|
||||||
} else {
|
} else {
|
||||||
config.removeFileSorting(path)
|
config.removeFileSorting(path)
|
||||||
config.fileSorting = sorting
|
config.sorting = sorting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback()
|
callback()
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.extensions
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -17,6 +16,7 @@ import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.gallery.BuildConfig
|
import com.simplemobiletools.gallery.BuildConfig
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
|
@ -32,34 +32,33 @@ import pl.droidsonroids.gif.GifDrawable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun Activity.shareUri(uri: Uri) {
|
fun Activity.sharePath(path: String) {
|
||||||
shareUri(uri, BuildConfig.APPLICATION_ID)
|
sharePathIntent(path, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.shareUris(uris: ArrayList<Uri>) {
|
fun Activity.sharePaths(paths: ArrayList<String>) {
|
||||||
shareUris(uris, BuildConfig.APPLICATION_ID)
|
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.shareMedium(medium: Medium) {
|
fun Activity.shareMedium(medium: Medium) {
|
||||||
val file = File(medium.path)
|
sharePath(medium.path)
|
||||||
shareUri(Uri.fromFile(file))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.shareMedia(media: List<Medium>) {
|
fun Activity.shareMedia(media: List<Medium>) {
|
||||||
val uris = media.map { Uri.fromFile(File(it.path)) } as ArrayList
|
val paths = media.map { it.path } as ArrayList
|
||||||
shareUris(uris)
|
sharePaths(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.setAs(uri: Uri) {
|
fun Activity.setAs(path: String) {
|
||||||
setAs(uri, BuildConfig.APPLICATION_ID)
|
setAsIntent(path, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.openFile(uri: Uri, forceChooser: Boolean) {
|
fun Activity.openPath(path: String, forceChooser: Boolean) {
|
||||||
openFile(uri, forceChooser, BuildConfig.APPLICATION_ID)
|
openPathIntent(path, forceChooser, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.openEditor(uri: Uri) {
|
fun Activity.openEditor(path: String) {
|
||||||
openEditor(uri, BuildConfig.APPLICATION_ID)
|
openEditorIntent(path, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.launchCamera() {
|
fun Activity.launchCamera() {
|
||||||
|
@ -100,8 +99,8 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
||||||
return
|
return
|
||||||
|
|
||||||
if (needsStupidWritePermissions(path)) {
|
if (needsStupidWritePermissions(path)) {
|
||||||
handleSAFDialog(file) {
|
handleSAFDialog(file.absolutePath) {
|
||||||
val fileDocument = getFileDocument(path)
|
val fileDocument = getDocumentFile(path)
|
||||||
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
|
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
|
||||||
fileDocument.createFile("", NOMEDIA)
|
fileDocument.createFile("", NOMEDIA)
|
||||||
} else {
|
} else {
|
||||||
|
@ -123,22 +122,23 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
||||||
|
|
||||||
fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
|
fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
|
||||||
val file = File(path, NOMEDIA)
|
val file = File(path, NOMEDIA)
|
||||||
deleteFile(file) {
|
deleteFile(file.toFileDirItem(applicationContext)) {
|
||||||
callback?.invoke()
|
callback?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: ((newFile: File) -> Unit)? = null) {
|
fun BaseSimpleActivity.toggleFileVisibility(oldPath: String, hide: Boolean, callback: ((newPath: String) -> Unit)? = null) {
|
||||||
val path = oldFile.parent
|
val path = oldPath.getParentPath()
|
||||||
var filename = oldFile.name
|
var filename = oldPath.getFilenameFromPath()
|
||||||
filename = if (hide) {
|
filename = if (hide) {
|
||||||
".${filename.trimStart('.')}"
|
".${filename.trimStart('.')}"
|
||||||
} else {
|
} else {
|
||||||
filename.substring(1, filename.length)
|
filename.substring(1, filename.length)
|
||||||
}
|
}
|
||||||
val newFile = File(path, filename)
|
|
||||||
renameFile(oldFile, newFile) {
|
val newPath = "$path/$filename"
|
||||||
callback?.invoke(newFile)
|
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) {
|
fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList<FileDirItem>, isCopyOperation: Boolean, callback: () -> Unit) {
|
||||||
if (files.isEmpty()) {
|
if (fileDirItems.isEmpty()) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val source = if (files[0].isFile) files[0].parent else files[0].absolutePath
|
val source = fileDirItems[0].getParentPath()
|
||||||
PickDirectoryDialog(this, source) {
|
PickDirectoryDialog(this, source) {
|
||||||
copyMoveFilesTo(files, source.trimEnd('/'), it, isCopyOperation, true, config.shouldShowHidden, callback)
|
copyMoveFilesTo(fileDirItems, source.trimEnd('/'), it, isCopyOperation, true, config.shouldShowHidden, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
|
@ -45,7 +45,7 @@ abstract class ViewPagerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (detailsFlag and EXT_RESOLUTION != 0) {
|
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) {
|
if (detailsFlag and EXT_LAST_MODIFIED != 0) {
|
||||||
|
|
|
@ -16,23 +16,19 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
fun newInstance(context: Context) = Config(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
|
var directorySorting: Int
|
||||||
get() = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
|
get() = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
|
||||||
set(order) = prefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply()
|
set(order) = prefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply()
|
||||||
|
|
||||||
fun saveFileSorting(path: String, value: Int) {
|
fun saveFileSorting(path: String, value: Int) {
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
fileSorting = value
|
sorting = value
|
||||||
} else {
|
} else {
|
||||||
prefs.edit().putInt(SORT_FOLDER_PREFIX + path.toLowerCase(), value).apply()
|
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) {
|
fun removeFileSorting(path: String) {
|
||||||
prefs.edit().remove(SORT_FOLDER_PREFIX + path.toLowerCase()).apply()
|
prefs.edit().remove(SORT_FOLDER_PREFIX + path.toLowerCase()).apply()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.simplemobiletools.gallery.helpers
|
package com.simplemobiletools.gallery.helpers
|
||||||
|
|
||||||
// shared preferences
|
// shared preferences
|
||||||
const val SORT_ORDER = "sort_order"
|
|
||||||
const val DIRECTORY_SORT_ORDER = "directory_sort_order"
|
const val DIRECTORY_SORT_ORDER = "directory_sort_order"
|
||||||
const val SORT_FOLDER_PREFIX = "sort_folder_"
|
const val SORT_FOLDER_PREFIX = "sort_folder_"
|
||||||
const val SHOW_HIDDEN_MEDIA = "show_hidden_media"
|
const val SHOW_HIDDEN_MEDIA = "show_hidden_media"
|
||||||
|
|
|
@ -138,8 +138,9 @@ class MediaFetcher(val context: Context) {
|
||||||
if (cur.moveToFirst()) {
|
if (cur.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
if (shouldStop)
|
if (shouldStop) {
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
|
||||||
val path = cur.getStringValue(MediaStore.Images.Media.DATA).trim()
|
val path = cur.getStringValue(MediaStore.Images.Media.DATA).trim()
|
||||||
var filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)?.trim() ?: ""
|
var filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)?.trim() ?: ""
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.simplemobiletools.gallery.models
|
||||||
|
|
||||||
import com.simplemobiletools.commons.extensions.formatDate
|
import com.simplemobiletools.commons.extensions.formatDate
|
||||||
import com.simplemobiletools.commons.extensions.formatSize
|
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.extensions.isDng
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.gallery.helpers.TYPE_GIF
|
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 isDng() = path.isDng()
|
||||||
|
|
||||||
fun getMimeType() = path.getMimeTypeFromPath()
|
fun getMimeType() = path.getMimeType()
|
||||||
|
|
||||||
override fun compareTo(other: Medium): Int {
|
override fun compareTo(other: Medium): Int {
|
||||||
var result: Int
|
var result: Int
|
||||||
|
|
|
@ -3,4 +3,6 @@
|
||||||
<integer name="directory_columns_horizontal_scroll">3</integer>
|
<integer name="directory_columns_horizontal_scroll">3</integer>
|
||||||
<integer name="media_columns_vertical_scroll">3</integer>
|
<integer name="media_columns_vertical_scroll">3</integer>
|
||||||
<integer name="media_columns_horizontal_scroll">4</integer>
|
<integer name="media_columns_horizontal_scroll">4</integer>
|
||||||
|
|
||||||
|
<integer name="default_sorting">1026</integer>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue