mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
rewrite the way directories are fetched
This commit is contained in:
parent
8399b4fccd
commit
a6437181cb
8 changed files with 143 additions and 135 deletions
|
@ -25,11 +25,11 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.BuildConfig
|
import com.simplemobiletools.gallery.BuildConfig
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
|
||||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.FilterMediaDialog
|
import com.simplemobiletools.gallery.dialogs.FilterMediaDialog
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
import com.simplemobiletools.gallery.helpers.*
|
import com.simplemobiletools.gallery.helpers.*
|
||||||
|
import com.simplemobiletools.gallery.models.AlbumCover
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
@ -58,7 +58,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
private var mLatestMediaDateId = 0L
|
private var mLatestMediaDateId = 0L
|
||||||
private var mLastMediaHandler = Handler()
|
private var mLastMediaHandler = Handler()
|
||||||
private var mTempShowHiddenHandler = Handler()
|
private var mTempShowHiddenHandler = Handler()
|
||||||
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
|
|
||||||
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
||||||
|
|
||||||
private var mStoredAnimateGifs = true
|
private var mStoredAnimateGifs = true
|
||||||
|
@ -185,10 +184,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
config.temporarilyShowHidden = false
|
config.temporarilyShowHidden = false
|
||||||
mTempShowHiddenHandler.removeCallbacksAndMessages(null)
|
mTempShowHiddenHandler.removeCallbacksAndMessages(null)
|
||||||
removeTempFolder()
|
removeTempFolder()
|
||||||
|
|
||||||
if (!mDirs.isEmpty()) {
|
|
||||||
mCurrAsyncTask?.stopFetching()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
@ -275,25 +270,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
||||||
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
||||||
|
|
||||||
if (!mLoadedInitialPhotos) {
|
|
||||||
getCachedDirectories(getVideosOnly, getImagesOnly) {
|
getCachedDirectories(getVideosOnly, getImagesOnly) {
|
||||||
if (it.isNotEmpty()) {
|
|
||||||
gotDirectories(it, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mLoadedInitialPhotos) {
|
if (!mLoadedInitialPhotos) {
|
||||||
|
runOnUiThread {
|
||||||
directories_refresh_layout.isRefreshing = true
|
directories_refresh_layout.isRefreshing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
mLoadedInitialPhotos = true
|
|
||||||
mCurrAsyncTask?.stopFetching()
|
|
||||||
mCurrAsyncTask = GetDirectoriesAsynctask(applicationContext, getVideosOnly, getImagesOnly) {
|
|
||||||
mCurrAsyncTask = null
|
|
||||||
gotDirectories(addTempFolderIfNeeded(it), false)
|
|
||||||
}
|
}
|
||||||
mCurrAsyncTask!!.execute()
|
gotDirectories(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog() {
|
||||||
|
@ -301,7 +285,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
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 {
|
||||||
gotDirectories(mDirs, true)
|
gotDirectories(mDirs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -338,7 +322,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
setupLayoutManager()
|
setupLayoutManager()
|
||||||
directories_grid.adapter = null
|
directories_grid.adapter = null
|
||||||
setupAdapter()
|
setupAdapter(getCurrentlyDisplayedDirs())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,6 +349,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
refreshItems()
|
refreshItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
folders.filter { !it.exists() }.forEach {
|
folders.filter { !it.exists() }.forEach {
|
||||||
galleryDB.DirectoryDao().deleteDirPath(it.absolutePath)
|
galleryDB.DirectoryDao().deleteDirPath(it.absolutePath)
|
||||||
|
@ -429,7 +414,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
FilePickerDialog(this, internalStoragePath, false, config.shouldShowHidden) {
|
FilePickerDialog(this, internalStoragePath, false, config.shouldShowHidden) {
|
||||||
CreateNewFolderDialog(this, it) {
|
CreateNewFolderDialog(this, it) {
|
||||||
config.tempFolderPath = it
|
config.tempFolderPath = it
|
||||||
gotDirectories(addTempFolderIfNeeded(mDirs), true)
|
gotDirectories(addTempFolderIfNeeded(mDirs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -561,116 +546,146 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotDirectories(newDirs: ArrayList<Directory>, isFromCache: Boolean) {
|
private fun gotDirectories(newDirs: ArrayList<Directory>) {
|
||||||
if (!isFromCache) {
|
|
||||||
Thread {
|
|
||||||
galleryDB.DirectoryDao().insertAll(newDirs)
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
val dirs = getSortedDirectories(newDirs)
|
val dirs = getSortedDirectories(newDirs)
|
||||||
mIsGettingDirs = false
|
var isPlaceholderVisible = dirs.isEmpty()
|
||||||
checkLastMediaChanged()
|
|
||||||
mDirs = dirs
|
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
directories_refresh_layout.isRefreshing = false
|
directories_empty_text_label.beVisibleIf(dirs.isEmpty())
|
||||||
directories_empty_text_label.beVisibleIf(dirs.isEmpty() && !isFromCache)
|
directories_empty_text.beVisibleIf(dirs.isEmpty())
|
||||||
directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache)
|
|
||||||
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
||||||
|
|
||||||
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
||||||
directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll)
|
directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll)
|
||||||
directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll)
|
directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll)
|
||||||
setupAdapter()
|
setupAdapter(dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFromCache) {
|
// cached folders have been loaded, recheck folders one by one starting with the first displayed
|
||||||
Thread {
|
Thread {
|
||||||
val mediaFetcher = MediaFetcher(applicationContext)
|
val mediaFetcher = MediaFetcher(applicationContext)
|
||||||
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
||||||
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
||||||
val hidden = getString(R.string.hidden)
|
val hiddenString = getString(R.string.hidden)
|
||||||
val albumCovers = config.parseAlbumCovers()
|
val albumCovers = config.parseAlbumCovers()
|
||||||
val hasOTG = hasOTGConnected() && config.OTGBasePath.isNotEmpty()
|
|
||||||
val includedFolders = config.includedFolders
|
val includedFolders = config.includedFolders
|
||||||
|
val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0
|
||||||
|
val mediumDao = galleryDB.MediumDao()
|
||||||
|
val directoryDao = galleryDB.DirectoryDao()
|
||||||
|
|
||||||
for (directory in dirs) {
|
for (directory in dirs) {
|
||||||
val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly)
|
val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly)
|
||||||
Medium.sorting = config.getFileSorting(directory.path)
|
val newDir = createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending)
|
||||||
curMedia.sort()
|
|
||||||
|
|
||||||
val firstItem = curMedia.first()
|
// we are looping through the already displayed folders looking for changes, do not do anything if nothing changed
|
||||||
val lastItem = curMedia.last()
|
if (directory == newDir) {
|
||||||
val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) {
|
continue
|
||||||
firstItem.parentPath
|
}
|
||||||
} else {
|
|
||||||
File(firstItem.path).parent
|
|
||||||
} ?: continue
|
|
||||||
|
|
||||||
|
directory.apply {
|
||||||
|
tmb = newDir.tmb
|
||||||
|
mediaCnt = newDir.mediaCnt
|
||||||
|
modified = newDir.modified
|
||||||
|
taken = newDir.taken
|
||||||
|
this@apply.size = newDir.size
|
||||||
|
types = newDir.types
|
||||||
|
}
|
||||||
|
|
||||||
|
showSortedDirs(dirs)
|
||||||
|
|
||||||
|
// update directories and media files in the local db, delete invalid items
|
||||||
|
updateDBDirectory(directory)
|
||||||
|
mediumDao.insertAll(curMedia)
|
||||||
|
getCachedMedia(directory.path, getVideosOnly, getImagesOnly) {
|
||||||
|
it.forEach {
|
||||||
|
if (!curMedia.contains(it)) {
|
||||||
|
mediumDao.deleteMediumPath(it.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val foldersToScan = mediaFetcher.getFoldersToScan("")
|
||||||
|
dirs.forEach {
|
||||||
|
foldersToScan.remove(it.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (folder in foldersToScan) {
|
||||||
|
val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly)
|
||||||
|
if (newMedia.isEmpty()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPlaceholderVisible) {
|
||||||
|
isPlaceholderVisible = false
|
||||||
|
runOnUiThread {
|
||||||
|
directories_empty_text_label.beGone()
|
||||||
|
directories_empty_text.beGone()
|
||||||
|
directories_grid.beVisible()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, isSortingAscending)
|
||||||
|
dirs.add(newDir)
|
||||||
|
showSortedDirs(dirs)
|
||||||
|
directoryDao.insert(newDir)
|
||||||
|
mediumDao.insertAll(newMedia)
|
||||||
|
}
|
||||||
|
|
||||||
|
mIsGettingDirs = false
|
||||||
|
mLoadedInitialPhotos = true
|
||||||
|
|
||||||
|
runOnUiThread {
|
||||||
|
directories_refresh_layout.isRefreshing = false
|
||||||
|
directories_vertical_fastscroller.measureRecyclerView()
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showSortedDirs(dirs: ArrayList<Directory>) {
|
||||||
|
val sortedDirs = getSortedDirectories(dirs).clone() as ArrayList<Directory>
|
||||||
|
runOnUiThread {
|
||||||
|
(directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
|
||||||
|
includedFolders: MutableSet<String>, isSortingAscending: Boolean): Directory {
|
||||||
var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: ""
|
var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: ""
|
||||||
if (thumbnail.startsWith(OTG_PATH)) {
|
if (thumbnail.startsWith(OTG_PATH)) {
|
||||||
thumbnail = thumbnail.getOTGPublicPath(applicationContext)
|
thumbnail = thumbnail.getOTGPublicPath(applicationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
albumCovers.forEach {
|
albumCovers.forEach {
|
||||||
if (it.path == parentDir && getDoesFilePathExist(it.tmb)) {
|
if (it.path == path && getDoesFilePathExist(it.tmb)) {
|
||||||
thumbnail = it.tmb
|
thumbnail = it.tmb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val mediaTypes = curMedia.getDirMediaTypes()
|
val mediaTypes = curMedia.getDirMediaTypes()
|
||||||
val dirName = checkAppendingHidden(parentDir, hidden, includedFolders)
|
val dirName = checkAppendingHidden(path, hiddenString, includedFolders)
|
||||||
val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified)
|
|
||||||
val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken)
|
val firstItem = curMedia.first()
|
||||||
|
val lastItem = curMedia.last()
|
||||||
|
val lastModified = if (!isSortingAscending) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified)
|
||||||
|
val dateTaken = if (!isSortingAscending) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken)
|
||||||
val size = curMedia.sumByLong { it.size }
|
val size = curMedia.sumByLong { it.size }
|
||||||
val newDir = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(parentDir), mediaTypes)
|
return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(path), mediaTypes)
|
||||||
directory.mediaCnt = curMedia.size
|
|
||||||
if (directory == newDir) {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
directory.apply {
|
private fun setupAdapter(dirs: ArrayList<Directory>) {
|
||||||
tmb = thumbnail
|
|
||||||
mediaCnt = curMedia.size
|
|
||||||
modified = lastModified
|
|
||||||
taken = dateTaken
|
|
||||||
this@apply.size = size
|
|
||||||
types = mediaTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDirectory(directory)
|
|
||||||
rescanFolderMediaSync(directory.path)
|
|
||||||
val sortedDirs = getSortedDirectories(dirs).clone() as ArrayList<Directory>
|
|
||||||
runOnUiThread {
|
|
||||||
(directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
} else {
|
|
||||||
storeDirectories()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun storeDirectories() {
|
|
||||||
if (!config.temporarilyShowHidden && config.tempFolderPath.isEmpty()) {
|
|
||||||
storeDirectoryItems(mDirs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupAdapter() {
|
|
||||||
val currAdapter = directories_grid.adapter
|
val currAdapter = directories_grid.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
initZoomListener()
|
initZoomListener()
|
||||||
val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller
|
val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller
|
||||||
DirectoryAdapter(this, mDirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) {
|
DirectoryAdapter(this, dirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) {
|
||||||
itemClicked((it as Directory).path)
|
itemClicked((it as Directory).path)
|
||||||
}.apply {
|
}.apply {
|
||||||
setupZoomListener(mZoomListener)
|
setupZoomListener(mZoomListener)
|
||||||
directories_grid.adapter = this
|
directories_grid.adapter = this
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(currAdapter as DirectoryAdapter).updateDirs(mDirs)
|
(currAdapter as DirectoryAdapter).updateDirs(dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
setupScrollDirection()
|
setupScrollDirection()
|
||||||
|
@ -698,6 +713,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCurrentlyDisplayedDirs() = getRecyclerAdapter()?.dirs ?: ArrayList()
|
||||||
|
|
||||||
private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: ""
|
private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: ""
|
||||||
|
|
||||||
private fun setupLatestMediaId() {
|
private fun setupLatestMediaId() {
|
||||||
|
@ -714,7 +731,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mLastMediaHandler.postDelayed({
|
/*mLastMediaHandler.postDelayed({
|
||||||
Thread {
|
Thread {
|
||||||
val mediaId = getLatestMediaId()
|
val mediaId = getLatestMediaId()
|
||||||
val mediaDateId = getLatestMediaByDateId()
|
val mediaDateId = getLatestMediaByDateId()
|
||||||
|
@ -729,7 +746,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
checkLastMediaChanged()
|
checkLastMediaChanged()
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}, LAST_MEDIA_CHECK_PERIOD)
|
}, LAST_MEDIA_CHECK_PERIOD)*/
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
|
@ -737,12 +754,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recheckPinnedFolders() {
|
override fun recheckPinnedFolders() {
|
||||||
gotDirectories(movePinnedDirectoriesToFront(mDirs), true)
|
gotDirectories(movePinnedDirectoriesToFront(mDirs))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateDirectories(directories: ArrayList<Directory>, refreshList: Boolean) {
|
override fun updateDirectories(directories: ArrayList<Directory>, refreshList: Boolean) {
|
||||||
if (refreshList) {
|
if (refreshList) {
|
||||||
gotDirectories(directories, true)
|
gotDirectories(directories)
|
||||||
} else {
|
} else {
|
||||||
mDirs = directories
|
mDirs = directories
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,8 +669,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
deleteDirectoryIfEmpty()
|
deleteDirectoryIfEmpty()
|
||||||
finish()
|
finish()
|
||||||
} else {
|
} else {
|
||||||
updateStoredDirectories()
|
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
val mediumDao = galleryDB.MediumDao()
|
val mediumDao = galleryDB.MediumDao()
|
||||||
filtered.forEach {
|
filtered.forEach {
|
||||||
|
|
|
@ -765,7 +765,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
updateMediaPath(oldPath, it)
|
updateDBMediaPath(oldPath, it)
|
||||||
}.start()
|
}.start()
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
val oldPath = getCurrentPath()
|
val oldPath = getCurrentPath()
|
||||||
RenameItemDialog(activity, oldPath) {
|
RenameItemDialog(activity, oldPath) {
|
||||||
Thread {
|
Thread {
|
||||||
activity.updateMediaPath(oldPath, it)
|
activity.updateDBMediaPath(oldPath, it)
|
||||||
}.start()
|
}.start()
|
||||||
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import com.simplemobiletools.commons.helpers.sumByLong
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.checkAppendingHidden
|
import com.simplemobiletools.gallery.extensions.checkAppendingHidden
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.galleryDB
|
|
||||||
import com.simplemobiletools.gallery.extensions.getDirMediaTypes
|
import com.simplemobiletools.gallery.extensions.getDirMediaTypes
|
||||||
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
|
@ -46,7 +45,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
File(firstItem.path).parent
|
File(firstItem.path).parent
|
||||||
} ?: continue
|
} ?: continue
|
||||||
|
|
||||||
context.galleryDB.MediumDao().insertAll(curMedia)
|
|
||||||
var thumbnail = curMedia.firstOrNull { context.getDoesFilePathExist(it.path) }?.path ?: ""
|
var thumbnail = curMedia.firstOrNull { context.getDoesFilePathExist(it.path) }?.path ?: ""
|
||||||
if (thumbnail.startsWith(OTG_PATH)) {
|
if (thumbnail.startsWith(OTG_PATH)) {
|
||||||
thumbnail = thumbnail.getOTGPublicPath(context)
|
thumbnail = thumbnail.getOTGPublicPath(context)
|
||||||
|
|
|
@ -152,7 +152,7 @@ fun BaseSimpleActivity.toggleFileVisibility(oldPath: String, hide: Boolean, call
|
||||||
renameFile(oldPath, newPath) {
|
renameFile(oldPath, newPath) {
|
||||||
callback?.invoke(newPath)
|
callback?.invoke(newPath)
|
||||||
Thread {
|
Thread {
|
||||||
updateMediaPath(oldPath, newPath)
|
updateDBMediaPath(oldPath, newPath)
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.OTG_PATH
|
import com.simplemobiletools.commons.helpers.OTG_PATH
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SettingsActivity
|
import com.simplemobiletools.gallery.activities.SettingsActivity
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||||
import com.simplemobiletools.gallery.databases.GalleryDataBase
|
import com.simplemobiletools.gallery.databases.GalleryDataBase
|
||||||
import com.simplemobiletools.gallery.helpers.*
|
import com.simplemobiletools.gallery.helpers.*
|
||||||
|
@ -158,14 +157,6 @@ fun Context.rescanFolderMediaSync(path: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.updateStoredDirectories() {
|
|
||||||
GetDirectoriesAsynctask(this, false, false) {
|
|
||||||
if (!config.temporarilyShowHidden) {
|
|
||||||
storeDirectoryItems(it)
|
|
||||||
}
|
|
||||||
}.execute()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
|
fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
|
||||||
Thread {
|
Thread {
|
||||||
galleryDB.DirectoryDao().insertAll(items)
|
galleryDB.DirectoryDao().insertAll(items)
|
||||||
|
@ -318,12 +309,12 @@ fun Context.removeInvalidDirectories(dirs: ArrayList<Directory>? = null, directo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.updateMediaPath(oldPath: String, newPath: String) {
|
fun Context.updateDBMediaPath(oldPath: String, newPath: String) {
|
||||||
val newFilename = newPath.getFilenameFromPath()
|
val newFilename = newPath.getFilenameFromPath()
|
||||||
val newParentPath = newPath.getParentPath()
|
val newParentPath = newPath.getParentPath()
|
||||||
galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath)
|
galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.updateDirectory(directory: Directory) {
|
fun Context.updateDBDirectory(directory: Directory) {
|
||||||
galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types)
|
galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,11 @@ class MediaFetcher(val context: Context) {
|
||||||
|
|
||||||
val curMedia = ArrayList<Medium>()
|
val curMedia = ArrayList<Medium>()
|
||||||
if (curPath.startsWith(OTG_PATH)) {
|
if (curPath.startsWith(OTG_PATH)) {
|
||||||
getMediaOnOTG(curPath, curMedia, isPickImage, isPickVideo, filterMedia)
|
val newMedia = getMediaOnOTG(curPath, isPickImage, isPickVideo, filterMedia)
|
||||||
|
curMedia.addAll(newMedia)
|
||||||
} else {
|
} else {
|
||||||
val foldersToScan = getFoldersToScan(curPath)
|
val newMedia = fetchFolderContent(curPath, isPickImage, isPickVideo, filterMedia)
|
||||||
foldersToScan.forEach {
|
curMedia.addAll(newMedia)
|
||||||
fetchFolderContent(it, curMedia, isPickImage, isPickVideo, filterMedia)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Medium.sorting = context.config.getFileSorting(curPath)
|
Medium.sorting = context.config.getFileSorting(curPath)
|
||||||
|
@ -45,7 +44,7 @@ class MediaFetcher(val context: Context) {
|
||||||
return curMedia
|
return curMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFoldersToScan(path: String): ArrayList<String> {
|
fun getFoldersToScan(path: String): ArrayList<String> {
|
||||||
val filterMedia = context.config.filterMedia
|
val filterMedia = context.config.filterMedia
|
||||||
val projection = arrayOf(MediaStore.Images.Media.DATA)
|
val projection = arrayOf(MediaStore.Images.Media.DATA)
|
||||||
val uri = MediaStore.Files.getContentUri("external")
|
val uri = MediaStore.Files.getContentUri("external")
|
||||||
|
@ -160,11 +159,11 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchFolderContent(path: String, curMedia: ArrayList<Medium>, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) {
|
private fun fetchFolderContent(path: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList<Medium> {
|
||||||
if (path.startsWith(OTG_PATH)) {
|
return if (path.startsWith(OTG_PATH)) {
|
||||||
getMediaOnOTG(path, curMedia, isPickImage, isPickVideo, filterMedia)
|
getMediaOnOTG(path, isPickImage, isPickVideo, filterMedia)
|
||||||
} else {
|
} else {
|
||||||
getMediaInFolder(path, curMedia, isPickImage, isPickVideo, filterMedia)
|
getMediaInFolder(path, isPickImage, isPickVideo, filterMedia)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,8 +184,9 @@ class MediaFetcher(val context: Context) {
|
||||||
return directories
|
return directories
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMediaInFolder(folder: String, curMedia: ArrayList<Medium>, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) {
|
private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList<Medium> {
|
||||||
val files = File(folder).listFiles() ?: return
|
val media = ArrayList<Medium>()
|
||||||
|
val files = File(folder).listFiles() ?: return media
|
||||||
val doExtraCheck = context.config.doExtraCheck
|
val doExtraCheck = context.config.doExtraCheck
|
||||||
val showHidden = context.config.shouldShowHidden
|
val showHidden = context.config.shouldShowHidden
|
||||||
|
|
||||||
|
@ -229,12 +229,14 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type)
|
val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type)
|
||||||
curMedia.add(medium)
|
media.add(medium)
|
||||||
}
|
}
|
||||||
|
return media
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMediaOnOTG(folder: String, curMedia: ArrayList<Medium>, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) {
|
private fun getMediaOnOTG(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList<Medium> {
|
||||||
val files = context.getDocumentFile(folder)?.listFiles() ?: return
|
val media = ArrayList<Medium>()
|
||||||
|
val files = context.getDocumentFile(folder)?.listFiles() ?: return media
|
||||||
val doExtraCheck = context.config.doExtraCheck
|
val doExtraCheck = context.config.doExtraCheck
|
||||||
val showHidden = context.config.shouldShowHidden
|
val showHidden = context.config.shouldShowHidden
|
||||||
|
|
||||||
|
@ -278,7 +280,9 @@ class MediaFetcher(val context: Context) {
|
||||||
|
|
||||||
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH))
|
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH))
|
||||||
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type)
|
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type)
|
||||||
curMedia.add(medium)
|
media.add(medium)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return media
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue