Skip to content

Commit

Permalink
fix images appearing
Browse files Browse the repository at this point in the history
  • Loading branch information
rlam20 committed Jun 28, 2024
1 parent 9b1cdf5 commit c7b14ba
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.callback.NotificationCallback
import org.ole.planet.myplanet.databinding.RowNotificationBinding
import org.ole.planet.myplanet.model.Notifications

class AdapterNotification(
private val context: Context,
private val notificationList: MutableList<Notifications>,
private val callback: NotificationCallback,
private val showMarkAsReadButton: Boolean
private val showMarkAsReadButton: Boolean,
private val showImages: Boolean // Add this flag
) : RecyclerView.Adapter<AdapterNotification.ViewHolderNotification>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderNotification {
Expand All @@ -28,7 +27,7 @@ class AdapterNotification(
}

override fun onBindViewHolder(holder: ViewHolderNotification, position: Int) {
holder.bind(notificationList[position])
holder.bind(notificationList[position], showImages)
}

override fun getItemCount(): Int {
Expand All @@ -39,12 +38,21 @@ class AdapterNotification(
private val title: TextView = itemView.findViewById(R.id.title)
private val timestamp: TextView = itemView.findViewById(R.id.timestamp)
private val btnMarkAsRead: Button = itemView.findViewById(R.id.btn_mark_as_read)
private val icon: ImageView = itemView.findViewById(R.id.icon) // Reference to ImageView

fun bind(notification: Notifications) {
fun bind(notification: Notifications, showImages: Boolean) {
title.text = notification.text
timestamp.visibility = View.GONE // You can set the timestamp if available
btnMarkAsRead.visibility = if (showMarkAsReadButton) View.VISIBLE else View.GONE

// Conditionally show or hide the icon
if (showImages) {
icon.visibility = View.VISIBLE
icon.setImageResource(notification.icon)
} else {
icon.visibility = View.GONE
}

btnMarkAsRead.setOnClickListener {
markAsRead(bindingAdapterPosition)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ class NotificationFragment : BottomSheetDialogFragment() {
}
}


fragmentNotificationBinding.rvNotifications.adapter = AdapterNotification(
requireActivity(),
notificationList,
callback,
false,
true
)
fragmentNotificationBinding.rvNotifications.layoutManager = LinearLayoutManager(requireActivity())
fragmentNotificationBinding.rvNotifications.adapter = AdapterNotification(requireActivity(), notificationList, callback, false)
fragmentNotificationBinding.rvNotifications.adapter = AdapterNotification(requireActivity(), notificationList, callback, false, true)
fragmentNotificationBinding.rvNotifications.layoutManager = LinearLayoutManager(requireActivity())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SeeAllNotificationsFragment : Fragment() {
override fun downloadDictionary() {}
override fun showTaskListDialog() {}
override fun syncKeyId() {}
}, showMarkAsReadButton = true)
}, showMarkAsReadButton = true, false)

recyclerView.adapter = notificationsAdapter

Expand Down
65 changes: 34 additions & 31 deletions app/src/main/res/layout/row_notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,48 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:orientation="horizontal"
android:padding="@dimen/padding_small">

<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/_40dp"
android:layout_height="@dimen/_40dp"
android:layout_gravity="center_vertical"
android:padding="@dimen/padding_normal"
app:tint="@color/md_black_1000" />

<LinearLayout
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_weight="1"
android:orientation="vertical">

<LinearLayout
android:layout_width="0dp"
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="@dimen/padding_normal"
android:textColor="@color/md_black_1000"
android:textSize="@dimen/text_size_mid" />
android:layout_gravity="center_vertical"
android:padding="@dimen/padding_normal"
android:textColor="@color/md_black_1000"
android:textSize="@dimen/text_size_mid" />

<TextView
android:id="@+id/timestamp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingStart="@dimen/padding_normal"
android:paddingEnd="@dimen/padding_normal"
android:textColor="@color/md_grey_600"
android:textSize="@dimen/text_size_small" />
</LinearLayout>
<Button
android:id="@+id/btn_mark_as_read"
android:layout_width="wrap_content"
<TextView
android:id="@+id/timestamp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Mark as Read"
android:padding="@dimen/padding_normal" />
android:paddingStart="@dimen/padding_normal"
android:paddingEnd="@dimen/padding_normal"
android:textColor="@color/md_grey_600"
android:textSize="@dimen/text_size_small" />
</LinearLayout>

<Button
android:id="@+id/btn_mark_as_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Mark as Read"
android:padding="@dimen/padding_normal" />
</LinearLayout>

0 comments on commit c7b14ba

Please sign in to comment.