adding a couple more Favorite improvements

This commit is contained in:
tibbi 2018-06-20 16:22:11 +02:00
parent 58877df88e
commit 5677367fbf
6 changed files with 33 additions and 7 deletions

View File

@ -661,11 +661,18 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
val favoriteMedia = mediumDao.getFavorites() as ArrayList<Medium>
if (favoriteMedia.isNotEmpty() && dirs.none { it.areFavorites() }) {
if (favoriteMedia.isNotEmpty()) {
val favorites = createDirectoryFromMedia(FAVORITES, favoriteMedia, albumCovers, hiddenString, includedFolders, isSortingAscending)
dirs.add(favorites)
showSortedDirs(dirs)
directoryDao.insert(favorites)
} else if (dirs.any { it.areFavorites() }) {
val currentFavoriteDir = dirs.firstOrNull { it.areFavorites() }
if (currentFavoriteDir != null) {
dirs.remove(currentFavoriteDir)
showSortedDirs(dirs)
directoryDao.deleteDirPath(FAVORITES)
}
}
// check the remaining folders which were not cached at all yet

View File

@ -290,6 +290,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
val dirName = when {
mPath == FAVORITES -> getString(R.string.favorites)
mPath == OTG_PATH -> getString(R.string.otg)
mPath.startsWith(OTG_PATH) -> mPath.trimEnd('/').substringAfterLast('/')
else -> getHumanizedFilename(mPath)
@ -488,9 +489,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
private fun isDirEmpty(): Boolean {
return if (mPath != FAVORITES && mMedia.size <= 0 && config.filterMedia > 0) {
deleteDirectoryIfEmpty()
deleteDBDirectory()
return if (mMedia.size <= 0 && config.filterMedia > 0) {
if (mPath != FAVORITES) {
deleteDirectoryIfEmpty()
deleteDBDirectory()
}
finish()
true
} else {
@ -642,6 +645,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
Intent(this, ViewPagerActivity::class.java).apply {
putExtra(PATH, path)
putExtra(SHOW_ALL, mShowAll)
putExtra(SHOW_FAVORITES, mPath == FAVORITES)
startActivity(this)
}
}

View File

@ -59,6 +59,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private var mPos = -1
private var mShowAll = false
private var mIsSlideshowActive = false
private var mIsShowingFavorites = false
private var mRotationDegrees = 0
private var mPrevHashcode = 0
@ -84,6 +85,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_medium)
mMediaFiles = MediaActivity.mMedia.clone() as ArrayList<Medium>
mIsShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false)
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
@ -198,7 +200,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (!getDoesFilePathExist(mPath)) {
Thread {
scanPathRecursively(mPath)
if (!getIsPathDirectory(mPath)) {
scanPathRecursively(mPath)
}
}.start()
finish()
return
@ -216,7 +220,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
showSystemUI()
mDirectory = mPath.getParentPath()
mDirectory = if (mIsShowingFavorites) FAVORITES else mPath.getParentPath()
if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) {
mDirectory += "/"
}

View File

@ -4,7 +4,9 @@ import android.content.Context
import android.os.AsyncTask
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.galleryDB
import com.simplemobiletools.gallery.extensions.getFavoritePaths
import com.simplemobiletools.gallery.helpers.FAVORITES
import com.simplemobiletools.gallery.helpers.MediaFetcher
import com.simplemobiletools.gallery.models.Medium
import java.util.*
@ -28,7 +30,11 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
MediaFetcher(context).sortMedia(media, context.config.getFileSorting(""))
media
} else {
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths)
if (mPath == FAVORITES) {
context.galleryDB.MediumDao().getFavorites() as ArrayList<Medium>
} else {
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths)
}
}
}

View File

@ -320,6 +320,10 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
val mediumDao = galleryDB.MediumDao()
val foldersToScan = if (path == "/") MediaFetcher(this).getFoldersToScan() else arrayListOf(path)
var media = ArrayList<Medium>()
if (path == FAVORITES) {
media.addAll(mediumDao.getFavorites())
}
val shouldShowHidden = config.shouldShowHidden
foldersToScan.forEach {
try {

View File

@ -64,6 +64,7 @@ const val SLIDESHOW_SCROLL_DURATION = 500L
const val NOMEDIA = ".nomedia"
const val FAVORITES = "favorites"
const val SHOW_FAVORITES = "show_favorites"
const val MAX_COLUMN_COUNT = 20
const val SHOW_TEMP_HIDDEN_DURATION = 300000L
const val CLICK_MAX_DURATION = 150