feat(notifications): Add hint on notif remove & on no notifs
This commit is contained in:
parent
9aa6b5217d
commit
307afd1f0c
|
@ -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<NotificationResponse>
|
||||
private lateinit var invitations: MutableMap<String, InvitationResponse> // 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,4 +62,36 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
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>
|
||||
|
|
|
@ -79,4 +79,6 @@
|
|||
<string name="decline">Decline</string>
|
||||
<string name="notifications">Notifications</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>
|
Loading…
Reference in a new issue