mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-27 06:30:29 +00:00
Touch: refactor download list
This commit is contained in:
parent
454a4fea3d
commit
91c0fb9e3a
4 changed files with 41 additions and 46 deletions
|
@ -44,7 +44,6 @@ import de.nicidienase.chaosflix.touch.settings.SettingsActivity
|
|||
class BrowseActivity : AppCompatActivity(),
|
||||
ConferencesTabBrowseFragment.OnInteractionListener,
|
||||
LivestreamListFragment.InteractionListener,
|
||||
DownloadsListFragment.InteractionListener,
|
||||
OnEventSelectedListener {
|
||||
|
||||
private var drawerOpen: Boolean = false
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package de.nicidienase.chaosflix.touch.browse.download
|
||||
|
||||
import android.arch.lifecycle.Observer
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
|
@ -9,54 +8,47 @@ import android.support.v7.widget.LinearLayoutManager
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import de.nicidienase.chaosflix.touch.browse.BrowseFragment
|
||||
import de.nicidienase.chaosflix.touch.databinding.FragmentDownloadsBinding
|
||||
import de.nicidienase.chaosflix.touch.eventdetails.EventDetailsActivity
|
||||
|
||||
class DownloadsListFragment : BrowseFragment() {
|
||||
|
||||
private lateinit var listener: InteractionListener
|
||||
private lateinit var binding: FragmentDownloadsBinding
|
||||
// private lateinit var binding: FragmentDownloadsBinding
|
||||
|
||||
private val handler = Handler()
|
||||
|
||||
private val UPDATE_DELAY = 700L
|
||||
private var columnCount = 1;
|
||||
private var columnCount = 1
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
columnCount = arguments?.getInt(ARG_COLUMN_COUNT) ?: 1
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context?) {
|
||||
super.onAttach(context)
|
||||
if (context is InteractionListener) {
|
||||
listener = context
|
||||
} else {
|
||||
throw RuntimeException(context.toString() + " must implement LivestreamListFragment.InteractionListener")
|
||||
}
|
||||
columnCount = arguments?.getInt(ARG_COLUMN_COUNT) ?: columnCount
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = FragmentDownloadsBinding.inflate(inflater, container, false)
|
||||
setupToolbar(binding.incToolbar?.toolbar!!, R.string.downloads)
|
||||
overlay = binding.incOverlay?.loadingOverlay
|
||||
val offlineEventAdapter = OfflineEventAdapter(emptyList(), viewModel, listener)
|
||||
binding.list.adapter = offlineEventAdapter
|
||||
if (columnCount <= 1) {
|
||||
binding.list.layoutManager = LinearLayoutManager(context)
|
||||
} else {
|
||||
binding.list.layoutManager = GridLayoutManager(context, columnCount - 1)
|
||||
}
|
||||
viewModel.getOfflineEvents().observe(this, Observer { events ->
|
||||
if (events != null) {
|
||||
offlineEventAdapter.items = events
|
||||
offlineEventAdapter.notifyDataSetChanged()
|
||||
setLoadingOverlayVisibility(false)
|
||||
with(FragmentDownloadsBinding.inflate(inflater, container, false)){
|
||||
setupToolbar(incToolbar.toolbar, R.string.downloads)
|
||||
overlay = incOverlay.loadingOverlay
|
||||
val offlineEventAdapter = OfflineEventAdapter(viewModel.offlineItemManager, viewModel::deleteOfflineItem) {
|
||||
EventDetailsActivity.launch(requireContext(), it)
|
||||
}
|
||||
})
|
||||
return binding.root
|
||||
list.adapter = offlineEventAdapter
|
||||
if (columnCount <= 1) {
|
||||
list.layoutManager = LinearLayoutManager(context)
|
||||
} else {
|
||||
list.layoutManager = GridLayoutManager(context, columnCount - 1)
|
||||
}
|
||||
viewModel.getOfflineEvents().observe(this@DownloadsListFragment, Observer { events ->
|
||||
if (events != null) {
|
||||
offlineEventAdapter.items = events
|
||||
} else {
|
||||
offlineEventAdapter.items = emptyList()
|
||||
}
|
||||
setLoadingOverlayVisibility(false)
|
||||
})
|
||||
return root
|
||||
}
|
||||
}
|
||||
|
||||
private var updateRunnable: Runnable? = null
|
||||
|
@ -93,7 +85,4 @@ class DownloadsListFragment : BrowseFragment() {
|
|||
return fragment
|
||||
}
|
||||
}
|
||||
|
||||
interface InteractionListener : OnEventSelectedListener {
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import de.nicidienase.chaosflix.common.OfflineItemManager
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEvent
|
||||
|
@ -14,10 +15,18 @@ import de.nicidienase.chaosflix.touch.databinding.ItemOfflineEventBinding
|
|||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.common.viewmodel.BrowseViewModel
|
||||
|
||||
class OfflineEventAdapter(var items: List<Pair<OfflineEvent, Event>>, val viewModel: BrowseViewModel, val listener: OnEventSelectedListener) :
|
||||
class OfflineEventAdapter(private val offlineItemManager: OfflineItemManager,
|
||||
private val eventDeleteListener: (OfflineEvent) -> Unit,
|
||||
private val eventSelectedListener: (Event)->Unit) :
|
||||
RecyclerView.Adapter<OfflineEventAdapter.ViewHolder>() {
|
||||
|
||||
override fun onBindViewHolder(holder: OfflineEventAdapter.ViewHolder, position: Int) {
|
||||
var items: List<Pair<OfflineEvent, Event>> = emptyList()
|
||||
set(value) {
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = items[position]
|
||||
|
||||
holder.binding.event = item.second
|
||||
|
@ -27,12 +36,12 @@ class OfflineEventAdapter(var items: List<Pair<OfflineEvent, Event>>, val viewMo
|
|||
.into(holder.thumbnail)
|
||||
|
||||
with(holder.binding){
|
||||
downloadStatus = viewModel.offlineItemManager.downloadStatus[item.first.downloadReference]
|
||||
downloadStatus = offlineItemManager.downloadStatus[item.first.downloadReference]
|
||||
buttonDelete.setOnClickListener {
|
||||
viewModel.deleteOfflineItem(item.first)
|
||||
eventDeleteListener(item.first)
|
||||
}
|
||||
content?.setOnClickListener { _ ->
|
||||
listener.onEventSelected(item.second)
|
||||
eventSelectedListener(item.second)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,16 +81,14 @@ class EventDetailsFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
val binding = FragmentEventDetailsBinding.bind(view)
|
||||
binding.event = event
|
||||
binding.playFab.setOnClickListener { _ -> play() }
|
||||
binding.playFab.setOnClickListener { play() }
|
||||
if (listener != null) {
|
||||
(activity as AppCompatActivity).setSupportActionBar(binding.animToolbar)
|
||||
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
||||
binding.relatedItemsList.apply {
|
||||
// relatedEventsAdapter = RelatedEventsRecyclerViewAdapter(listener)
|
||||
relatedEventsAdapter = EventRecyclerViewAdapter(){
|
||||
// viewModel.playEvent(it)
|
||||
relatedEventsAdapter = EventRecyclerViewAdapter {
|
||||
viewModel.relatedEventSelected(it)
|
||||
}
|
||||
adapter = relatedEventsAdapter
|
||||
|
|
Loading…
Reference in a new issue