mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[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(
|
||||
val context: Context,
|
||||
val eventList: List<EventFull>,
|
||||
val parentDialog: EventListDialog
|
||||
) : RecyclerView.Adapter<EventListAdapter.ViewHolder>() {
|
||||
|
||||
private val app by lazy { context.applicationContext as App }
|
||||
|
||||
val eventList = mutableListOf<EventFull>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
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 lateinit var b: DialogEventListBinding
|
||||
private lateinit var dialog: AlertDialog
|
||||
private lateinit var adapter: EventListAdapter
|
||||
|
||||
private var lesson: LessonFull? = null
|
||||
|
||||
@ -111,16 +112,24 @@ class EventListDialog(
|
||||
b.eventListView.apply {
|
||||
setHasFixedSize(false)
|
||||
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 ->
|
||||
if (events.isNullOrEmpty()) {
|
||||
b.eventListView.visibility = View.GONE
|
||||
b.textNoEvents.visibility = View.VISIBLE
|
||||
} else {
|
||||
val adapter = EventListAdapter(activity, events, this)
|
||||
b.eventListView.adapter = adapter
|
||||
adapter.run {
|
||||
eventList.apply {
|
||||
clear()
|
||||
addAll(events)
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user