Skip to content

Commit

Permalink
Merge pull request #93 from pauliancu97/feature/NextAndPreviousEpisod…
Browse files Browse the repository at this point in the history
…esButtonsImprovement

Fixed issues regarding the next and previous episode buttons
  • Loading branch information
justdvnsh authored Oct 25, 2021
2 parents 1b8e0ed + db4bc11 commit 3875809
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class PlayerFragment: Fragment(), PlayerControlListener {
binding.exoPlayerView.exo_pause.setImageResource(0)
}
STATE_READY -> {
setEnabledStatusOfPreviousAndNextEpisodesButtons(true)
exoPlayerView.videoSurfaceView.visibility = View.VISIBLE
exoplayerErrorLayoutChange(visible = false)
binding.exoPlayerView.exo_play.setImageResource(R.drawable.ic_media_play)
Expand Down Expand Up @@ -214,10 +215,18 @@ class PlayerFragment: Fragment(), PlayerControlListener {
Log.i("Player-Frag", it.data.toString())
it.data?.let { it1 ->
initializePlayer(it1)
if (it1.nextEpisodeUrl == null || it1.nextEpisodeUrl.equals("null"))
binding.exoPlayerView.nextEpisode.visibility = View.GONE
if (it1.previousEpisodeUrl == null || it1.previousEpisodeUrl.equals("null"))
binding.exoPlayerView.previousEpisode.visibility = View.GONE
val nextEpisodeButtonVisibility = if (it1.nextEpisodeUrl == null || it1.nextEpisodeUrl.equals("null")) {
View.GONE
} else {
View.VISIBLE
}
binding.exoPlayerView.nextEpisode.visibility = nextEpisodeButtonVisibility
val previousEpisodeButtonVisibility = if (it1.previousEpisodeUrl == null || it1.previousEpisodeUrl.equals("null")) {
View.GONE
} else {
View.VISIBLE
}
binding.exoPlayerView.previousEpisode.visibility = previousEpisodeButtonVisibility
episodeName.text = it1.animeName
nextEpisode.setOnClickListener { it1.nextEpisodeUrl?.let { it2 ->
onEpisodeClicked(
Expand All @@ -231,6 +240,9 @@ class PlayerFragment: Fragment(), PlayerControlListener {
} }
}
}
is ResultWrapper.Loading -> {
setEnabledStatusOfPreviousAndNextEpisodesButtons(false)
}
else -> {
Log.i("Player-Frag", it.toString())
}
Expand Down Expand Up @@ -304,6 +316,11 @@ class PlayerFragment: Fragment(), PlayerControlListener {
exoPlayer.setAudioAttributes(audioAttributes, true)
}

private fun setEnabledStatusOfPreviousAndNextEpisodesButtons(isEnabled: Boolean) {
nextEpisode.isEnabled = isEnabled
previousEpisode.isEnabled = isEnabled
}

private fun speedControl(){
var playbackPosition = 2
val alertDialog: AlertDialog.Builder = AlertDialog.Builder(requireContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PlayerViewModel @Inject constructor(
val clickControlLiveData: LiveData<PlayerClick> get() = _clickControlLiveData

fun getStreamingUrl(episodeUrl: String) = viewModelScope.launch(Dispatchers.IO) {
_streamingUrlLiveData.postValue(ResultWrapper.Loading())
val url = if (!episodeUrl.startsWith(BASE_URL)) BASE_URL + episodeUrl else episodeUrl
Log.i("Player", url)
val response = playerRepo.getEpisodeDetails(url)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/color/player_episodes_buttons_color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@android:color/darker_gray"/>
<item android:color="@android:color/white"/>
</selector>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/exo_player_custom_controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:layout_height="wrap_content"
android:text="@string/previous_episode"
android:layout_marginStart="16dp"
android:textColor="@color/media_player_controls"
android:textColor="@color/player_episodes_buttons_color"
android:textSize="16sp"
android:padding="8dp"
android:id="@+id/previousEpisode"
Expand Down Expand Up @@ -205,7 +205,7 @@
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp"
android:textSize="16sp"
android:textColor="@color/media_player_controls"
android:textColor="@color/player_episodes_buttons_color"
android:padding="8dp"
android:id="@+id/nextEpisode"
app:layout_constraintBottom_toTopOf="@id/exo_duration"
Expand Down

0 comments on commit 3875809

Please sign in to comment.