From 307afd1f0c03688f6828c59a77f49db67e69ce8f Mon Sep 17 00:00:00 2001 From: Peter Vacho Date: Sat, 4 Jan 2025 20:27:52 +0100 Subject: [PATCH] feat(notifications): Add hint on notif remove & on no notifs --- .../activities/NotificationsActivity.kt | 14 ++++++++ .../res/layout/activity_notifications.xml | 32 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 48 insertions(+) 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 c22c06b..79d3f1b 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 @@ -2,7 +2,9 @@ package com.p_vacho.neat_calendar.activities import android.os.Bundle import android.util.Log +import android.view.View import android.widget.ImageButton +import android.widget.TextView import android.widget.Toast import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity @@ -33,6 +35,8 @@ import retrofit2.HttpException class NotificationsActivity : AppCompatActivity() { private lateinit var rvNotifications: RecyclerView private lateinit var btnBack: ImageButton + private lateinit var tvEmptyState: TextView + private lateinit var tvSwipeHint: TextView private lateinit var notifications: MutableList private lateinit var invitations: MutableMap // invitation id -> invitation @@ -52,6 +56,8 @@ class NotificationsActivity : AppCompatActivity() { rvNotifications = findViewById(R.id.rvNotifications) btnBack = findViewById(R.id.btnBack) + tvEmptyState = findViewById(R.id.tvEmptyState) + tvSwipeHint = findViewById(R.id.tvSwipeHint) btnBack.setOnClickListener { finish() } @@ -78,6 +84,7 @@ class NotificationsActivity : AppCompatActivity() { rvNotifications.adapter = adapter setupSwipeToDelete(adapter) + updateEmptyState() } } @@ -278,6 +285,7 @@ class NotificationsActivity : AppCompatActivity() { notifications.removeAt(position) adapter.notifyItemRemoved(position) Toast.makeText(this@NotificationsActivity, "Notification deleted", Toast.LENGTH_SHORT).show() + updateEmptyState() } } catch (e: Exception) { withContext(Dispatchers.Main) { @@ -293,4 +301,10 @@ class NotificationsActivity : AppCompatActivity() { // Attach ItemTouchHelper to the RecyclerView itemTouchHelper.attachToRecyclerView(rvNotifications) } + + private fun updateEmptyState() { + val isEmpty = notifications.isEmpty() + tvEmptyState.visibility = if (isEmpty) View.VISIBLE else View.GONE + tvSwipeHint.visibility = if (isEmpty) View.GONE else View.VISIBLE + } } diff --git a/app/src/main/res/layout/activity_notifications.xml b/app/src/main/res/layout/activity_notifications.xml index b83489f..e0073ed 100644 --- a/app/src/main/res/layout/activity_notifications.xml +++ b/app/src/main/res/layout/activity_notifications.xml @@ -62,4 +62,36 @@ android:layout_marginBottom="16dp" android:layout_marginTop="8dp" /> + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index efa3806..e078925 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,4 +79,6 @@ Decline Notifications View Event + Swipe right on a notification to delete it. + You\'re all caught up! No notifications right now. \ No newline at end of file