feat(notifications): Add hint on notif remove & on no notifs

This commit is contained in:
Peter Vacho 2025-01-04 20:27:52 +01:00
parent 9aa6b5217d
commit 307afd1f0c
Signed by: school
GPG key ID: 8CFC3837052871B4
3 changed files with 48 additions and 0 deletions

View file

@ -2,7 +2,9 @@ package com.p_vacho.neat_calendar.activities
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.View
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@ -33,6 +35,8 @@ import retrofit2.HttpException
class NotificationsActivity : AppCompatActivity() { class NotificationsActivity : AppCompatActivity() {
private lateinit var rvNotifications: RecyclerView private lateinit var rvNotifications: RecyclerView
private lateinit var btnBack: ImageButton private lateinit var btnBack: ImageButton
private lateinit var tvEmptyState: TextView
private lateinit var tvSwipeHint: TextView
private lateinit var notifications: MutableList<NotificationResponse> private lateinit var notifications: MutableList<NotificationResponse>
private lateinit var invitations: MutableMap<String, InvitationResponse> // invitation id -> invitation private lateinit var invitations: MutableMap<String, InvitationResponse> // invitation id -> invitation
@ -52,6 +56,8 @@ class NotificationsActivity : AppCompatActivity() {
rvNotifications = findViewById(R.id.rvNotifications) rvNotifications = findViewById(R.id.rvNotifications)
btnBack = findViewById(R.id.btnBack) btnBack = findViewById(R.id.btnBack)
tvEmptyState = findViewById(R.id.tvEmptyState)
tvSwipeHint = findViewById(R.id.tvSwipeHint)
btnBack.setOnClickListener { finish() } btnBack.setOnClickListener { finish() }
@ -78,6 +84,7 @@ class NotificationsActivity : AppCompatActivity() {
rvNotifications.adapter = adapter rvNotifications.adapter = adapter
setupSwipeToDelete(adapter) setupSwipeToDelete(adapter)
updateEmptyState()
} }
} }
@ -278,6 +285,7 @@ class NotificationsActivity : AppCompatActivity() {
notifications.removeAt(position) notifications.removeAt(position)
adapter.notifyItemRemoved(position) adapter.notifyItemRemoved(position)
Toast.makeText(this@NotificationsActivity, "Notification deleted", Toast.LENGTH_SHORT).show() Toast.makeText(this@NotificationsActivity, "Notification deleted", Toast.LENGTH_SHORT).show()
updateEmptyState()
} }
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
@ -293,4 +301,10 @@ class NotificationsActivity : AppCompatActivity() {
// Attach ItemTouchHelper to the RecyclerView // Attach ItemTouchHelper to the RecyclerView
itemTouchHelper.attachToRecyclerView(rvNotifications) 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
}
} }

View file

@ -62,4 +62,36 @@
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:layout_marginTop="8dp" /> android:layout_marginTop="8dp" />
<!-- Swipe Hint -->
<TextView
android:id="@+id/tvSwipeHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/swipe_to_delete_hint"
android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:gravity="center"
android:padding="16dp"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintTop_toBottomOf="@id/rvNotifications"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<!-- Empty State -->
<TextView
android:id="@+id/tvEmptyState"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/no_notifications"
android:textSize="16sp"
android:textColor="?android:attr/textColorSecondary"
android:gravity="center"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/titleBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -79,4 +79,6 @@
<string name="decline">Decline</string> <string name="decline">Decline</string>
<string name="notifications">Notifications</string> <string name="notifications">Notifications</string>
<string name="view_event">View Event</string> <string name="view_event">View Event</string>
<string name="swipe_to_delete_hint">Swipe right on a notification to delete it.</string>
<string name="no_notifications">You\'re all caught up! No notifications right now.</string>
</resources> </resources>