Skip to content

Commit

Permalink
Display program info on channel list item long press
Browse files Browse the repository at this point in the history
  • Loading branch information
cemrich committed Dec 20, 2023
1 parent 8269535 commit ac0d722
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class ChannelPlayerActivity : AbstractPlayerActivity() {
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.menu_program_info -> {
val modalBottomSheet = ProgramInfoSheetDialogFragment(programInfoViewModel)
val modalBottomSheet = ProgramInfoSheetDialogFragment(
programInfoViewModel,
ProgramInfoSheetDialogFragment.Size.Small
)
modalBottomSheet.show(supportFragmentManager, ProgramInfoSheetDialogFragment.TAG)
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import de.christinecoenen.code.zapp.databinding.ProgramInfoSheetDialogFragmentBi
import kotlin.math.roundToInt

class ProgramInfoSheetDialogFragment(
private val programInfoViewModel: ProgramInfoViewModel
private val programInfoViewModel: ProgramInfoViewModel,
private val size: Size,
) : BottomSheetDialogFragment() {

enum class Size {
Small, Large
}

private var _binding: ProgramInfoSheetDialogFragmentBinding? = null
private val binding: ProgramInfoSheetDialogFragmentBinding get() = _binding!!

Expand All @@ -32,7 +37,9 @@ class ProgramInfoSheetDialogFragment(
programInfoViewModel.time.observe(this, ::onTimeChanged)
programInfoViewModel.progressPercent.observe(this, ::onProgressPercentChanged)

binding.root.viewTreeObserver.addOnGlobalLayoutListener(::updatePeekHeight)
if (size == Size.Small) {
binding.root.viewTreeObserver.addOnGlobalLayoutListener(::setMinimalPeekHeight)
}

return binding.root
}
Expand Down Expand Up @@ -81,7 +88,7 @@ class ProgramInfoSheetDialogFragment(
/**
* Sheet should reveal most important info only on initial show.
*/
private fun updatePeekHeight() {
private fun setMinimalPeekHeight() {
val behavior = (dialog as BottomSheetDialog).behavior
behavior.peekHeight = binding.showProgress.bottom + 20
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import de.christinecoenen.code.zapp.R
import de.christinecoenen.code.zapp.app.livestream.ui.ProgramInfoViewModel
import de.christinecoenen.code.zapp.app.livestream.ui.detail.ChannelPlayerActivity
import de.christinecoenen.code.zapp.app.livestream.ui.detail.ProgramInfoSheetDialogFragment
import de.christinecoenen.code.zapp.app.livestream.ui.list.adapter.BaseChannelListAdapter
import de.christinecoenen.code.zapp.app.livestream.ui.list.adapter.ChannelListAdapter
import de.christinecoenen.code.zapp.app.livestream.ui.list.adapter.ListItemListener
Expand Down Expand Up @@ -71,19 +73,39 @@ class ChannelListFragment : Fragment(), MenuProvider, ListItemListener {
startActivity(intent)
}

override fun onItemLongClick(channel: ChannelModel, view: View) {
override fun onItemLongClick(
channel: ChannelModel,
programInfoViewModel: ProgramInfoViewModel,
view: View
) {
val menu = PopupMenu(context, view, Gravity.TOP or Gravity.END)
menu.inflate(R.menu.channel_list_fragment_context)
menu.show()
menu.setOnMenuItemClickListener { menuItem -> onContextMenuItemClicked(menuItem, channel) }
menu.setOnMenuItemClickListener { menuItem ->
onContextMenuItemClicked(menuItem, channel, programInfoViewModel)
}
}

private fun onContextMenuItemClicked(menuItem: MenuItem, channel: ChannelModel): Boolean {
private fun onContextMenuItemClicked(
menuItem: MenuItem,
channel: ChannelModel,
programInfoViewModel: ProgramInfoViewModel
): Boolean {
return when (menuItem.itemId) {
R.id.menu_share -> {
channel.playExternally(requireContext())
true
}

R.id.menu_program_info -> {
val modalBottomSheet = ProgramInfoSheetDialogFragment(
programInfoViewModel,
ProgramInfoSheetDialogFragment.Size.Large
)
modalBottomSheet.show(parentFragmentManager, ProgramInfoSheetDialogFragment.TAG)
true
}

else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ChannelViewHolder(
}

override fun onLongClick(view: View): Boolean {
channel?.let { listener.onItemLongClick(it, view) }
channel?.let { listener.onItemLongClick(it, currentViewModel!!, view) }
return true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package de.christinecoenen.code.zapp.app.livestream.ui.list.adapter

import android.view.View
import de.christinecoenen.code.zapp.app.livestream.ui.ProgramInfoViewModel
import de.christinecoenen.code.zapp.models.channels.ChannelModel

interface ListItemListener {

fun onItemClick(channel: ChannelModel)

fun onItemLongClick(channel: ChannelModel, view: View)
fun onItemLongClick(channel: ChannelModel, programInfoViewModel: ProgramInfoViewModel, view: View)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import de.christinecoenen.code.zapp.app.livestream.ui.ProgramInfoViewModel
import de.christinecoenen.code.zapp.app.livestream.ui.list.adapter.ListItemListener
import de.christinecoenen.code.zapp.app.player.VideoInfo
import de.christinecoenen.code.zapp.databinding.TvFragmentChannelListBinding
Expand Down Expand Up @@ -36,7 +37,11 @@ class ChannelListFragment : Fragment(), ListItemListener {
startActivity(intent)
}

override fun onItemLongClick(channel: ChannelModel, view: View) {
override fun onItemLongClick(
channel: ChannelModel,
programInfoViewModel: ProgramInfoViewModel,
view: View
) {
// no action
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/menu/channel_list_fragment_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
android:icon="@drawable/ic_outline_share_24"
app:showAsAction="never"/>

<item
android:id="@+id/menu_program_info"
android:icon="@drawable/ic_outline_info_24"
android:title="@string/menu_program_info"
app:showAsAction="never" />

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/raw/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Absturz beim Starten von Zapp behoben, wenn vorher eine SD-Karte mit Downloads entfernt wurde
* Zapp auf Android 14 vorbereitet
* FAQ und Changelog ins Englische übersetzt (danke an eUgEntOptIc)
* Programm-Informationen sind per Kontext-Menüs der Sender-Liste aufrufbar

# 8.3.2
* Behoben, dass Download-Benachrichtigungen nicht die Sendung öffnen
Expand Down

0 comments on commit ac0d722

Please sign in to comment.