diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 546f1c5e7..b65e42f98 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -93,6 +93,7 @@
()
private var mPath = ""
private var mDirectory = ""
@@ -77,7 +76,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
mDirectory = File(mPath).parent
title = mPath.getFilenameFromPath()
- window.decorView.setOnSystemUiVisibilityChangeListener(this)
reloadViewPager()
scanPath(mPath) {}
}
@@ -114,12 +112,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return true
}
- override fun onConfigurationChanged(newConfig: Configuration) {
- super.onConfigurationChanged(newConfig)
- val adapter = view_pager.adapter as MyPagerAdapter
- adapter.updateItems(mPos)
- }
-
private fun updatePagerItems() {
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, mMedia)
view_pager.apply {
@@ -260,6 +252,15 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
}
+ override fun systemUiVisibilityChanged(visibility: Int) {
+ if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
+ mIsFullScreen = false
+ showSystemUI()
+ } else {
+ mIsFullScreen = true
+ }
+ }
+
private fun updateActionbarTitle() {
runOnUiThread {
title = mMedia[mPos].path.getFilenameFromPath()
@@ -286,20 +287,5 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
override fun onPageScrollStateChanged(state: Int) {
- if (state == ViewPager.SCROLL_STATE_DRAGGING) {
- val adapter = view_pager.adapter as MyPagerAdapter
- adapter.itemDragged(mPos)
- }
- }
-
- override fun onSystemUiVisibilityChange(visibility: Int) {
- view_pager.adapter?.apply {
- if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
- mIsFullScreen = false
- showSystemUI()
- }
-
- (this as MyPagerAdapter).updateUiVisibility(mIsFullScreen, mPos)
- }
}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt
index dc46c5d8c..7f6f1c179 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt
@@ -5,7 +5,6 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v4.view.PagerAdapter
-import android.util.SparseArray
import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.fragments.PhotoFragment
import com.simplemobiletools.gallery.fragments.VideoFragment
@@ -14,8 +13,6 @@ import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium
class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList) : FragmentStatePagerAdapter(fm) {
- private val mFragments: SparseArray = SparseArray()
-
override fun getCount() = media.size
override fun getItem(position: Int): Fragment {
@@ -30,25 +27,10 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m
fragment = PhotoFragment()
}
- mFragments.put(position, fragment)
fragment.arguments = bundle
fragment.listener = activity
return fragment
}
override fun getItemPosition(item: Any?) = PagerAdapter.POSITION_NONE
-
- fun itemDragged(pos: Int) {
- mFragments[pos]?.itemDragged()
- }
-
- fun updateUiVisibility(isFullscreen: Boolean, pos: Int) {
- (-1..1).map { mFragments[pos + it] }
- .forEach { it?.systemUiVisibilityChanged(isFullscreen) }
- }
-
- fun updateItems(pos: Int) {
- (-1..1).map { mFragments[pos + it] }
- .forEach { it?.updateItem() }
- }
}
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 d6386c5a4..b7be1490b 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt
@@ -1,12 +1,17 @@
package com.simplemobiletools.gallery.fragments
+import android.content.res.Configuration
+import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
+import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
+import com.bumptech.glide.request.RequestListener
+import com.bumptech.glide.request.target.Target
import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.simplemobiletools.gallery.R
@@ -15,82 +20,90 @@ import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.pager_photo_item.view.*
-class PhotoFragment : ViewPagerFragment(), View.OnClickListener {
- lateinit var subsamplingView: SubsamplingScaleImageView
+class PhotoFragment : ViewPagerFragment() {
lateinit var medium: Medium
+ lateinit var mView: View
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
- val view = inflater.inflate(R.layout.pager_photo_item, container, false)
+ mView = inflater.inflate(R.layout.pager_photo_item, container, false)
medium = arguments.getSerializable(MEDIUM) as Medium
if (medium.path.startsWith("content://"))
medium.path = context.getRealPathFromURI(Uri.parse(medium.path)) ?: ""
- subsamplingView = view.photo_view
- if (medium.isGif()) {
- subsamplingView.visibility = View.GONE
- view.glide_view.apply {
- visibility = View.VISIBLE
- Glide.with(context).load(medium.path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).into(this)
- setOnClickListener(this@PhotoFragment)
- }
- } else {
- subsamplingView.apply {
- setDoubleTapZoomScale(1.2f)
- orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF
- setImage(ImageSource.uri(medium.path))
- maxScale = 4f
- setMinimumTileDpi(100)
- setOnClickListener(this@PhotoFragment)
- setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener {
- override fun onImageLoaded() {
- }
+ loadImage(medium)
- override fun onReady() {
- }
-
- override fun onTileLoadError(p0: Exception?) {
- }
-
- override fun onPreviewReleased() {
- }
-
- override fun onImageLoadError(p0: Exception?) {
- subsamplingView.visibility = View.GONE
- view.glide_view.apply {
- visibility = View.VISIBLE
- Glide.with(context).load(medium.path).diskCacheStrategy(DiskCacheStrategy.NONE).into(this)
- setOnClickListener(this@PhotoFragment)
- }
- }
-
- override fun onPreviewLoadError(p0: Exception?) {
- }
- })
- }
+ activity.window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
+ listener?.systemUiVisibilityChanged(visibility)
}
- return view
+ return mView
}
- override fun itemDragged() {
+ private fun loadImage(medium: Medium) {
+ val subsamplingView = mView.photo_view.apply { setOnClickListener({ photoClicked() }) }
+ val glideView = mView.glide_view.apply { setOnClickListener({ photoClicked() }) }
+
+ if (medium.isGif()) {
+ Glide.with(this)
+ .load(medium.path)
+ .asGif()
+ .diskCacheStrategy(DiskCacheStrategy.NONE)
+ .into(glideView)
+ } else {
+ Glide.with(this)
+ .load(medium.path)
+ .asBitmap()
+ .format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565)
+ .diskCacheStrategy(DiskCacheStrategy.NONE)
+ .listener(object : RequestListener {
+ override fun onException(e: Exception?, model: String?, target: Target?, isFirstResource: Boolean): Boolean {
+ return false
+ }
+
+ override fun onResourceReady(resource: Bitmap?, model: String?, target: Target?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean {
+ if (!medium.isPng()) {
+ subsamplingView.visibility = View.VISIBLE
+ subsamplingView.apply {
+ setDoubleTapZoomScale(1.2f)
+ setImage(ImageSource.uri(medium.path))
+ orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF
+ maxScale = 5f
+ setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener {
+ override fun onImageLoaded() {
+ }
+
+ override fun onReady() {
+ glideView.visibility = View.GONE
+ subsamplingView.visibility = View.VISIBLE
+ }
+
+ override fun onTileLoadError(p0: Exception?) {
+ }
+
+ override fun onPreviewReleased() {
+ }
+
+ override fun onImageLoadError(p0: Exception?) {
+ }
+
+ override fun onPreviewLoadError(p0: Exception?) {
+ }
+ })
+ }
+ }
+ return false
+ }
+ }).into(glideView)
+ }
}
- override fun systemUiVisibilityChanged(toFullscreen: Boolean) {
- }
-
- override fun updateItem() {
- subsamplingView.setImage(ImageSource.uri(medium.path))
- }
-
- override fun onClick(v: View) {
- photoClicked()
+ override fun onConfigurationChanged(newConfig: Configuration?) {
+ super.onConfigurationChanged(newConfig)
+ loadImage(medium)
}
private fun photoClicked() {
- if (listener == null)
- listener = activity as ViewPagerFragment.FragmentClickListener
-
listener?.fragmentClicked()
}
}
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 19986d0d7..e6c0a4f57 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt
@@ -5,6 +5,7 @@ import android.media.AudioManager
import android.media.MediaPlayer
import android.media.MediaPlayer.OnPreparedListener
import android.net.Uri
+import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.util.DisplayMetrics
@@ -61,6 +62,13 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C
setupPlayer()
mView.setOnClickListener(this)
+ activity.window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
+ val fullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
+ mIsFullscreen = fullscreen
+ checkFullscreen()
+ listener?.systemUiVisibilityChanged(visibility)
+ }
+
return mView
}
@@ -85,21 +93,14 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C
if (context != null && Config.newInstance(context).autoplayVideos) {
playVideo()
}
+ } else {
+ if (mIsPlaying)
+ pauseVideo()
}
}
- override fun itemDragged() {
- pauseVideo()
- }
-
- override fun systemUiVisibilityChanged(toFullscreen: Boolean) {
- if (mIsFullscreen != toFullscreen) {
- mIsFullscreen = toFullscreen
- checkFullscreen()
- }
- }
-
- override fun updateItem() {
+ override fun onConfigurationChanged(newConfig: Configuration?) {
+ super.onConfigurationChanged(newConfig)
setVideoSize()
initTimeHolder()
}
@@ -162,10 +163,6 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C
else -> {
mIsFullscreen = !mIsFullscreen
checkFullscreen()
-
- if (listener == null)
- listener = activity as ViewPagerFragment.FragmentClickListener
-
listener?.fragmentClicked()
}
}
@@ -302,7 +299,7 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C
val screenWidth: Int
val screenHeight: Int
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val realMetrics = DisplayMetrics()
display.getRealMetrics(realMetrics)
screenWidth = realMetrics.widthPixels
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt
index 0fcdd8607..bd6bc4a50 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt
@@ -3,15 +3,11 @@ package com.simplemobiletools.gallery.fragments
import android.support.v4.app.Fragment
abstract class ViewPagerFragment : Fragment() {
- var listener: FragmentClickListener? = null
+ var listener: FragmentListener? = null
- abstract fun itemDragged()
-
- abstract fun systemUiVisibilityChanged(toFullscreen: Boolean)
-
- abstract fun updateItem()
-
- interface FragmentClickListener {
+ interface FragmentListener {
fun fragmentClicked()
+
+ fun systemUiVisibilityChanged(visibility: Int)
}
}
diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml
index 463630ace..94eb1e06a 100644
--- a/app/src/main/res/layout/pager_photo_item.xml
+++ b/app/src/main/res/layout/pager_photo_item.xml
@@ -5,13 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
-
-