feat(eventCard): Show event leave button on invited events

This commit is contained in:
Peter Vacho 2025-01-02 14:58:39 +01:00
parent 1a09a163e0
commit d434a533bf
Signed by: school
GPG key ID: 8CFC3837052871B4
5 changed files with 39 additions and 2 deletions

View file

@ -86,7 +86,7 @@ class DayViewActivity : AppCompatActivity() {
return
}
rvEvents.layoutManager = LinearLayoutManager(this)
rvEvents.adapter = EventCardAdapter(events, userId, this, ::onEventEdit, ::onEventDelete)
rvEvents.adapter = EventCardAdapter(events, userId, this, ::onEventEdit, ::onEventDelete, ::onEventLeave)
btnBack.setOnClickListener { finish() }
btnAddEvent.setOnClickListener { onEventCreate() }
@ -128,6 +128,17 @@ class DayViewActivity : AppCompatActivity() {
}
}
/**
* This is triggered on the leave button click from the event card adapter.
*
* This can be triggered for invited events only, delete equivalent.
*/
private fun onEventLeave(event: EventResponse, position: Int) {
TODO("API call for leaving event")
events.removeAt(position)
rvEvents.adapter!!.notifyItemRemoved(position)
}
/**
* Triggered with the CreateEventActivity return value.
*/

View file

@ -31,7 +31,8 @@ class EventCardAdapter(
private val userId: String,
private val lifecycleOwner: LifecycleOwner,
private val onEditEvent: (EventResponse, Int) -> Unit,
private val onDeleteEvent: (EventResponse, Int) -> Unit
private val onDeleteEvent: (EventResponse, Int) -> Unit,
private val onLeaveEvent: (EventResponse, Int) -> Unit,
) :
RecyclerView.Adapter<EventCardAdapter.EventViewHolder>() {
@ -43,6 +44,7 @@ class EventCardAdapter(
val eventColorIndicator: View = view.findViewById(R.id.eventColorIndicator)
val btnEdit: ImageButton = view.findViewById(R.id.btnEditEvent)
val btnDelete: ImageButton = view.findViewById(R.id.btnDeleteEvent)
val btnLeave: ImageButton = view.findViewById(R.id.btnLeaveEvent)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventViewHolder {
@ -69,6 +71,7 @@ class EventCardAdapter(
// Forward the Delete & Edit Button Clicks
holder.btnEdit.setOnClickListener { onEditEvent(event, position) }
holder.btnDelete.setOnClickListener { onDeleteEvent(event, position) }
holder.btnLeave.setOnClickListener { onLeaveEvent(event, position) }
// Initialize empty state for categories
holder.rvCategories.layoutManager =
@ -81,6 +84,7 @@ class EventCardAdapter(
if (event.owner_user_id != userId) {
holder.btnEdit.visibility = View.GONE
holder.btnDelete.visibility = View.GONE
holder.btnLeave.visibility = View.VISIBLE
} else {
// Fetch categories dynamically
fetchAndBindCategories(event.id, holder)

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M640,440v-80h240v80L640,440ZM360,480q-66,0 -113,-47t-47,-113q0,-66 47,-113t113,-47q66,0 113,47t47,113q0,66 -47,113t-113,47ZM40,800v-112q0,-34 17.5,-62.5T104,582q62,-31 126,-46.5T360,520q66,0 130,15.5T616,582q29,15 46.5,43.5T680,688v112L40,800ZM120,720h480v-32q0,-11 -5.5,-20T580,654q-54,-27 -109,-40.5T360,600q-56,0 -111,13.5T140,654q-9,5 -14.5,14t-5.5,20v32ZM360,400q33,0 56.5,-23.5T440,320q0,-33 -23.5,-56.5T360,240q-33,0 -56.5,23.5T280,320q0,33 23.5,56.5T360,400ZM360,320ZM360,720Z"
android:fillColor="#e8eaed"/>
</vector>

View file

@ -74,6 +74,18 @@
android:src="@drawable/ic_trashbin"
android:contentDescription="@string/delete_event"
app:tint="?android:attr/textColorSecondary" />
<!-- Leave Event Button (invited events only) -->
<ImageButton
android:id="@+id/btnLeaveEvent"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="4dp"
android:src="@drawable/ic_person_remove"
android:contentDescription="@string/leave_invited_event"
app:tint="?android:attr/textColorSecondary"
android:visibility="gone"/>
</LinearLayout>
<!-- Event Time -->

View file

@ -44,4 +44,5 @@
<string name="remove_category">Remove the category</string>
<string name="add_category">Add category</string>
<string name="update_event">Update Event</string>
<string name="leave_invited_event">Leave invited event</string>
</resources>