forked from github/szkolny
[UI/Events] Add button tooltips in dialogs. Add showing weekday in home card. Add 'go to timetable' button in details dialog.
This commit is contained in:
@ -18,6 +18,7 @@ import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@ -118,9 +119,43 @@ class EventDetailsDialog(
|
||||
)
|
||||
}
|
||||
|
||||
b.goToTimetableButton.setOnClickListener {
|
||||
dialog.dismiss()
|
||||
val dateStr = event.eventDate?.stringY_m_d ?: return@setOnClickListener
|
||||
|
||||
val intent =
|
||||
if (activity is MainActivity && activity.navTargetId == MainActivity.DRAWER_ITEM_TIMETABLE)
|
||||
Intent(TimetableFragment.ACTION_SCROLL_TO_DATE)
|
||||
else if (activity is MainActivity)
|
||||
Intent("android.intent.action.MAIN")
|
||||
else
|
||||
Intent(activity, MainActivity::class.java)
|
||||
|
||||
intent.apply {
|
||||
putExtra("fragmentId", MainActivity.DRAWER_ITEM_TIMETABLE)
|
||||
putExtra("timetableDate", dateStr)
|
||||
}
|
||||
if (activity is MainActivity)
|
||||
activity.sendBroadcast(intent)
|
||||
else
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
b.saveInCalendarButton.setOnClickListener {
|
||||
openInCalendar()
|
||||
}
|
||||
|
||||
b.goToTimetableButton.setOnLongClickListener {
|
||||
Toast.makeText(activity, R.string.hint_go_to_timetable, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
b.saveInCalendarButton.setOnLongClickListener {
|
||||
Toast.makeText(activity, R.string.hint_save_in_calendar, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
b.editButton.setOnLongClickListener {
|
||||
Toast.makeText(activity, R.string.hint_edit_event, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun showRemoveEventDialog() {
|
||||
|
@ -8,16 +8,19 @@ import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.databinding.EventListItemBinding
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
||||
class EventListAdapter(
|
||||
val context: Context,
|
||||
val simpleMode: Boolean = false,
|
||||
val showDate: Boolean = false,
|
||||
val showWeekDay: Boolean = false,
|
||||
val onItemClick: ((event: EventFull) -> Unit)? = null,
|
||||
val onEventEditClick: ((event: EventFull) -> Unit)? = null
|
||||
) : RecyclerView.Adapter<EventListAdapter.ViewHolder>() {
|
||||
@ -47,6 +50,7 @@ class EventListAdapter(
|
||||
b.topic.text = event.topic
|
||||
|
||||
b.details.text = mutableListOf<CharSequence?>(
|
||||
if (showWeekDay) Week.getFullDayName(event.eventDate.weekDay) else null,
|
||||
if (showDate) event.eventDate.getRelativeString(context, 7) ?: event.eventDate.formattedStringShort else null,
|
||||
event.typeName,
|
||||
if (simpleMode) null else event.startTime?.stringHM ?: app.getString(R.string.event_all_day),
|
||||
@ -70,11 +74,16 @@ class EventListAdapter(
|
||||
|
||||
b.typeColor.background?.setTintColor(event.getColor())
|
||||
|
||||
b.editButton.visibility = if (event.addedManually) View.VISIBLE else View.GONE
|
||||
b.editButton.visibility = if (event.addedManually && !simpleMode) View.VISIBLE else View.GONE
|
||||
b.editButton.onClick {
|
||||
onEventEditClick?.invoke(event)
|
||||
}
|
||||
|
||||
b.editButton.setOnLongClickListener {
|
||||
Toast.makeText(context, R.string.hint_edit_event, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
/*with(holder) {
|
||||
b.eventListItemRoot.background.colorFilter = when (event.type) {
|
||||
Event.TYPE_HOMEWORK -> PorterDuffColorFilter(0xffffffff.toInt(), PorterDuff.Mode.CLEAR)
|
||||
|
@ -61,6 +61,7 @@ class HomeEventsCard(
|
||||
activity,
|
||||
simpleMode = true,
|
||||
showDate = true,
|
||||
showWeekDay = true,
|
||||
onItemClick = {
|
||||
EventDetailsDialog(
|
||||
activity,
|
||||
|
Reference in New Issue
Block a user