properly update the colors onResume

This commit is contained in:
tibbi 2021-02-19 17:05:36 +01:00
parent 4f79d196d6
commit 698448b847
3 changed files with 37 additions and 35 deletions

View file

@ -77,7 +77,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:5.33.32' implementation 'com.simplemobiletools:commons:5.33.33'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22'

View file

@ -84,7 +84,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private var mStoredCropThumbnails = true private var mStoredCropThumbnails = true
private var mStoredScrollHorizontally = true private var mStoredScrollHorizontally = true
private var mStoredTextColor = 0 private var mStoredTextColor = 0
private var mStoredPrimaryColor = 0 private var mStoredAdjustedPrimaryColor = 0
private var mStoredStyleString = "" private var mStoredStyleString = ""
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -108,7 +108,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
mIsSetWallpaperIntent = isSetWallpaperIntent(intent) mIsSetWallpaperIntent = isSetWallpaperIntent(intent)
mAllowPickingMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false) mAllowPickingMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent ||
mIsGetAnyContentIntent || mIsSetWallpaperIntent mIsGetAnyContentIntent || mIsSetWallpaperIntent
directories_refresh_layout.setOnRefreshListener { getDirectories() } directories_refresh_layout.setOnRefreshListener { getDirectories() }
storeStateVariables() storeStateVariables()
@ -185,10 +185,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
getRecyclerAdapter()?.updateTextColor(config.textColor) getRecyclerAdapter()?.updateTextColor(config.textColor)
} }
if (mStoredPrimaryColor != config.primaryColor) { val adjustedPrimaryColor = getAdjustedPrimaryColor()
if (mStoredAdjustedPrimaryColor != adjustedPrimaryColor) {
getRecyclerAdapter()?.updatePrimaryColor(config.primaryColor) getRecyclerAdapter()?.updatePrimaryColor(config.primaryColor)
directories_vertical_fastscroller.updatePrimaryColor() directories_vertical_fastscroller.updatePrimaryColor(adjustedPrimaryColor)
directories_horizontal_fastscroller.updatePrimaryColor() directories_horizontal_fastscroller.updatePrimaryColor(adjustedPrimaryColor)
} }
val styleString = "${config.folderStyle}${config.showFolderMediaCount}${config.limitFolderTitle}" val styleString = "${config.folderStyle}${config.showFolderMediaCount}${config.limitFolderTitle}"
@ -201,8 +202,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
directories_refresh_layout.isEnabled = config.enablePullToRefresh directories_refresh_layout.isEnabled = config.enablePullToRefresh
directories_empty_placeholder.setTextColor(config.textColor) directories_empty_placeholder.setTextColor(config.textColor)
directories_empty_placeholder_2.setTextColor(getAdjustedPrimaryColor()) directories_empty_placeholder_2.setTextColor(adjustedPrimaryColor)
directories_switch_searching.setTextColor(getAdjustedPrimaryColor()) directories_switch_searching.setTextColor(adjustedPrimaryColor)
directories_switch_searching.underlineText() directories_switch_searching.underlineText()
if (!mIsSearchOpen) { if (!mIsSearchOpen) {
@ -337,9 +338,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
mStoredCropThumbnails = cropThumbnails mStoredCropThumbnails = cropThumbnails
mStoredScrollHorizontally = scrollHorizontally mStoredScrollHorizontally = scrollHorizontally
mStoredTextColor = textColor mStoredTextColor = textColor
mStoredPrimaryColor = primaryColor
mStoredStyleString = "$folderStyle$showFolderMediaCount$limitFolderTitle" mStoredStyleString = "$folderStyle$showFolderMediaCount$limitFolderTitle"
} }
mStoredAdjustedPrimaryColor = getAdjustedPrimaryColor()
} }
private fun setupSearch(menu: Menu) { private fun setupSearch(menu: Menu) {
@ -571,11 +572,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
val files = File(it.path).listFiles() val files = File(it.path).listFiles()
files?.filter { files?.filter {
it.absolutePath.isMediaFile() && (showHidden || !it.name.startsWith('.')) && it.absolutePath.isMediaFile() && (showHidden || !it.name.startsWith('.')) &&
((it.isImageFast() && filter and TYPE_IMAGES != 0) || ((it.isImageFast() && filter and TYPE_IMAGES != 0) ||
(it.isVideoFast() && filter and TYPE_VIDEOS != 0) || (it.isVideoFast() && filter and TYPE_VIDEOS != 0) ||
(it.isGif() && filter and TYPE_GIFS != 0) || (it.isGif() && filter and TYPE_GIFS != 0) ||
(it.isRawFast() && filter and TYPE_RAWS != 0) || (it.isRawFast() && filter and TYPE_RAWS != 0) ||
(it.isSvg() && filter and TYPE_SVGS != 0)) (it.isSvg() && filter and TYPE_SVGS != 0))
}?.mapTo(itemsToDelete) { it.toFileDirItem(applicationContext) } }?.mapTo(itemsToDelete) { it.toFileDirItem(applicationContext) }
} }
@ -776,20 +777,20 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun isGetContentIntent(intent: Intent) = intent.action == Intent.ACTION_GET_CONTENT && intent.type != null private fun isGetContentIntent(intent: Intent) = intent.action == Intent.ACTION_GET_CONTENT && intent.type != null
private fun isGetImageContentIntent(intent: Intent) = isGetContentIntent(intent) && private fun isGetImageContentIntent(intent: Intent) = isGetContentIntent(intent) &&
(intent.type!!.startsWith("image/") || intent.type == Images.Media.CONTENT_TYPE) (intent.type!!.startsWith("image/") || intent.type == Images.Media.CONTENT_TYPE)
private fun isGetVideoContentIntent(intent: Intent) = isGetContentIntent(intent) && private fun isGetVideoContentIntent(intent: Intent) = isGetContentIntent(intent) &&
(intent.type!!.startsWith("video/") || intent.type == Video.Media.CONTENT_TYPE) (intent.type!!.startsWith("video/") || intent.type == Video.Media.CONTENT_TYPE)
private fun isGetAnyContentIntent(intent: Intent) = isGetContentIntent(intent) && intent.type == "*/*" private fun isGetAnyContentIntent(intent: Intent) = isGetContentIntent(intent) && intent.type == "*/*"
private fun isSetWallpaperIntent(intent: Intent?) = intent?.action == Intent.ACTION_SET_WALLPAPER private fun isSetWallpaperIntent(intent: Intent?) = intent?.action == Intent.ACTION_SET_WALLPAPER
private fun hasImageContentData(intent: Intent) = (intent.data == Images.Media.EXTERNAL_CONTENT_URI || private fun hasImageContentData(intent: Intent) = (intent.data == Images.Media.EXTERNAL_CONTENT_URI ||
intent.data == Images.Media.INTERNAL_CONTENT_URI) intent.data == Images.Media.INTERNAL_CONTENT_URI)
private fun hasVideoContentData(intent: Intent) = (intent.data == Video.Media.EXTERNAL_CONTENT_URI || private fun hasVideoContentData(intent: Intent) = (intent.data == Video.Media.EXTERNAL_CONTENT_URI ||
intent.data == Video.Media.INTERNAL_CONTENT_URI) intent.data == Video.Media.INTERNAL_CONTENT_URI)
private fun isImageType(intent: Intent) = (intent.type?.startsWith("image/") == true || intent.type == Images.Media.CONTENT_TYPE) private fun isImageType(intent: Intent) = (intent.type?.startsWith("image/") == true || intent.type == Images.Media.CONTENT_TYPE)
@ -948,14 +949,14 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
val sorting = config.getFolderSorting(directory.path) val sorting = config.getFolderSorting(directory.path)
val grouping = config.getFolderGrouping(directory.path) val grouping = config.getFolderGrouping(directory.path)
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 || val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 ||
sorting and SORT_BY_DATE_TAKEN != 0 || sorting and SORT_BY_DATE_TAKEN != 0 ||
grouping and GROUP_BY_DATE_TAKEN_DAILY != 0 || grouping and GROUP_BY_DATE_TAKEN_DAILY != 0 ||
grouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0 grouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0
val getProperLastModified = config.directorySorting and SORT_BY_DATE_MODIFIED != 0 || val getProperLastModified = config.directorySorting and SORT_BY_DATE_MODIFIED != 0 ||
sorting and SORT_BY_DATE_MODIFIED != 0 || sorting and SORT_BY_DATE_MODIFIED != 0 ||
grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 || grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0 grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens) getProperFileSize, favoritePaths, false, lastModifieds, dateTakens)
@ -1047,14 +1048,14 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
val sorting = config.getFolderSorting(folder) val sorting = config.getFolderSorting(folder)
val grouping = config.getFolderGrouping(folder) val grouping = config.getFolderGrouping(folder)
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 || val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 ||
sorting and SORT_BY_DATE_TAKEN != 0 || sorting and SORT_BY_DATE_TAKEN != 0 ||
grouping and GROUP_BY_DATE_TAKEN_DAILY != 0 || grouping and GROUP_BY_DATE_TAKEN_DAILY != 0 ||
grouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0 grouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0
val getProperLastModified = config.directorySorting and SORT_BY_DATE_MODIFIED != 0 || val getProperLastModified = config.directorySorting and SORT_BY_DATE_MODIFIED != 0 ||
sorting and SORT_BY_DATE_MODIFIED != 0 || sorting and SORT_BY_DATE_MODIFIED != 0 ||
grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 || grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0 grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens) getProperFileSize, favoritePaths, false, lastModifieds, dateTakens)

View file

@ -77,7 +77,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
private var mStoredShowFileTypes = true private var mStoredShowFileTypes = true
private var mStoredRoundedCorners = false private var mStoredRoundedCorners = false
private var mStoredTextColor = 0 private var mStoredTextColor = 0
private var mStoredPrimaryColor = 0 private var mStoredAdjustedPrimaryColor = 0
private var mStoredThumbnailSpacing = 0 private var mStoredThumbnailSpacing = 0
companion object { companion object {
@ -150,10 +150,11 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
getMediaAdapter()?.updateTextColor(config.textColor) getMediaAdapter()?.updateTextColor(config.textColor)
} }
if (mStoredPrimaryColor != config.primaryColor) { val adjustedPrimaryColor = getAdjustedPrimaryColor()
if (mStoredAdjustedPrimaryColor != adjustedPrimaryColor) {
getMediaAdapter()?.updatePrimaryColor(config.primaryColor) getMediaAdapter()?.updatePrimaryColor(config.primaryColor)
media_horizontal_fastscroller.updatePrimaryColor() media_horizontal_fastscroller.updatePrimaryColor(adjustedPrimaryColor)
media_vertical_fastscroller.updatePrimaryColor() media_vertical_fastscroller.updatePrimaryColor(adjustedPrimaryColor)
} }
if (mStoredThumbnailSpacing != config.thumbnailSpacing) { if (mStoredThumbnailSpacing != config.thumbnailSpacing) {
@ -310,11 +311,11 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
mStoredScrollHorizontally = scrollHorizontally mStoredScrollHorizontally = scrollHorizontally
mStoredShowFileTypes = showThumbnailFileTypes mStoredShowFileTypes = showThumbnailFileTypes
mStoredTextColor = textColor mStoredTextColor = textColor
mStoredPrimaryColor = primaryColor
mStoredThumbnailSpacing = thumbnailSpacing mStoredThumbnailSpacing = thumbnailSpacing
mStoredRoundedCorners = fileRoundedCorners mStoredRoundedCorners = fileRoundedCorners
mShowAll = showAll mShowAll = showAll
} }
mStoredAdjustedPrimaryColor = getAdjustedPrimaryColor()
} }
private fun setupSearch(menu: Menu) { private fun setupSearch(menu: Menu) {