couple changes related to toggling fullscreen

This commit is contained in:
tibbi 2017-06-28 21:56:36 +02:00
parent bb81275b79
commit d3d64865af
6 changed files with 35 additions and 34 deletions

View file

@ -98,6 +98,11 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
} finally { } finally {
cursor?.close() cursor?.close()
} }
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
val isFullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
mFragment.fullscreenToggled(isFullscreen)
}
} }
override fun onResume() { override fun onResume() {
@ -157,13 +162,4 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
showSystemUI() showSystemUI()
} }
} }
override fun systemUiVisibilityChanged(visibility: Int) {
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
mIsFullScreen = false
showSystemUI()
} else {
mIsFullScreen = true
}
}
} }

View file

@ -112,6 +112,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (config.hideSystemUI) if (config.hideSystemUI)
fragmentClicked() 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() { override fun onDestroy() {
@ -445,6 +453,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
override fun fragmentClicked() { override fun fragmentClicked() {
mIsFullScreen = !mIsFullScreen mIsFullScreen = !mIsFullScreen
checkSystemUI()
}
private fun checkSystemUI() {
if (mIsFullScreen) { if (mIsFullScreen) {
hideSystemUI() hideSystemUI()
} else { } 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() { private fun updateActionbarTitle() {
runOnUiThread { runOnUiThread {
if (mPos < mMedia.size) { if (mPos < mMedia.size) {

View file

@ -5,7 +5,6 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v4.view.PagerAdapter import android.support.v4.view.PagerAdapter
import android.util.SparseArray
import android.view.ViewGroup import android.view.ViewGroup
import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.fragments.PhotoFragment import com.simplemobiletools.gallery.fragments.PhotoFragment
@ -15,7 +14,7 @@ import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList<Medium>) : FragmentStatePagerAdapter(fm) { class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList<Medium>) : FragmentStatePagerAdapter(fm) {
private val mFragments = SparseArray<ViewPagerFragment>() private val mFragments = HashMap<Int, ViewPagerFragment>()
override fun getCount() = media.size override fun getCount() = media.size
override fun getItem(position: Int): Fragment { 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 getCurrentFragment(position: Int) = mFragments.get(position)
fun toggleFullscreen(isFullscreen: Boolean) {
for ((pos, fragment) in mFragments) {
fragment.fullscreenToggled(isFullscreen)
}
}
} }

View file

@ -42,7 +42,6 @@ class PhotoFragment : ViewPagerFragment() {
lateinit var view: ViewGroup lateinit var view: ViewGroup
private var isFragmentVisible = false private var isFragmentVisible = false
private var wasInit = false private var wasInit = false
private var RATIO_THRESHOLD = 0.1
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
view = inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup view = inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup
@ -100,9 +99,6 @@ class PhotoFragment : ViewPagerFragment() {
} }
loadImage() loadImage()
activity.window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
listener?.systemUiVisibilityChanged(visibility)
}
wasInit = true wasInit = true
return view return view
@ -256,4 +252,8 @@ class PhotoFragment : ViewPagerFragment() {
private fun photoClicked() { private fun photoClicked() {
listener?.fragmentClicked() listener?.fragmentClicked()
} }
override fun fullscreenToggled(isFullscreen: Boolean) {
}
} }

View file

@ -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 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() checkFullscreen()
return mView return mView
@ -114,8 +108,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
} }
private fun toggleFullscreen() { private fun toggleFullscreen() {
mIsFullscreen = !mIsFullscreen
checkFullscreen()
listener?.fragmentClicked() listener?.fragmentClicked()
} }
@ -372,4 +364,9 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
mIsDragged = false mIsDragged = false
} }
override fun fullscreenToggled(isFullscreen: Boolean) {
mIsFullscreen = isFullscreen
checkFullscreen()
}
} }

View file

@ -5,9 +5,9 @@ import android.support.v4.app.Fragment
abstract class ViewPagerFragment : Fragment() { abstract class ViewPagerFragment : Fragment() {
var listener: FragmentListener? = null var listener: FragmentListener? = null
abstract fun fullscreenToggled(isFullscreen: Boolean)
interface FragmentListener { interface FragmentListener {
fun fragmentClicked() fun fragmentClicked()
fun systemUiVisibilityChanged(visibility: Int)
} }
} }