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

View File

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

View File

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

View File

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

View File

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