avoid initializing the first 3 fragments unnecessarily
This commit is contained in:
parent
fa0ce89d81
commit
7d9e9c6df0
|
@ -61,7 +61,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.12.17'
|
||||
implementation 'com.simplemobiletools:commons:5.12.22'
|
||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||
|
|
|
@ -366,8 +366,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private fun updatePagerItems(media: MutableList<Medium>) {
|
||||
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media)
|
||||
if (!isDestroyed) {
|
||||
pagerAdapter.shouldInitFragment = mPos < 5
|
||||
view_pager.apply {
|
||||
adapter = pagerAdapter
|
||||
pagerAdapter.shouldInitFragment = true
|
||||
currentItem = mPos
|
||||
removeOnPageChangeListener(this@ViewPagerActivity)
|
||||
addOnPageChangeListener(this@ViewPagerActivity)
|
||||
|
|
|
@ -12,16 +12,20 @@ import com.simplemobiletools.gallery.pro.fragments.PhotoFragment
|
|||
import com.simplemobiletools.gallery.pro.fragments.VideoFragment
|
||||
import com.simplemobiletools.gallery.pro.fragments.ViewPagerFragment
|
||||
import com.simplemobiletools.gallery.pro.helpers.MEDIUM
|
||||
import com.simplemobiletools.gallery.pro.helpers.SHOULD_INIT_FRAGMENT
|
||||
import com.simplemobiletools.gallery.pro.models.Medium
|
||||
|
||||
class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList<Medium>) : FragmentStatePagerAdapter(fm) {
|
||||
private val fragments = HashMap<Int, ViewPagerFragment>()
|
||||
var shouldInitFragment = true
|
||||
|
||||
override fun getCount() = media.size
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
val medium = media[position]
|
||||
val bundle = Bundle()
|
||||
bundle.putSerializable(MEDIUM, medium)
|
||||
bundle.putBoolean(SHOULD_INIT_FRAGMENT, shouldInitFragment)
|
||||
val fragment = if (medium.isVideo()) {
|
||||
VideoFragment()
|
||||
} else {
|
||||
|
|
|
@ -40,10 +40,7 @@ import com.simplemobiletools.gallery.pro.R
|
|||
import com.simplemobiletools.gallery.pro.activities.PanoramaPhotoActivity
|
||||
import com.simplemobiletools.gallery.pro.activities.PhotoActivity
|
||||
import com.simplemobiletools.gallery.pro.extensions.*
|
||||
import com.simplemobiletools.gallery.pro.helpers.MEDIUM
|
||||
import com.simplemobiletools.gallery.pro.helpers.PATH
|
||||
import com.simplemobiletools.gallery.pro.helpers.PicassoDecoder
|
||||
import com.simplemobiletools.gallery.pro.helpers.PicassoRegionDecoder
|
||||
import com.simplemobiletools.gallery.pro.helpers.*
|
||||
import com.simplemobiletools.gallery.pro.models.Medium
|
||||
import com.simplemobiletools.gallery.pro.svg.SvgSoftwareLayerSetter
|
||||
import com.squareup.picasso.Callback
|
||||
|
@ -90,7 +87,12 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
private lateinit var mMedium: Medium
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
mView = (inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup).apply {
|
||||
mView = (inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup)
|
||||
if (!arguments!!.getBoolean(SHOULD_INIT_FRAGMENT)) {
|
||||
return mView
|
||||
}
|
||||
|
||||
mView.apply {
|
||||
subsampling_view.setOnClickListener { photoClicked() }
|
||||
gestures_view.setOnClickListener { photoClicked() }
|
||||
gif_view.setOnClickListener { photoClicked() }
|
||||
|
|
|
@ -28,10 +28,7 @@ import com.simplemobiletools.gallery.pro.R
|
|||
import com.simplemobiletools.gallery.pro.activities.PanoramaVideoActivity
|
||||
import com.simplemobiletools.gallery.pro.activities.VideoActivity
|
||||
import com.simplemobiletools.gallery.pro.extensions.*
|
||||
import com.simplemobiletools.gallery.pro.helpers.Config
|
||||
import com.simplemobiletools.gallery.pro.helpers.MEDIUM
|
||||
import com.simplemobiletools.gallery.pro.helpers.MIN_SKIP_LENGTH
|
||||
import com.simplemobiletools.gallery.pro.helpers.PATH
|
||||
import com.simplemobiletools.gallery.pro.helpers.*
|
||||
import com.simplemobiletools.gallery.pro.models.Medium
|
||||
import com.simplemobiletools.gallery.pro.views.MediaSideScroll
|
||||
import kotlinx.android.synthetic.main.bottom_video_time_holder.view.*
|
||||
|
@ -125,6 +122,10 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
|||
}
|
||||
}
|
||||
|
||||
if (!arguments!!.getBoolean(SHOULD_INIT_FRAGMENT)) {
|
||||
return mView
|
||||
}
|
||||
|
||||
storeStateVariables()
|
||||
mMedium = arguments!!.getSerializable(MEDIUM) as Medium
|
||||
Glide.with(context!!).load(mMedium.path).into(mView.video_preview)
|
||||
|
|
|
@ -119,6 +119,7 @@ const val GET_ANY_INTENT = "get_any_intent"
|
|||
const val SET_WALLPAPER_INTENT = "set_wallpaper_intent"
|
||||
const val IS_VIEW_INTENT = "is_view_intent"
|
||||
const val PICKED_PATHS = "picked_paths"
|
||||
const val SHOULD_INIT_FRAGMENT = "should_init_fragment"
|
||||
|
||||
// rotations
|
||||
const val ROTATE_BY_SYSTEM_SETTING = 0
|
||||
|
|
Loading…
Reference in New Issue