From d3d64865af227016f92f40c0bb62bb4a83cc34aa Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 28 Jun 2017 21:56:36 +0200 Subject: [PATCH] couple changes related to toggling fullscreen --- .../gallery/activities/PhotoVideoActivity.kt | 14 +++++-------- .../gallery/activities/ViewPagerActivity.kt | 21 +++++++++++-------- .../gallery/adapters/MyPagerAdapter.kt | 9 ++++++-- .../gallery/fragments/PhotoFragment.kt | 8 +++---- .../gallery/fragments/VideoFragment.kt | 13 +++++------- .../gallery/fragments/ViewPagerFragment.kt | 4 ++-- 6 files changed, 35 insertions(+), 34 deletions(-) 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 0aa50ac78..defe41a5f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -98,6 +98,11 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList } finally { cursor?.close() } + + window.decorView.setOnSystemUiVisibilityChangeListener { visibility -> + val isFullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0 + mFragment.fullscreenToggled(isFullscreen) + } } override fun onResume() { @@ -157,13 +162,4 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList showSystemUI() } } - - override fun systemUiVisibilityChanged(visibility: Int) { - if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) { - mIsFullScreen = false - showSystemUI() - } else { - mIsFullScreen = true - } - } } 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 cba51a109..0023d8a99 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -112,6 +112,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (config.hideSystemUI) fragmentClicked() + + window.decorView.setOnSystemUiVisibilityChangeListener { visibility -> + mIsFullScreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0 + view_pager.adapter?.let { + (it as MyPagerAdapter).toggleFullscreen(mIsFullScreen) + checkSystemUI() + } + } } override fun onDestroy() { @@ -445,6 +453,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View override fun fragmentClicked() { mIsFullScreen = !mIsFullScreen + checkSystemUI() + } + + private fun checkSystemUI() { if (mIsFullScreen) { hideSystemUI() } else { @@ -452,15 +464,6 @@ 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 { if (mPos < mMedia.size) { 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 fbd05d975..b1d72481b 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 android.view.ViewGroup import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.fragments.PhotoFragment @@ -15,7 +14,7 @@ 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() + private val mFragments = HashMap() override fun getCount() = media.size override fun getItem(position: Int): Fragment { @@ -49,4 +48,10 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m } fun getCurrentFragment(position: Int) = mFragments.get(position) + + fun toggleFullscreen(isFullscreen: Boolean) { + for ((pos, fragment) in mFragments) { + fragment.fullscreenToggled(isFullscreen) + } + } } 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 dfccd0d2c..d5747ad86 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -42,7 +42,6 @@ class PhotoFragment : ViewPagerFragment() { lateinit var view: ViewGroup private var isFragmentVisible = false private var wasInit = false - private var RATIO_THRESHOLD = 0.1 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { view = inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup @@ -100,9 +99,6 @@ class PhotoFragment : ViewPagerFragment() { } loadImage() - activity.window.decorView.setOnSystemUiVisibilityChangeListener { visibility -> - listener?.systemUiVisibilityChanged(visibility) - } wasInit = true return view @@ -256,4 +252,8 @@ class PhotoFragment : ViewPagerFragment() { private fun photoClicked() { listener?.fragmentClicked() } + + override fun fullscreenToggled(isFullscreen: Boolean) { + + } } 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 6c2fd1776..70815d787 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -60,12 +60,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee } mIsFullscreen = activity.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN - - activity.window.decorView.setOnSystemUiVisibilityChangeListener { visibility -> - mIsFullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0 - checkFullscreen() - listener?.systemUiVisibilityChanged(visibility) - } checkFullscreen() return mView @@ -114,8 +108,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee } private fun toggleFullscreen() { - mIsFullscreen = !mIsFullscreen - checkFullscreen() listener?.fragmentClicked() } @@ -372,4 +364,9 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee mIsDragged = false } + + override fun fullscreenToggled(isFullscreen: Boolean) { + mIsFullscreen = isFullscreen + checkFullscreen() + } } 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 bd6bc4a50..c8f443502 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt @@ -5,9 +5,9 @@ import android.support.v4.app.Fragment abstract class ViewPagerFragment : Fragment() { var listener: FragmentListener? = null + abstract fun fullscreenToggled(isFullscreen: Boolean) + interface FragmentListener { fun fragmentClicked() - - fun systemUiVisibilityChanged(visibility: Int) } }