mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-27 14:41:28 +00:00
Touch: use databinding for Conference- and Event-Lists
This commit is contained in:
parent
818db73d44
commit
537391a458
12 changed files with 182 additions and 159 deletions
|
@ -123,7 +123,10 @@ dependencies {
|
|||
}
|
||||
implementation 'com.google.android.exoplayer:exoplayer:r2.5.2'
|
||||
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.0'
|
||||
|
||||
implementation 'com.github.bumptech.glide:glide:4.6.1'
|
||||
implementation 'com.squareup.picasso:picasso:2.5.2'
|
||||
|
||||
implementation 'net.opacapp:multiline-collapsingtoolbar:27.1.1'
|
||||
implementation 'net.rdrei.android.dirchooser:library:3.2@aar'
|
||||
// implementation 'com.gu:option:1.3'
|
||||
|
|
|
@ -2,14 +2,14 @@ package de.nicidienase.chaosflix.touch
|
|||
|
||||
import android.databinding.BindingAdapter
|
||||
import android.widget.ImageView
|
||||
import com.squareup.picasso.Picasso
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
|
||||
|
||||
@BindingAdapter("bind:imageUrl")
|
||||
fun loadImage(imageView: ImageView, url: String){
|
||||
Picasso.with(imageView.context)
|
||||
Glide.with(imageView.context)
|
||||
.load(url)
|
||||
.fit()
|
||||
.centerInside()
|
||||
.apply(RequestOptions().fitCenter())
|
||||
.into(imageView)
|
||||
}
|
|
@ -74,7 +74,7 @@ public class ConferenceGroupFragment extends BrowseFragment {
|
|||
if(conferenceList.size() > 0){
|
||||
setLoadingOverlayVisibility(false);
|
||||
}
|
||||
conferencesAdapter.setItems(conferenceList);
|
||||
conferencesAdapter.setConferences(conferenceList);
|
||||
Parcelable layoutState = getArguments().getParcelable(LAYOUTMANAGER_STATE);
|
||||
if (layoutState != null) {
|
||||
layoutManager.onRestoreInstanceState(layoutState);
|
||||
|
|
|
@ -10,18 +10,18 @@ import de.nicidienase.chaosflix.touch.databinding.ItemConferenceCardviewBinding
|
|||
class ConferenceRecyclerViewAdapter(private val mListener: ConferencesTabBrowseFragment.OnInteractionListener?) :
|
||||
RecyclerView.Adapter<ConferenceRecyclerViewAdapter.ViewHolder>() {
|
||||
|
||||
var items: List<Conference> = ArrayList()
|
||||
var conferences: List<Conference> = emptyList()
|
||||
set(value) {
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.size
|
||||
override fun getItemCount() = conferences.size
|
||||
|
||||
class ViewHolder(val binding: ItemConferenceCardviewBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return items.get(position).id
|
||||
return conferences.get(position).id
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
|
@ -30,10 +30,10 @@ class ConferenceRecyclerViewAdapter(private val mListener: ConferencesTabBrowseF
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.binding.conference = items[position]
|
||||
holder.binding.conference = conferences[position]
|
||||
|
||||
holder.binding.root.setOnClickListener { _ ->
|
||||
mListener?.onConferenceSelected((items[position]))
|
||||
mListener?.onConferenceSelected((conferences[position]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package de.nicidienase.chaosflix.touch.browse.adapters
|
||||
|
||||
import android.support.v4.view.ViewCompat
|
||||
import android.view.View
|
||||
import com.squareup.picasso.Picasso
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.touch.databinding.ItemEventCardviewBinding
|
||||
import java.util.*
|
||||
|
||||
open class EventRecyclerViewAdapter(val listener: OnEventSelectedListener) :
|
||||
ItemRecyclerViewAdapter<Event>() {
|
||||
|
||||
ItemRecyclerViewAdapter<Event, EventRecyclerViewAdapter.ViewHolder>() {
|
||||
override fun getComparator(): Comparator<in Event>? {
|
||||
return Comparator { o1, o2 -> o1.title.compareTo(o2.title) }
|
||||
}
|
||||
|
@ -27,40 +27,22 @@ open class EventRecyclerViewAdapter(val listener: OnEventSelectedListener) :
|
|||
).filterNotNull()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(p0: ViewGroup, pItemConferenceCardviewBinding1: Int): ViewHolder {
|
||||
val binding = ItemEventCardviewBinding.inflate(LayoutInflater.from(p0.context), p0, false)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override val layout = R.layout.item_event_cardview
|
||||
var showTags: Boolean = false
|
||||
|
||||
override fun onBindViewHolder(holder: ItemRecyclerViewAdapter<Event>.ViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val event = items[position]
|
||||
holder.binding.event = event
|
||||
holder.binding.root.setOnClickListener {
|
||||
listener.onEventSelected(event)
|
||||
}
|
||||
|
||||
holder.titleText.text = event.title
|
||||
holder.subtitle.text = event.subtitle
|
||||
if (showTags) {
|
||||
val tagString = StringBuilder()
|
||||
for (tag in event.tags!!) {
|
||||
if (tagString.length > 0) {
|
||||
tagString.append(", ")
|
||||
ViewCompat.setTransitionName(holder.binding.titleText, "title_${event.guid}")
|
||||
ViewCompat.setTransitionName(holder.binding.subtitleText, "subtitle_${event.guid}")
|
||||
ViewCompat.setTransitionName(holder.binding.imageView, "thumb_${event.guid}")
|
||||
}
|
||||
tagString.append(tag)
|
||||
}
|
||||
holder.tag.text = tagString
|
||||
}
|
||||
Picasso.with(holder.icon.context)
|
||||
.load(event.thumbUrl)
|
||||
.noFade()
|
||||
.fit()
|
||||
.centerInside()
|
||||
.into(holder.icon)
|
||||
|
||||
val resources = holder.titleText.context.getResources()
|
||||
ViewCompat.setTransitionName(holder.titleText,
|
||||
resources.getString(R.string.title) + event.id)
|
||||
ViewCompat.setTransitionName(holder.subtitle,
|
||||
resources.getString(R.string.subtitle) + event.id)
|
||||
ViewCompat.setTransitionName(holder.icon,
|
||||
resources.getString(R.string.thumbnail) + event.id)
|
||||
|
||||
holder.mView.setOnClickListener({ _: View -> listener.onEventSelected(items[position]) })
|
||||
}
|
||||
inner class ViewHolder(val binding: ItemEventCardviewBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
}
|
||||
|
|
|
@ -11,10 +11,8 @@ import android.widget.TextView
|
|||
import de.nicidienase.chaosflix.touch.R
|
||||
import java.util.*
|
||||
|
||||
abstract class ItemRecyclerViewAdapter<T>()
|
||||
: RecyclerView.Adapter<ItemRecyclerViewAdapter<T>.ViewHolder>(), Filterable {
|
||||
|
||||
internal abstract val layout: Int
|
||||
abstract class ItemRecyclerViewAdapter<T,VH : RecyclerView.ViewHolder?>()
|
||||
: RecyclerView.Adapter<VH>(), Filterable {
|
||||
|
||||
abstract fun getComparator(): Comparator<in T>?
|
||||
|
||||
|
@ -52,23 +50,10 @@ abstract class ItemRecyclerViewAdapter<T>()
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(layout, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return filteredItems.size
|
||||
}
|
||||
|
||||
inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) {
|
||||
val icon: ImageView = mView.findViewById<View>(R.id.imageView) as ImageView
|
||||
val titleText: TextView = mView.findViewById<View>(R.id.title_text) as TextView
|
||||
val subtitle: TextView = mView.findViewById<View>(R.id.subtitle_text) as TextView
|
||||
val tag: TextView = mView.findViewById<View>(R.id.tag_text) as TextView
|
||||
}
|
||||
|
||||
inner class ItemFilter : Filter() {
|
||||
override fun performFiltering(filterText: CharSequence?): FilterResults {
|
||||
val filterResults = FilterResults()
|
||||
|
|
|
@ -117,7 +117,7 @@ public class EventsListFragment extends BrowseFragment implements SearchView.OnQ
|
|||
} else if (type == TYPE_EVENTS) {
|
||||
{
|
||||
setupToolbar(binding.incToolbar.toolbar, conference.getTitle(), false);
|
||||
eventAdapter.setShowTags(conference.getTagsUsefull());
|
||||
// eventAdapter.setShowTags(conference.getTagsUsefull());
|
||||
getViewModel().getEventsforConference(conference).observe(this, events -> {
|
||||
if(events != null){
|
||||
setEvents(events);
|
||||
|
|
|
@ -31,7 +31,6 @@ import de.nicidienase.chaosflix.common.viewmodel.DetailsViewModel
|
|||
import de.nicidienase.chaosflix.touch.databinding.FragmentEventDetailsBinding
|
||||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
|
||||
import de.nicidienase.chaosflix.touch.browse.adapters.EventRecyclerViewAdapter
|
||||
|
||||
class EventDetailsFragment : Fragment() {
|
||||
|
||||
|
@ -44,7 +43,7 @@ class EventDetailsFragment : Fragment() {
|
|||
private var selectDialog: AlertDialog? = null
|
||||
|
||||
private lateinit var viewModel: DetailsViewModel
|
||||
private lateinit var relatedEventsAdapter: EventRecyclerViewAdapter
|
||||
private lateinit var relatedEventsAdapter: RelatedEventsRecyclerViewAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -120,7 +119,9 @@ class EventDetailsFragment : Fragment() {
|
|||
|
||||
})
|
||||
viewModel.getRelatedEvents(event).observe(this, Observer {
|
||||
relatedEventsAdapter.items = ArrayList(it)
|
||||
if(it != null){
|
||||
relatedEventsAdapter.events = it
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.state.observe(this, Observer { liveEvent ->
|
||||
|
|
|
@ -1,9 +1,34 @@
|
|||
package de.nicidienase.chaosflix.touch.eventdetails
|
||||
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.touch.browse.adapters.EventRecyclerViewAdapter
|
||||
import de.nicidienase.chaosflix.touch.databinding.RelatedEventCardviewLayoutBinding
|
||||
|
||||
class RelatedEventsRecyclerViewAdapter(listener: OnEventSelectedListener) : EventRecyclerViewAdapter(listener) {
|
||||
override val layout = R.layout.related_event_cardview_layout
|
||||
class RelatedEventsRecyclerViewAdapter(listener: OnEventSelectedListener) : RecyclerView.Adapter<RelatedEventsRecyclerViewAdapter.ViewHolder>() {
|
||||
|
||||
init {
|
||||
setHasStableIds(true)
|
||||
}
|
||||
|
||||
var events: List<Event> = emptyList()
|
||||
set(value) {
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemCount() = events.size
|
||||
|
||||
override fun onCreateViewHolder(p0: ViewGroup, pItemConferenceCardviewBinding1: Int): ViewHolder {
|
||||
val binding = RelatedEventCardviewLayoutBinding.inflate(LayoutInflater.from(p0.context), p0, false)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||
viewHolder.binding.event = events[position]
|
||||
}
|
||||
|
||||
inner class ViewHolder(val binding: RelatedEventCardviewLayoutBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
}
|
|
@ -5,7 +5,9 @@
|
|||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="event"
|
||||
type="de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event"/>
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -52,7 +54,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:text=""
|
||||
android:text="@{event.title}"
|
||||
tools:text="Title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title"
|
||||
app:layout_constraintEnd_toEndOf="@+id/subtitle_text"
|
||||
|
@ -69,7 +71,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:text=""
|
||||
android:text="@{event.subtitle}"
|
||||
tools:text="subtitle"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tag_text"
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="event"
|
||||
type="de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event"/>
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -24,12 +26,25 @@
|
|||
android:layout_margin="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
imageUrl="@{event.thumbUrl}"
|
||||
android:layout_width="@dimen/thumbnail_width"
|
||||
android:layout_height="@dimen/thumbnail_height"
|
||||
android:scaleType="fitCenter"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<!--android:text="@{event.length}"-->
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -46,7 +61,7 @@
|
|||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_weight="1"
|
||||
android:text=""
|
||||
android:text="@{event.title}"
|
||||
tools:text="Title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
|
||||
|
||||
|
@ -55,7 +70,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text=""
|
||||
android:text="@{event.subtitle}"
|
||||
tools:text="Subtitle"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"/>
|
||||
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:card_view="http://schemas.android.com/tools"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
<variable
|
||||
name="event"
|
||||
type="de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event"/>
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
@ -28,6 +36,7 @@
|
|||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="14dp"
|
||||
imageUrl="@{event.thumbUrl}"
|
||||
android:contentDescription="@string/titleimage"
|
||||
android:scaleType="fitCenter"
|
||||
app:layout_constraintBottom_toTopOf="@+id/title_text"
|
||||
|
@ -43,7 +52,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:text=""
|
||||
android:text="@{event.title}"
|
||||
tools:text="Title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title"
|
||||
app:layout_constraintEnd_toEndOf="@+id/subtitle_text"
|
||||
|
@ -60,7 +69,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:text=""
|
||||
android:text="@{event.subtitle}"
|
||||
tools:text="subtitle"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tag_text"
|
||||
|
@ -85,4 +94,5 @@
|
|||
</android.support.constraint.ConstraintLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
Loading…
Reference in a new issue