Merge pull request #2617 from Naveen3Singh/slideshow

Fix position issues related to random slideshow
This commit is contained in:
Tibor Kaputa 2022-10-03 17:14:11 +02:00 committed by GitHub
commit 527457c000
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 66 deletions

View file

@ -294,7 +294,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
if (mCurrentPathPrefix.isEmpty()) { if (mCurrentPathPrefix.isEmpty()) {
super.onBackPressed() super.onBackPressed()
} else { } else {
mOpenedSubfolders.removeAt(mOpenedSubfolders.size - 1) mOpenedSubfolders.removeLast()
mCurrentPathPrefix = mOpenedSubfolders.last() mCurrentPathPrefix = mOpenedSubfolders.last()
setupAdapter(mDirs) setupAdapter(mDirs)
} }

View file

@ -80,6 +80,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private var mSlideshowMoveBackwards = false private var mSlideshowMoveBackwards = false
private var mSlideshowMedia = mutableListOf<Medium>() private var mSlideshowMedia = mutableListOf<Medium>()
private var mAreSlideShowMediaVisible = false private var mAreSlideShowMediaVisible = false
private var mRandomSlideshowStopped = false
private var mIsOrientationLocked = false private var mIsOrientationLocked = false
@ -505,6 +506,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
hideSystemUI(true) hideSystemUI(true)
mRandomSlideshowStopped = false
mSlideshowInterval = config.slideshowInterval mSlideshowInterval = config.slideshowInterval
mSlideshowMoveBackwards = config.slideshowMoveBackwards mSlideshowMoveBackwards = config.slideshowMoveBackwards
mIsSlideshowActive = true mIsSlideshowActive = true
@ -600,6 +602,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
mSlideshowHandler.removeCallbacksAndMessages(null) mSlideshowHandler.removeCallbacksAndMessages(null)
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
mAreSlideShowMediaVisible = false mAreSlideShowMediaVisible = false
if (config.slideshowRandomOrder) {
mRandomSlideshowStopped = true
}
} }
} }
@ -1279,7 +1285,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (refetchViewPagerPosition || mPos == -1) { if (refetchViewPagerPosition || mPos == -1) {
mPos = getPositionInList(media) mPos = getPositionInList(media)
if (mPos == -1) { if (mPos == -1) {
min(mPos, media.size - 1) min(mPos, media.lastIndex)
} }
} }
@ -1384,7 +1390,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
putExtra(IS_FROM_GALLERY, true) putExtra(IS_FROM_GALLERY, true)
putExtra(REAL_FILE_PATH, path) putExtra(REAL_FILE_PATH, path)
putExtra(SHOW_PREV_ITEM, view_pager.currentItem != 0) putExtra(SHOW_PREV_ITEM, view_pager.currentItem != 0)
putExtra(SHOW_NEXT_ITEM, view_pager.currentItem != mMediaFiles.size - 1) putExtra(SHOW_NEXT_ITEM, view_pager.currentItem != mMediaFiles.lastIndex)
try { try {
startActivityForResult(this, REQUEST_VIEW_VIDEO) startActivityForResult(this, REQUEST_VIEW_VIDEO)
@ -1429,8 +1435,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun updateActionbarTitle() { private fun updateActionbarTitle() {
runOnUiThread { runOnUiThread {
if (mPos < getCurrentMedia().size) { val medium = getCurrentMedium()
medium_viewer_toolbar.title = getCurrentMedia()[mPos].path.getFilenameFromPath() if (medium != null) {
medium_viewer_toolbar.title = medium.path.getFilenameFromPath()
} }
} }
} }
@ -1439,11 +1446,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return if (getCurrentMedia().isEmpty() || mPos == -1) { return if (getCurrentMedia().isEmpty() || mPos == -1) {
null null
} else { } else {
getCurrentMedia()[min(mPos, getCurrentMedia().size - 1)] getCurrentMedia()[min(mPos, getCurrentMedia().lastIndex)]
} }
} }
private fun getCurrentMedia() = if (mAreSlideShowMediaVisible) mSlideshowMedia else mMediaFiles private fun getCurrentMedia() = if (mAreSlideShowMediaVisible || mRandomSlideshowStopped) mSlideshowMedia else mMediaFiles
private fun getCurrentPath() = getCurrentMedium()?.path ?: "" private fun getCurrentPath() = getCurrentMedium()?.path ?: ""

