Browse Source

migrate player episodes list to DialogFragment; change hideBars() behaviour

develop
Jannik 3 months ago
parent
commit
a898a70653
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 7
      app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt
  2. 68
      app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/EpisodeListDialogFragment.kt
  3. 2
      app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/LanguageSettingsDialogFragment.kt
  4. 48
      app/src/main/java/org/mosad/teapod/ui/components/EpisodesListPlayer.kt
  5. 2
      app/src/main/java/org/mosad/teapod/util/Utils.kt
  6. 16
      app/src/main/res/layout/player_controls.xml
  7. 5
      app/src/main/res/values/dimens.xml

7
app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt

@ -53,8 +53,8 @@ import kotlinx.coroutines.launch
import org.mosad.teapod.R
import org.mosad.teapod.parser.crunchyroll.NoneEpisode
import org.mosad.teapod.preferences.Preferences
import org.mosad.teapod.ui.activity.player.fragment.EpisodeListDialogFragment
import org.mosad.teapod.ui.activity.player.fragment.LanguageSettingsDialogFragment
import org.mosad.teapod.ui.components.EpisodesListPlayer
import org.mosad.teapod.util.hideBars
import org.mosad.teapod.util.isInPiPMode
import org.mosad.teapod.util.navToLauncherTask
@ -480,11 +480,8 @@ class PlayerActivity : AppCompatActivity() {
}
private fun showEpisodesList() {
val episodesList = EpisodesListPlayer(this, model = model).apply {
onViewRemovedAction = { model.player.play() }
}
player_layout.addView(episodesList)
pauseAndHideControls()
EpisodeListDialogFragment().show(supportFragmentManager, EpisodeListDialogFragment.TAG)
}
private fun showLanguageSettings() {

68
app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/EpisodeListDialogFragment.kt

@ -0,0 +1,68 @@
package org.mosad.teapod.ui.activity.player.fragment
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.ViewModelProvider
import org.mosad.teapod.R
import org.mosad.teapod.databinding.PlayerEpisodesListBinding
import org.mosad.teapod.ui.activity.player.PlayerViewModel
import org.mosad.teapod.util.adapter.EpisodeItemAdapter
import org.mosad.teapod.util.hideBars
class EpisodeListDialogFragment : DialogFragment() {
private lateinit var model: PlayerViewModel
private lateinit var binding: PlayerEpisodesListBinding
companion object {
const val TAG = "LanguageSettingsDialogFragment"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, R.style.FullScreenDialogStyle)
model = ViewModelProvider(requireActivity())[PlayerViewModel::class.java]
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = PlayerEpisodesListBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.buttonCloseEpisodesList.setOnClickListener {
dismiss()
}
val adapterRecEpisodes = EpisodeItemAdapter(
model.episodes.items,
null,
mapOf(),
EpisodeItemAdapter.OnClickListener { episode ->
dismiss()
model.setCurrentEpisode(episode.id, startPlayback = true)
},
EpisodeItemAdapter.ViewType.PLAYER
)
// episodeNumber starts at 1, we need the episode index -> - 1
adapterRecEpisodes.currentSelected = model.currentEpisode.episodeNumber?.minus(1) ?: 0
binding.recyclerEpisodesPlayer.adapter = adapterRecEpisodes
binding.recyclerEpisodesPlayer.scrollToPosition(adapterRecEpisodes.currentSelected)
// initially hide the status and navigation bar
hideBars(requireDialog().window, binding.root)
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
model.player.play()
}
}

2
app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/LanguageSettingsDialogFragment.kt

@ -116,4 +116,4 @@ class LanguageSettingsDialogFragment : DialogFragment() {
compoundDrawablePadding = 12
}
}
}
}

48
app/src/main/java/org/mosad/teapod/ui/components/EpisodesListPlayer.kt

@ -1,48 +0,0 @@
package org.mosad.teapod.ui.components
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.LinearLayout
import org.mosad.teapod.databinding.PlayerEpisodesListBinding
import org.mosad.teapod.ui.activity.player.PlayerViewModel
import org.mosad.teapod.util.adapter.EpisodeItemAdapter
class EpisodesListPlayer @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
model: PlayerViewModel? = null
) : LinearLayout(context, attrs, defStyleAttr) {
private val binding = PlayerEpisodesListBinding.inflate(LayoutInflater.from(context), this, true)
var onViewRemovedAction: (() -> Unit)? = null // TODO find a better solution for this
init {
binding.buttonCloseEpisodesList.setOnClickListener {
(this.parent as ViewGroup).removeView(this)
onViewRemovedAction?.invoke()
}
model?.let {
val adapterRecEpisodes = EpisodeItemAdapter(
model.episodes.items,
null,
mapOf(),
EpisodeItemAdapter.OnClickListener { episode ->
(this.parent as ViewGroup).removeView(this)
model.setCurrentEpisode(episode.id, startPlayback = true)
},
EpisodeItemAdapter.ViewType.PLAYER
)
// episodeNumber starts at 1, we need the episode index -> - 1
adapterRecEpisodes.currentSelected = model.currentEpisode.episodeNumber?.minus(1) ?: 0
binding.recyclerEpisodesPlayer.adapter = adapterRecEpisodes
binding.recyclerEpisodesPlayer.scrollToPosition(adapterRecEpisodes.currentSelected)
}
}
}

2
app/src/main/java/org/mosad/teapod/util/Utils.kt

@ -61,7 +61,7 @@ fun hideBars(window: Window?, root: View) {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, root).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.navigationBars())
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
}

16
app/src/main/res/layout/player_controls.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#73000000">
@ -17,12 +18,12 @@
<ImageButton
android:id="@+id/exo_close_player"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@android:color/transparent"
android:scaleType="fitXY"
android:layout_width="44dp"
android:layout_height="44dp"
android:contentDescription="@string/close_player"
android:padding="10dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_baseline_arrow_back_24" />
<TextView
@ -32,8 +33,9 @@
android:layout_marginEnd="44dp"
android:text="@string/text_title_ex"
android:textAlignment="center"
android:textColor="@color/exo_white"
android:textSize="16sp" />
android:textColor="@color/player_white"
android:textSize="16sp"
tools:ignore="TextContrastCheck" />
</LinearLayout>
<LinearLayout
@ -90,12 +92,12 @@
android:layout_gravity="bottom"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="@dimen/exo_styled_progress_margin_bottom">
android:layout_marginBottom="@dimen/player_styled_progress_margin_bottom">
<View
android:id="@+id/exo_progress_placeholder"
android:layout_width="0dp"
android:layout_height="@dimen/exo_styled_progress_layout_height"
android:layout_height="@dimen/player_styled_progress_layout_height"
android:layout_marginBottom="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/exo_remaining"

5
app/src/main/res/values/dimens.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="player_styled_progress_layout_height">48dp</dimen>
<dimen name="player_styled_progress_margin_bottom">52dp</dimen>
</resources>
Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close