mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-06-11 05:00:46 +02:00
[UI] Implement new Event Adapter and Day Dialog (partially).
This commit is contained in:
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-12-16.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.day
|
||||
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogDayBinding
|
||||
import pl.szczodrzynski.edziennik.onClick
|
||||
import pl.szczodrzynski.edziennik.setText
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
|
||||
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class DayDialog(
|
||||
val activity: AppCompatActivity,
|
||||
val profileId: Int,
|
||||
val date: Date,
|
||||
val onShowListener: ((tag: String) -> Unit)? = null,
|
||||
val onDismissListener: ((tag: String) -> Unit)? = null
|
||||
) : CoroutineScope {
|
||||
companion object {
|
||||
private const val TAG = "DayDialog"
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var b: DialogDayBinding
|
||||
private lateinit var dialog: AlertDialog
|
||||
|
||||
private val job = Job()
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Main
|
||||
|
||||
private lateinit var adapter: EventListAdapter
|
||||
|
||||
init { run {
|
||||
if (activity.isFinishing)
|
||||
return@run
|
||||
onShowListener?.invoke(TAG)
|
||||
app = activity.applicationContext as App
|
||||
b = DialogDayBinding.inflate(activity.layoutInflater)
|
||||
dialog = MaterialAlertDialogBuilder(activity)
|
||||
.setView(b.root)
|
||||
.setPositiveButton(R.string.close) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNeutralButton(R.string.add, null)
|
||||
.setOnDismissListener {
|
||||
onDismissListener?.invoke(TAG)
|
||||
}
|
||||
.show()
|
||||
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL)?.onClick {
|
||||
EventManualDialog(
|
||||
activity,
|
||||
profileId,
|
||||
defaultDate = date,
|
||||
onShowListener = onShowListener,
|
||||
onDismissListener = onDismissListener
|
||||
)
|
||||
}
|
||||
|
||||
update()
|
||||
}}
|
||||
|
||||
private fun update() {
|
||||
b.dayDate.setText(
|
||||
R.string.dialog_day_date_format,
|
||||
Week.getFullDayName(date.weekDay),
|
||||
date.formattedString
|
||||
)
|
||||
|
||||
adapter = EventListAdapter(
|
||||
activity,
|
||||
onItemClick = {
|
||||
Toast.makeText(activity, "Event clicked ${it.topic}", Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
onEventEditClick = {
|
||||
EventManualDialog(
|
||||
activity,
|
||||
profileId,
|
||||
editingEvent = it,
|
||||
onShowListener = onShowListener,
|
||||
onDismissListener = onDismissListener
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
app.db.eventDao().getAllByDate(profileId, date).observe(activity, Observer { events ->
|
||||
adapter.items = events
|
||||
if (b.eventsView.adapter == null) {
|
||||
b.eventsView.adapter = adapter
|
||||
b.eventsView.apply {
|
||||
setHasFixedSize(true)
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
addItemDecoration(SimpleDividerItemDecoration(context))
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
|
||||
if (events != null && events.isNotEmpty()) {
|
||||
b.eventsView.visibility = View.VISIBLE
|
||||
b.eventsNoData.visibility = View.GONE
|
||||
} else {
|
||||
b.eventsView.visibility = View.GONE
|
||||
b.eventsNoData.visibility = View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -5,41 +5,72 @@
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.event
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||
import pl.szczodrzynski.edziennik.databinding.RowDialogEventListItemBinding
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.bs
|
||||
import pl.szczodrzynski.edziennik.databinding.EventListItemBinding
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class EventListAdapter(
|
||||
val context: Context,
|
||||
val parentDialog: EventListDialog
|
||||
val onItemClick: ((event: EventFull) -> Unit)? = null,
|
||||
val onEventEditClick: ((event: EventFull) -> Unit)? = null
|
||||
) : RecyclerView.Adapter<EventListAdapter.ViewHolder>() {
|
||||
|
||||
private val app by lazy { context.applicationContext as App }
|
||||
|
||||
val eventList = mutableListOf<EventFull>()
|
||||
var items = listOf<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)
|
||||
val view = EventListItemBinding.inflate(inflater, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val event = eventList[position]
|
||||
val event = items[position]
|
||||
val b = holder.b
|
||||
|
||||
holder.apply {
|
||||
b.root.onClick {
|
||||
onItemClick?.invoke(event)
|
||||
}
|
||||
|
||||
val bullet = " • "
|
||||
|
||||
b.topic.text = event.topic
|
||||
|
||||
b.details.text = mutableListOf<CharSequence?>(
|
||||
event.typeName,
|
||||
event.startTime?.stringHM ?: app.getString(R.string.event_all_day),
|
||||
event.subjectLongName
|
||||
).concat(bullet)
|
||||
|
||||
b.addedBy.setText(
|
||||
when (event.sharedBy) {
|
||||
null -> when {
|
||||
event.addedManually -> R.string.event_list_added_by_self_format
|
||||
event.teacherFullName == null -> R.string.event_list_added_by_unknown_format
|
||||
else -> R.string.event_list_added_by_format
|
||||
}
|
||||
"self" -> R.string.event_list_shared_by_self_format
|
||||
else -> R.string.event_list_shared_by_format
|
||||
},
|
||||
Date.fromMillis(event.addedDate).formattedString,
|
||||
event.sharedByName ?: event.teacherFullName ?: "",
|
||||
event.teamName?.let { bullet+it } ?: ""
|
||||
)
|
||||
|
||||
b.typeColor.background?.setTintColor(event.getColor())
|
||||
|
||||
b.editButton.visibility = if (event.addedManually) View.VISIBLE else View.GONE
|
||||
b.editButton.onClick {
|
||||
onEventEditClick?.invoke(event)
|
||||
}
|
||||
|
||||
/*with(holder) {
|
||||
b.eventListItemRoot.background.colorFilter = when (event.type) {
|
||||
Event.TYPE_HOMEWORK -> PorterDuffColorFilter(0xffffffff.toInt(), PorterDuff.Mode.CLEAR)
|
||||
else -> PorterDuffColorFilter(event.color, PorterDuff.Mode.MULTIPLY)
|
||||
@ -67,10 +98,10 @@ class EventListAdapter(
|
||||
onDismissListener = parentDialog.onDismissListener
|
||||
)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = eventList.size
|
||||
override fun getItemCount() = items.size
|
||||
|
||||
class ViewHolder(val b: RowDialogEventListItemBinding) : RecyclerView.ViewHolder(b.root)
|
||||
class ViewHolder(val b: EventListItemBinding) : RecyclerView.ViewHolder(b.root)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package pl.szczodrzynski.edziennik.ui.dialogs.event
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
@ -117,7 +118,9 @@ class EventListDialog(
|
||||
layoutManager = LinearLayoutManager(activity)
|
||||
}
|
||||
|
||||
adapter = EventListAdapter(activity, this@EventListDialog)
|
||||
adapter = EventListAdapter(activity) {
|
||||
Toast.makeText(activity, "Event clicked ${it.topic}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
b.eventListView.adapter = adapter
|
||||
|
||||
app.db.eventDao().getAllByDateTime(profileId, date, time).observe(activity, Observer { events ->
|
||||
@ -126,10 +129,10 @@ class EventListDialog(
|
||||
b.textNoEvents.visibility = View.VISIBLE
|
||||
} else {
|
||||
adapter.run {
|
||||
eventList.apply {
|
||||
/*items.apply {
|
||||
clear()
|
||||
addAll(events)
|
||||
}
|
||||
}*/
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ class EventManualDialog(
|
||||
saveEvent()
|
||||
}
|
||||
|
||||
val negativeButton = dialog.getButton(BUTTON_NEUTRAL)
|
||||
negativeButton?.setOnClickListener {
|
||||
val neutralButton = dialog.getButton(BUTTON_NEUTRAL)
|
||||
neutralButton?.setOnClickListener {
|
||||
showRemoveEventDialog()
|
||||
}
|
||||
}
|
||||
|
@ -50,24 +50,6 @@ class LessonDetailsDialog(
|
||||
onShowListener = onShowListener,
|
||||
onDismissListener = onDismissListener
|
||||
)
|
||||
/*MaterialAlertDialogBuilder(activity)
|
||||
.setItems(R.array.main_menu_add_options) { dialog2, which ->
|
||||
dialog2.dismiss()
|
||||
EventManualDialogOld(activity, lesson.profileId)
|
||||
.show(
|
||||
activity.application as App,
|
||||
null,
|
||||
lesson.displayDate,
|
||||
lesson.displayStartTime,
|
||||
when (which) {
|
||||
1 -> EventManualDialogOld.DIALOG_HOMEWORK
|
||||
else -> EventManualDialogOld.DIALOG_EVENT
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
.setNegativeButton(R.string.cancel) { dialog2, _ -> dialog2.dismiss() }
|
||||
.show()*/
|
||||
}
|
||||
.setOnDismissListener {
|
||||
onDismissListener?.invoke(TAG)
|
||||
|
@ -42,7 +42,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceFull;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaCalendarBinding;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.day.DayDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog;
|
||||
@ -56,7 +56,6 @@ import pl.szczodrzynski.edziennik.utils.Colors;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem;
|
||||
|
||||
@ -332,7 +331,7 @@ public class AgendaFragment extends Fragment {
|
||||
@Override
|
||||
public void onEventSelected(CalendarEvent calendarEvent) {
|
||||
if (calendarEvent instanceof BaseCalendarEvent) {
|
||||
if (!calendarEvent.isPlaceholder() && !calendarEvent.isAllDay()) {
|
||||
/*if (!calendarEvent.isPlaceholder() && !calendarEvent.isAllDay()) {
|
||||
// new EventListDialogOld(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()), Time.fromMillis(calendarEvent.getStartTime().getTimeInMillis()), true);
|
||||
new EventListDialog(
|
||||
activity,
|
||||
@ -341,16 +340,23 @@ public class AgendaFragment extends Fragment {
|
||||
Time.fromMillis(calendarEvent.getStartTime().getTimeInMillis()),
|
||||
null,
|
||||
null);
|
||||
} else {
|
||||
} else {*/
|
||||
// new EventListDialogOld(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
|
||||
new EventListDialog(
|
||||
new DayDialog(
|
||||
activity,
|
||||
App.profileId,
|
||||
Date.fromCalendar(calendarEvent.getInstanceDay()),
|
||||
null,
|
||||
null
|
||||
);
|
||||
/*new EventListDialog(
|
||||
activity,
|
||||
App.profileId,
|
||||
Date.fromCalendar(calendarEvent.getInstanceDay()),
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
null);*/
|
||||
//}
|
||||
} else if (calendarEvent instanceof LessonChangeEvent) {
|
||||
new LessonChangeDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
|
||||
//Toast.makeText(app, "Clicked "+((LessonChangeEvent) calendarEvent).getLessonChangeDate().getFormattedString(), Toast.LENGTH_SHORT).show();
|
||||
@ -434,15 +440,22 @@ public class AgendaFragment extends Fragment {
|
||||
unreadEventDates.remove((Integer) scrolledDate);
|
||||
}
|
||||
|
||||
new DayDialog(
|
||||
activity,
|
||||
App.profileId,
|
||||
dayDate,
|
||||
null,
|
||||
null
|
||||
);
|
||||
// new EventListDialogOld(getContext()).show(app, dayDate);
|
||||
new EventListDialog(
|
||||
/*new EventListDialog(
|
||||
activity,
|
||||
App.profileId,
|
||||
dayDate,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
);*/
|
||||
});
|
||||
b_calendar.progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
Reference in New Issue
Block a user