From 014c2b951d64b5ba9c3a5fb7b0631f1194e2ab00 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 13:57:24 +0100 Subject: [PATCH 01/39] clear Glide cache after rotating an image, to avoid some glitches --- .../gallery/activities/ViewPagerActivity.kt | 8 ++++++++ 1 file changed, 8 insertions(+) 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 2a8099959..98497f5f2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -23,6 +23,7 @@ import android.support.v4.view.ViewPager import android.util.DisplayMetrics import android.view.* import android.view.animation.DecelerateInterpolator +import com.bumptech.glide.Glide import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* @@ -530,6 +531,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View it.close() mRotationDegrees = 0f invalidateOptionsMenu() + + // we cannot refresh a specific image in Glide Cache, so just clear it all + val glide = Glide.get(applicationContext) + glide.clearDiskCache() + runOnUiThread { + glide.clearMemory() + } } } catch (e: OutOfMemoryError) { toast(R.string.out_of_memory_error) From aa5b5b3081e446f8ef39419d56838f07a4ab35d7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 14:11:52 +0100 Subject: [PATCH 02/39] move the image saving things in a separate function to reduce indentation --- .../gallery/activities/ViewPagerActivity.kt | 100 ++++++++++-------- 1 file changed, 53 insertions(+), 47 deletions(-) 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 98497f5f2..802f0eb9e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -498,59 +498,65 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View Thread({ val selectedFile = File(it) handleSAFDialog(selectedFile) { - toast(R.string.saving) - val tmpFile = File(filesDir, ".tmp_${it.getFilenameFromPath()}") - try { - val bitmap = BitmapFactory.decodeFile(currPath) - getFileOutputStream(tmpFile) { - if (it == null) { - toast(R.string.unknown_error_occurred) - return@getFileOutputStream - } + saveImageToFile(currPath, it) - val oldLastModified = getCurrentFile().lastModified() - if (currPath.isJpg()) { - saveRotation(getCurrentFile(), tmpFile) - } else { - saveFile(tmpFile, bitmap, it as FileOutputStream) - } - - if (tmpFile.length() > 0 && selectedFile.exists()) { - deleteFile(selectedFile) {} - } - copyFile(tmpFile, selectedFile) - scanFile(selectedFile) {} - toast(R.string.file_saved) - - if (config.keepLastModified) { - selectedFile.setLastModified(oldLastModified) - updateLastModified(selectedFile, oldLastModified) - } - - it.flush() - it.close() - mRotationDegrees = 0f - invalidateOptionsMenu() - - // we cannot refresh a specific image in Glide Cache, so just clear it all - val glide = Glide.get(applicationContext) - glide.clearDiskCache() - runOnUiThread { - glide.clearMemory() - } - } - } catch (e: OutOfMemoryError) { - toast(R.string.out_of_memory_error) - } catch (e: Exception) { - showErrorToast(e) - } finally { - deleteFile(tmpFile) {} - } } }).start() } } + private fun saveImageToFile(oldPath: String, newPath: String) { + val newFile = File(newPath) + toast(R.string.saving) + val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}") + try { + val bitmap = BitmapFactory.decodeFile(oldPath) + getFileOutputStream(tmpFile) { + if (it == null) { + toast(R.string.unknown_error_occurred) + return@getFileOutputStream + } + + val oldLastModified = getCurrentFile().lastModified() + if (oldPath.isJpg()) { + saveRotation(getCurrentFile(), tmpFile) + } else { + saveFile(tmpFile, bitmap, it as FileOutputStream) + } + + if (tmpFile.length() > 0 && newFile.exists()) { + deleteFile(newFile) {} + } + copyFile(tmpFile, newFile) + scanFile(newFile) {} + toast(R.string.file_saved) + + if (config.keepLastModified) { + newFile.setLastModified(oldLastModified) + updateLastModified(newFile, oldLastModified) + } + + it.flush() + it.close() + mRotationDegrees = 0f + invalidateOptionsMenu() + + // we cannot refresh a specific image in Glide Cache, so just clear it all + val glide = Glide.get(applicationContext) + glide.clearDiskCache() + runOnUiThread { + glide.clearMemory() + } + } + } catch (e: OutOfMemoryError) { + toast(R.string.out_of_memory_error) + } catch (e: Exception) { + showErrorToast(e) + } finally { + deleteFile(tmpFile) {} + } + } + private fun copyFile(source: File, destination: File) { var inputStream: InputStream? = null var out: OutputStream? = null From 0bb48601f4b45fde24b3b231923442bb58b0d016 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 14:50:05 +0100 Subject: [PATCH 03/39] remove some empty callbacks to avoid memory leaks --- app/build.gradle | 2 +- .../gallery/activities/IncludedFoldersActivity.kt | 2 +- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/activities/MediaActivity.kt | 2 +- .../gallery/activities/PhotoVideoActivity.kt | 4 ++-- .../gallery/activities/ViewPagerActivity.kt | 12 ++++++------ .../gallery/adapters/MediaAdapter.kt | 2 +- .../simplemobiletools/gallery/extensions/activity.kt | 8 ++++---- .../gallery/helpers/MediaFetcher.kt | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 42f9024db..bb8dd42ad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.37.12' + compile 'com.simplemobiletools:commons:2.38.0' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' 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 f69f4f987..c6ccb0437 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt @@ -60,7 +60,7 @@ class IncludedFoldersActivity : SimpleActivity() { FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { config.addIncludedFolder(it) updateIncludedFolders() - scanPath(it) {} + scanPath(it) } } } 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 62c143735..013311afc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -209,7 +209,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val newFolder = File(config.tempFolderPath) if (newFolder.exists() && newFolder.isDirectory) { if (newFolder.list()?.isEmpty() == true) { - deleteFileBg(newFolder, true) { } + deleteFileBg(newFolder, true) } } config.tempFolderPath = "" 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 b500af01e..c26f78104 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -347,7 +347,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun deleteDirectoryIfEmpty() { val file = File(mPath) if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) { - deleteFile(file, true) {} + deleteFile(file, true) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 960db4d14..20e8f48d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -59,14 +59,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false) if (mUri!!.scheme == "file") { - scanPath(mUri!!.path) {} + scanPath(mUri!!.path) sendViewPagerIntent(mUri!!.path) finish() return } else { val path = applicationContext.getRealPathFromURI(mUri!!) ?: "" if (path != mUri.toString() && path.isNotEmpty()) { - scanPath(mUri!!.path) {} + scanPath(mUri!!.path) sendViewPagerIntent(path) finish() return 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 802f0eb9e..e808a8441 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -194,7 +194,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } reloadViewPager() - scanPath(mPath) {} + scanPath(mPath) if (config.darkBackground) view_pager.background = ColorDrawable(Color.BLACK) @@ -525,10 +525,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } if (tmpFile.length() > 0 && newFile.exists()) { - deleteFile(newFile) {} + deleteFile(newFile) } copyFile(tmpFile, newFile) - scanFile(newFile) {} + scanFile(newFile) toast(R.string.file_saved) if (config.keepLastModified) { @@ -553,7 +553,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } catch (e: Exception) { showErrorToast(e) } finally { - deleteFile(tmpFile) {} + deleteFile(tmpFile) } } @@ -794,10 +794,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteDirectoryIfEmpty() { val file = File(mDirectory) if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) { - deleteFile(file, true) {} + deleteFile(file, true) } - scanPath(mDirectory) {} + scanPath(mDirectory) } private fun checkOrientation() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 039ac332a..2c1c3e012 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -173,7 +173,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, Thread({ getSelectedMedia().forEach { val oldFile = File(it.path) - activity.toggleFileVisibility(oldFile, hide) {} + activity.toggleFileVisibility(oldFile, hide) } activity.runOnUiThread { listener?.refreshItems() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 200b2897b..0cfb3f900 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -116,14 +116,14 @@ fun SimpleActivity.addNoMedia(path: String, callback: () -> Unit) { } } -fun SimpleActivity.removeNoMedia(path: String, callback: () -> Unit) { +fun SimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) { val file = File(path, NOMEDIA) deleteFile(file) { - callback() + callback?.invoke() } } -fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: (newFile: File) -> Unit) { +fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: ((newFile: File) -> Unit)? = null) { val path = oldFile.parent var filename = oldFile.name filename = if (hide) { @@ -133,7 +133,7 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: } val newFile = File(path, filename) renameFile(oldFile, newFile) { - callback(newFile) + callback?.invoke(newFile) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index c42db1b4e..33e1fa98c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -282,7 +282,7 @@ class MediaFetcher(val context: Context) { val isAlreadyAdded = curMedia.any { it.path == file.absolutePath } if (!isAlreadyAdded) { curMedia.add(medium) - context.scanPath(file.absolutePath) {} + context.scanPath(file.absolutePath) } } } From 5808ec3b62718ee63f313f465d8a5ec5695d8e8c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 16:00:24 +0100 Subject: [PATCH 04/39] update commons to 2.38.1 --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index bb8dd42ad..4b22423ea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.38.0' + compile 'com.simplemobiletools:commons:2.38.1' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ff7ff3399..e0e44d1c3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ + Date: Thu, 9 Nov 2017 16:47:36 +0100 Subject: [PATCH 05/39] make sure we save the rotated image on the background thread --- .../gallery/activities/ViewPagerActivity.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 e808a8441..595e76c55 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -495,13 +495,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun saveImageAs() { val currPath = getCurrentPath() SaveAsDialog(this, currPath, false) { - Thread({ - val selectedFile = File(it) - handleSAFDialog(selectedFile) { + val selectedFile = File(it) + handleSAFDialog(selectedFile) { + Thread({ saveImageToFile(currPath, it) - - } - }).start() + }).start() + } } } From f657a64baac993efaa046a5ec9d8179f7687ebf7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 16:50:32 +0100 Subject: [PATCH 06/39] reset video SurfaceView and SurfaceHolder on destroy --- .../com/simplemobiletools/gallery/fragments/VideoFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index e6433e246..228ac1fc8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -457,6 +457,8 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee releaseMediaPlayer() mSeekBar?.progress = 0 mTimerHandler?.removeCallbacksAndMessages(null) + mSurfaceView = null + mSurfaceHolder = null } private fun releaseMediaPlayer() { From e1ec8c5623fec8c739737c7f85cde72a28065a42 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 17:04:10 +0100 Subject: [PATCH 07/39] clean up some more things after usage at videofragment --- .../com/simplemobiletools/gallery/fragments/VideoFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 228ac1fc8..bf0765466 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -458,10 +458,12 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee mSeekBar?.progress = 0 mTimerHandler?.removeCallbacksAndMessages(null) mSurfaceView = null + mSurfaceHolder?.removeCallback(this) mSurfaceHolder = null } private fun releaseMediaPlayer() { + mMediaPlayer?.setSurface(null) mMediaPlayer?.release() mMediaPlayer = null } From f374cfde6767ab2ced87c7bd12969915be123baa Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 17:14:28 +0100 Subject: [PATCH 08/39] reenable GlideDecoder for loading fullscreen media --- .../gallery/fragments/PhotoFragment.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 345ca57e4..e596e9d16 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -27,6 +27,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.PhotoActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.extensions.* +import com.simplemobiletools.gallery.helpers.GlideDecoder import com.simplemobiletools.gallery.helpers.GlideRotateTransformation import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium @@ -131,12 +132,6 @@ class PhotoFragment : ViewPagerFragment() { private fun photoFragmentVisibilityChanged(isVisible: Boolean) { if (isVisible) { addZoomableView() - } else { - view.subsampling_view.apply { - recycle() - beGone() - background = ColorDrawable(Color.TRANSPARENT) - } } } @@ -226,7 +221,7 @@ class PhotoFragment : ViewPagerFragment() { private fun addZoomableView() { if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.visibility == View.GONE) { view.subsampling_view.apply { - //setBitmapDecoderClass(GlideDecoder::class.java) // causing random crashes on Android 7+, at rotating + setBitmapDecoderClass(GlideDecoder::class.java) maxScale = 10f beVisible() setImage(ImageSource.uri(medium.path)) @@ -281,7 +276,8 @@ class PhotoFragment : ViewPagerFragment() { } fun rotateImageViewBy(degrees: Float) { - view.subsampling_view.beGone() + // do not make Subsampling view Gone, because it gets recycled and can crash with "Error, cannot access an invalid/free'd bitmap here!" + view.subsampling_view.beInvisible() loadBitmap(degrees) } From 3e7d4b6f5b39fa0671733e622c3694be32fe4dc4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 17:23:47 +0100 Subject: [PATCH 09/39] make resultData.data nullable at pick intent result --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 013311afc..ef0a5ffad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -451,7 +451,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { else -> fillIntentPath(resultData, resultIntent) } } else if ((mIsPickImageIntent || mIsPickVideoIntent)) { - val path = resultData.data.path + val path = resultData.data?.path val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID) resultIntent.data = uri resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION From 80fadfec6284fffccbb689f0bf9becd658c2e3ff Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 17:28:38 +0100 Subject: [PATCH 10/39] make videoFragment timeHolder nullable --- .../gallery/fragments/VideoFragment.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index bf0765466..47c97d86b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -34,6 +34,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee private var mCurrTimeView: TextView? = null private var mTimerHandler: Handler? = null private var mSeekBar: SeekBar? = null + private var mTimeHolder: View? = null private var mIsPlaying = false private var mIsDragged = false @@ -60,7 +61,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee lateinit var mView: View lateinit var medium: Medium - lateinit var mTimeHolder: View override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { mView = inflater.inflate(R.layout.pager_video_item, container, false) @@ -287,8 +287,8 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee private fun initTimeHolder() { val res = resources val height = context!!.navigationBarHeight - val left = mTimeHolder.paddingLeft - val top = mTimeHolder.paddingTop + val left = mTimeHolder!!.paddingLeft + val top = mTimeHolder!!.paddingTop var right = res.getDimension(R.dimen.timer_padding).toInt() var bottom = 0 @@ -299,7 +299,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee right += height bottom += context!!.navigationBarHeight } - mTimeHolder.setPadding(left, top, right, bottom) + mTimeHolder!!.setPadding(left, top, right, bottom) } mCurrTimeView = mView.video_curr_time @@ -307,7 +307,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee mSeekBar!!.setOnSeekBarChangeListener(this) if (mIsFullscreen) - mTimeHolder.beInvisible() + mTimeHolder!!.beInvisible() } private fun hasNavBar(): Boolean { @@ -375,7 +375,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee AnimationUtils.loadAnimation(activity, anim).apply { duration = 150 fillAfter = true - mTimeHolder.startAnimation(this) + mTimeHolder?.startAnimation(this) } } @@ -557,7 +557,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee onGlobalLayout { if (height != 0) { val smallMargin = resources.getDimension(R.dimen.small_margin) - val timeHolderHeight = mTimeHolder.height - context.navigationBarHeight + val timeHolderHeight = mTimeHolder!!.height - context.navigationBarHeight y = context.usableScreenSize.y - height - timeHolderHeight - if (context.navigationBarHeight == 0) smallMargin else 0f } } @@ -598,7 +598,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee mView.video_details.apply { if (visibility == View.VISIBLE) { val smallMargin = resources.getDimension(R.dimen.small_margin) - val timeHolderHeight = mTimeHolder.height - context.navigationBarHeight.toFloat() + val timeHolderHeight = mTimeHolder!!.height - context.navigationBarHeight.toFloat() val fullscreenOffset = context.navigationBarHeight.toFloat() - smallMargin val newY = context.usableScreenSize.y - height + if (mIsFullscreen) fullscreenOffset else -(timeHolderHeight + if (context.navigationBarHeight == 0) smallMargin else 0f) animate().y(newY) From ae9cce880ae097c22cde2ec93c0d304926748a36 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 19:09:31 +0100 Subject: [PATCH 11/39] make sure extended details are always properly positioned --- .../gallery/fragments/PhotoFragment.kt | 19 ++++++++++++------- .../gallery/fragments/VideoFragment.kt | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index e596e9d16..173becce8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -39,6 +39,7 @@ import java.io.FileOutputStream class PhotoFragment : ViewPagerFragment() { private var isFragmentVisible = false + private var isFullscreen = false private var wasInit = false private var storedShowExtendedDetails = false private var storedExtendedDetails = 0 @@ -86,6 +87,7 @@ class PhotoFragment : ViewPagerFragment() { } } + isFullscreen = activity!!.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN view.subsampling_view.setOnClickListener { photoClicked() } view.gif_view.setOnClickListener { photoClicked() } loadImage() @@ -288,9 +290,8 @@ class PhotoFragment : ViewPagerFragment() { setTextColor(context.config.textColor) beVisibleIf(text.isNotEmpty()) onGlobalLayout { - if (height != 0) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - y = context.usableScreenSize.y - height - if (context.navigationBarHeight == 0) smallMargin else 0f + if (height != 0 && isAdded) { + y = getExtendedDetailsY(height) } } } @@ -317,13 +318,17 @@ class PhotoFragment : ViewPagerFragment() { } override fun fullscreenToggled(isFullscreen: Boolean) { + this.isFullscreen = isFullscreen view.photo_details.apply { if (visibility == View.VISIBLE) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - val fullscreenOffset = context.navigationBarHeight.toFloat() - smallMargin - val newY = context.usableScreenSize.y - height + if (isFullscreen) fullscreenOffset else -(if (context.navigationBarHeight == 0) smallMargin else 0f) - animate().y(newY) + animate().y(getExtendedDetailsY(height)) } } } + + private fun getExtendedDetailsY(height: Int): Float { + val smallMargin = resources.getDimension(R.dimen.small_margin) + val fullscreenOffset = context!!.navigationBarHeight.toFloat() - smallMargin + return context!!.usableScreenSize.y - height + if (isFullscreen) fullscreenOffset else -(if (context!!.navigationBarHeight == 0) smallMargin else 0f) + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 47c97d86b..4bbb1e138 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -555,10 +555,8 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee setTextColor(context.config.textColor) beVisibleIf(text.isNotEmpty()) onGlobalLayout { - if (height != 0) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - val timeHolderHeight = mTimeHolder!!.height - context.navigationBarHeight - y = context.usableScreenSize.y - height - timeHolderHeight - if (context.navigationBarHeight == 0) smallMargin else 0f + if (height != 0 && isAdded) { + y = getExtendedDetailsY(height) } } } @@ -597,12 +595,15 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee checkFullscreen() mView.video_details.apply { if (visibility == View.VISIBLE) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - val timeHolderHeight = mTimeHolder!!.height - context.navigationBarHeight.toFloat() - val fullscreenOffset = context.navigationBarHeight.toFloat() - smallMargin - val newY = context.usableScreenSize.y - height + if (mIsFullscreen) fullscreenOffset else -(timeHolderHeight + if (context.navigationBarHeight == 0) smallMargin else 0f) - animate().y(newY) + animate().y(getExtendedDetailsY(height)) } } } + + private fun getExtendedDetailsY(height: Int): Float { + val smallMargin = resources.getDimension(R.dimen.small_margin) + val timeHolderHeight = mTimeHolder!!.height - context!!.navigationBarHeight.toFloat() + val fullscreenOffset = context!!.navigationBarHeight.toFloat() - smallMargin + return context!!.usableScreenSize.y - height + if (mIsFullscreen) fullscreenOffset else -(timeHolderHeight + if (context!!.navigationBarHeight == 0) smallMargin else 0f) + } } From 96065615b4e0cf6da253a880dbca403b29d39676 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 19:14:51 +0100 Subject: [PATCH 12/39] use some view visiblity extension functions --- app/build.gradle | 2 +- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 2 +- .../com/simplemobiletools/gallery/fragments/PhotoFragment.kt | 4 ++-- .../com/simplemobiletools/gallery/fragments/VideoFragment.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4b22423ea..c9d936f65 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.38.1' + compile 'com.simplemobiletools:commons:2.38.2' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 2c1c3e012..496584e12 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -372,7 +372,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, fun bindView(medium: Medium, displayFilenames: Boolean, scrollHorizontally: Boolean, isListViewType: Boolean, textColor: Int, animateGifs: Boolean, cropThumbnails: Boolean): View { itemView.apply { - play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE + play_outline.beVisibleIf(medium.video) photo_name.beVisibleIf(displayFilenames || isListViewType) photo_name.text = medium.name activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 173becce8..697434a6f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -221,7 +221,7 @@ class PhotoFragment : ViewPagerFragment() { } private fun addZoomableView() { - if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.visibility == View.GONE) { + if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.isGone()) { view.subsampling_view.apply { setBitmapDecoderClass(GlideDecoder::class.java) maxScale = 10f @@ -320,7 +320,7 @@ class PhotoFragment : ViewPagerFragment() { override fun fullscreenToggled(isFullscreen: Boolean) { this.isFullscreen = isFullscreen view.photo_details.apply { - if (visibility == View.VISIBLE) { + if (isVisible()) { animate().y(getExtendedDetailsY(height)) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 4bbb1e138..423ecd1ea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -594,7 +594,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee mIsFullscreen = isFullscreen checkFullscreen() mView.video_details.apply { - if (visibility == View.VISIBLE) { + if (isVisible()) { animate().y(getExtendedDetailsY(height)) } } From ad3befbe789fe2e3733ccdec517f17412fc56c4c Mon Sep 17 00:00:00 2001 From: Phoenix1747 Date: Thu, 9 Nov 2017 19:20:07 +0100 Subject: [PATCH 13/39] Translated strings for screen orientation --- app/src/main/res/values-de/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0a90b0dcd..9676c7754 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -23,8 +23,8 @@ Lautstärke Helligkeit Nicht erneut fragen (in dieser Sitzung) - Lock orientation - Unlock orientation + Bildschirmausrichtung sperren + Bildschirmausrichtung entsperren Filter From 11fb678edea4341a7f70722272f20d86e88b1177 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 19:31:10 +0100 Subject: [PATCH 14/39] updating Release notes --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 1 + app/src/main/res/values/donottranslate.xml | 3 +++ 2 files changed, 4 insertions(+) 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 ef0a5ffad..bf1dfe512 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -659,6 +659,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { add(Release(136, R.string.release_136)) add(Release(137, R.string.release_137)) add(Release(138, R.string.release_138)) + add(Release(143, R.string.release_143)) checkWhatsNew(this, BuildConfig.VERSION_CODE) } } diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index a8c998266..5475edd14 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -2,6 +2,9 @@ + + Added new options to use english language on non-english devices, to password protect whole app and to lock screen orientation at fullscreen view + Added an option to keep last-modified field at file copy/move/rename Added an option to hide folder media count on the main screen Added an option to show customizable extended details over fullscreen media From 349aeac252dc3b108d1a9fd498458528115ac9f5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 19:31:17 +0100 Subject: [PATCH 15/39] update version to 2.18.0 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c9d936f65..b8fed0c4f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 142 - versionName "2.17.4" + versionCode 143 + versionName "2.18.0" } signingConfigs { From d6ab31674b51b861f1e32a3c37d2842f8cb15b9b Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 19:31:22 +0100 Subject: [PATCH 16/39] updating changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b2897c4b..73bf0516e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ Changelog ========== +Version 2.18.0 *(2017-11-09)* +---------------------------- + + * Added an option to use english language on non-english devices + * Added an option to password protect the whole app + * Added an option to lock screen orientation at fullscreen view + * Split the Rotate button to 3 buttons per degrees + * Changed the way fullscreen images are loaded for better quality + * Fixed many memory leaks and smaller issues + Version 2.17.4 *(2017-11-06)* ---------------------------- From c294ff41103b7c838d2c821bad40e9c0e1869e0c Mon Sep 17 00:00:00 2001 From: Pzqqt <821026875@qq.com> Date: Fri, 10 Nov 2017 11:40:41 +0800 Subject: [PATCH 17/39] Update strings.xml --- app/src/main/res/values-zh-rCN/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index e6b3ceaf9..072ef4393 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -23,8 +23,8 @@ 音量 亮度 不再提醒 - Lock orientation - Unlock orientation + 锁定方向 + 解锁方向 要显示的媒体文件 From 66a1f117d40ee4b331b8db9508aa9247b98081d4 Mon Sep 17 00:00:00 2001 From: gcalzo <26879397+gcalzo@users.noreply.github.com> Date: Fri, 10 Nov 2017 13:25:24 +0100 Subject: [PATCH 18/39] Update strings.xml --- app/src/main/res/values-it/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 7f9f0e294..9e6cd32b8 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -23,8 +23,8 @@ Volume Luminosità Non chiedere nuovamente in questa sessione - Lock orientation - Unlock orientation + Blocca orientamento + Sblocca orientamento Filtra i media @@ -115,7 +115,7 @@ Anima le GIF in miniatura Luminosità max durante visualizzazione Ritaglia le miniature in quadrati - Ruota a schermo intero per + Ruota schermo per Impostazione di sistema Rotazione dispositivo Proporzioni From ed05aca8527058d9083237c2d1e584d9c3eb16d2 Mon Sep 17 00:00:00 2001 From: gcalzo <26879397+gcalzo@users.noreply.github.com> Date: Fri, 10 Nov 2017 16:24:31 +0100 Subject: [PATCH 19/39] Update strings.xml Replaced "dall\'app" with "dalla app" which is grammatically acceptable... :) --- app/src/main/res/values-it/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 9e6cd32b8..3498ff272 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -133,7 +133,7 @@ Una galleria per visualizzare foto e video senza pubblicità. - Un semplice strumento per visualizzare foto e video. Gli elementi possono essere ordinati per data, dimensioni, nome sia ascendente che discendente; le foto possono essere ingrandite. I file sono mostrati in colonne multiple a seconda delle dimensioni dello schermo, puoi modificare il numero di colonne con il tocco. Possono essere rinominate, condivise, eliminate, copiate, spostate. Le immagini possono anche essere ritagliate, ruotate o impostate come sfondo direttamente dall\'app. + Un semplice strumento per visualizzare foto e video. Gli elementi possono essere ordinati per data, dimensioni, nome sia ascendente che discendente; le foto possono essere ingrandite. I file sono mostrati in colonne multiple a seconda delle dimensioni dello schermo, puoi modificare il numero di colonne con il tocco. Possono essere rinominate, condivise, eliminate, copiate, spostate. Le immagini possono anche essere ritagliate, ruotate o impostate come sfondo direttamente dalla app. Simple Gallery è anche offerta per utilizzo di terze parti per anteprime di immagini / video, aggiunta di allegati ai client email, ecc. È perfetta per un uso quotidiano. From abbf25ddf8daca5ac78eec6941778bf17279985b Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 10 Nov 2017 21:17:34 +0100 Subject: [PATCH 20/39] make sure we show the Use English toggle when it was changed --- app/build.gradle | 2 +- .../simplemobiletools/gallery/activities/SettingsActivity.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b8fed0c4f..3b08a6a9c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.38.2' + compile 'com.simplemobiletools:commons:2.38.6' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' 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 a09c3bd53..4bb90d013 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -67,7 +67,7 @@ class SettingsActivity : SimpleActivity() { } private fun setupUseEnglish() { - settings_use_english_holder.beVisibleIf(Locale.getDefault().language != "en") + settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en") settings_use_english.isChecked = config.useEnglish settings_use_english_holder.setOnClickListener { settings_use_english.toggle() From e04b11a049a36cc396f3613dff01301d76430dc9 Mon Sep 17 00:00:00 2001 From: gregory678 Date: Sat, 11 Nov 2017 01:50:50 +0100 Subject: [PATCH 21/39] Updates for version 2.18 --- app/src/main/res/values-pl/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index c6b18239b..51ae29cca 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -23,8 +23,8 @@ Głośność Jasność Nie pytaj więcej w tej sesji - Lock orientation - Unlock orientation + Zablokuj orientację ekranu + Odblokuj orientację ekranu Filtruj multimedia From 4d4b40e6fdfc08f7a9fb171f33b894e77ca0d6fd Mon Sep 17 00:00:00 2001 From: alpenblauwtje Date: Sat, 11 Nov 2017 16:59:55 +0100 Subject: [PATCH 22/39] Small grammar corrections --- app/src/main/res/values-nl/strings.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 1f49212f3..bbd0a82dd 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -27,12 +27,12 @@ Schermrotatie ontgrendelen - Media kiezen + Filter media Afbeeldingen Video\'s GIF-bestanden Geen bestanden gevonden met de huidige filters. - Media kiezen + Filters aanpassen Deze functie verbergt de map door het bestand \'.nomedia\' toe te voegen. Alle submappen zullen ook worden verborgen. Kies \'Verborgen mappen tonen\' in de instellingen om toch verborgen mappen te kunnen inzien. Doorgaan? @@ -46,8 +46,8 @@ Verwijder alles uit de lijst van uitgesloten mappen? Dit zal de mappen zelf niet verwijderen. - Ingesloten mappen - Ingesloten mappen beheren + Toegevoegde mappen + Toegevoegde mappen beheren Map toevoegen Als er mappen zijn die wel media bevatten, maar niet niet door de galerij worden herkend, voeg deze mappen dan hier handmatig toe.\n\nHet hier toevoegen van mappen zal andere mappen niet uitsluiten. From 1419f979aa4d9073e35cd8ba3df83e07f9fe6bfa Mon Sep 17 00:00:00 2001 From: Daria Szatan Date: Sun, 12 Nov 2017 13:10:49 +0100 Subject: [PATCH 23/39] [Update] Polish app name + translation --- app/src/main/res/values-pl/strings.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 51ae29cca..eb749c168 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -1,7 +1,7 @@ - Simple Gallery - Simple Gallery + Prosta Galeria + Galeria Edytuj Uruchom aplikację aparatu (ukryty) @@ -35,7 +35,7 @@ Zmień filtry - Ta funkcja ukrywa foldery dodając do nich pusty plik .nomedia. Aby móc je zobaczyć, należy włączyć opcję \'Pokazuj ukryte foldery\' w ustawieniach. Kontyntynuować? + Ta funkcja ukrywa foldery, dodając do nich pusty plik .nomedia. Aby móc je zobaczyć, należy włączyć opcję \'Pokazuj ukryte foldery\' w ustawieniach. Kontynuować? Wyklucz Wykluczone foldery Zarządzaj wykluczonymi folderami @@ -49,7 +49,7 @@ Dołączone foldery Zarządzaj dołączonymi folderami Dodaj folder - Jeśli masz jakieś foldery z multimediami, ale aplikacja ich nie wykryła, możesz je tutaj dodać ręcznie. + Jeśli masz jakieś foldery z multimediami, ale aplikacja ich nie wykryła, możesz je dodać ręcznie tutaj. Zmień rozmiar @@ -131,13 +131,13 @@ - Darmowa galeria bez reklam do przeglądania obrazów i filmów. + Prosta galeria bez reklam do przeglądania obrazów i filmów. - Prosta aplikacja galerii do oglądania obrazów i filmów. Pliki mogą być sortowane według daty, rozmiaru i nazwy, zarówno w porządku rosnącym, jak i malejącym. W zależności od wielkości ekranu wyświetlane mogą być w wielu kolumnach. Liczbę kolumn można zmieniać za pomocą gestów. Zdjęcia mogą być powiększane, przycinane, obracane lub ustawiane jako tapeta bezpośrednio z poziomu aplikacji. Kolory aplikacji można dowolnie ustawiać. + Prosta aplikacja galerii do oglądania obrazów i filmów. Pliki mogą być sortowane według daty, rozmiaru i nazwy, zarówno w porządku rosnącym, jak i malejącym. W zależności od wielkości ekranu, wyświetlane mogą być w wielu kolumnach. Liczbę kolumn można zmieniać za pomocą gestów, a zdjęcia mogą być powiększane, przycinane, obracane lub ustawiane jako tapeta bezpośrednio z poziomu Prostej Galerii. Kolory aplikacji można dowolnie ustawiać. - Aplikacja nie zawiera żadnych reklam ani niepotrzebnych uprawnień. Jest też w pełni otawrtoźrodłowa. - - Niniejsza aplikacja jest tylko częścią naszego zestawu prostych aplikacji. Znajdziecie je na stronie http://www.simplemobiletools.com. + Nie zawiera natomiast żadnych reklam i nie potrzebuje całej masy uprawnień. Jest w pełni otwartoźródłowa i w pełni podatna na kolorowanie. + + Niniejsza aplikacja jest tylko częścią naszej kolekcji prostych narzędzi. Ta, jak i pozostałe, dostępne są na stronie http://www.simplemobiletools.com @color/default_dark_theme_text_color @color/default_dark_theme_background_color - - @color/color_primary From 6f78a6e9ce898d12baa880a574ce3bca6c4977fb Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 14:44:39 +0100 Subject: [PATCH 29/39] rewriting MediaAdapter to the Commons MyRecyclerViewAdapter --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 7 +- .../gallery/activities/MediaActivity.kt | 42 +-- .../gallery/adapters/DirectoryAdapter.kt | 12 +- .../gallery/adapters/MediaAdapter.kt | 318 +++++------------- .../gallery/dialogs/PickMediumDialog.kt | 4 +- 6 files changed, 124 insertions(+), 261 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b076fd8a1..80fe23f3e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.39.7' + compile 'com.simplemobiletools:commons:2.39.8' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.android.support:multidex:1.0.2' 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 e2884e12e..25806c41e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -340,8 +340,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } else { setupListLayoutManager() } - getDirectoryAdapter()?.setupZoomListener(mZoomListener) - getDirectoryAdapter()?.setupDragListener(true) + + getDirectoryAdapter()?.apply { + setupZoomListener(mZoomListener) + setupDragListener(true) + } } private fun setupGridLayoutManager() { 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 076541e2b..d4fdd4955 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -23,6 +23,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.commons.models.RadioItem +import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask @@ -57,6 +58,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mLatestMediaId = 0L private var mLastMediaHandler = Handler() private var mCurrAsyncTask: GetMediaAsynctask? = null + private var mZoomListener: MyRecyclerView.MyZoomListener? = null companion object { var mMedia = ArrayList() @@ -174,8 +176,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val currAdapter = media_grid.adapter if (currAdapter == null) { - media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple) { - itemClicked(it.path) + media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid) { + itemClicked((it as Medium).path) } } else { (currAdapter as MediaAdapter).updateMedia(mMedia) @@ -395,10 +397,16 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun getRecyclerAdapter() = (media_grid.adapter as MediaAdapter) private fun setupLayoutManager() { - if (config.viewTypeFiles == VIEW_TYPE_GRID) + if (config.viewTypeFiles == VIEW_TYPE_GRID) { setupGridLayoutManager() - else + } else { setupListLayoutManager() + } + + getMediaAdapter()?.apply { + setupZoomListener(mZoomListener) + setupDragListener(true) + } } private fun setupGridLayoutManager() { @@ -411,42 +419,30 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } - /*media_grid.isDragSelectionEnabled = true - media_grid.isZoomingEnabled = true layoutManager.spanCount = config.mediaColumnCnt - media_grid.listener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener { + mZoomListener = object : MyRecyclerView.MyZoomListener { override fun zoomIn() { if (layoutManager.spanCount > 1) { reduceColumnCount() - getRecyclerAdapter().actMode?.finish() + getRecyclerAdapter().finishActMode() } } override fun zoomOut() { if (layoutManager.spanCount < MAX_COLUMN_COUNT) { increaseColumnCount() - getRecyclerAdapter().actMode?.finish() + getRecyclerAdapter().finishActMode() } } - - override fun selectItem(position: Int) { - getRecyclerAdapter().selectItem(position) - } - - override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) { - getRecyclerAdapter().selectRange(initialSelection, lastDraggedIndex, minReached, maxReached) - } - }*/ + } } private fun setupListLayoutManager() { - //media_grid.isDragSelectionEnabled = true - //media_grid.isZoomingEnabled = false - val layoutManager = media_grid.layoutManager as GridLayoutManager layoutManager.spanCount = 1 layoutManager.orientation = GridLayoutManager.VERTICAL media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + mZoomListener = null } private fun increaseColumnCount() { @@ -572,10 +568,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { }, 1000) } - override fun itemLongClicked(position: Int) { - media_grid.setDragSelectActive(position) - } - override fun selectedPaths(paths: ArrayList) { Intent().apply { putExtra(PICKED_PATHS, paths) 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 8042ff84f..6e1ffed01 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -58,7 +58,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, - val allowMultiplePicks: Boolean, val itemClick: (Medium) -> Unit) : RecyclerView.Adapter() { +class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, + val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { private val config = activity.config - var actMode: ActionMode? = null - var primaryColor = config.primaryColor - - private val multiSelector = MultiSelector() private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST private var skipConfirmationDialog = false - private var itemViews = SparseArray() - private val selectedPositions = HashSet() private var scrollHorizontally = config.scrollHorizontally private var animateGifs = config.animateGifs private var cropThumbnails = config.cropThumbnails - private var textColor = config.textColor private var displayFilenames = config.displayFileNames - fun toggleItemSelection(select: Boolean, pos: Int) { - if (select) { - if (itemViews[pos] != null) { - itemViews[pos].medium_check?.background?.applyColorFilter(primaryColor) - selectedPositions.add(pos) - } - } else { - selectedPositions.remove(pos) - } - - itemViews[pos]?.medium_check?.beVisibleIf(select) - - if (selectedPositions.isEmpty()) { - actMode?.finish() - return - } - - updateTitle(selectedPositions.size) + init { + selectableItemCount = media.count() } - private fun updateTitle(cnt: Int) { - actMode?.title = "$cnt / ${media.size}" - actMode?.invalidate() + override fun getActionMenuId() = R.menu.cab_media + + override fun prepareItemSelection(view: View) { + view.medium_check?.background?.applyColorFilter(primaryColor) } - private val adapterListener = object : MyAdapterListener { - override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { - toggleItemSelection(select, position) - } - - override fun getSelectedPositions(): HashSet = selectedPositions - - override fun itemLongClicked(position: Int) {} + override fun markItemSelection(select: Boolean, view: View?) { + view?.medium_check?.beVisibleIf(select) } - private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { - override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - when (item.itemId) { - R.id.cab_confirm_selection -> confirmSelection() - R.id.cab_properties -> showProperties() - R.id.cab_rename -> renameFile() - R.id.cab_edit -> editFile() - R.id.cab_hide -> toggleFileVisibility(true) - R.id.cab_unhide -> toggleFileVisibility(false) - R.id.cab_share -> shareMedia() - R.id.cab_copy_to -> copyMoveTo(true) - R.id.cab_move_to -> copyMoveTo(false) - R.id.cab_select_all -> selectAll() - R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile()), true) - R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile())) - R.id.cab_delete -> checkDeleteConfirmation() - else -> return false + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { + val layoutType = if (isListViewType) R.layout.photo_video_item_list else R.layout.photo_video_item_grid + val view = activity.layoutInflater.inflate(layoutType, parent, false) + return createViewHolder(view) + } + + override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { + val medium = media[position] + val view = holder.bindView(medium, !allowMultiplePicks) { + setupView(it, medium) + } + itemViews.put(position, view) + toggleItemSelection(selectedPositions.contains(position), position) + holder.itemView.tag = holder + } + + override fun getItemCount() = media.size + + override fun actionItemPressed(id: Int) { + when (id) { + R.id.cab_confirm_selection -> confirmSelection() + R.id.cab_properties -> showProperties() + R.id.cab_rename -> renameFile() + R.id.cab_edit -> editFile() + R.id.cab_hide -> toggleFileVisibility(true) + R.id.cab_unhide -> toggleFileVisibility(false) + R.id.cab_share -> shareMedia() + R.id.cab_copy_to -> copyMoveTo(true) + R.id.cab_move_to -> copyMoveTo(false) + R.id.cab_select_all -> selectAll() + R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile()), true) + R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile())) + R.id.cab_delete -> checkDeleteConfirmation() + } + } + + override fun prepareActionMode(menu: Menu) { + menu.apply { + findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 + findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 + findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 + + checkHideBtnVisibility(this) + } + } + + private fun checkHideBtnVisibility(menu: Menu) { + var hiddenCnt = 0 + var unhiddenCnt = 0 + selectedPositions.mapNotNull { media.getOrNull(it) }.forEach { + if (it.name.startsWith('.')) { + hiddenCnt++ + } else { + unhiddenCnt++ } - return true } - override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean { - super.onCreateActionMode(actionMode, menu) - actMode = actionMode - activity.menuInflater.inflate(R.menu.cab_media, menu) - return true - } - - override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean { - menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 - menu.findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 - menu.findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 - - checkHideBtnVisibility(menu) - - return true - } - - override fun onDestroyActionMode(actionMode: ActionMode?) { - super.onDestroyActionMode(actionMode) - selectedPositions.forEach { - itemViews[it]?.medium_check?.beGone() - } - selectedPositions.clear() - actMode = null - } - - fun checkHideBtnVisibility(menu: Menu) { - var hiddenCnt = 0 - var unhiddenCnt = 0 - selectedPositions.mapNotNull { media.getOrNull(it) }.forEach { - if (it.name.startsWith('.')) { - hiddenCnt++ - } else { - unhiddenCnt++ - } - } - - menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 - menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 - } + menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 + menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 } private fun confirmSelection() { @@ -163,14 +130,14 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList(selectedPositions.size) if (media.size <= selectedPositions.first()) { - actMode?.finish() + finishActMode() return } @@ -269,7 +226,8 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList newItems.put(curIndex, itemViews[i]) } itemViews = newItems - actMode?.finish() + selectableItemCount = media.size + finishActMode() } } @@ -279,29 +237,18 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList) { media = newMedia + selectableItemCount = media.size notifyDataSetChanged() - actMode?.finish() + finishActMode() } fun updateDisplayFilenames(displayFilenames: Boolean) { @@ -324,96 +271,17 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList -1 && min < to) { - (min until to).filter { it != from } - .forEach { toggleItemSelection(false, it) } + if (isListViewType) { + photo_name.setTextColor(textColor) + play_outline.setColorFilter(textColor, PorterDuff.Mode.SRC_IN) } - if (max > -1) { - for (i in from + 1..max) - toggleItemSelection(false, i) - } - } else { - for (i in from..to) - toggleItemSelection(true, i) - - if (max > -1 && max > to) { - (to + 1..max).filter { it != from } - .forEach { toggleItemSelection(false, it) } - } - - if (min > -1) { - for (i in min until from) - toggleItemSelection(false, i) - } - } - } - - class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: BaseSimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, - val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val allowMultiplePicks: Boolean, - val itemClick: (Medium) -> (Unit)) : - SwappingHolder(view, MultiSelector()) { - fun bindView(medium: Medium, displayFilenames: Boolean, scrollHorizontally: Boolean, isListViewType: Boolean, textColor: Int, - animateGifs: Boolean, cropThumbnails: Boolean): View { - itemView.apply { - play_outline.beVisibleIf(medium.video) - photo_name.beVisibleIf(displayFilenames || isListViewType) - photo_name.text = medium.name - activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) - - if (isListViewType) { - photo_name.setTextColor(textColor) - play_outline.setColorFilter(textColor, PorterDuff.Mode.SRC_IN) - } - - setOnClickListener { viewClicked(medium) } - setOnLongClickListener { if (allowMultiplePicks) viewLongClicked() else viewClicked(medium); true } - } - return itemView - } - - private fun viewClicked(medium: Medium) { - if (multiSelector.isSelectable) { - val isSelected = adapterListener.getSelectedPositions().contains(adapterPosition) - adapterListener.toggleItemSelectionAdapter(!isSelected, adapterPosition) - } else { - itemClick(medium) - } - } - - private fun viewLongClicked() { - if (listener != null) { - if (!multiSelector.isSelectable) { - activity.startSupportActionMode(multiSelectorCallback) - adapterListener.toggleItemSelectionAdapter(true, adapterPosition) - } - - listener.itemLongClicked(adapterPosition) - } - } - - fun stopLoad() { - if (!activity.isActivityDestroyed()) - Glide.with(activity).clear(view.medium_thumbnail) } } @@ -422,8 +290,6 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList) - fun itemLongClicked(position: Int) - fun selectedPaths(paths: ArrayList) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 1903462c4..ad579e02c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -58,8 +58,8 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c return shownMedia = media - val adapter = MediaAdapter(activity, media, null, true, false) { - callback(it.path) + val adapter = MediaAdapter(activity, media, null, true, false, view.media_grid) { + callback((it as Medium).path) dialog.dismiss() } From 1afddbc7bbd1527b1e50b03a2ea2340f483b05d2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 14:53:21 +0100 Subject: [PATCH 30/39] update Commons to 2.39.9 --- app/build.gradle | 2 +- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 7 ++----- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 7 ++----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 80fe23f3e..1e3496d73 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.39.8' + compile 'com.simplemobiletools:commons:2.39.9' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.android.support:multidex:1.0.2' 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 6e1ffed01..45ef0b575 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -52,8 +52,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList, override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { val layoutType = if (isListViewType) R.layout.photo_video_item_list else R.layout.photo_video_item_grid - val view = activity.layoutInflater.inflate(layoutType, parent, false) - return createViewHolder(view) + return createViewHolder(layoutType, parent) } override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { @@ -61,9 +60,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val view = holder.bindView(medium, !allowMultiplePicks) { setupView(it, medium) } - itemViews.put(position, view) - toggleItemSelection(selectedPositions.contains(position), position) - holder.itemView.tag = holder + bindViewHolder(holder, position, view) } override fun getItemCount() = media.size From 12e3f615746a0fe2d641b37df4e87bd326b78002 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 14:56:14 +0100 Subject: [PATCH 31/39] catch outofmemory errors at gif loading --- .../kotlin/com/simplemobiletools/gallery/extensions/activity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 143a5a4e4..9910aa225 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -160,6 +160,8 @@ fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER } catch (e: Exception) { loadJpg(path, target, cropThumbnails) + } catch (e: OutOfMemoryError) { + loadJpg(path, target, cropThumbnails) } } } From 73441a021abee8b02d39cdc5a83597029c508a4f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 18:57:04 +0100 Subject: [PATCH 32/39] update Subsampling Scale Image View to 3.8.0 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 1e3496d73..8ab505b18 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ ext { dependencies { compile 'com.simplemobiletools:commons:2.39.9' - compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' + compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.8.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.android.support:multidex:1.0.2' compile 'com.google.code.gson:gson:2.8.2' From 27f00cfe3cd761c27d1828c6fd33c7622de020a3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 19:26:25 +0100 Subject: [PATCH 33/39] improve some double-tap zoom ratios --- .../gallery/activities/ViewPagerActivity.kt | 1 + .../gallery/fragments/PhotoFragment.kt | 11 +++++++++-- .../simplemobiletools/gallery/helpers/GlideDecoder.kt | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) 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 936a06623..7e2f54cb8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -74,6 +74,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View companion object { var screenWidth = 0 var screenHeight = 0 + var wasDecodedByGlide = false } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index c46fbf60e..22005b630 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -221,6 +221,7 @@ class PhotoFragment : ViewPagerFragment() { private fun addZoomableView() { if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.isGone()) { + ViewPagerActivity.wasDecodedByGlide = false view.subsampling_view.apply { setBitmapDecoderClass(GlideDecoder::class.java) maxScale = 10f @@ -233,7 +234,8 @@ class PhotoFragment : ViewPagerFragment() { override fun onReady() { background = ColorDrawable(if (context.config.darkBackground) Color.BLACK else context.config.backgroundColor) - setDoubleTapZoomScale(getDoubleTapZoomScale()) + val zoomScale = if (ViewPagerActivity.wasDecodedByGlide) 1f else getDoubleTapZoomScale() + setDoubleTapZoomScale(zoomScale) } override fun onTileLoadError(e: Exception?) { @@ -264,13 +266,18 @@ class PhotoFragment : ViewPagerFragment() { val height = bitmapOptions.outHeight val bitmapAspectRatio = height / (width).toFloat() - if (context == null) + if (context == null) { return 2f + } return if (context!!.portrait && bitmapAspectRatio <= 1f) { ViewPagerActivity.screenHeight / height.toFloat() + } else if (context!!.portrait && bitmapAspectRatio > 1f) { + ViewPagerActivity.screenHeight / width.toFloat() } else if (!context!!.portrait && bitmapAspectRatio >= 1f) { ViewPagerActivity.screenWidth / width.toFloat() + } else if (!context!!.portrait && bitmapAspectRatio < 1f) { + ViewPagerActivity.screenWidth / height.toFloat() } else { 2f } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt index 78ea3c9dc..55e12722a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt @@ -23,6 +23,7 @@ class GlideDecoder : ImageDecoder { val targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth val targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight + ViewPagerActivity.wasDecodedByGlide = true val options = RequestOptions() .signature(uri.path.getFileSignature()) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) From d596829fd649912e3793d67c21055d860e6b7127 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 22:05:44 +0100 Subject: [PATCH 34/39] rewrite ExcludeFolders activity to use a recyclerview --- app/build.gradle | 2 +- .../activities/ExcludedFoldersActivity.kt | 37 +++----- .../activities/IncludedFoldersActivity.kt | 11 +-- .../gallery/adapters/DirectoryAdapter.kt | 20 ++-- .../adapters/ExcludedFoldersAdapter.kt | 95 +++++++++++++++++++ .../gallery/adapters/MediaAdapter.kt | 20 ++-- .../gallery/helpers/MediaFetcher.kt | 6 +- .../res/layout/activity_excluded_folders.xml | 42 ++++---- .../main/res/layout/item_manage_folder.xml | 21 ++-- 9 files changed, 161 insertions(+), 93 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ExcludedFoldersAdapter.kt diff --git a/app/build.gradle b/app/build.gradle index 8ab505b18..ebbea3a28 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.39.9' + compile 'com.simplemobiletools:commons:2.39.10' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.8.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.android.support:multidex:1.0.2' 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 a37f6d452..b05f8fbcd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt @@ -1,17 +1,17 @@ package com.simplemobiletools.gallery.activities -import android.graphics.PorterDuff import android.os.Bundle import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.adapters.ExcludedFoldersAdapter import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.activity_excluded_folders.* -import kotlinx.android.synthetic.main.item_manage_folder.view.* -class ExcludedFoldersActivity : SimpleActivity() { +class ExcludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_excluded_folders) @@ -19,27 +19,14 @@ class ExcludedFoldersActivity : SimpleActivity() { } private fun updateExcludedFolders() { - excluded_folders_holder.removeAllViews() - val folders = config.excludedFolders - excluded_folders_placeholder.beVisibleIf(folders.isEmpty()) - excluded_folders_placeholder.setTextColor(config.textColor) + val folders = ArrayList() + config.excludedFolders.mapTo(folders, { it }) + manage_excluded_folders_placeholder.beVisibleIf(folders.isEmpty()) + manage_excluded_folders_placeholder.setTextColor(config.textColor) - for (folder in folders) { - layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply { - managed_folder_title.apply { - text = folder - setTextColor(config.textColor) - } - managed_folders_icon.apply { - setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN) - setOnClickListener { - config.removeExcludedFolder(folder) - updateExcludedFolders() - } - } - excluded_folders_holder.addView(this) - } - } + val adapter = ExcludedFoldersAdapter(this, folders, this, manage_exclude_folders_list) {} + adapter.setupDragListener(true) + manage_exclude_folders_list.adapter = adapter } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -55,6 +42,10 @@ class ExcludedFoldersActivity : SimpleActivity() { return true } + override fun refreshItems() { + updateExcludedFolders() + } + private fun addExcludedFolder() { FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { config.addExcludedFolder(it) 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 c6ccb0437..2ddc9aaa7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.gallery.activities -import android.graphics.PorterDuff import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -27,18 +26,10 @@ class IncludedFoldersActivity : SimpleActivity() { for (folder in folders) { layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply { - managed_folder_title.apply { + manage_folder_title.apply { text = folder setTextColor(config.textColor) } - managed_folders_icon.apply { - setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN) - setOnClickListener { - config.removeIncludedFolder(folder) - updateIncludedFolders() - } - } - included_folders_holder.addView(this) } } } 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 45ef0b575..74a25b4a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -65,6 +65,16 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList showProperties() @@ -83,16 +93,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList, val listener: RefreshRecyclerViewListener?, recyclerView: MyRecyclerView, + itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { + + private val config = activity.config + + init { + selectableItemCount = folders.size + } + + override fun getActionMenuId() = R.menu.cab_delete_only + + override fun prepareActionMode(menu: Menu) {} + + override fun prepareItemSelection(view: View) {} + + override fun markItemSelection(select: Boolean, view: View?) { + view?.manage_folder_holder?.isSelected = select + } + + override fun actionItemPressed(id: Int) { + when (id) { + R.id.cab_delete -> askConfirmDelete() + } + } + + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int) = createViewHolder(R.layout.item_manage_folder, parent) + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val folder = folders[position] + val view = holder.bindView(folder) { + setupView(it, folder) + } + bindViewHolder(holder, position, view) + } + + override fun getItemCount() = folders.size + + private fun setupView(view: View, folder: String) { + view.apply { + manage_folder_title.apply { + text = folder + setTextColor(config.textColor) + } + } + } + + private fun askConfirmDelete() { + ConfirmationDialog(activity) { + deleteSelection() + } + } + + private fun deleteSelection() { + val removeFolders = ArrayList(selectedPositions.size) + + selectedPositions.sortedDescending().forEach { + val folder = folders[it] + removeFolders.add(folder) + notifyItemRemoved(it) + itemViews.put(it, null) + config.removeExcludedFolder(folder) + } + + folders.removeAll(removeFolders) + selectedPositions.clear() + + val newItems = SparseArray() + (0 until itemViews.size()) + .filter { itemViews[it] != null } + .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } + + itemViews = newItems + selectableItemCount = folders.size + finishActMode() + if (folders.isEmpty()) { + listener?.refreshItems() + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 25839994a..c1a4a2c1d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -65,6 +65,16 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, override fun getItemCount() = media.size + override fun prepareActionMode(menu: Menu) { + menu.apply { + findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 + findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 + findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 + + checkHideBtnVisibility(this) + } + } + override fun actionItemPressed(id: Int) { when (id) { R.id.cab_confirm_selection -> confirmSelection() @@ -83,16 +93,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - override fun prepareActionMode(menu: Menu) { - menu.apply { - findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 - findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 - findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 - - checkHideBtnVisibility(this) - } - } - private fun checkHideBtnVisibility(menu: Menu) { var hiddenCnt = 0 var unhiddenCnt = 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 33e1fa98c..cce57aa36 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -247,7 +247,6 @@ class MediaFetcher(val context: Context) { private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet, includedPaths: MutableSet) = includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) } - private fun getMediaInFolder(folder: String, curMedia: ArrayList, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) { val files = File(folder).listFiles() ?: return for (file in files) { @@ -296,10 +295,11 @@ class MediaFetcher(val context: Context) { else -> MediaStore.Images.Media.DATE_TAKEN } - return if (sorting and SORT_DESCENDING > 0) + return if (sorting and SORT_DESCENDING > 0) { "$sortValue DESC" - else + } else { "$sortValue ASC" + } } private fun getNoMediaFolders(): ArrayList { diff --git a/app/src/main/res/layout/activity_excluded_folders.xml b/app/src/main/res/layout/activity_excluded_folders.xml index 64df37244..62e36ecb6 100644 --- a/app/src/main/res/layout/activity_excluded_folders.xml +++ b/app/src/main/res/layout/activity_excluded_folders.xml @@ -1,30 +1,28 @@ - - + android:layout_height="match_parent" + android:clipToPadding="false" + app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> - + - - - + diff --git a/app/src/main/res/layout/item_manage_folder.xml b/app/src/main/res/layout/item_manage_folder.xml index ac706585a..594e3a45b 100644 --- a/app/src/main/res/layout/item_manage_folder.xml +++ b/app/src/main/res/layout/item_manage_folder.xml @@ -1,29 +1,22 @@ - - + android:layout_marginTop="@dimen/medium_margin"/> From 69bc80fa4e8eab3f4bdf437d2c430da3cd10b747 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 22:15:33 +0100 Subject: [PATCH 35/39] rewriting the Included Folders to recyclerview too --- .../activities/ExcludedFoldersActivity.kt | 15 +++++---- .../activities/IncludedFoldersActivity.kt | 33 ++++++++++--------- ...dersAdapter.kt => ManageFoldersAdapter.kt} | 10 ++++-- .../res/layout/activity_included_folders.xml | 30 ----------------- ...olders.xml => activity_manage_folders.xml} | 9 +++-- 5 files changed, 36 insertions(+), 61 deletions(-) rename app/src/main/kotlin/com/simplemobiletools/gallery/adapters/{ExcludedFoldersAdapter.kt => ManageFoldersAdapter.kt} (84%) delete mode 100644 app/src/main/res/layout/activity_included_folders.xml rename app/src/main/res/layout/{activity_excluded_folders.xml => activity_manage_folders.xml} (75%) 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 b05f8fbcd..0b1c722cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt @@ -7,26 +7,27 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.adapters.ExcludedFoldersAdapter +import com.simplemobiletools.gallery.adapters.ManageFoldersAdapter import com.simplemobiletools.gallery.extensions.config -import kotlinx.android.synthetic.main.activity_excluded_folders.* +import kotlinx.android.synthetic.main.activity_manage_folders.* class ExcludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_excluded_folders) + setContentView(R.layout.activity_manage_folders) updateExcludedFolders() } private fun updateExcludedFolders() { val folders = ArrayList() config.excludedFolders.mapTo(folders, { it }) - manage_excluded_folders_placeholder.beVisibleIf(folders.isEmpty()) - manage_excluded_folders_placeholder.setTextColor(config.textColor) + manage_folders_placeholder.text = getString(R.string.excluded_activity_placeholder) + manage_folders_placeholder.beVisibleIf(folders.isEmpty()) + manage_folders_placeholder.setTextColor(config.textColor) - val adapter = ExcludedFoldersAdapter(this, folders, this, manage_exclude_folders_list) {} + val adapter = ManageFoldersAdapter(this, folders, true, this, manage_folders_list) {} adapter.setupDragListener(true) - manage_exclude_folders_list.adapter = adapter + manage_folders_list.adapter = adapter } override fun onCreateOptionsMenu(menu: Menu?): Boolean { 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 2ddc9aaa7..3f4067312 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt @@ -6,32 +6,29 @@ import android.view.MenuItem import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.scanPath +import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.adapters.ManageFoldersAdapter import com.simplemobiletools.gallery.extensions.config -import kotlinx.android.synthetic.main.activity_included_folders.* -import kotlinx.android.synthetic.main.item_manage_folder.view.* +import kotlinx.android.synthetic.main.activity_manage_folders.* -class IncludedFoldersActivity : SimpleActivity() { +class IncludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_included_folders) + setContentView(R.layout.activity_manage_folders) updateIncludedFolders() } private fun updateIncludedFolders() { - included_folders_holder.removeAllViews() - val folders = config.includedFolders - included_folders_placeholder.beVisibleIf(folders.isEmpty()) - included_folders_placeholder.setTextColor(config.textColor) + val folders = ArrayList() + config.includedFolders.mapTo(folders, { it }) + manage_folders_placeholder.text = getString(R.string.included_activity_placeholder) + manage_folders_placeholder.beVisibleIf(folders.isEmpty()) + manage_folders_placeholder.setTextColor(config.textColor) - for (folder in folders) { - layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply { - manage_folder_title.apply { - text = folder - setTextColor(config.textColor) - } - } - } + val adapter = ManageFoldersAdapter(this, folders, false, this, manage_folders_list) {} + adapter.setupDragListener(true) + manage_folders_list.adapter = adapter } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -47,6 +44,10 @@ class IncludedFoldersActivity : SimpleActivity() { return true } + override fun refreshItems() { + updateIncludedFolders() + } + private fun addIncludedFolder() { FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { config.addIncludedFolder(it) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ExcludedFoldersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt similarity index 84% rename from app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ExcludedFoldersAdapter.kt rename to app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt index 99b4ea001..675490a0c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ExcludedFoldersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageFoldersAdapter.kt @@ -14,8 +14,8 @@ import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.item_manage_folder.view.* import java.util.* -class ExcludedFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList, val listener: RefreshRecyclerViewListener?, recyclerView: MyRecyclerView, - itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { +class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList, val isShowingExcludedFolders: Boolean, val listener: RefreshRecyclerViewListener?, + recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { private val config = activity.config @@ -74,7 +74,11 @@ class ExcludedFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayLis removeFolders.add(folder) notifyItemRemoved(it) itemViews.put(it, null) - config.removeExcludedFolder(folder) + if (isShowingExcludedFolders) { + config.removeExcludedFolder(folder) + } else { + config.removeIncludedFolder(folder) + } } folders.removeAll(removeFolders) diff --git a/app/src/main/res/layout/activity_included_folders.xml b/app/src/main/res/layout/activity_included_folders.xml deleted file mode 100644 index 527cdd94a..000000000 --- a/app/src/main/res/layout/activity_included_folders.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_excluded_folders.xml b/app/src/main/res/layout/activity_manage_folders.xml similarity index 75% rename from app/src/main/res/layout/activity_excluded_folders.xml rename to app/src/main/res/layout/activity_manage_folders.xml index 62e36ecb6..aaac86a7f 100644 --- a/app/src/main/res/layout/activity_excluded_folders.xml +++ b/app/src/main/res/layout/activity_manage_folders.xml @@ -1,21 +1,20 @@ Date: Thu, 16 Nov 2017 23:02:49 +0100 Subject: [PATCH 36/39] make it easier to keep the device in landscape mode --- .../simplemobiletools/gallery/activities/ViewPagerActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 7e2f54cb8..1c00f66a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -228,8 +228,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mOrientationEventListener = object : OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { override fun onOrientationChanged(orientation: Int) { val currOrient = when (orientation) { - in 60..134 -> ORIENT_LANDSCAPE_RIGHT - in 225..299 -> ORIENT_LANDSCAPE_LEFT + in 75..134 -> ORIENT_LANDSCAPE_RIGHT + in 225..285 -> ORIENT_LANDSCAPE_LEFT else -> ORIENT_PORTRAIT } From a3c680fc736a56e23a430723fa313e8329c024fe Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 23:37:14 +0100 Subject: [PATCH 37/39] improve some double-tap zoom handling --- .../gallery/fragments/PhotoFragment.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 22005b630..323731665 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -37,6 +37,7 @@ import java.io.File import java.io.FileOutputStream class PhotoFragment : ViewPagerFragment() { + private var DEFAULT_DOUBLE_TAP_ZOOM = 5f private var isFragmentVisible = false private var isFullscreen = false private var wasInit = false @@ -234,8 +235,7 @@ class PhotoFragment : ViewPagerFragment() { override fun onReady() { background = ColorDrawable(if (context.config.darkBackground) Color.BLACK else context.config.backgroundColor) - val zoomScale = if (ViewPagerActivity.wasDecodedByGlide) 1f else getDoubleTapZoomScale() - setDoubleTapZoomScale(zoomScale) + setDoubleTapZoomScale(getDoubleTapZoomScale()) } override fun onTileLoadError(e: Exception?) { @@ -266,11 +266,13 @@ class PhotoFragment : ViewPagerFragment() { val height = bitmapOptions.outHeight val bitmapAspectRatio = height / (width).toFloat() - if (context == null) { - return 2f - } - - return if (context!!.portrait && bitmapAspectRatio <= 1f) { + return if (context == null) { + DEFAULT_DOUBLE_TAP_ZOOM + } else if (ViewPagerActivity.screenHeight / ViewPagerActivity.screenWidth.toFloat() == bitmapAspectRatio) { + DEFAULT_DOUBLE_TAP_ZOOM + } else if (ViewPagerActivity.wasDecodedByGlide) { + 1f + } else if (context!!.portrait && bitmapAspectRatio <= 1f) { ViewPagerActivity.screenHeight / height.toFloat() } else if (context!!.portrait && bitmapAspectRatio > 1f) { ViewPagerActivity.screenHeight / width.toFloat() @@ -279,7 +281,7 @@ class PhotoFragment : ViewPagerFragment() { } else if (!context!!.portrait && bitmapAspectRatio < 1f) { ViewPagerActivity.screenWidth / height.toFloat() } else { - 2f + DEFAULT_DOUBLE_TAP_ZOOM } } From e62f75e28d6b384fbde648d6e2d2e6597813f24c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 23:53:10 +0100 Subject: [PATCH 38/39] update version to 2.18.1 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ebbea3a28..38604d2c2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 143 - versionName "2.18.0" + versionCode 144 + versionName "2.18.1" multiDexEnabled true setProperty("archivesBaseName", "gallery") } From 8b5f4369c56072f8b303de5f87183665f7a19081 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 23:53:16 +0100 Subject: [PATCH 39/39] updating changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73bf0516e..6e90ef9f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========== +Version 2.18.1 *(2017-11-16)* +---------------------------- + + * Fixed some double-tap zoom issues + * Misc smaller fixes and improvements here and there + Version 2.18.0 *(2017-11-09)* ----------------------------