1717
1818import java .util .ArrayList ;
1919import java .util .List ;
20+ import java .util .Map ;
21+ import java .util .HashMap ;
2022
2123public class DeletedMessagesAdapter extends RecyclerView .Adapter <DeletedMessagesAdapter .ViewHolder > {
2224
2325 private List <DeletedMessage > messages = new ArrayList <>();
26+ private final Map <String , android .graphics .drawable .Drawable > iconCache = new HashMap <>();
2427 private final OnItemClickListener listener ;
2528
2629 public interface OnItemClickListener {
@@ -60,12 +63,11 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
6063 if (contactName == null && displayJid != null ) {
6164 contactName = com .wmods .wppenhacer .utils .ContactHelper .getContactName (context , displayJid );
6265 }
63-
6466 String displayText ;
6567 if (contactName != null ) {
6668 displayText = contactName ;
6769 } else {
68- // Fallback to formatted JID
70+ // Fallback to formatted JID if contact name is missing
6971 displayText = displayJid ;
7072 if (displayText != null ) {
7173 displayText = displayText .replace ("@s.whatsapp.net" , "" ).replace ("@g.us" , "" );
@@ -75,21 +77,20 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
7577 displayText = "Unknown" ;
7678 }
7779 }
78-
7980 holder .contactName .setText (displayText );
8081
81- // Timestamp
82- holder .timestamp .setText (Utils .getDateTimeFromMillis (message .getTimestamp ()));
82+ java .text .SimpleDateFormat sdf = new java .text .SimpleDateFormat ("dd/MM/yyyy hh:mm a" ,
83+ java .util .Locale .getDefault ());
84+ holder .timestamp .setText (sdf .format (new java .util .Date (message .getTimestamp ())));
8385
84- // Message Preview
86+ // Message Preview Logic... (unchanged)
8587 String text = message .getTextContent ();
8688 String senderPrefix = "" ;
8789 if (message .isFromMe ()) {
8890 senderPrefix = "You: " ;
8991 }
9092
9193 // Sanitize text for media messages (Fix for weird strings/URLs)
92- // If it's a media message, ignore text if it looks like a URL or Hash
9394 if (message .getMediaType () > 0 && text != null ) {
9495 if (text .startsWith ("http" ) || (text .length () > 20 && !text .contains (" " ))) {
9596 text = null ;
@@ -126,7 +127,7 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
126127 break ;
127128 case 42 :
128129 text = "🔄 Status Reply" ;
129- break ; // Sometimes seen
130+ break ;
130131 default :
131132 text = "📁 Media" ;
132133 break ;
@@ -140,19 +141,33 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
140141 // Avatar (Placeholder)
141142 // Holder.avatar.setImageDrawable(...)
142143
143- // App Badge
144+ // App Badge Logic (New: Fetch Exact Icon)
144145 String pkg = message .getPackageName ();
145146 if (pkg != null ) {
146147 holder .appBadge .setVisibility (View .VISIBLE );
147- if ( pkg . equals ( "com.whatsapp.w4b" )) {
148- // WhatsApp Business - Teal
149- holder . appBadge . setImageTintList (
150- android . content . res . ColorStateList . valueOf ( android . graphics . Color . parseColor ( "#00BFA5" ) ));
148+
149+ // Try to load from cache first
150+ if ( iconCache . containsKey ( pkg )) {
151+ holder . appBadge . setImageDrawable ( iconCache . get ( pkg ));
151152 } else {
152- // WhatsApp - Green
153- holder .appBadge .setImageTintList (
154- android .content .res .ColorStateList .valueOf (android .graphics .Color .parseColor ("#25D366" )));
153+ try {
154+ android .content .pm .PackageManager pm = holder .itemView .getContext ().getPackageManager ();
155+ android .graphics .drawable .Drawable icon = pm .getApplicationIcon (pkg );
156+ if (icon != null ) {
157+ iconCache .put (pkg , icon );
158+ holder .appBadge .setImageDrawable (icon );
159+ } else {
160+ // Fallback if icon is null (rare)
161+ holder .appBadge .setVisibility (View .GONE );
162+ }
163+ } catch (android .content .pm .PackageManager .NameNotFoundException e ) {
164+ // App not installed or invalid package name
165+ holder .appBadge .setVisibility (View .GONE );
166+ }
155167 }
168+ // Remove any tint since we want original colors
169+ holder .appBadge .setImageTintList (null );
170+
156171 } else {
157172 holder .appBadge .setVisibility (View .GONE );
158173 }
0 commit comments