@ -323,22 +323,33 @@ public class DailyNotificationWorker extends Worker {
builder . setDefaults ( NotificationCompat . DEFAULT_SOUND ) ;
builder . setDefaults ( NotificationCompat . DEFAULT_SOUND ) ;
}
}
// Add click action if URL is available
// Add click action - always open the app, optionally with URL
Intent clickIntent ;
if ( content . getUrl ( ) ! = null & & ! content . getUrl ( ) . isEmpty ( ) ) {
if ( content . getUrl ( ) ! = null & & ! content . getUrl ( ) . isEmpty ( ) ) {
Intent clickIntent = new Intent ( Intent . ACTION_VIEW ) ;
// If URL is provided, open the app and pass the URL as data
clickIntent = new Intent ( Intent . ACTION_VIEW ) ;
clickIntent . setData ( android . net . Uri . parse ( content . getUrl ( ) ) ) ;
clickIntent . setData ( android . net . Uri . parse ( content . getUrl ( ) ) ) ;
clickIntent . setPackage ( getApplicationContext ( ) . getPackageName ( ) ) ;
PendingIntent clickPendingIntent = PendingIntent . getActivity (
clickIntent . addFlags ( Intent . FLAG_ACTIVITY_NEW_TASK | Intent . FLAG_ACTIVITY_CLEAR_TOP ) ;
getApplicationContext ( ) ,
Log . d ( TAG , "DN|CLICK_INTENT with_url=" + content . getUrl ( ) ) ;
content . getId ( ) . hashCode ( ) ,
} else {
clickIntent ,
// If no URL, just open the main app
PendingIntent . FLAG_UPDATE_CURRENT | PendingIntent . FLAG_IMMUTABLE
clickIntent = getApplicationContext ( ) . getPackageManager ( ) . getLaunchIntentForPackage ( getApplicationContext ( ) . getPackageName ( ) ) ;
) ;
clickIntent . addFlags ( Intent . FLAG_ACTIVITY_NEW_TASK | Intent . FLAG_ACTIVITY_CLEAR_TOP ) ;
Log . d ( TAG , "DN|CLICK_INTENT app_only" ) ;
builder . setContentIntent ( clickPendingIntent ) ;
}
}
// Add dismiss action
PendingIntent clickPendingIntent = PendingIntent . getActivity (
getApplicationContext ( ) ,
content . getId ( ) . hashCode ( ) ,
clickIntent ,
PendingIntent . FLAG_UPDATE_CURRENT | PendingIntent . FLAG_IMMUTABLE
) ;
builder . setContentIntent ( clickPendingIntent ) ;
// Add action buttons
// 1. Dismiss action
Intent dismissIntent = new Intent ( getApplicationContext ( ) , DailyNotificationReceiver . class ) ;
Intent dismissIntent = new Intent ( getApplicationContext ( ) , DailyNotificationReceiver . class ) ;
dismissIntent . setAction ( "com.timesafari.daily.DISMISS" ) ;
dismissIntent . setAction ( "com.timesafari.daily.DISMISS" ) ;
dismissIntent . putExtra ( "notification_id" , content . getId ( ) ) ;
dismissIntent . putExtra ( "notification_id" , content . getId ( ) ) ;
@ -356,6 +367,30 @@ public class DailyNotificationWorker extends Worker {
dismissPendingIntent
dismissPendingIntent
) ;
) ;
// 2. View Details action (if URL is available)
if ( content . getUrl ( ) ! = null & & ! content . getUrl ( ) . isEmpty ( ) ) {
Intent viewDetailsIntent = new Intent ( Intent . ACTION_VIEW ) ;
viewDetailsIntent . setData ( android . net . Uri . parse ( content . getUrl ( ) ) ) ;
viewDetailsIntent . addFlags ( Intent . FLAG_ACTIVITY_NEW_TASK ) ;
PendingIntent viewDetailsPendingIntent = PendingIntent . getActivity (
getApplicationContext ( ) ,
content . getId ( ) . hashCode ( ) + 2000 , // Different request code
viewDetailsIntent ,
PendingIntent . FLAG_UPDATE_CURRENT | PendingIntent . FLAG_IMMUTABLE
) ;
builder . addAction (
android . R . drawable . ic_menu_info_details ,
"View Details" ,
viewDetailsPendingIntent
) ;
Log . d ( TAG , "DN|ACTION_BUTTONS added_view_details url=" + content . getUrl ( ) ) ;
} else {
Log . d ( TAG , "DN|ACTION_BUTTONS dismiss_only" ) ;
}
// Build and display notification
// Build and display notification
int notificationId = content . getId ( ) . hashCode ( ) ;
int notificationId = content . getId ( ) . hashCode ( ) ;
notificationManager . notify ( notificationId , builder . build ( ) ) ;
notificationManager . notify ( notificationId , builder . build ( ) ) ;