forked from github/szkolny
[Dialog/Events] Create adapter outside of the observer.
This commit is contained in:
parent
8482c27689
commit
8df24dc1c4
@ -23,12 +23,13 @@ import pl.szczodrzynski.edziennik.utils.models.Date
|
|||||||
|
|
||||||
class EventListAdapter(
|
class EventListAdapter(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
val eventList: List<EventFull>,
|
|
||||||
val parentDialog: EventListDialog
|
val parentDialog: EventListDialog
|
||||||
) : RecyclerView.Adapter<EventListAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<EventListAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val app by lazy { context.applicationContext as App }
|
private val app by lazy { context.applicationContext as App }
|
||||||
|
|
||||||
|
val eventList = mutableListOf<EventFull>()
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val inflater = LayoutInflater.from(parent.context)
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
val view: RowDialogEventListItemBinding = DataBindingUtil.inflate(inflater, R.layout.row_dialog_event_list_item, parent, false)
|
val view: RowDialogEventListItemBinding = DataBindingUtil.inflate(inflater, R.layout.row_dialog_event_list_item, parent, false)
|
||||||
|
@ -43,6 +43,7 @@ class EventListDialog(
|
|||||||
private val app by lazy { activity.application as App }
|
private val app by lazy { activity.application as App }
|
||||||
private lateinit var b: DialogEventListBinding
|
private lateinit var b: DialogEventListBinding
|
||||||
private lateinit var dialog: AlertDialog
|
private lateinit var dialog: AlertDialog
|
||||||
|
private lateinit var adapter: EventListAdapter
|
||||||
|
|
||||||
private var lesson: LessonFull? = null
|
private var lesson: LessonFull? = null
|
||||||
|
|
||||||
@ -111,16 +112,24 @@ class EventListDialog(
|
|||||||
b.eventListView.apply {
|
b.eventListView.apply {
|
||||||
setHasFixedSize(false)
|
setHasFixedSize(false)
|
||||||
isNestedScrollingEnabled = true
|
isNestedScrollingEnabled = true
|
||||||
layoutManager = LinearLayoutManager(context)
|
layoutManager = LinearLayoutManager(activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adapter = EventListAdapter(activity, this@EventListDialog)
|
||||||
|
b.eventListView.adapter = adapter
|
||||||
|
|
||||||
app.db.eventDao().getAllByDateTime(profileId, date, time).observe(activity, Observer { events ->
|
app.db.eventDao().getAllByDateTime(profileId, date, time).observe(activity, Observer { events ->
|
||||||
if (events.isNullOrEmpty()) {
|
if (events.isNullOrEmpty()) {
|
||||||
b.eventListView.visibility = View.GONE
|
b.eventListView.visibility = View.GONE
|
||||||
b.textNoEvents.visibility = View.VISIBLE
|
b.textNoEvents.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
val adapter = EventListAdapter(activity, events, this)
|
adapter.run {
|
||||||
b.eventListView.adapter = adapter
|
eventList.apply {
|
||||||
|
clear()
|
||||||
|
addAll(events)
|
||||||
|
}
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user