avoid creating unnecessary background threads
This commit is contained in:
parent
4958402919
commit
86f73f8d5c
21 changed files with 163 additions and 152 deletions
|
@ -61,7 +61,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.14.0'
|
implementation 'com.simplemobiletools:commons:5.14.2'
|
||||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||||
|
|
|
@ -26,10 +26,7 @@ import com.bumptech.glide.request.RequestOptions
|
||||||
import com.bumptech.glide.request.target.Target
|
import com.bumptech.glide.request.target.Target
|
||||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
|
||||||
import com.simplemobiletools.commons.helpers.SIDELOADING_TRUE
|
|
||||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.gallery.pro.BuildConfig
|
import com.simplemobiletools.gallery.pro.BuildConfig
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
|
@ -259,9 +256,9 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
if (!wasDrawCanvasPositioned) {
|
if (!wasDrawCanvasPositioned) {
|
||||||
wasDrawCanvasPositioned = true
|
wasDrawCanvasPositioned = true
|
||||||
editor_draw_canvas.onGlobalLayout {
|
editor_draw_canvas.onGlobalLayout {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
fillCanvasBackground()
|
fillCanvasBackground()
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,7 +333,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
bottom_actions_filter_list.adapter = null
|
bottom_actions_filter_list.adapter = null
|
||||||
bottom_actions_filter_list.beGone()
|
bottom_actions_filter_list.beGone()
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
val originalBitmap = Glide.with(applicationContext).asBitmap().load(uri).submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get()
|
val originalBitmap = Glide.with(applicationContext).asBitmap().load(uri).submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get()
|
||||||
currentFilter.filter.processFilter(originalBitmap)
|
currentFilter.filter.processFilter(originalBitmap)
|
||||||
|
@ -344,23 +341,23 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
} catch (e: OutOfMemoryError) {
|
} catch (e: OutOfMemoryError) {
|
||||||
toast(R.string.out_of_memory_error)
|
toast(R.string.out_of_memory_error)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shareImage() {
|
private fun shareImage() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
when {
|
when {
|
||||||
default_image_view.isVisible() -> {
|
default_image_view.isVisible() -> {
|
||||||
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
||||||
if (currentFilter == null) {
|
if (currentFilter == null) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
return@Thread
|
return@ensureBackgroundThread
|
||||||
}
|
}
|
||||||
|
|
||||||
val originalBitmap = Glide.with(applicationContext).asBitmap().load(uri).submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get()
|
val originalBitmap = Glide.with(applicationContext).asBitmap().load(uri).submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get()
|
||||||
currentFilter!!.filter.processFilter(originalBitmap)
|
currentFilter.filter.processFilter(originalBitmap)
|
||||||
shareBitmap(originalBitmap)
|
shareBitmap(originalBitmap)
|
||||||
}
|
}
|
||||||
crop_image_view.isVisible() -> {
|
crop_image_view.isVisible() -> {
|
||||||
|
@ -371,12 +368,12 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
editor_draw_canvas.isVisible() -> shareBitmap(editor_draw_canvas.getBitmap())
|
editor_draw_canvas.isVisible() -> shareBitmap(editor_draw_canvas.getBitmap())
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTempImagePath(bitmap: Bitmap, callback: (path: String?) -> Unit) {
|
private fun getTempImagePath(bitmap: Bitmap, callback: (path: String?) -> Unit) {
|
||||||
val bytes = ByteArrayOutputStream()
|
val bytes = ByteArrayOutputStream()
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bytes)
|
bitmap.compress(CompressFormat.PNG, 0, bytes)
|
||||||
|
|
||||||
val folder = File(cacheDir, TEMP_FOLDER_NAME)
|
val folder = File(cacheDir, TEMP_FOLDER_NAME)
|
||||||
if (!folder.exists()) {
|
if (!folder.exists()) {
|
||||||
|
@ -581,7 +578,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
bottom_editor_draw_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_DRAW)
|
bottom_editor_draw_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_DRAW)
|
||||||
|
|
||||||
if (currPrimaryAction == PRIMARY_ACTION_FILTER && bottom_actions_filter_list.adapter == null) {
|
if (currPrimaryAction == PRIMARY_ACTION_FILTER && bottom_actions_filter_list.adapter == null) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val thumbnailSize = resources.getDimension(R.dimen.bottom_filters_thumbnail_size).toInt()
|
val thumbnailSize = resources.getDimension(R.dimen.bottom_filters_thumbnail_size).toInt()
|
||||||
|
|
||||||
val bitmap = try {
|
val bitmap = try {
|
||||||
|
@ -600,7 +597,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
} catch (e: GlideException) {
|
} catch (e: GlideException) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
finish()
|
finish()
|
||||||
return@Thread
|
return@ensureBackgroundThread
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
@ -630,7 +627,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
bottom_actions_filter_list.adapter = adapter
|
bottom_actions_filter_list.adapter = adapter
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currPrimaryAction != PRIMARY_ACTION_CROP_ROTATE) {
|
if (currPrimaryAction != PRIMARY_ACTION_CROP_ROTATE) {
|
||||||
|
@ -811,7 +808,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
|
|
||||||
private fun saveBitmapToFile(bitmap: Bitmap, path: String, showSavingToast: Boolean) {
|
private fun saveBitmapToFile(bitmap: Bitmap, path: String, showSavingToast: Boolean) {
|
||||||
try {
|
try {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
||||||
getFileOutputStream(fileDirItem, true) {
|
getFileOutputStream(fileDirItem, true) {
|
||||||
|
@ -821,7 +818,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
toast(R.string.image_editing_failed)
|
toast(R.string.image_editing_failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
} catch (e: OutOfMemoryError) {
|
} catch (e: OutOfMemoryError) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.adapters.ManageHiddenFoldersAdapter
|
import com.simplemobiletools.gallery.pro.adapters.ManageHiddenFoldersAdapter
|
||||||
|
@ -55,11 +56,11 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
private fun addFolder() {
|
private fun addFolder() {
|
||||||
FilePickerDialog(this, config.lastFilepickerPath, false, config.shouldShowHidden, false, true) {
|
FilePickerDialog(this, config.lastFilepickerPath, false, config.shouldShowHidden, false, true) {
|
||||||
config.lastFilepickerPath = it
|
config.lastFilepickerPath = it
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
addNoMedia(it) {
|
addNoMedia(it) {
|
||||||
updateFolders()
|
updateFolders()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,7 +346,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkOTGPath() {
|
private fun checkOTGPath() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
|
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
|
||||||
getStorageDirectories().firstOrNull { it.trimEnd('/') != internalStoragePath && it.trimEnd('/') != sdCardPath }?.apply {
|
getStorageDirectories().firstOrNull { it.trimEnd('/') != internalStoragePath && it.trimEnd('/') != sdCardPath }?.apply {
|
||||||
config.wasOTGHandled = true
|
config.wasOTGHandled = true
|
||||||
|
@ -364,7 +364,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkDefaultSpamFolders() {
|
private fun checkDefaultSpamFolders() {
|
||||||
|
@ -434,9 +434,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
if (config.directorySorting and SORT_BY_DATE_MODIFIED > 0 || config.directorySorting and SORT_BY_DATE_TAKEN > 0) {
|
if (config.directorySorting and SORT_BY_DATE_MODIFIED > 0 || config.directorySorting and SORT_BY_DATE_TAKEN > 0) {
|
||||||
getDirectories()
|
getDirectories()
|
||||||
} else {
|
} else {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
gotDirectories(getCurrentlyDisplayedDirs())
|
gotDirectories(getCurrentlyDisplayedDirs())
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -540,11 +540,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
refreshItems()
|
refreshItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
folders.filter { !it.exists() }.forEach {
|
folders.filter { !it.exists() }.forEach {
|
||||||
mDirectoryDao.deleteDirPath(it.absolutePath)
|
mDirectoryDao.deleteDirPath(it.absolutePath)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,22 +629,22 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
private fun toggleRecycleBin(show: Boolean) {
|
private fun toggleRecycleBin(show: Boolean) {
|
||||||
config.showRecycleBinAtFolders = show
|
config.showRecycleBinAtFolders = show
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
var dirs = getCurrentlyDisplayedDirs()
|
var dirs = getCurrentlyDisplayedDirs()
|
||||||
if (!show) {
|
if (!show) {
|
||||||
dirs = dirs.filter { it.path != RECYCLE_BIN } as ArrayList<Directory>
|
dirs = dirs.filter { it.path != RECYCLE_BIN } as ArrayList<Directory>
|
||||||
}
|
}
|
||||||
gotDirectories(dirs)
|
gotDirectories(dirs)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createNewFolder() {
|
private fun createNewFolder() {
|
||||||
FilePickerDialog(this, internalStoragePath, false, config.shouldShowHidden, false, true) {
|
FilePickerDialog(this, internalStoragePath, false, config.shouldShowHidden, false, true) {
|
||||||
CreateNewFolderDialog(this, it) {
|
CreateNewFolderDialog(this, it) {
|
||||||
config.tempFolderPath = it
|
config.tempFolderPath = it
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
gotDirectories(addTempFolderIfNeeded(getCurrentlyDisplayedDirs()))
|
gotDirectories(addTempFolderIfNeeded(getCurrentlyDisplayedDirs()))
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1098,12 +1098,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
?: ""
|
?: ""
|
||||||
|
|
||||||
private fun setupLatestMediaId() {
|
private fun setupLatestMediaId() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
if (hasPermission(PERMISSION_READ_STORAGE)) {
|
if (hasPermission(PERMISSION_READ_STORAGE)) {
|
||||||
mLatestMediaId = getLatestMediaId()
|
mLatestMediaId = getLatestMediaId()
|
||||||
mLatestMediaDateId = getLatestMediaByDateId()
|
mLatestMediaDateId = getLatestMediaByDateId()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkLastMediaChanged() {
|
private fun checkLastMediaChanged() {
|
||||||
|
@ -1112,7 +1112,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
mLastMediaHandler.postDelayed({
|
mLastMediaHandler.postDelayed({
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val mediaId = getLatestMediaId()
|
val mediaId = getLatestMediaId()
|
||||||
val mediaDateId = getLatestMediaByDateId()
|
val mediaDateId = getLatestMediaByDateId()
|
||||||
if (mLatestMediaId != mediaId || mLatestMediaDateId != mediaDateId) {
|
if (mLatestMediaId != mediaId || mLatestMediaDateId != mediaDateId) {
|
||||||
|
@ -1125,7 +1125,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
mLastMediaHandler.removeCallbacksAndMessages(null)
|
mLastMediaHandler.removeCallbacksAndMessages(null)
|
||||||
checkLastMediaChanged()
|
checkLastMediaChanged()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}, LAST_MEDIA_CHECK_PERIOD)
|
}, LAST_MEDIA_CHECK_PERIOD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1133,12 +1133,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
if (config.useRecycleBin && config.lastBinCheck < System.currentTimeMillis() - DAY_SECONDS * 1000) {
|
if (config.useRecycleBin && config.lastBinCheck < System.currentTimeMillis() - DAY_SECONDS * 1000) {
|
||||||
config.lastBinCheck = System.currentTimeMillis()
|
config.lastBinCheck = System.currentTimeMillis()
|
||||||
Handler().postDelayed({
|
Handler().postDelayed({
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
mMediumDao.deleteOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS)
|
mMediumDao.deleteOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}, 3000L)
|
}, 3000L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1147,7 +1147,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
// /storage/emulated/0/Android/data/com.facebook.orca/files/stickers/175139712676531/209575122566323
|
// /storage/emulated/0/Android/data/com.facebook.orca/files/stickers/175139712676531/209575122566323
|
||||||
// /storage/emulated/0/Android/data/com.facebook.orca/files/stickers/497837993632037/499671223448714
|
// /storage/emulated/0/Android/data/com.facebook.orca/files/stickers/497837993632037/499671223448714
|
||||||
private fun excludeSpamFolders() {
|
private fun excludeSpamFolders() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
val internalPath = internalStoragePath
|
val internalPath = internalStoragePath
|
||||||
val checkedPaths = ArrayList<String>()
|
val checkedPaths = ArrayList<String>()
|
||||||
|
@ -1184,7 +1184,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
|
@ -1192,16 +1192,16 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recheckPinnedFolders() {
|
override fun recheckPinnedFolders() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
gotDirectories(movePinnedDirectoriesToFront(getCurrentlyDisplayedDirs()))
|
gotDirectories(movePinnedDirectoriesToFront(getCurrentlyDisplayedDirs()))
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateDirectories(directories: ArrayList<Directory>) {
|
override fun updateDirectories(directories: ArrayList<Directory>) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
storeDirectoryItems(directories, mDirectoryDao)
|
storeDirectoryItems(directories, mDirectoryDao)
|
||||||
removeInvalidDBDirectories()
|
removeInvalidDBDirectories()
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkWhatsNewDialog() {
|
private fun checkWhatsNewDialog() {
|
||||||
|
|
|
@ -27,6 +27,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.REQUEST_EDIT_IMAGE
|
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_RANDOM
|
import com.simplemobiletools.commons.helpers.SORT_BY_RANDOM
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
@ -327,7 +328,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchQueryChanged(text: String) {
|
private fun searchQueryChanged(text: String) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
val filtered = mMedia.filter { it is Medium && it.name.contains(text, true) } as ArrayList
|
val filtered = mMedia.filter { it is Medium && it.name.contains(text, true) } as ArrayList
|
||||||
filtered.sortBy { it is Medium && !it.name.startsWith(text, true) }
|
filtered.sortBy { it is Medium && !it.name.startsWith(text, true) }
|
||||||
|
@ -345,7 +346,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryLoadGallery() {
|
private fun tryLoadGallery() {
|
||||||
|
@ -435,7 +436,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
|
|
||||||
mLastMediaHandler.removeCallbacksAndMessages(null)
|
mLastMediaHandler.removeCallbacksAndMessages(null)
|
||||||
mLastMediaHandler.postDelayed({
|
mLastMediaHandler.postDelayed({
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val mediaId = getLatestMediaId()
|
val mediaId = getLatestMediaId()
|
||||||
val mediaDateId = getLatestMediaByDateId()
|
val mediaDateId = getLatestMediaByDateId()
|
||||||
if (mLatestMediaId != mediaId || mLatestMediaDateId != mediaDateId) {
|
if (mLatestMediaId != mediaId || mLatestMediaDateId != mediaDateId) {
|
||||||
|
@ -447,7 +448,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
} else {
|
} else {
|
||||||
checkLastMediaChanged()
|
checkLastMediaChanged()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}, LAST_MEDIA_CHECK_PERIOD)
|
}, LAST_MEDIA_CHECK_PERIOD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,9 +488,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
private fun restoreAllFiles() {
|
private fun restoreAllFiles() {
|
||||||
val paths = mMedia.filter { it is Medium }.map { (it as Medium).path } as ArrayList<String>
|
val paths = mMedia.filter { it is Medium }.map { (it as Medium).path } as ArrayList<String>
|
||||||
restoreRecycleBinPaths(paths, mMediumDao) {
|
restoreRecycleBinPaths(paths, mMediumDao) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mDirectoryDao.deleteDirPath(RECYCLE_BIN)
|
mDirectoryDao.deleteDirPath(RECYCLE_BIN)
|
||||||
}.start()
|
}
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -593,7 +594,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
private fun startAsyncTask() {
|
private fun startAsyncTask() {
|
||||||
mCurrAsyncTask?.stopFetching()
|
mCurrAsyncTask?.stopFetching()
|
||||||
mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) {
|
mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val oldMedia = mMedia.clone() as ArrayList<ThumbnailItem>
|
val oldMedia = mMedia.clone() as ArrayList<ThumbnailItem>
|
||||||
val newMedia = it
|
val newMedia = it
|
||||||
gotMedia(newMedia, false)
|
gotMedia(newMedia, false)
|
||||||
|
@ -603,7 +604,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrAsyncTask!!.execute()
|
mCurrAsyncTask!!.execute()
|
||||||
|
@ -617,9 +618,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPath == FAVORITES) {
|
if (mPath == FAVORITES) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mDirectoryDao.deleteDirPath(FAVORITES)
|
mDirectoryDao.deleteDirPath(FAVORITES)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finish()
|
finish()
|
||||||
|
@ -630,9 +631,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteDBDirectory() {
|
private fun deleteDBDirectory() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mDirectoryDao.deleteDirPath(mPath)
|
mDirectoryDao.deleteDirPath(mPath)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createNewFolder() {
|
private fun createNewFolder() {
|
||||||
|
@ -910,14 +911,14 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
|
|
||||||
mMedia.removeAll { filtered.map { it.path }.contains((it as? Medium)?.path) }
|
mMedia.removeAll { filtered.map { it.path }.contains((it as? Medium)?.path) }
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val useRecycleBin = config.useRecycleBin
|
val useRecycleBin = config.useRecycleBin
|
||||||
filtered.forEach {
|
filtered.forEach {
|
||||||
if (it.path.startsWith(recycleBinPath) || !useRecycleBin) {
|
if (it.path.startsWith(recycleBinPath) || !useRecycleBin) {
|
||||||
deleteDBPath(mMediumDao, it.path)
|
deleteDBPath(mMediumDao, it.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
|
|
||||||
if (mMedia.isEmpty()) {
|
if (mMedia.isEmpty()) {
|
||||||
deleteDirectoryIfEmpty()
|
deleteDirectoryIfEmpty()
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.simplemobiletools.commons.extensions.onGlobalLayout
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.extensions.*
|
import com.simplemobiletools.gallery.pro.extensions.*
|
||||||
import com.simplemobiletools.gallery.pro.helpers.PATH
|
import com.simplemobiletools.gallery.pro.helpers.PATH
|
||||||
|
@ -94,7 +95,7 @@ open class PanoramaPhotoActivity : SimpleActivity() {
|
||||||
try {
|
try {
|
||||||
val options = VrPanoramaView.Options()
|
val options = VrPanoramaView.Options()
|
||||||
options.inputType = VrPanoramaView.Options.TYPE_MONO
|
options.inputType = VrPanoramaView.Options.TYPE_MONO
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val bitmap = getBitmapToLoad(path)
|
val bitmap = getBitmapToLoad(path)
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
panorama_view.apply {
|
panorama_view.apply {
|
||||||
|
@ -120,7 +121,7 @@ open class PanoramaPhotoActivity : SimpleActivity() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import androidx.core.view.MenuItemCompat
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
|
@ -91,7 +92,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun textChanged(text: String) {
|
private fun textChanged(text: String) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
val filtered = mAllMedia.filter { it is Medium && it.name.contains(text, true) } as ArrayList
|
val filtered = mAllMedia.filter { it is Medium && it.name.contains(text, true) } as ArrayList
|
||||||
filtered.sortBy { it is Medium && !it.name.startsWith(text, true) }
|
filtered.sortBy { it is Medium && !it.name.startsWith(text, true) }
|
||||||
|
@ -109,7 +110,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
}
|
}
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAdapter() {
|
private fun setupAdapter() {
|
||||||
|
@ -323,14 +324,14 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
|
|
||||||
mAllMedia.removeAll { filtered.map { it.path }.contains((it as? Medium)?.path) }
|
mAllMedia.removeAll { filtered.map { it.path }.contains((it as? Medium)?.path) }
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val useRecycleBin = config.useRecycleBin
|
val useRecycleBin = config.useRecycleBin
|
||||||
filtered.forEach {
|
filtered.forEach {
|
||||||
if (it.path.startsWith(recycleBinPath) || !useRecycleBin) {
|
if (it.path.startsWith(recycleBinPath) || !useRecycleBin) {
|
||||||
deleteDBPath(galleryDB.MediumDao(), it.path)
|
deleteDBPath(galleryDB.MediumDao(), it.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
|
@ -117,7 +118,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
|
||||||
|
|
||||||
if (result.error == null) {
|
if (result.error == null) {
|
||||||
toast(R.string.setting_wallpaper)
|
toast(R.string.setting_wallpaper)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val bitmap = result.bitmap
|
val bitmap = result.bitmap
|
||||||
val wantedHeight = wallpaperManager.desiredMinimumHeight
|
val wantedHeight = wallpaperManager.desiredMinimumHeight
|
||||||
val ratio = wantedHeight / bitmap.height.toFloat()
|
val ratio = wantedHeight / bitmap.height.toFloat()
|
||||||
|
@ -135,7 +136,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
|
||||||
setResult(Activity.RESULT_CANCELED)
|
setResult(Activity.RESULT_CANCELED)
|
||||||
}
|
}
|
||||||
finish()
|
finish()
|
||||||
}.start()
|
}
|
||||||
} else {
|
} else {
|
||||||
toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
|
toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
|
||||||
}
|
}
|
||||||
|
|
|
@ -572,7 +572,7 @@ class SettingsActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupEmptyRecycleBin() {
|
private fun setupEmptyRecycleBin() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
mRecycleBinContentSize = galleryDB.MediumDao().getDeletedMedia().sumByLong { it.size }
|
mRecycleBinContentSize = galleryDB.MediumDao().getDeletedMedia().sumByLong { it.size }
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
|
@ -580,7 +580,7 @@ class SettingsActivity : SimpleActivity() {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
settings_empty_recycle_bin_size.text = mRecycleBinContentSize.formatSize()
|
settings_empty_recycle_bin_size.text = mRecycleBinContentSize.formatSize()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
|
|
||||||
settings_empty_recycle_bin_holder.setOnClickListener {
|
settings_empty_recycle_bin_holder.setOnClickListener {
|
||||||
if (mRecycleBinContentSize == 0L) {
|
if (mRecycleBinContentSize == 0L) {
|
||||||
|
@ -686,13 +686,13 @@ class SettingsActivity : SimpleActivity() {
|
||||||
private fun setupImportSettings() {
|
private fun setupImportSettings() {
|
||||||
settings_import_holder.setOnClickListener {
|
settings_import_holder.setOnClickListener {
|
||||||
FilePickerDialog(this) {
|
FilePickerDialog(this) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
parseFile(it)
|
parseFile(it)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.getParentPath
|
import com.simplemobiletools.commons.extensions.getParentPath
|
||||||
import com.simplemobiletools.commons.extensions.getRealPathFromURI
|
import com.simplemobiletools.commons.extensions.getRealPathFromURI
|
||||||
import com.simplemobiletools.commons.extensions.scanPathRecursively
|
import com.simplemobiletools.commons.extensions.scanPathRecursively
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
import com.simplemobiletools.commons.helpers.isPiePlus
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.extensions.addPathToDB
|
import com.simplemobiletools.gallery.pro.extensions.addPathToDB
|
||||||
|
@ -87,9 +88,9 @@ open class SimpleActivity : BaseSimpleActivity() {
|
||||||
config.lastFilepickerPath = it
|
config.lastFilepickerPath = it
|
||||||
config.addIncludedFolder(it)
|
config.addIncludedFolder(it)
|
||||||
callback()
|
callback()
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
scanPathRecursively(it)
|
scanPathRecursively(it)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.google.android.exoplayer2.upstream.DataSpec
|
||||||
import com.google.android.exoplayer2.video.VideoListener
|
import com.google.android.exoplayer2.video.VideoListener
|
||||||
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.ensureBackgroundThread
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.extensions.*
|
import com.simplemobiletools.gallery.pro.extensions.*
|
||||||
import com.simplemobiletools.gallery.pro.helpers.*
|
import com.simplemobiletools.gallery.pro.helpers.*
|
||||||
|
@ -566,10 +567,10 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
|
|
||||||
private fun releaseExoPlayer() {
|
private fun releaseExoPlayer() {
|
||||||
mExoPlayer?.stop()
|
mExoPlayer?.stop()
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mExoPlayer?.release()
|
mExoPlayer?.release()
|
||||||
mExoPlayer = null
|
mExoPlayer = null
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||||
|
@ -602,9 +603,9 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?) = false
|
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?) = false
|
||||||
|
|
||||||
override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
|
override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mExoPlayer?.setVideoSurface(Surface(video_surface!!.surfaceTexture))
|
mExoPlayer?.setVideoSurface(Surface(video_surface!!.surfaceTexture))
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {}
|
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {}
|
||||||
|
|
|
@ -335,7 +335,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent.action == "com.android.camera.action.REVIEW") {
|
if (intent.action == "com.android.camera.action.REVIEW") {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val mediumDao = galleryDB.MediumDao()
|
val mediumDao = galleryDB.MediumDao()
|
||||||
if (mediumDao.getMediaFromPath(mPath).isEmpty()) {
|
if (mediumDao.getMediaFromPath(mPath).isEmpty()) {
|
||||||
val type = when {
|
val type = when {
|
||||||
|
@ -352,7 +352,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val medium = Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0)
|
val medium = Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0)
|
||||||
mediumDao.insert(medium)
|
mediumDao.insert(medium)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,9 +362,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initFavorites() {
|
private fun initFavorites() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mFavoritePaths = getFavoritePaths()
|
mFavoritePaths = getFavoritePaths()
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOrientation() {
|
private fun setupOrientation() {
|
||||||
|
@ -635,14 +635,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val newPath = it
|
val newPath = it
|
||||||
handleSAFDialog(it) {
|
handleSAFDialog(it) {
|
||||||
toast(R.string.saving)
|
toast(R.string.saving)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val photoFragment = getCurrentPhotoFragment() ?: return@Thread
|
val photoFragment = getCurrentPhotoFragment() ?: return@ensureBackgroundThread
|
||||||
saveRotatedImageToFile(currPath, newPath, photoFragment.mCurrentRotationDegrees, true) {
|
saveRotatedImageToFile(currPath, newPath, photoFragment.mCurrentRotationDegrees, true) {
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0
|
getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -874,7 +874,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private fun toggleFavorite() {
|
private fun toggleFavorite() {
|
||||||
val medium = getCurrentMedium() ?: return
|
val medium = getCurrentMedium() ?: return
|
||||||
medium.isFavorite = !medium.isFavorite
|
medium.isFavorite = !medium.isFavorite
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
galleryDB.MediumDao().updateFavorite(medium.path, medium.isFavorite)
|
galleryDB.MediumDao().updateFavorite(medium.path, medium.isFavorite)
|
||||||
if (medium.isFavorite) {
|
if (medium.isFavorite) {
|
||||||
mFavoritePaths.add(medium.path)
|
mFavoritePaths.add(medium.path)
|
||||||
|
@ -882,7 +882,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
mFavoritePaths.remove(medium.path)
|
mFavoritePaths.remove(medium.path)
|
||||||
}
|
}
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun printFile() {
|
private fun printFile() {
|
||||||
|
@ -1053,9 +1053,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
name = it.getFilenameFromPath()
|
name = it.getFilenameFromPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
updateDBMediaPath(oldPath, it)
|
updateDBMediaPath(oldPath, it)
|
||||||
}.start()
|
}
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1156,8 +1156,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun launchViewVideoIntent(path: String) {
|
override fun launchViewVideoIntent(path: String) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val newUri = getFinalUriFromPath(path, BuildConfig.APPLICATION_ID) ?: return@Thread
|
val newUri = getFinalUriFromPath(path, BuildConfig.APPLICATION_ID) ?: return@ensureBackgroundThread
|
||||||
val mimeType = getUriMimeType(path, newUri)
|
val mimeType = getUriMimeType(path, newUri)
|
||||||
Intent().apply {
|
Intent().apply {
|
||||||
action = Intent.ACTION_VIEW
|
action = Intent.ACTION_VIEW
|
||||||
|
@ -1180,7 +1180,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkSystemUI() {
|
private fun checkSystemUI() {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import android.widget.RelativeLayout
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
|
import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
|
||||||
import com.simplemobiletools.gallery.pro.extensions.*
|
import com.simplemobiletools.gallery.pro.extensions.*
|
||||||
|
@ -89,9 +90,9 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||||
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
|
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
|
||||||
config.showWidgetFolderName = folder_picker_show_folder_name.isChecked
|
config.showWidgetFolderName = folder_picker_show_folder_name.isChecked
|
||||||
val widget = Widget(null, mWidgetId, mFolderPath)
|
val widget = Widget(null, mWidgetId, mFolderPath)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
widgetsDB.insertOrUpdate(widget)
|
widgetsDB.insertOrUpdate(widget)
|
||||||
}.start()
|
}
|
||||||
|
|
||||||
storeWidgetColors()
|
storeWidgetColors()
|
||||||
requestWidgetUpdate()
|
requestWidgetUpdate()
|
||||||
|
@ -161,14 +162,14 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||||
config_folder_name.text = getFolderNameFromPath(folderPath)
|
config_folder_name.text = getFolderNameFromPath(folderPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val path = directoryDB.getDirectoryThumbnail(folderPath)
|
val path = directoryDB.getDirectoryThumbnail(folderPath)
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
loadJpg(path, config_image, config.cropThumbnails)
|
loadJpg(path, config_image, config.cropThumbnails)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleFolderNameDisplay() {
|
private fun handleFolderNameDisplay() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemsDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemsDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.FastScroller
|
import com.simplemobiletools.commons.views.FastScroller
|
||||||
|
@ -170,10 +171,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
tmb = File(it, tmb.getFilenameFromPath()).absolutePath
|
tmb = File(it, tmb.getFilenameFromPath()).absolutePath
|
||||||
}
|
}
|
||||||
updateDirs(dirs)
|
updateDirs(dirs)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath)
|
activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath)
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -431,10 +432,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
if (it.isRecycleBin()) {
|
if (it.isRecycleBin()) {
|
||||||
tryEmptyRecycleBin(false)
|
tryEmptyRecycleBin(false)
|
||||||
} else {
|
} else {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
activity.galleryDB.MediumDao().clearFavorites()
|
activity.galleryDB.MediumDao().clearFavorites()
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedKeys.size == 1) {
|
if (selectedKeys.size == 1) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemsPatternDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemsPatternDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
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
|
||||||
|
@ -203,7 +204,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
if (selectedKeys.size == 1) {
|
if (selectedKeys.size == 1) {
|
||||||
val oldPath = getFirstSelectedItemPath() ?: return
|
val oldPath = getFirstSelectedItemPath() ?: return
|
||||||
RenameItemDialog(activity, oldPath) {
|
RenameItemDialog(activity, oldPath) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
activity.updateDBMediaPath(oldPath, it)
|
activity.updateDBMediaPath(oldPath, it)
|
||||||
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
|
@ -211,7 +212,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RenameItemsPatternDialog(activity, getSelectedPaths()) {
|
RenameItemsPatternDialog(activity, getSelectedPaths()) {
|
||||||
|
@ -238,7 +239,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFileVisibility(hide: Boolean) {
|
private fun toggleFileVisibility(hide: Boolean) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
getSelectedItems().forEach {
|
getSelectedItems().forEach {
|
||||||
activity.toggleFileVisibility(it.path, hide)
|
activity.toggleFileVisibility(it.path, hide)
|
||||||
}
|
}
|
||||||
|
@ -246,11 +247,11 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFavorites(add: Boolean) {
|
private fun toggleFavorites(add: Boolean) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val mediumDao = activity.galleryDB.MediumDao()
|
val mediumDao = activity.galleryDB.MediumDao()
|
||||||
getSelectedItems().forEach {
|
getSelectedItems().forEach {
|
||||||
it.isFavorite = add
|
it.isFavorite = add
|
||||||
|
@ -260,7 +261,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restoreFiles() {
|
private fun restoreFiles() {
|
||||||
|
@ -280,7 +281,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
|
|
||||||
private fun rotateSelection(degrees: Int) {
|
private fun rotateSelection(degrees: Int) {
|
||||||
activity.toast(R.string.saving)
|
activity.toast(R.string.saving)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val paths = getSelectedPaths().filter { it.isImageFast() }
|
val paths = getSelectedPaths().filter { it.isImageFast() }
|
||||||
var fileCnt = paths.size
|
var fileCnt = paths.size
|
||||||
rotatedImagePaths.clear()
|
rotatedImagePaths.clear()
|
||||||
|
@ -296,7 +297,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moveFilesTo() {
|
private fun moveFilesTo() {
|
||||||
|
@ -333,12 +334,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fixDateTaken() {
|
private fun fixDateTaken() {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
activity.fixDateTaken(getSelectedPaths(), true) {
|
activity.fixDateTaken(getSelectedPaths(), true) {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkDeleteConfirmation() {
|
private fun checkDeleteConfirmation() {
|
||||||
|
|
|
@ -190,9 +190,9 @@ fun BaseSimpleActivity.toggleFileVisibility(oldPath: String, hide: Boolean, call
|
||||||
val newPath = "$path/$filename"
|
val newPath = "$path/$filename"
|
||||||
renameFile(oldPath, newPath) {
|
renameFile(oldPath, newPath) {
|
||||||
callback?.invoke(newPath)
|
callback?.invoke(newPath)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
updateDBMediaPath(oldPath, newPath)
|
updateDBMediaPath(oldPath, newPath)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,12 +212,12 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet
|
||||||
callback: ((wasSuccess: Boolean) -> Unit)? = null) {
|
callback: ((wasSuccess: Boolean) -> Unit)? = null) {
|
||||||
deleteFile(fileDirItem, allowDeleteFolder) {
|
deleteFile(fileDirItem, allowDeleteFolder) {
|
||||||
if (deleteFromDatabase) {
|
if (deleteFromDatabase) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
deleteDBPath(galleryDB.MediumDao(), fileDirItem.path)
|
deleteDBPath(galleryDB.MediumDao(), fileDirItem.path)
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
callback?.invoke(it)
|
callback?.invoke(it)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
} else {
|
} else {
|
||||||
callback?.invoke(it)
|
callback?.invoke(it)
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: ((wasSuccess: Boolean) -> Unit)?) {
|
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: ((wasSuccess: Boolean) -> Unit)?) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
var pathsCnt = paths.size
|
var pathsCnt = paths.size
|
||||||
paths.forEach {
|
paths.forEach {
|
||||||
val file = File(it)
|
val file = File(it)
|
||||||
|
@ -246,7 +246,7 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback?.invoke(pathsCnt == 0)
|
callback?.invoke(pathsCnt == 0)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit) {
|
fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit) {
|
||||||
|
@ -254,7 +254,7 @@ fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: () -> Unit) {
|
fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: () -> Unit) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val newPaths = ArrayList<String>()
|
val newPaths = ArrayList<String>()
|
||||||
paths.forEach {
|
paths.forEach {
|
||||||
val source = it
|
val source = it
|
||||||
|
@ -288,11 +288,11 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDa
|
||||||
}
|
}
|
||||||
|
|
||||||
fixDateTaken(newPaths, false)
|
fixDateTaken(newPaths, false)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) {
|
fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
try {
|
try {
|
||||||
recycleBin.deleteRecursively()
|
recycleBin.deleteRecursively()
|
||||||
galleryDB.MediumDao().clearRecycleBin()
|
galleryDB.MediumDao().clearRecycleBin()
|
||||||
|
@ -302,16 +302,16 @@ fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) {
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.emptyAndDisableTheRecycleBin(callback: () -> Unit) {
|
fun BaseSimpleActivity.emptyAndDisableTheRecycleBin(callback: () -> Unit) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
emptyTheRecycleBin {
|
emptyTheRecycleBin {
|
||||||
config.useRecycleBin = false
|
config.useRecycleBin = false
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.showRecycleBinEmptyingDialog(callback: () -> Unit) {
|
fun BaseSimpleActivity.showRecycleBinEmptyingDialog(callback: () -> Unit) {
|
||||||
|
@ -321,12 +321,12 @@ fun BaseSimpleActivity.showRecycleBinEmptyingDialog(callback: () -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.updateFavoritePaths(fileDirItems: ArrayList<FileDirItem>, destination: String) {
|
fun BaseSimpleActivity.updateFavoritePaths(fileDirItems: ArrayList<FileDirItem>, destination: String) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
fileDirItems.forEach {
|
fileDirItems.forEach {
|
||||||
val newPath = "$destination/${it.name}"
|
val newPath = "$destination/${it.name}"
|
||||||
updateDBMediaPath(it.path, newPath)
|
updateDBMediaPath(it.path, newPath)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.hasNavBar(): Boolean {
|
fun Activity.hasNavBar(): Boolean {
|
||||||
|
@ -515,7 +515,7 @@ fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream, degrees: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.getShortcutImage(tmb: String, drawable: Drawable, callback: () -> Unit) {
|
fun Activity.getShortcutImage(tmb: String, drawable: Drawable, callback: () -> Unit) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val options = RequestOptions()
|
val options = RequestOptions()
|
||||||
.format(DecodeFormat.PREFER_ARGB_8888)
|
.format(DecodeFormat.PREFER_ARGB_8888)
|
||||||
.skipMemoryCache(true)
|
.skipMemoryCache(true)
|
||||||
|
@ -538,5 +538,5 @@ fun Activity.getShortcutImage(tmb: String, drawable: Drawable, callback: () -> U
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,7 +358,7 @@ fun Context.updateSubfolderCounts(children: ArrayList<Directory>, parentDirs: Ar
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
|
fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val folders = ArrayList<String>()
|
val folders = ArrayList<String>()
|
||||||
|
|
||||||
val uri = MediaStore.Files.getContentUri("external")
|
val uri = MediaStore.Files.getContentUri("external")
|
||||||
|
@ -384,20 +384,20 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(folders)
|
callback(folders)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.rescanFolderMedia(path: String) {
|
fun Context.rescanFolderMedia(path: String) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
rescanFolderMediaSync(path)
|
rescanFolderMediaSync(path)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.rescanFolderMediaSync(path: String) {
|
fun Context.rescanFolderMediaSync(path: String) {
|
||||||
getCachedMedia(path) {
|
getCachedMedia(path) {
|
||||||
val cached = it
|
val cached = it
|
||||||
GetMediaAsynctask(applicationContext, path, false, false, false) {
|
GetMediaAsynctask(applicationContext, path, false, false, false) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val newMedia = it
|
val newMedia = it
|
||||||
val mediumDao = galleryDB.MediumDao()
|
val mediumDao = galleryDB.MediumDao()
|
||||||
val media = newMedia.filter { it is Medium } as ArrayList<Medium>
|
val media = newMedia.filter { it is Medium } as ArrayList<Medium>
|
||||||
|
@ -411,15 +411,15 @@ fun Context.rescanFolderMediaSync(path: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}.execute()
|
}.execute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.storeDirectoryItems(items: ArrayList<Directory>, directoryDao: DirectoryDao) {
|
fun Context.storeDirectoryItems(items: ArrayList<Directory>, directoryDao: DirectoryDao) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
directoryDao.insertAll(items)
|
directoryDao.insertAll(items)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>): String {
|
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>): String {
|
||||||
|
@ -539,7 +539,7 @@ fun Context.loadSVG(path: String, target: MySquareImageView, cropThumbnails: Boo
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, directoryDao: DirectoryDao = galleryDB.DirectoryDao(), forceShowHidden: Boolean = false, callback: (ArrayList<Directory>) -> Unit) {
|
fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, directoryDao: DirectoryDao = galleryDB.DirectoryDao(), forceShowHidden: Boolean = false, callback: (ArrayList<Directory>) -> Unit) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val directories = try {
|
val directories = try {
|
||||||
directoryDao.getAll() as ArrayList<Directory>
|
directoryDao.getAll() as ArrayList<Directory>
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -581,12 +581,12 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
|
||||||
callback(clone.distinctBy { it.path.getDistinctPath() } as ArrayList<Directory>)
|
callback(clone.distinctBy { it.path.getDistinctPath() } as ArrayList<Directory>)
|
||||||
|
|
||||||
removeInvalidDBDirectories(filteredDirectories, directoryDao)
|
removeInvalidDBDirectories(filteredDirectories, directoryDao)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, mediumDao: MediumDao = galleryDB.MediumDao(),
|
fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, mediumDao: MediumDao = galleryDB.MediumDao(),
|
||||||
callback: (ArrayList<ThumbnailItem>) -> Unit) {
|
callback: (ArrayList<ThumbnailItem>) -> Unit) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val mediaFetcher = MediaFetcher(this)
|
val mediaFetcher = MediaFetcher(this)
|
||||||
val foldersToScan = if (path.isEmpty()) mediaFetcher.getFoldersToScan() else arrayListOf(path)
|
val foldersToScan = if (path.isEmpty()) mediaFetcher.getFoldersToScan() else arrayListOf(path)
|
||||||
var media = ArrayList<Medium>()
|
var media = ArrayList<Medium>()
|
||||||
|
@ -644,7 +644,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
|
||||||
}
|
}
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
|
fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
|
||||||
|
@ -768,9 +768,9 @@ fun Context.parseFileChannel(path: String, fc: FileChannel, level: Int, start: L
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.addPathToDB(path: String) {
|
fun Context.addPathToDB(path: String) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
if (!File(path).exists()) {
|
if (!File(path).exists()) {
|
||||||
return@Thread
|
return@ensureBackgroundThread
|
||||||
}
|
}
|
||||||
|
|
||||||
val type = when {
|
val type = when {
|
||||||
|
@ -791,7 +791,7 @@ fun Context.addPathToDB(path: String) {
|
||||||
mediumDao.insert(medium)
|
mediumDao.insert(medium)
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
|
fun Context.createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
|
||||||
|
|
|
@ -36,6 +36,7 @@ import com.davemorrissey.labs.subscaleview.ImageRegionDecoder
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
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.ensureBackgroundThread
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.activities.PanoramaPhotoActivity
|
import com.simplemobiletools.gallery.pro.activities.PanoramaPhotoActivity
|
||||||
import com.simplemobiletools.gallery.pro.activities.PhotoActivity
|
import com.simplemobiletools.gallery.pro.activities.PhotoActivity
|
||||||
|
@ -241,10 +242,10 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
|
|
||||||
mLoadZoomableViewHandler.removeCallbacksAndMessages(null)
|
mLoadZoomableViewHandler.removeCallbacksAndMessages(null)
|
||||||
if (mCurrentRotationDegrees != 0) {
|
if (mCurrentRotationDegrees != 0) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val path = mMedium.path
|
val path = mMedium.path
|
||||||
(activity as? BaseSimpleActivity)?.saveRotatedImageToFile(path, path, mCurrentRotationDegrees, false) {}
|
(activity as? BaseSimpleActivity)?.saveRotatedImageToFile(path, path, mCurrentRotationDegrees, false) {}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import com.google.android.exoplayer2.upstream.DataSource
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec
|
import com.google.android.exoplayer2.upstream.DataSpec
|
||||||
import com.google.android.exoplayer2.upstream.FileDataSource
|
import com.google.android.exoplayer2.upstream.FileDataSource
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.activities.PanoramaVideoActivity
|
import com.simplemobiletools.gallery.pro.activities.PanoramaVideoActivity
|
||||||
import com.simplemobiletools.gallery.pro.activities.VideoActivity
|
import com.simplemobiletools.gallery.pro.activities.VideoActivity
|
||||||
|
@ -139,12 +140,12 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
initTimeHolder()
|
initTimeHolder()
|
||||||
checkIfPanorama()
|
checkIfPanorama()
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
activity?.getVideoResolution(mMedium.path)?.apply {
|
activity?.getVideoResolution(mMedium.path)?.apply {
|
||||||
mVideoSize.x = x
|
mVideoSize.x = x
|
||||||
mVideoSize.y = y
|
mVideoSize.y = y
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
|
|
||||||
if (mIsPanorama) {
|
if (mIsPanorama) {
|
||||||
mView.apply {
|
mView.apply {
|
||||||
|
@ -657,10 +658,10 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
private fun releaseExoPlayer() {
|
private fun releaseExoPlayer() {
|
||||||
mExoPlayer?.stop()
|
mExoPlayer?.stop()
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mExoPlayer?.release()
|
mExoPlayer?.release()
|
||||||
mExoPlayer = null
|
mExoPlayer = null
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {}
|
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {}
|
||||||
|
@ -670,9 +671,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?) = false
|
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?) = false
|
||||||
|
|
||||||
override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
|
override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
mExoPlayer?.setVideoSurface(Surface(mTextureView.surfaceTexture))
|
mExoPlayer?.setVideoSurface(Surface(mTextureView.surfaceTexture))
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setVideoSize() {
|
private fun setVideoSize() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.simplemobiletools.commons.extensions.getFileSignature
|
||||||
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
||||||
import com.simplemobiletools.commons.extensions.setText
|
import com.simplemobiletools.commons.extensions.setText
|
||||||
import com.simplemobiletools.commons.extensions.setVisibleIf
|
import com.simplemobiletools.commons.extensions.setVisibleIf
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.activities.MediaActivity
|
import com.simplemobiletools.gallery.pro.activities.MediaActivity
|
||||||
import com.simplemobiletools.gallery.pro.extensions.config
|
import com.simplemobiletools.gallery.pro.extensions.config
|
||||||
|
@ -34,7 +35,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||||
|
|
||||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
val config = context.config
|
val config = context.config
|
||||||
context.widgetsDB.getWidgets().filter { appWidgetIds.contains(it.widgetId) }.forEach {
|
context.widgetsDB.getWidgets().filter { appWidgetIds.contains(it.widgetId) }.forEach {
|
||||||
val views = RemoteViews(context.packageName, R.layout.widget).apply {
|
val views = RemoteViews(context.packageName, R.layout.widget).apply {
|
||||||
|
@ -75,7 +76,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||||
setupAppOpenIntent(context, views, R.id.widget_holder, it)
|
setupAppOpenIntent(context, views, R.id.widget_holder, it)
|
||||||
appWidgetManager.updateAppWidget(it.widgetId, views)
|
appWidgetManager.updateAppWidget(it.widgetId, views)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAppWidgetOptionsChanged(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int, newOptions: Bundle) {
|
override fun onAppWidgetOptionsChanged(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int, newOptions: Bundle) {
|
||||||
|
@ -85,10 +86,10 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||||
|
|
||||||
override fun onDeleted(context: Context, appWidgetIds: IntArray) {
|
override fun onDeleted(context: Context, appWidgetIds: IntArray) {
|
||||||
super.onDeleted(context, appWidgetIds)
|
super.onDeleted(context, appWidgetIds)
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
appWidgetIds.forEach {
|
appWidgetIds.forEach {
|
||||||
context.widgetsDB.deleteWidgetId(it)
|
context.widgetsDB.deleteWidgetId(it)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import android.os.Handler
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import com.simplemobiletools.commons.extensions.getParentPath
|
import com.simplemobiletools.commons.extensions.getParentPath
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.gallery.pro.extensions.addPathToDB
|
import com.simplemobiletools.gallery.pro.extensions.addPathToDB
|
||||||
import com.simplemobiletools.gallery.pro.extensions.updateDirectoryPath
|
import com.simplemobiletools.gallery.pro.extensions.updateDirectoryPath
|
||||||
|
|
||||||
|
@ -94,11 +95,11 @@ class NewPhotoFetcher : JobService() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
ensureBackgroundThread {
|
||||||
affectedFolderPaths.forEach {
|
affectedFolderPaths.forEach {
|
||||||
updateDirectoryPath(it)
|
updateDirectoryPath(it)
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
|
|
||||||
mHandler.post(mWorker)
|
mHandler.post(mWorker)
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue