-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/site/leos/apps/lespas/helper/MediaSliderTransitionListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package site.leos.apps.lespas.helper | ||
|
||
import android.view.View | ||
import android.widget.ImageView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.transition.Transition | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.google.android.exoplayer2.ui.PlayerView | ||
import site.leos.apps.lespas.R | ||
|
||
class MediaSliderTransitionListener(private val slider: ViewPager2): Transition.TransitionListener { | ||
var isVideo = false | ||
override fun onTransitionStart(transition: Transition) { | ||
slider.getChildAt(0)?.apply { | ||
findViewById<ImageView>(R.id.media)?.let { mediaView-> | ||
// media imageview in exoplayer item view is always in invisible state | ||
if (mediaView.visibility != View.VISIBLE) { | ||
isVideo = true | ||
findViewById<PlayerView>(R.id.player_view)?.visibility = View.INVISIBLE | ||
} | ||
else { | ||
mediaView.visibility = View.INVISIBLE | ||
(slider.adapter as MediaSliderAdapter<*>).setAutoStart(true) | ||
} | ||
} | ||
} | ||
} | ||
override fun onTransitionEnd(transition: Transition) { | ||
(slider.getChildAt(0) as RecyclerView).apply { | ||
findViewById<ImageView>(R.id.media)?.visibility = View.VISIBLE | ||
if (isVideo) (findViewHolderForAdapterPosition(slider.currentItem) as MediaSliderAdapter<*>.VideoViewHolder).startOver() | ||
} | ||
} | ||
override fun onTransitionCancel(transition: Transition) { | ||
(slider.getChildAt(0) as RecyclerView).apply { | ||
findViewById<ImageView>(R.id.media)?.visibility = View.VISIBLE | ||
if (isVideo) (findViewHolderForAdapterPosition(slider.currentItem) as MediaSliderAdapter<*>.VideoViewHolder).startOver() | ||
} | ||
} | ||
override fun onTransitionPause(transition: Transition) {} | ||
override fun onTransitionResume(transition: Transition) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.