diff --git a/app/src/main/java/com/p_vacho/neat_calendar/activities/NotificationsActivity.kt b/app/src/main/java/com/p_vacho/neat_calendar/activities/NotificationsActivity.kt index 9bb64de..1865238 100644 --- a/app/src/main/java/com/p_vacho/neat_calendar/activities/NotificationsActivity.kt +++ b/app/src/main/java/com/p_vacho/neat_calendar/activities/NotificationsActivity.kt @@ -1,21 +1,77 @@ package com.p_vacho.neat_calendar.activities import android.os.Bundle +import android.widget.ImageButton import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.p_vacho.neat_calendar.R +import com.p_vacho.neat_calendar.adapters.NotificationAdapter +import com.p_vacho.neat_calendar.api.models.NotificationResponse +import java.time.OffsetDateTime class NotificationsActivity : AppCompatActivity() { + private lateinit var rvNotifications: RecyclerView + private lateinit var btnBack: ImageButton + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() - setContentView(R.layout.activity_notification) + setContentView(R.layout.activity_notifications) + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) insets } + + rvNotifications = findViewById(R.id.rvNotifications) + btnBack = findViewById(R.id.btnBack) + + val notifications = fetchNotifications() + val adapter = NotificationAdapter(notifications, ::handleNotificationAction, ::handleNotificationClick) + rvNotifications.layoutManager = LinearLayoutManager(this) + rvNotifications.adapter = adapter + + btnBack.setOnClickListener { finish() } } -} \ No newline at end of file + + private fun fetchNotifications(): List { + // TODO: Replace with actual API calls + return listOf( + NotificationResponse( + "1", "2", "invitation", + "You've been invited to event X", + "12", false, OffsetDateTime.now(), null + ), + NotificationResponse( + "2", "2", "message", + "System maintenance scheduled", + "", false, OffsetDateTime.now(), null + ), + NotificationResponse( + "2", "2", "message", + "App update available", + "", true, OffsetDateTime.now(), null + ), + ) + } + + private fun handleNotificationAction(notification: NotificationResponse, action: NotificationAdapter.Action, position: Int) { + when (action) { + NotificationAdapter.Action.ACCEPT -> { + //TODO("Handle accept action") + } + NotificationAdapter.Action.DECLINE -> { + //TODO("Handle decline action") + } + } + } + + private fun handleNotificationClick(notification: NotificationResponse, position: Int) { + TODO("Handle marking notification as read") + } +} diff --git a/app/src/main/java/com/p_vacho/neat_calendar/adapters/NotificationAdapter.kt b/app/src/main/java/com/p_vacho/neat_calendar/adapters/NotificationAdapter.kt new file mode 100644 index 0000000..9e6fee6 --- /dev/null +++ b/app/src/main/java/com/p_vacho/neat_calendar/adapters/NotificationAdapter.kt @@ -0,0 +1,68 @@ +package com.p_vacho.neat_calendar.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageButton +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.p_vacho.neat_calendar.R +import com.p_vacho.neat_calendar.api.models.NotificationResponse + +class NotificationAdapter( + private val notifications: List, + private val onActionClick: (NotificationResponse, Action, Int) -> Unit, + private val onNotificationClick: (NotificationResponse, Int) -> Unit, +) : RecyclerView.Adapter() { + + enum class Action { + ACCEPT, DECLINE + } + + inner class NotificationViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val message: TextView = view.findViewById(R.id.notificationMessage) + val acceptButton: ImageButton = view.findViewById(R.id.acceptButton) + val declineButton: ImageButton = view.findViewById(R.id.declineButton) + val invitationActions: View = view.findViewById(R.id.invitationActions) + val unreadIndicator: View = view.findViewById(R.id.notificationIndicator) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.item_notification, parent, false) + return NotificationViewHolder(view) + } + + override fun onBindViewHolder(holder: NotificationViewHolder, position: Int) { + val notification = notifications[position] + + holder.message.text = notification.message + + // Set visibility based on read/unread status + holder.unreadIndicator.visibility = if (notification.read) View.GONE else View.VISIBLE + + // Handle invitation actions + if (notification.event_type == "invitation") { + holder.invitationActions.visibility = View.VISIBLE + holder.acceptButton.setOnClickListener { + onActionClick(notification, Action.ACCEPT, position) + } + holder.declineButton.setOnClickListener { + onActionClick(notification, Action.DECLINE, position) + } + } else { + holder.invitationActions.visibility = View.GONE + } + + // Set click listener for the whole notification (excluding buttons) + holder.itemView.setOnClickListener { + onNotificationClick(notification, position) + } + + // Ensure buttons consume their click events + holder.acceptButton.isClickable = true + holder.declineButton.isClickable = true + } + + override fun getItemCount(): Int = notifications.size +} diff --git a/app/src/main/java/com/p_vacho/neat_calendar/api/models/NotificationModels.kt b/app/src/main/java/com/p_vacho/neat_calendar/api/models/NotificationModels.kt index e21d0bc..8d16820 100644 --- a/app/src/main/java/com/p_vacho/neat_calendar/api/models/NotificationModels.kt +++ b/app/src/main/java/com/p_vacho/neat_calendar/api/models/NotificationModels.kt @@ -5,7 +5,7 @@ import java.time.OffsetDateTime data class NotificationResponse( val id: String, val user_id: String, - val event_type: String, // "reminder" / "invitation" + val event_type: String, // "message" / "invitation" val message: String, val data: String, val read: Boolean, diff --git a/app/src/main/res/drawable/bg_notification_item_ripple.xml b/app/src/main/res/drawable/bg_notification_item_ripple.xml new file mode 100644 index 0000000..675d0e9 --- /dev/null +++ b/app/src/main/res/drawable/bg_notification_item_ripple.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_check.xml b/app/src/main/res/drawable/ic_check.xml new file mode 100644 index 0000000..73c17d8 --- /dev/null +++ b/app/src/main/res/drawable/ic_check.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_visibility.xml b/app/src/main/res/drawable/ic_visibility.xml new file mode 100644 index 0000000..c9e095f --- /dev/null +++ b/app/src/main/res/drawable/ic_visibility.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_notification.xml b/app/src/main/res/layout/activity_notification.xml deleted file mode 100644 index 7714bee..0000000 --- a/app/src/main/res/layout/activity_notification.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_notifications.xml b/app/src/main/res/layout/activity_notifications.xml new file mode 100644 index 0000000..b83489f --- /dev/null +++ b/app/src/main/res/layout/activity_notifications.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/item_notification.xml b/app/src/main/res/layout/item_notification.xml new file mode 100644 index 0000000..1ddd245 --- /dev/null +++ b/app/src/main/res/layout/item_notification.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6ecdb08..751b51f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,5 @@ #121212 #0035D0 + #bb6633 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 612c4ae..efa3806 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -75,4 +75,8 @@ Choose Event Color Select Time Manage categories + Accept + Decline + Notifications + View Event \ No newline at end of file