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()) {
super.onBackPressed()
} else {
mOpenedSubfolders.removeAt(mOpenedSubfolders.size - 1)
mOpenedSubfolders.removeLast()
mCurrentPathPrefix = mOpenedSubfolders.last()
setupAdapter(mDirs)
}

View file

@ -80,6 +80,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private var mSlideshowMoveBackwards = false
private var mSlideshowMedia = mutableListOf<Medium>()
private var mAreSlideShowMediaVisible = false
private var mRandomSlideshowStopped = false
private var mIsOrientationLocked = false
@ -505,6 +506,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
hideSystemUI(true)
mRandomSlideshowStopped = false
mSlideshowInterval = config.slideshowInterval
mSlideshowMoveBackwards = config.slideshowMoveBackwards
mIsSlideshowActive = true
@ -600,6 +602,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
mSlideshowHandler.removeCallbacksAndMessages(null)
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
mAreSlideShowMediaVisible = false
if (config.slideshowRandomOrder) {
mRandomSlideshowStopped = true
}
}
}
@ -1279,7 +1285,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (refetchViewPagerPosition || mPos == -1) {
mPos = getPositionInList(media)
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(REAL_FILE_PATH, path)
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 {
startActivityForResult(this, REQUEST_VIEW_VIDEO)
@ -1429,8 +1435,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun updateActionbarTitle() {
runOnUiThread {
if (mPos < getCurrentMedia().size) {
medium_viewer_toolbar.title = getCurrentMedia()[mPos].path.getFilenameFromPath()
val medium = getCurrentMedium()
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) {
null
} 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 ?: ""

View file

@ -13,10 +13,9 @@ import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.extensions.getFileKey
import com.simplemobiletools.gallery.pro.R
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) :
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
var currentSelectionIndex = -1
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) {
fun bindView(photo: String, position: Int): View {
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
} else {
itemWidth
@ -61,15 +60,15 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
}
val options = RequestOptions()
.signature(ObjectKey(photo.getFileKey()))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.signature(ObjectKey(photo.getFileKey()))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
Glide.with(context)
.load(photo)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.into(portrait_photo_item_thumbnail)
.load(photo)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.into(portrait_photo_item_thumbnail)
if (photo.isNotEmpty()) {
isClickable = true

View file

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

View file

@ -42,9 +42,11 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.commons.helpers.mydebug
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.extensions.config
import com.simplemobiletools.gallery.pro.extensions.saveRotatedImageToFile
@ -99,12 +101,16 @@ class PhotoFragment : ViewPagerFragment() {
private lateinit var mMedium: Medium
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)
if (!arguments!!.getBoolean(SHOULD_INIT_FRAGMENT, true)) {
if (!arguments.getBoolean(SHOULD_INIT_FRAGMENT, true)) {
return mView
}
mMedium = arguments!!.getSerializable(MEDIUM) as Medium
mMedium = arguments.getSerializable(MEDIUM) as Medium
mOriginalPath = mMedium.path
mView.apply {
@ -118,7 +124,7 @@ class PhotoFragment : ViewPagerFragment() {
instant_prev_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 {
if (subsampling_view.isVisible()) {
subsampling_view.sendFakeClick(x, y)
@ -214,7 +220,7 @@ class PhotoFragment : ViewPagerFragment() {
override fun onResume() {
super.onResume()
val config = context!!.config
val config = requireContext().config
if (mWasInit && (config.showExtendedDetails != mStoredShowExtendedDetails || config.extendedDetails != mStoredExtendedDetails)) {
initExtendedDetails()
}
@ -253,7 +259,7 @@ class PhotoFragment : ViewPagerFragment() {
try {
if (context != null) {
Glide.with(context!!).clear(mView.gestures_view)
Glide.with(requireContext()).clear(mView.gestures_view)
}
} catch (ignored: Exception) {
}
@ -307,7 +313,7 @@ class PhotoFragment : ViewPagerFragment() {
}
private fun storeStateVariables() {
context!!.config.apply {
requireContext().config.apply {
mStoredShowExtendedDetails = showExtendedDetails
mStoredHideExtendedDetails = hideExtendedDetails
mStoredAllowDeepZoomableImages = allowZoomingImages
@ -379,7 +385,7 @@ class PhotoFragment : ViewPagerFragment() {
try {
val pathToLoad = getPathToLoad(mMedium)
val source = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) {
InputSource.UriSource(context!!.contentResolver, Uri.parse(pathToLoad))
InputSource.UriSource(requireContext().contentResolver, Uri.parse(pathToLoad))
} else {
InputSource.FileSource(pathToLoad)
}
@ -400,7 +406,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadSVG() {
if (context != null) {
Glide.with(context!!)
Glide.with(requireContext())
.`as`(PictureDrawable::class.java)
.listener(SvgSoftwareLayerSetter())
.load(mMedium.path)
@ -448,7 +454,7 @@ class PhotoFragment : ViewPagerFragment() {
options.diskCacheStrategy(DiskCacheStrategy.NONE)
}
Glide.with(context!!)
Glide.with(requireContext())
.load(path)
.apply(options)
.listener(object : RequestListener<Drawable> {
@ -517,7 +523,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun showPortraitStripe() {
val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File>
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 sideWidth = screenWidth / 2 - itemWidth / 2
val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt()
@ -529,7 +535,7 @@ class PhotoFragment : ViewPagerFragment() {
}
val sideElementWidth = curWidth - screenWidth
val adapter = PortraitPhotosAdapter(context!!, paths, sideElementWidth) { position, x ->
val adapter = PortraitPhotosAdapter(requireContext(), paths, sideElementWidth) { position, x ->
if (mIsFullscreen) {
return@PortraitPhotosAdapter
}
@ -579,8 +585,8 @@ class PhotoFragment : ViewPagerFragment() {
}
private fun setupStripeBottomMargin() {
var bottomMargin = context!!.navigationBarHeight + resources.getDimension(R.dimen.normal_margin).toInt()
if (context!!.config.bottomActions) {
var bottomMargin = requireContext().navigationBarHeight + resources.getDimension(R.dimen.normal_margin).toInt()
if (requireContext().config.bottomActions) {
bottomMargin += resources.getDimension(R.dimen.bottom_actions_height).toInt()
}
(mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin
@ -647,7 +653,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun addZoomableView() {
val rotation = degreesForRotation(mImageOrientation)
mIsSubsamplingVisible = true
val config = context!!.config
val config = requireContext().config
val showHighestQuality = config.showHighestQuality
val minTileDpi = if (showHighestQuality) -1 else getMinTileDpi()
@ -734,7 +740,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun checkIfPanorama() {
mIsPanorama = try {
val inputStream = if (mMedium.path.startsWith("content:/")) {
context!!.contentResolver.openInputStream(Uri.parse(mMedium.path))
requireContext().contentResolver.openInputStream(Uri.parse(mMedium.path))
} else {
File(mMedium.path).inputStream()
}
@ -763,7 +769,7 @@ class PhotoFragment : ViewPagerFragment() {
try {
val path = getFilePathToShow()
orient = if (path.startsWith("content:/")) {
val inputStream = context!!.contentResolver.openInputStream(Uri.parse(path))
val inputStream = requireContext().contentResolver.openInputStream(Uri.parse(path))
val exif = ExifInterface()
exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL)
val tag = exif.getTag(ExifInterface.TAG_ORIENTATION)
@ -773,9 +779,9 @@ class PhotoFragment : ViewPagerFragment() {
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 inputStream = context!!.contentResolver.openInputStream(uri)
val inputStream = requireContext().contentResolver.openInputStream(uri)
val exif2 = ExifInterface()
exif2.readExif(inputStream, ExifInterface.Options.OPTION_ALL)
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) {
DEFAULT_DOUBLE_TAP_ZOOM
} else if (context!!.portrait && bitmapAspectRatio <= screenAspectRatio) {
} else if (requireContext().portrait && bitmapAspectRatio <= screenAspectRatio) {
mScreenHeight / height.toFloat()
} else if (context!!.portrait && bitmapAspectRatio > screenAspectRatio) {
} else if (requireContext().portrait && bitmapAspectRatio > screenAspectRatio) {
mScreenWidth / width.toFloat()
} else if (!context!!.portrait && bitmapAspectRatio >= screenAspectRatio) {
} else if (!requireContext().portrait && bitmapAspectRatio >= screenAspectRatio) {
mScreenWidth / width.toFloat()
} else if (!context!!.portrait && bitmapAspectRatio < screenAspectRatio) {
} else if (!requireContext().portrait && bitmapAspectRatio < screenAspectRatio) {
mScreenHeight / height.toFloat()
} else {
DEFAULT_DOUBLE_TAP_ZOOM
@ -817,7 +823,7 @@ class PhotoFragment : ViewPagerFragment() {
}
private fun initExtendedDetails() {
if (context!!.config.showExtendedDetails) {
if (requireContext().config.showExtendedDetails) {
mView.photo_details.apply {
beInvisible() // make it invisible so we can measure it, but not show yet
text = getMediumExtendedDetails(mMedium)
@ -827,7 +833,7 @@ class PhotoFragment : ViewPagerFragment() {
if (realY > 0) {
y = realY
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 {
val smallMargin = context?.resources?.getDimension(R.dimen.small_margin) ?: return 0f
val fullscreenOffset = smallMargin + if (mIsFullscreen) 0 else context!!.navigationBarHeight
val actionsHeight = if (context!!.config.bottomActions && !mIsFullscreen) resources.getDimension(R.dimen.bottom_actions_height) else 0f
return context!!.realScreenSize.y - height - actionsHeight - fullscreenOffset
val fullscreenOffset = smallMargin + if (mIsFullscreen) 0 else requireContext().navigationBarHeight
val actionsHeight = if (requireContext().config.bottomActions && !mIsFullscreen) resources.getDimension(R.dimen.bottom_actions_height) else 0f
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 mSeekBar: SeekBar
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mMedium = arguments!!.getSerializable(MEDIUM) as Medium
mConfig = context!!.config
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val context = requireContext()
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 {
panorama_outline.setOnClickListener { openPanorama() }
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
}
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)
if (!mIsFragmentVisible && activity is VideoActivity) {
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()
checkIfPanorama()
ensureBackgroundThread {
activity?.getVideoResolution(mMedium.path)?.apply {
activity.getVideoResolution(mMedium.path)?.apply {
mVideoSize.x = x
mVideoSize.y = y
}
@ -183,7 +187,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
video_play_outline.beGone()
mVolumeSideScroll.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()
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) {
listener?.goToPrevItem()
} else {
@ -206,7 +210,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
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) {
listener?.goToNextItem()
} else {
@ -234,8 +238,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
override fun onResume() {
super.onResume()
mConfig = context!!.config // make sure we get a new config, in case the user changed something in the app settings
activity!!.updateTextColors(mView.video_holder)
mConfig = requireContext().config // make sure we get a new config, in case the user changed something in the app settings
requireActivity().updateTextColors(mView.video_holder)
val allowVideoGestures = mConfig.allowVideoGestures
mTextureView.beGoneIf(mConfig.openVideosOnSeparateScreen || mIsPanorama)
mView.video_surface_frame.beGoneIf(mTextureView.isGone())
@ -456,13 +460,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private fun initTimeHolder() {
var right = 0
var bottom = context!!.navigationBarHeight
var bottom = requireContext().navigationBarHeight
if (mConfig.bottomActions) {
bottom += resources.getDimension(R.dimen.bottom_actions_height).toInt()
}
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && activity?.hasNavBar() == true) {
right += activity!!.navigationBarWidth
right += requireActivity().navigationBarWidth
}
(mTimeHolder.layoutParams as RelativeLayout.LayoutParams).apply {
@ -476,7 +480,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
try {
val fis = FileInputStream(File(mMedium.path))
fis.use {
context!!.parseFileChannel(mMedium.path, it.channel, 0, 0, 0) {
requireContext().parseFileChannel(mMedium.path, it.channel, 0, 0, 0) {
mIsPanorama = true
}
}
@ -518,7 +522,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private fun getExtendedDetailsY(height: Int): Float {
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
if (!mIsFullscreen) {
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)
}
}
return context!!.realScreenSize.y - height - actionsHeight - fullscreenOffset
return requireContext().realScreenSize.y - height - actionsHeight - fullscreenOffset
}
private fun skip(forward: Boolean) {
@ -774,7 +778,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
}
val videoProportion = mVideoSize.x.toFloat() / mVideoSize.y.toFloat()
val display = activity!!.windowManager.defaultDisplay
val display = requireActivity().windowManager.defaultDisplay
val screenWidth: Int
val screenHeight: Int

View file

@ -70,7 +70,7 @@ class NewPhotoFetcher : JobService() {
for (uri in params.triggeredContentUris!!) {
val path = uri.pathSegments
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])
}
}