feat: Handle showing invited events
This commit is contained in:
parent
c1e3e09bf4
commit
1a09a163e0
|
@ -2,6 +2,7 @@ package com.p_vacho.neat_calendar.activities
|
|||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
|
@ -11,6 +12,7 @@ import androidx.core.view.WindowInsetsCompat
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.p_vacho.neat_calendar.MyApplication
|
||||
import com.p_vacho.neat_calendar.R
|
||||
import com.p_vacho.neat_calendar.adapters.EventCardAdapter
|
||||
import com.p_vacho.neat_calendar.api.RetrofitClient
|
||||
|
@ -77,8 +79,14 @@ class DayViewActivity : AppCompatActivity() {
|
|||
// Setup UI
|
||||
tvDate.text = calendarDay.date.toString()
|
||||
|
||||
val userId = (application as MyApplication).tokenManager.userId
|
||||
if (userId == null) {
|
||||
Log.e("DayViewActivity", "Exiting activity, user id is null")
|
||||
finish()
|
||||
return
|
||||
}
|
||||
rvEvents.layoutManager = LinearLayoutManager(this)
|
||||
rvEvents.adapter = EventCardAdapter(events, this, ::onEventEdit, ::onEventDelete)
|
||||
rvEvents.adapter = EventCardAdapter(events, userId, this, ::onEventEdit, ::onEventDelete)
|
||||
|
||||
btnBack.setOnClickListener { finish() }
|
||||
btnAddEvent.setOnClickListener { onEventCreate() }
|
||||
|
|
|
@ -11,6 +11,8 @@ import androidx.lifecycle.LifecycleOwner
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.transition.Visibility
|
||||
import com.p_vacho.neat_calendar.MyApplication
|
||||
import com.p_vacho.neat_calendar.R
|
||||
import com.p_vacho.neat_calendar.activities.CreateEventActivity
|
||||
import com.p_vacho.neat_calendar.activities.EventMode
|
||||
|
@ -26,6 +28,7 @@ import java.util.Locale
|
|||
|
||||
class EventCardAdapter(
|
||||
private val events: MutableList<EventResponse>,
|
||||
private val userId: String,
|
||||
private val lifecycleOwner: LifecycleOwner,
|
||||
private val onEditEvent: (EventResponse, Int) -> Unit,
|
||||
private val onDeleteEvent: (EventResponse, Int) -> Unit
|
||||
|
@ -72,8 +75,16 @@ class EventCardAdapter(
|
|||
LinearLayoutManager(holder.itemView.context, LinearLayoutManager.HORIZONTAL, false)
|
||||
holder.rvCategories.adapter = CategoryChipAdapter(emptyList())
|
||||
|
||||
// Fetch categories dynamically
|
||||
fetchAndBindCategories(event.id, holder)
|
||||
// Events list might contain events that are owned by others (invited events)
|
||||
// we can't show the categories & edit / delete buttons for these, as we don't
|
||||
// have rights for that.
|
||||
if (event.owner_user_id != userId) {
|
||||
holder.btnEdit.visibility = View.GONE
|
||||
holder.btnDelete.visibility = View.GONE
|
||||
} else {
|
||||
// Fetch categories dynamically
|
||||
fetchAndBindCategories(event.id, holder)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = events.size
|
||||
|
|
Loading…
Reference in a new issue