View file

@ -13,10 +13,9 @@ import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.extensions.getFileKey import com.simplemobiletools.commons.extensions.getFileKey
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import kotlinx.android.synthetic.main.portrait_photo_item.view.* import kotlinx.android.synthetic.main.portrait_photo_item.view.*
import java.util.*
class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int, Int) -> Unit) : class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int, Int) -> Unit) :
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() { RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
var currentSelectionIndex = -1 var currentSelectionIndex = -1
var views = HashMap<Int, View>() var views = HashMap<Int, View>()
@ -48,7 +47,7 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(photo: String, position: Int): View { fun bindView(photo: String, position: Int): View {
itemView.apply { itemView.apply {
portrait_photo_item_thumbnail.layoutParams.width = if (position == 0 || position == photos.size - 1) { portrait_photo_item_thumbnail.layoutParams.width = if (position == 0 || position == photos.lastIndex) {
sideElementWidth sideElementWidth
} else { } else {
itemWidth itemWidth
@ -61,15 +60,15 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
} }
val options = RequestOptions() val options = RequestOptions()
.signature(ObjectKey(photo.getFileKey())) .signature(ObjectKey(photo.getFileKey()))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .centerCrop()
Glide.with(context) Glide.with(context)
.load(photo) .load(photo)
.transition(DrawableTransitionOptions.withCrossFade()) .transition(DrawableTransitionOptions.withCrossFade())
.apply(options) .apply(options)
.into(portrait_photo_item_thumbnail) .into(portrait_photo_item_thumbnail)
if (photo.isNotEmpty()) { if (photo.isNotEmpty()) {
isClickable = true isClickable = true

View file

@ -147,7 +147,7 @@ class PickDirectoryDialog(
if (currentPathPrefix.isEmpty()) { if (currentPathPrefix.isEmpty()) {
dialog?.dismiss() dialog?.dismiss()
} else { } else {
openedSubfolders.removeAt(openedSubfolders.size - 1) openedSubfolders.removeLast()
currentPathPrefix = openedSubfolders.last() currentPathPrefix = openedSubfolders.last()
gotDirectories(allDirectories) gotDirectories(allDirectories)
} }

View file

@ -42,9 +42,11 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isRPlus import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.commons.helpers.mydebug
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.activities.* import com.simplemobiletools.gallery.pro.activities.PanoramaPhotoActivity
import com.simplemobiletools.gallery.pro.activities.PhotoActivity
import com.simplemobiletools.gallery.pro.activities.PhotoVideoActivity
import com.simplemobiletools.gallery.pro.activities.ViewPagerActivity
import com.simplemobiletools.gallery.pro.adapters.PortraitPhotosAdapter import com.simplemobiletools.gallery.pro.adapters.PortraitPhotosAdapter
import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.extensions.config
import com.simplemobiletools.gallery.pro.extensions.saveRotatedImageToFile import com.simplemobiletools.gallery.pro.extensions.saveRotatedImageToFile
@ -99,12 +101,16 @@ class PhotoFragment : ViewPagerFragment() {
private lateinit var mMedium: Medium private lateinit var mMedium: Medium
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val context = requireContext()
val activity = requireActivity()
val arguments = requireArguments()
mView = (inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup) mView = (inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup)
if (!arguments!!.getBoolean(SHOULD_INIT_FRAGMENT, true)) { if (!arguments.getBoolean(SHOULD_INIT_FRAGMENT, true)) {
return mView return mView
} }
mMedium = arguments!!.getSerializable(MEDIUM) as Medium mMedium = arguments.getSerializable(MEDIUM) as Medium
mOriginalPath = mMedium.path mOriginalPath = mMedium.path
mView.apply { mView.apply {
@ -118,7 +124,7 @@ class PhotoFragment : ViewPagerFragment() {
instant_prev_item.parentView = container instant_prev_item.parentView = container
instant_next_item.parentView = container instant_next_item.parentView = container
photo_brightness_controller.initialize(activity!!, slide_info, true, container, singleTap = { x, y -> photo_brightness_controller.initialize(activity, slide_info, true, container, singleTap = { x, y ->
mView.apply { mView.apply {
if (subsampling_view.isVisible()) { if (subsampling_view.isVisible()) {
subsampling_view.sendFakeClick(x, y) subsampling_view.sendFakeClick(x, y)
@ -214,7 +220,7 @@ class PhotoFragment : ViewPagerFragment() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
val config = context!!.config val config = requireContext().config
if (mWasInit && (config.showExtendedDetails != mStoredShowExtendedDetails || config.extendedDetails != mStoredExtendedDetails)) { if (mWasInit && (config.showExtendedDetails != mStoredShowExtendedDetails || config.extendedDetails != mStoredExtendedDetails)) {
initExtendedDetails() initExtendedDetails()
} }
@ -253,7 +259,7 @@ class PhotoFragment : ViewPagerFragment() {
try { try {
if (context != null) { if (context != null) {
Glide.with(context!!).clear(mView.gestures_view) Glide.with(requireContext()).clear(mView.gestures_view)
} }
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
@ -307,7 +313,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun storeStateVariables() { private fun storeStateVariables() {
context!!.config.apply { requireContext().config.apply {
mStoredShowExtendedDetails = showExtendedDetails mStoredShowExtendedDetails = showExtendedDetails
mStoredHideExtendedDetails = hideExtendedDetails mStoredHideExtendedDetails = hideExtendedDetails
mStoredAllowDeepZoomableImages = allowZoomingImages mStoredAllowDeepZoomableImages = allowZoomingImages
@ -379,7 +385,7 @@ class PhotoFragment : ViewPagerFragment() {
try { try {
val pathToLoad = getPathToLoad(mMedium) val pathToLoad = getPathToLoad(mMedium)
val source = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) { val source = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) {
InputSource.UriSource(context!!.contentResolver, Uri.parse(pathToLoad)) InputSource.UriSource(requireContext().contentResolver, Uri.parse(pathToLoad))
} else { } else {
InputSource.FileSource(pathToLoad) InputSource.FileSource(pathToLoad)
} }
@ -400,7 +406,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadSVG() { private fun loadSVG() {
if (context != null) { if (context != null) {
Glide.with(context!!) Glide.with(requireContext())
.`as`(PictureDrawable::class.java) .`as`(PictureDrawable::class.java)
.listener(SvgSoftwareLayerSetter()) .listener(SvgSoftwareLayerSetter())
.load(mMedium.path) .load(mMedium.path)
@ -448,7 +454,7 @@ class PhotoFragment : ViewPagerFragment() {
options.diskCacheStrategy(DiskCacheStrategy.NONE) options.diskCacheStrategy(DiskCacheStrategy.NONE)
} }
Glide.with(context!!) Glide.with(requireContext())
.load(path) .load(path)
.apply(options) .apply(options)
.listener(object : RequestListener<Drawable> { .listener(object : RequestListener<Drawable> {
@ -517,7 +523,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun showPortraitStripe() { private fun showPortraitStripe() {
val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File> val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File>
if (files != null) { if (files != null) {
val screenWidth = context!!.realScreenSize.x val screenWidth = requireContext().realScreenSize.x
val itemWidth = resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt() + resources.getDimension(R.dimen.one_dp).toInt() val itemWidth = resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt() + resources.getDimension(R.dimen.one_dp).toInt()
val sideWidth = screenWidth / 2 - itemWidth / 2 val sideWidth = screenWidth / 2 - itemWidth / 2
val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt() val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt()
@ -529,7 +535,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
val sideElementWidth = curWidth - screenWidth val sideElementWidth = curWidth - screenWidth
val adapter = PortraitPhotosAdapter(context!!, paths, sideElementWidth) { position, x -> val adapter = PortraitPhotosAdapter(requireContext(), paths, sideElementWidth) { position, x ->
if (mIsFullscreen) { if (mIsFullscreen) {
return@PortraitPhotosAdapter return@PortraitPhotosAdapter
} }
@ -579,8 +585,8 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun setupStripeBottomMargin() { private fun setupStripeBottomMargin() {
var bottomMargin = context!!.navigationBarHeight + resources.getDimension(R.dimen.normal_margin).toInt() var bottomMargin = requireContext().navigationBarHeight + resources.getDimension(R.dimen.normal_margin).toInt()
if (context!!.config.bottomActions) { if (requireContext().config.bottomActions) {
bottomMargin += resources.getDimension(R.dimen.bottom_actions_height).toInt() bottomMargin += resources.getDimension(R.dimen.bottom_actions_height).toInt()
} }
(mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin (mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin
@ -647,7 +653,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun addZoomableView() { private fun addZoomableView() {
val rotation = degreesForRotation(mImageOrientation) val rotation = degreesForRotation(mImageOrientation)
mIsSubsamplingVisible = true mIsSubsamplingVisible = true
val config = context!!.config val config = requireContext().config
val showHighestQuality = config.showHighestQuality val showHighestQuality = config.showHighestQuality
val minTileDpi = if (showHighestQuality) -1 else getMinTileDpi() val minTileDpi = if (showHighestQuality) -1 else getMinTileDpi()
@ -734,7 +740,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun checkIfPanorama() { private fun checkIfPanorama() {
mIsPanorama = try { mIsPanorama = try {
val inputStream = if (mMedium.path.startsWith("content:/")) { val inputStream = if (mMedium.path.startsWith("content:/")) {
context!!.contentResolver.openInputStream(Uri.parse(mMedium.path)) requireContext().contentResolver.openInputStream(Uri.parse(mMedium.path))
} else { } else {
File(mMedium.path).inputStream() File(mMedium.path).inputStream()
} }
@ -763,7 +769,7 @@ class PhotoFragment : ViewPagerFragment() {
try { try {
val path = getFilePathToShow() val path = getFilePathToShow()
orient = if (path.startsWith("content:/")) { orient = if (path.startsWith("content:/")) {
val inputStream = context!!.contentResolver.openInputStream(Uri.parse(path)) val inputStream = requireContext().contentResolver.openInputStream(Uri.parse(path))
val exif = ExifInterface() val exif = ExifInterface()
exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL) exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL)
val tag = exif.getTag(ExifInterface.TAG_ORIENTATION) val tag = exif.getTag(ExifInterface.TAG_ORIENTATION)
@ -773,9 +779,9 @@ class PhotoFragment : ViewPagerFragment() {
exif.getAttributeInt(TAG_ORIENTATION, defaultOrientation) exif.getAttributeInt(TAG_ORIENTATION, defaultOrientation)
} }
if (orient == defaultOrientation || context!!.isPathOnOTG(getFilePathToShow())) { if (orient == defaultOrientation || requireContext().isPathOnOTG(getFilePathToShow())) {
val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path)) val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path))
val inputStream = context!!.contentResolver.openInputStream(uri) val inputStream = requireContext().contentResolver.openInputStream(uri)
val exif2 = ExifInterface() val exif2 = ExifInterface()
exif2.readExif(inputStream, ExifInterface.Options.OPTION_ALL) exif2.readExif(inputStream, ExifInterface.Options.OPTION_ALL)
orient = exif2.getTag(ExifInterface.TAG_ORIENTATION)?.getValueAsInt(defaultOrientation) ?: defaultOrientation orient = exif2.getTag(ExifInterface.TAG_ORIENTATION)?.getValueAsInt(defaultOrientation) ?: defaultOrientation
@ -792,13 +798,13 @@ class PhotoFragment : ViewPagerFragment() {
return if (context == null || Math.abs(bitmapAspectRatio - screenAspectRatio) < SAME_ASPECT_RATIO_THRESHOLD) { return if (context == null || Math.abs(bitmapAspectRatio - screenAspectRatio) < SAME_ASPECT_RATIO_THRESHOLD) {
DEFAULT_DOUBLE_TAP_ZOOM DEFAULT_DOUBLE_TAP_ZOOM
} else if (context!!.portrait && bitmapAspectRatio <= screenAspectRatio) { } else if (requireContext().portrait && bitmapAspectRatio <= screenAspectRatio) {
mScreenHeight / height.toFloat() mScreenHeight / height.toFloat()
} else if (context!!.portrait && bitmapAspectRatio > screenAspectRatio) { } else if (requireContext().portrait && bitmapAspectRatio > screenAspectRatio) {
mScreenWidth / width.toFloat() mScreenWidth / width.toFloat()
} else if (!context!!.portrait && bitmapAspectRatio >= screenAspectRatio) { } else if (!requireContext().portrait && bitmapAspectRatio >= screenAspectRatio) {
mScreenWidth / width.toFloat() mScreenWidth / width.toFloat()
} else if (!context!!.portrait && bitmapAspectRatio < screenAspectRatio) { } else if (!requireContext().portrait && bitmapAspectRatio < screenAspectRatio) {
mScreenHeight / height.toFloat() mScreenHeight / height.toFloat()
} else { } else {
DEFAULT_DOUBLE_TAP_ZOOM DEFAULT_DOUBLE_TAP_ZOOM
@ -817,7 +823,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun initExtendedDetails() { private fun initExtendedDetails() {
if (context!!.config.showExtendedDetails) { if (requireContext().config.showExtendedDetails) {
mView.photo_details.apply { mView.photo_details.apply {
beInvisible() // make it invisible so we can measure it, but not show yet beInvisible() // make it invisible so we can measure it, but not show yet
text = getMediumExtendedDetails(mMedium) text = getMediumExtendedDetails(mMedium)
@ -827,7 +833,7 @@ class PhotoFragment : ViewPagerFragment() {
if (realY > 0) { if (realY > 0) {
y = realY y = realY
beVisibleIf(text.isNotEmpty()) beVisibleIf(text.isNotEmpty())
alpha = if (!context!!.config.hideExtendedDetails || !mIsFullscreen) 1f else 0f alpha = if (!requireContext().config.hideExtendedDetails || !mIsFullscreen) 1f else 0f
} }
} }
} }
@ -881,8 +887,8 @@ class PhotoFragment : ViewPagerFragment() {
private fun getExtendedDetailsY(height: Int): Float { private fun getExtendedDetailsY(height: Int): Float {
val smallMargin = context?.resources?.getDimension(R.dimen.small_margin) ?: return 0f val smallMargin = context?.resources?.getDimension(R.dimen.small_margin) ?: return 0f
val fullscreenOffset = smallMargin + if (mIsFullscreen) 0 else context!!.navigationBarHeight val fullscreenOffset = smallMargin + if (mIsFullscreen) 0 else requireContext().navigationBarHeight
val actionsHeight = if (context!!.config.bottomActions && !mIsFullscreen) resources.getDimension(R.dimen.bottom_actions_height) else 0f val actionsHeight = if (requireContext().config.bottomActions && !mIsFullscreen) resources.getDimension(R.dimen.bottom_actions_height) else 0f
return context!!.realScreenSize.y - height - actionsHeight - fullscreenOffset return requireContext().realScreenSize.y - height - actionsHeight - fullscreenOffset
} }
} }

View file

@ -79,9 +79,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private lateinit var mPlayPauseButton: ImageView private lateinit var mPlayPauseButton: ImageView
private lateinit var mSeekBar: SeekBar private lateinit var mSeekBar: SeekBar
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
mMedium = arguments!!.getSerializable(MEDIUM) as Medium val context = requireContext()
mConfig = context!!.config val activity = requireActivity()
val arguments = requireArguments()
mMedium = arguments.getSerializable(MEDIUM) as Medium
mConfig = context.config
mView = inflater.inflate(R.layout.pager_video_item, container, false).apply { mView = inflater.inflate(R.layout.pager_video_item, container, false).apply {
panorama_outline.setOnClickListener { openPanorama() } panorama_outline.setOnClickListener { openPanorama() }
video_curr_time.setOnClickListener { skip(false) } video_curr_time.setOnClickListener { skip(false) }
@ -154,24 +158,24 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
} }
} }
if (!arguments!!.getBoolean(SHOULD_INIT_FRAGMENT, true)) { if (!arguments.getBoolean(SHOULD_INIT_FRAGMENT, true)) {
return mView return mView
} }
storeStateVariables() storeStateVariables()
Glide.with(context!!).load(mMedium.path).into(mView.video_preview) Glide.with(context).load(mMedium.path).into(mView.video_preview)
// setMenuVisibility is not called at VideoActivity (third party intent) // setMenuVisibility is not called at VideoActivity (third party intent)
if (!mIsFragmentVisible && activity is VideoActivity) { if (!mIsFragmentVisible && activity is VideoActivity) {
mIsFragmentVisible = true mIsFragmentVisible = true
} }
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
initTimeHolder() initTimeHolder()
checkIfPanorama() checkIfPanorama()
ensureBackgroundThread { ensureBackgroundThread {
activity?.getVideoResolution(mMedium.path)?.apply { activity.getVideoResolution(mMedium.path)?.apply {
mVideoSize.x = x mVideoSize.x = x
mVideoSize.y = y mVideoSize.y = y
} }
@ -183,7 +187,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
video_play_outline.beGone() video_play_outline.beGone()
mVolumeSideScroll.beGone() mVolumeSideScroll.beGone()
mBrightnessSideScroll.beGone() mBrightnessSideScroll.beGone()
Glide.with(context!!).load(mMedium.path).into(video_preview) Glide.with(context).load(mMedium.path).into(video_preview)
} }
} }
@ -196,7 +200,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
setVideoSize() setVideoSize()
mView.apply { mView.apply {
mBrightnessSideScroll.initialize(activity!!, slide_info, true, container, singleTap = { x, y -> mBrightnessSideScroll.initialize(activity, slide_info, true, container, singleTap = { x, y ->
if (mConfig.allowInstantChange) { if (mConfig.allowInstantChange) {
listener?.goToPrevItem() listener?.goToPrevItem()
} else { } else {
@ -206,7 +210,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
doSkip(false) doSkip(false)
}) })
mVolumeSideScroll.initialize(activity!!, slide_info, false, container, singleTap = { x, y -> mVolumeSideScroll.initialize(activity, slide_info, false, container, singleTap = { x, y ->
if (mConfig.allowInstantChange) { if (mConfig.allowInstantChange) {
listener?.goToNextItem() listener?.goToNextItem()
} else { } else {
@ -234,8 +238,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
mConfig = context!!.config // make sure we get a new config, in case the user changed something in the app settings mConfig = requireContext().config // make sure we get a new config, in case the user changed something in the app settings
activity!!.updateTextColors(mView.video_holder) requireActivity().updateTextColors(mView.video_holder)
val allowVideoGestures = mConfig.allowVideoGestures val allowVideoGestures = mConfig.allowVideoGestures
mTextureView.beGoneIf(mConfig.openVideosOnSeparateScreen || mIsPanorama) mTextureView.beGoneIf(mConfig.openVideosOnSeparateScreen || mIsPanorama)
mView.video_surface_frame.beGoneIf(mTextureView.isGone()) mView.video_surface_frame.beGoneIf(mTextureView.isGone())
@ -456,13 +460,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private fun initTimeHolder() { private fun initTimeHolder() {
var right = 0 var right = 0
var bottom = context!!.navigationBarHeight var bottom = requireContext().navigationBarHeight
if (mConfig.bottomActions) { if (mConfig.bottomActions) {
bottom += resources.getDimension(R.dimen.bottom_actions_height).toInt() bottom += resources.getDimension(R.dimen.bottom_actions_height).toInt()
} }
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && activity?.hasNavBar() == true) { if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && activity?.hasNavBar() == true) {
right += activity!!.navigationBarWidth right += requireActivity().navigationBarWidth
} }
(mTimeHolder.layoutParams as RelativeLayout.LayoutParams).apply { (mTimeHolder.layoutParams as RelativeLayout.LayoutParams).apply {
@ -476,7 +480,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
try { try {
val fis = FileInputStream(File(mMedium.path)) val fis = FileInputStream(File(mMedium.path))
fis.use { fis.use {
context!!.parseFileChannel(mMedium.path, it.channel, 0, 0, 0) { requireContext().parseFileChannel(mMedium.path, it.channel, 0, 0, 0) {
mIsPanorama = true mIsPanorama = true
} }
} }
@ -518,7 +522,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private fun getExtendedDetailsY(height: Int): Float { private fun getExtendedDetailsY(height: Int): Float {
val smallMargin = context?.resources?.getDimension(R.dimen.small_margin) ?: return 0f val smallMargin = context?.resources?.getDimension(R.dimen.small_margin) ?: return 0f
val fullscreenOffset = smallMargin + if (mIsFullscreen) 0 else context!!.navigationBarHeight val fullscreenOffset = smallMargin + if (mIsFullscreen) 0 else requireContext().navigationBarHeight
var actionsHeight = 0f var actionsHeight = 0f
if (!mIsFullscreen) { if (!mIsFullscreen) {
actionsHeight += resources.getDimension(R.dimen.video_player_play_pause_size) actionsHeight += resources.getDimension(R.dimen.video_player_play_pause_size)
@ -526,7 +530,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
actionsHeight += resources.getDimension(R.dimen.bottom_actions_height) actionsHeight += resources.getDimension(R.dimen.bottom_actions_height)
} }
} }
return context!!.realScreenSize.y - height - actionsHeight - fullscreenOffset return requireContext().realScreenSize.y - height - actionsHeight - fullscreenOffset
} }
private fun skip(forward: Boolean) { private fun skip(forward: Boolean) {
@ -774,7 +778,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
} }
val videoProportion = mVideoSize.x.toFloat() / mVideoSize.y.toFloat() val videoProportion = mVideoSize.x.toFloat() / mVideoSize.y.toFloat()
val display = activity!!.windowManager.defaultDisplay val display = requireActivity().windowManager.defaultDisplay
val screenWidth: Int val screenWidth: Int
val screenHeight: Int val screenHeight: Int

View file

@ -70,7 +70,7 @@ class NewPhotoFetcher : JobService() {
for (uri in params.triggeredContentUris!!) { for (uri in params.triggeredContentUris!!) {
val path = uri.pathSegments val path = uri.pathSegments
if (path != null && (path.size == PHOTO_PATH_SEGMENTS.size + 1 || path.size == VIDEO_PATH_SEGMENTS.size + 1)) { if (path != null && (path.size == PHOTO_PATH_SEGMENTS.size + 1 || path.size == VIDEO_PATH_SEGMENTS.size + 1)) {
ids.add(path[path.size - 1]) ids.add(path[path.lastIndex])
} }
} }