moving the function for creating directories from files to Context extension
This commit is contained in:
parent
16a6eb8f6a
commit
b77e7fbca6
|
@ -39,7 +39,6 @@ import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao
|
||||||
import com.simplemobiletools.gallery.pro.interfaces.DirectoryOperationsListener
|
import com.simplemobiletools.gallery.pro.interfaces.DirectoryOperationsListener
|
||||||
import com.simplemobiletools.gallery.pro.interfaces.MediumDao
|
import com.simplemobiletools.gallery.pro.interfaces.MediumDao
|
||||||
import com.simplemobiletools.gallery.pro.jobs.NewPhotoFetcher
|
import com.simplemobiletools.gallery.pro.jobs.NewPhotoFetcher
|
||||||
import com.simplemobiletools.gallery.pro.models.AlbumCover
|
|
||||||
import com.simplemobiletools.gallery.pro.models.Directory
|
import com.simplemobiletools.gallery.pro.models.Directory
|
||||||
import com.simplemobiletools.gallery.pro.models.Medium
|
import com.simplemobiletools.gallery.pro.models.Medium
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
@ -1007,25 +1006,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
|
|
||||||
includedFolders: MutableSet<String>, isSortingAscending: Boolean, getProperFileSize: Boolean): Directory {
|
|
||||||
var thumbnail = curMedia.firstOrNull { File(it.path).exists() }?.path ?: ""
|
|
||||||
albumCovers.forEach {
|
|
||||||
if (it.path == path && File(it.tmb).exists()) {
|
|
||||||
thumbnail = it.tmb
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val firstItem = curMedia.first()
|
|
||||||
val lastItem = curMedia.last()
|
|
||||||
val dirName = checkAppendingHidden(path, hiddenString, includedFolders)
|
|
||||||
val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified)
|
|
||||||
val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken)
|
|
||||||
val size = if (getProperFileSize) curMedia.sumByLong { it.size } else 0L
|
|
||||||
val mediaTypes = curMedia.getDirMediaTypes()
|
|
||||||
return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupAdapter(dirs: ArrayList<Directory>, textToSearch: String = "") {
|
private fun setupAdapter(dirs: ArrayList<Directory>, textToSearch: String = "") {
|
||||||
val currAdapter = directories_grid.adapter
|
val currAdapter = directories_grid.adapter
|
||||||
val distinctDirs = dirs.distinctBy { it.path.getDistinctPath() }.toMutableList() as ArrayList<Directory>
|
val distinctDirs = dirs.distinctBy { it.path.getDistinctPath() }.toMutableList() as ArrayList<Directory>
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.simplemobiletools.gallery.pro.helpers.*
|
||||||
import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao
|
import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao
|
||||||
import com.simplemobiletools.gallery.pro.interfaces.MediumDao
|
import com.simplemobiletools.gallery.pro.interfaces.MediumDao
|
||||||
import com.simplemobiletools.gallery.pro.interfaces.WidgetsDao
|
import com.simplemobiletools.gallery.pro.interfaces.WidgetsDao
|
||||||
|
import com.simplemobiletools.gallery.pro.models.AlbumCover
|
||||||
import com.simplemobiletools.gallery.pro.models.Directory
|
import com.simplemobiletools.gallery.pro.models.Directory
|
||||||
import com.simplemobiletools.gallery.pro.models.Medium
|
import com.simplemobiletools.gallery.pro.models.Medium
|
||||||
import com.simplemobiletools.gallery.pro.models.ThumbnailItem
|
import com.simplemobiletools.gallery.pro.models.ThumbnailItem
|
||||||
|
@ -786,3 +787,22 @@ fun Context.addPathToDB(path: String) {
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
|
||||||
|
includedFolders: MutableSet<String>, isSortingAscending: Boolean, getProperFileSize: Boolean): Directory {
|
||||||
|
var thumbnail = curMedia.firstOrNull { File(it.path).exists() }?.path ?: ""
|
||||||
|
albumCovers.forEach {
|
||||||
|
if (it.path == path && File(it.tmb).exists()) {
|
||||||
|
thumbnail = it.tmb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val firstItem = curMedia.first()
|
||||||
|
val lastItem = curMedia.last()
|
||||||
|
val dirName = checkAppendingHidden(path, hiddenString, includedFolders)
|
||||||
|
val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified)
|
||||||
|
val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken)
|
||||||
|
val size = if (getProperFileSize) curMedia.sumByLong { it.size } else 0L
|
||||||
|
val mediaTypes = curMedia.getDirMediaTypes()
|
||||||
|
return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue