diff --git a/CHANGELOG.md b/CHANGELOG.md index f7493d164..11c107a5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,27 @@ Changelog ========== +Version 3.7.1 *(2018-04-12)* +---------------------------- + + * Fix no media being shown to some people + * Fix some glitches at renaming files + * Show a count of files being deleted at the confirmation prompt + +Version 3.7.0 *(2018-04-10)* +---------------------------- + + * Rewrote media file fetching for better performance and new item discovering + * Make un/hiding folders quicker + * Make automatic fullscreen toggling animation smoother by delaying it + * Many other smaller performance and UX improvements + +Version 3.6.3 *(2018-03-30)* +---------------------------- + + * Couple file scanning and thumbnail displaying updates + * Show a dialog about the new Simple Clock app to some users + Version 3.6.2 *(2018-03-23)* ---------------------------- diff --git a/app/build.gradle b/app/build.gradle index 3f01904bc..b9b4cbddb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 168 - versionName "3.6.2" + versionCode 171 + versionName "3.7.1" multiDexEnabled true setProperty("archivesBaseName", "gallery") } @@ -46,16 +46,15 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.16.15' + implementation 'com.simplemobiletools:commons:3.18.22' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.android.support:multidex:1.0.3' - implementation 'com.google.code.gson:gson:2.8.2' implementation 'it.sephiroth.android.exif:library:1.0.1' - implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.8' + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' implementation 'com.github.chrisbanes:PhotoView:2.1.3' //implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0' - implementation 'com.github.tibbi:subsampling-scale-image-view:v3.9.0.6-fork' + implementation 'com.github.tibbi:subsampling-scale-image-view:v3.10.0-fork' debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt index f8d398eac..d59f0b7f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt @@ -28,7 +28,6 @@ class ExcludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { } val adapter = ManageFoldersAdapter(this, folders, true, this, manage_folders_list) {} - adapter.setupDragListener(true) manage_folders_list.adapter = adapter } @@ -50,7 +49,8 @@ class ExcludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { } private fun addFolder() { - FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { + FilePickerDialog(this, config.lastFilepickerPath, false, config.shouldShowHidden) { + config.lastFilepickerPath = it config.addExcludedFolder(it) updateFolders() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt index 79ce030f4..598e153be 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt @@ -30,7 +30,6 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { } val adapter = ManageHiddenFoldersAdapter(this, it, this, manage_folders_list) {} - adapter.setupDragListener(true) manage_folders_list.adapter = adapter } } @@ -54,7 +53,8 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { } private fun addFolder() { - FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { + FilePickerDialog(this, config.lastFilepickerPath, false, config.shouldShowHidden) { + config.lastFilepickerPath = it Thread { addNoMedia(it) { updateFolders() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt index cb565c6b3..cbbb5e701 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt @@ -29,7 +29,6 @@ class IncludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { } val adapter = ManageFoldersAdapter(this, folders, false, this, manage_folders_list) {} - adapter.setupDragListener(true) manage_folders_list.adapter = adapter } @@ -51,7 +50,8 @@ class IncludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { } private fun addFolder() { - FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { + FilePickerDialog(this, config.lastFilepickerPath, false, config.shouldShowHidden) { + config.lastFilepickerPath = it config.addIncludedFolder(it) updateFolders() Thread { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 1ca189290..677b1caab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -5,7 +5,6 @@ import android.content.ClipData import android.content.Intent import android.net.Uri import android.os.Bundle -import android.os.Environment import android.os.Handler import android.provider.MediaStore import android.support.v7.widget.GridLayoutManager @@ -15,7 +14,6 @@ import android.view.ViewGroup import android.widget.FrameLayout import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog -import com.simplemobiletools.commons.dialogs.NewAppDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_READ_STORAGE @@ -38,13 +36,12 @@ import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.activity_main.* import java.io.* -import java.util.* class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private val PICK_MEDIA = 2 private val PICK_WALLPAPER = 3 private val LAST_MEDIA_CHECK_PERIOD = 3000L - private val CONTACTS_PACKAGE = "com.simplemobiletools.contacts" + private val NEW_APP_PACKAGE = "com.simplemobiletools.clock" lateinit var mDirs: ArrayList @@ -66,13 +63,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null - private var mStoredUseEnglish = false private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true private var mStoredScrollHorizontally = true private var mStoredShowMediaCount = true private var mStoredShowInfoBubble = true private var mStoredTextColor = 0 + private var mStoredPrimaryColor = 0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -102,10 +99,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsPasswordProtectionPending = config.appPasswordProtectionOn setupLatestMediaId() - // notify the users about the Contacts app - /*if (System.currentTimeMillis() < 1521015000000 && !config.wasNewAppShown && config.appRunCount > 100 && config.appRunCount % 50 != 0 && !isPackageInstalled(CONTACTS_PACKAGE)) { + // notify some users about the Clock app + /*if (System.currentTimeMillis() < 1523750400000 && !config.wasNewAppShown && config.appRunCount > 100 && config.appRunCount % 50 != 0 && !isPackageInstalled(NEW_APP_PACKAGE)) { config.wasNewAppShown = true - NewAppDialog(this, CONTACTS_PACKAGE, "Simple Contacts") + NewAppDialog(this, NEW_APP_PACKAGE, "Simple Clock") }*/ } @@ -117,30 +114,32 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { override fun onResume() { super.onResume() config.isThirdPartyIntent = false - if (mStoredUseEnglish != config.useEnglish) { - restartActivity() - return - } if (mStoredAnimateGifs != config.animateGifs) { - getDirectoryAdapter()?.updateAnimateGifs(config.animateGifs) + getRecyclerAdapter()?.updateAnimateGifs(config.animateGifs) } if (mStoredCropThumbnails != config.cropThumbnails) { - getDirectoryAdapter()?.updateCropThumbnails(config.cropThumbnails) + getRecyclerAdapter()?.updateCropThumbnails(config.cropThumbnails) } if (mStoredShowMediaCount != config.showMediaCount) { - getDirectoryAdapter()?.updateShowMediaCount(config.showMediaCount) + getRecyclerAdapter()?.updateShowMediaCount(config.showMediaCount) } if (mStoredScrollHorizontally != config.scrollHorizontally || mStoredShowInfoBubble != config.showInfoBubble) { - getDirectoryAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally) + getRecyclerAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally) setupScrollDirection() } if (mStoredTextColor != config.textColor) { - getDirectoryAdapter()?.updateTextColor(config.textColor) + getRecyclerAdapter()?.updateTextColor(config.textColor) + } + + if (mStoredPrimaryColor != config.primaryColor) { + getRecyclerAdapter()?.updatePrimaryColor(config.primaryColor) + directories_vertical_fastscroller.updatePrimaryColor() + directories_horizontal_fastscroller.updatePrimaryColor() } directories_horizontal_fastscroller.updateBubbleColors() @@ -188,6 +187,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.temporarilyShowHidden = false mTempShowHiddenHandler.removeCallbacksAndMessages(null) removeTempFolder() + + if (!mDirs.isEmpty()) { + mCurrAsyncTask?.stopFetching() + } } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -222,28 +225,28 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { return true } - private fun getDirectoryAdapter() = directories_grid.adapter as? DirectoryAdapter + private fun getRecyclerAdapter() = directories_grid.adapter as? DirectoryAdapter private fun storeStateVariables() { config.apply { - mStoredUseEnglish = useEnglish mStoredAnimateGifs = animateGifs mStoredCropThumbnails = cropThumbnails mStoredScrollHorizontally = scrollHorizontally mStoredShowMediaCount = showMediaCount mStoredShowInfoBubble = showInfoBubble mStoredTextColor = textColor + mStoredPrimaryColor = primaryColor } } private fun removeTempFolder() { if (config.tempFolderPath.isNotEmpty()) { - /*val newFolder = File(config.tempFolderPath) + val newFolder = File(config.tempFolderPath) if (newFolder.exists() && newFolder.isDirectory) { if (newFolder.list()?.isEmpty() == true) { deleteFile(newFolder.toFileDirItem(applicationContext), true) } - }*/ + } config.tempFolderPath = "" } } @@ -258,7 +261,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } setupLayoutManager() - checkIfColorChanged() } else { toast(R.string.no_storage_permissions) finish() @@ -288,17 +290,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { gotDirectories(addTempFolderIfNeeded(it), false) } mCurrAsyncTask!!.execute() - - // try ensuring that the screenshots folders is properly added to the mediastore - if (config.appRunCount < 5) { - Thread { - val pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) - val screenshots = File(pictures, "Screenshots") - if (screenshots.exists()) { - scanFile(screenshots) - } - }.start() - } } private fun showSortingDialog() { @@ -362,14 +353,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { invalidateOptionsMenu() } - private fun checkIfColorChanged() { - if (directories_grid.adapter != null && getRecyclerAdapter().primaryColor != config.primaryColor) { - getRecyclerAdapter().primaryColor = config.primaryColor - directories_vertical_fastscroller.updatePrimaryColor() - directories_horizontal_fastscroller.updatePrimaryColor() - } - } - override fun deleteFolders(folders: ArrayList) { val fileDirItems = folders.map { FileDirItem(it.absolutePath, it.name, true) } as ArrayList deleteFolders(fileDirItems) { @@ -379,8 +362,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } - private fun getRecyclerAdapter() = (directories_grid.adapter as DirectoryAdapter) - private fun setupLayoutManager() { if (config.viewTypeFolders == VIEW_TYPE_GRID) { setupGridLayoutManager() @@ -409,14 +390,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { override fun zoomIn() { if (layoutManager.spanCount > 1) { reduceColumnCount() - getRecyclerAdapter().finishActMode() + getRecyclerAdapter()?.finishActMode() } } override fun zoomOut() { if (layoutManager.spanCount < MAX_COLUMN_COUNT) { increaseColumnCount() - getRecyclerAdapter().finishActMode() + getRecyclerAdapter()?.finishActMode() } } } @@ -570,11 +551,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun gotDirectories(newDirs: ArrayList, isFromCache: Boolean) { - if (!isFromCache) { + /*if (!isFromCache) { Thread { checkFolderContentChange(newDirs) }.start() - } + }*/ val dirs = getSortedDirectories(newDirs) directories_refresh_layout.isRefreshing = false @@ -627,7 +608,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { itemClicked((it as Directory).path) }.apply { setupZoomListener(mZoomListener) - setupDragListener(true) directories_grid.adapter = this } } else { @@ -659,7 +639,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } - private fun getBubbleTextItem(index: Int) = getRecyclerAdapter().dirs.getOrNull(index)?.getBubbleText() ?: "" + private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: "" private fun setupLatestMediaId() { Thread { @@ -701,6 +681,15 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { gotDirectories(movePinnedDirectoriesToFront(mDirs), true) } + override fun updateDirectories(directories: ArrayList, refreshList: Boolean) { + if (refreshList) { + gotDirectories(directories, true) + } else { + mDirs = directories + storeDirectories() + } + } + private fun checkWhatsNewDialog() { arrayListOf().apply { add(Release(46, R.string.release_46)) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 9df15a242..cb26c7c38 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -63,12 +63,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mSearchMenuItem: MenuItem? = null - private var mStoredUseEnglish = false private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true private var mStoredScrollHorizontally = true private var mStoredShowInfoBubble = true private var mStoredTextColor = 0 + private var mStoredPrimaryColor = 0 companion object { var mMedia = ArrayList() @@ -109,11 +109,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun onResume() { super.onResume() - if (mStoredUseEnglish != config.useEnglish) { - restartActivity() - return - } - if (mStoredAnimateGifs != config.animateGifs) { getMediaAdapter()?.updateAnimateGifs(config.animateGifs) } @@ -131,6 +126,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { getMediaAdapter()?.updateTextColor(config.textColor) } + if (mStoredPrimaryColor != config.primaryColor) { + getMediaAdapter()?.updatePrimaryColor(config.primaryColor) + media_horizontal_fastscroller.updatePrimaryColor() + media_vertical_fastscroller.updatePrimaryColor() + } + media_horizontal_fastscroller.updateBubbleColors() media_vertical_fastscroller.updateBubbleColors() media_refresh_layout.isEnabled = config.enablePullToRefresh @@ -225,12 +226,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun storeStateVariables() { config.apply { - mStoredUseEnglish = useEnglish mStoredAnimateGifs = animateGifs mStoredCropThumbnails = cropThumbnails mStoredScrollHorizontally = scrollHorizontally mStoredShowInfoBubble = showInfoBubble mStoredTextColor = textColor + mStoredPrimaryColor = primaryColor mShowAll = showAll } } @@ -287,7 +288,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { supportActionBar?.title = if (mShowAll) resources.getString(R.string.all_folders) else dirName getMedia() setupLayoutManager() - checkIfColorChanged() } else { toast(R.string.no_storage_permissions) finish() @@ -297,14 +297,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun getMediaAdapter() = media_grid.adapter as? MediaAdapter - private fun checkIfColorChanged() { - if (media_grid.adapter != null && getRecyclerAdapter().primaryColor != config.primaryColor) { - getRecyclerAdapter().primaryColor = config.primaryColor - media_horizontal_fastscroller.updatePrimaryColor() - media_vertical_fastscroller.updatePrimaryColor() - } - } - private fun setupAdapter() { if (!mShowAll && isDirEmpty()) { return @@ -318,7 +310,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { itemClicked((it as Medium).path) }.apply { setupZoomListener(mZoomListener) - setupDragListener(true) media_grid.adapter = this } } else { @@ -348,7 +339,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - private fun getBubbleTextItem(index: Int) = getRecyclerAdapter().media.getOrNull(index)?.getBubbleText() ?: "" + private fun getBubbleTextItem(index: Int) = getMediaAdapter()?.media?.getOrNull(index)?.getBubbleText() ?: "" private fun checkLastMediaChanged() { if (isActivityDestroyed()) @@ -388,7 +379,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun toggleFilenameVisibility() { config.displayFileNames = !config.displayFileNames if (media_grid.adapter != null) - getRecyclerAdapter().updateDisplayFilenames(config.displayFileNames) + getMediaAdapter()?.updateDisplayFilenames(config.displayFileNames) } private fun switchToFolderView() { @@ -501,8 +492,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { invalidateOptionsMenu() } - private fun getRecyclerAdapter() = (media_grid.adapter as MediaAdapter) - private fun setupLayoutManager() { if (config.viewTypeFiles == VIEW_TYPE_GRID) { setupGridLayoutManager() @@ -531,14 +520,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun zoomIn() { if (layoutManager.spanCount > 1) { reduceColumnCount() - getRecyclerAdapter().finishActMode() + getMediaAdapter()?.finishActMode() } } override fun zoomOut() { if (layoutManager.spanCount < MAX_COLUMN_COUNT) { increaseColumnCount() - getRecyclerAdapter().finishActMode() + getMediaAdapter()?.finishActMode() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index 0930d4463..939e68f1d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -6,7 +6,10 @@ import android.os.Bundle import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.SecurityDialog -import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor +import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection +import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.helpers.PROTECTION_FINGERPRINT import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS import com.simplemobiletools.commons.models.RadioItem @@ -89,7 +92,7 @@ class SettingsActivity : SimpleActivity() { settings_use_english_holder.setOnClickListener { settings_use_english.toggle() config.useEnglish = settings_use_english.isChecked - useEnglishToggled() + System.exit(0) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 55705a928..ab5e68d4a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -56,7 +56,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mShowAll = false private var mIsSlideshowActive = false private var mSkipConfirmationDialog = false - private var mRotationDegrees = 0f + private var mRotationDegrees = 0 private var mPrevHashcode = 0 private var mSlideshowHandler = Handler() @@ -66,7 +66,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mAreSlideShowMediaVisible = false private var mIsOrientationLocked = false - private var mStoredUseEnglish = false private var mStoredReplaceZoomableImages = false private var mMediaFiles = ArrayList() @@ -101,11 +100,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } - if (mStoredUseEnglish != config.useEnglish) { - restartActivity() - return - } - if (mStoredReplaceZoomableImages != config.replaceZoomableImages) { mPrevHashcode = 0 refreshViewPager() @@ -224,7 +218,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } if (config.hideSystemUI) { - fragmentClicked() + view_pager.onGlobalLayout { + Handler().postDelayed({ + fragmentClicked() + }, 500) + } } window.decorView.setOnSystemUiVisibilityChangeListener { visibility -> @@ -256,13 +254,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View findItem(R.id.menu_share_1).isVisible = !config.replaceShare findItem(R.id.menu_share_2).isVisible = config.replaceShare findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() - findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0f + findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0 findItem(R.id.menu_hide).isVisible = !currentMedium.name.startsWith('.') findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.') - findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0f + findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0 findItem(R.id.menu_lock_orientation).title = getString(if (mIsOrientationLocked) R.string.unlock_orientation else R.string.lock_orientation) findItem(R.id.menu_rotate).setShowAsAction( - if (mRotationDegrees != 0f) { + if (mRotationDegrees != 0) { MenuItem.SHOW_AS_ACTION_ALWAYS } else { MenuItem.SHOW_AS_ACTION_IF_ROOM @@ -304,7 +302,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun storeStateVariables() { config.apply { - mStoredUseEnglish = useEnglish mStoredReplaceZoomableImages = replaceZoomableImages } } @@ -543,7 +540,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val oldLastModified = getCurrentFile().lastModified() if (oldPath.isJpg()) { copyFile(getCurrentFile(), tmpFile) - saveExifRotation(ExifInterface(tmpFile.absolutePath)) + saveExifRotation(ExifInterface(tmpFile.absolutePath), mRotationDegrees) } else { val bitmap = BitmapFactory.decodeFile(oldPath) saveFile(tmpFile, bitmap, it as FileOutputStream) @@ -563,7 +560,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View it.flush() it.close() - mRotationDegrees = 0f + mRotationDegrees = 0 invalidateOptionsMenu() // we cannot refresh a specific image in Glide Cache, so just clear it all @@ -584,29 +581,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View @TargetApi(Build.VERSION_CODES.N) private fun tryRotateByExif(path: String): Boolean { - try { - if (!isPathOnSD(path)) { - saveExifRotation(ExifInterface(path)) - mRotationDegrees = 0f - invalidateOptionsMenu() - toast(R.string.file_saved) - return true - } else if (isNougatPlus()) { - val documentFile = getSomeDocumentFile(path) - if (documentFile != null) { - val parcelFileDescriptor = contentResolver.openFileDescriptor(documentFile.uri, "rw") - val fileDescriptor = parcelFileDescriptor.fileDescriptor - saveExifRotation(ExifInterface(fileDescriptor)) - mRotationDegrees = 0f - invalidateOptionsMenu() - toast(R.string.file_saved) - return true - } - } - } catch (e: Exception) { - showErrorToast(e) + return if (saveImageRotation(path, mRotationDegrees)) { + mRotationDegrees = 0 + invalidateOptionsMenu() + toast(R.string.file_saved) + true + } else { + false } - return false } private fun copyFile(source: File, destination: File) { @@ -625,32 +607,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun saveFile(file: File, bitmap: Bitmap, out: FileOutputStream) { val matrix = Matrix() - matrix.postRotate(mRotationDegrees) + matrix.postRotate(mRotationDegrees.toFloat()) val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) bmp.compress(file.absolutePath.getCompressionFormat(), 90, out) } - private fun saveExifRotation(exif: ExifInterface) { - val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL) - val orientationDegrees = (degreesForRotation(orientation) + mRotationDegrees) % 360 - exif.setAttribute(ExifInterface.TAG_ORIENTATION, rotationFromDegrees(orientationDegrees)) - exif.saveAttributes() - } - - private fun degreesForRotation(orientation: Int) = when (orientation) { - ExifInterface.ORIENTATION_ROTATE_270 -> 270f - ExifInterface.ORIENTATION_ROTATE_180 -> 180f - ExifInterface.ORIENTATION_ROTATE_90 -> 90f - else -> 0f - } - - private fun rotationFromDegrees(degrees: Float) = when (degrees) { - 270f -> ExifInterface.ORIENTATION_ROTATE_270 - 180f -> ExifInterface.ORIENTATION_ROTATE_180 - 90f -> ExifInterface.ORIENTATION_ROTATE_90 - else -> ExifInterface.ORIENTATION_NORMAL - }.toString() - private fun isShowHiddenFlagNeeded(): Boolean { val file = File(mPath) if (file.isHidden) { @@ -767,7 +728,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun askConfirmDelete() { - DeleteWithRememberDialog(this) { + DeleteWithRememberDialog(this, getString(R.string.proceed_with_deletion)) { mSkipConfirmationDialog = it deleteConfirmed() } @@ -943,7 +904,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (mPos != position) { mPos = position updateActionbarTitle() - mRotationDegrees = 0f + mRotationDegrees = 0 supportInvalidateOptionsMenu() scheduleSwipe() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 20e7802d7..f290cdc87 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.gallery.adapters +import android.util.SparseArray import android.view.Menu import android.view.View import android.view.ViewGroup @@ -27,8 +28,9 @@ import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item_list.view.* import java.io.File import java.util.* +import kotlin.collections.ArrayList -class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList, val listener: DirOperationsListener?, recyclerView: MyRecyclerView, +class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList, val listener: DirOperationsListener?, recyclerView: MyRecyclerView, val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { @@ -41,6 +43,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList