Fix issue #215 - Only last notification is displayed
This commit is contained in:
parent
b8addbc3f1
commit
17ed03af91
|
@ -117,6 +117,7 @@ import java.security.Security;
|
|||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
@ -1379,6 +1380,10 @@ public class Helper {
|
|||
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
|
||||
|
||||
private static final List<String> present = new ArrayList<>();
|
||||
private static int notificationId = 1;
|
||||
|
||||
/**
|
||||
* Sends notification with intent
|
||||
*
|
||||
|
@ -1389,7 +1394,7 @@ public class Helper {
|
|||
* @param message String message for the notification
|
||||
*/
|
||||
@SuppressLint("UnspecifiedImmutableFlag")
|
||||
public static void notify_user(Context context, int notificationId, BaseAccount account, Intent intent, Bitmap icon, NotifType notifType, String title, String message) {
|
||||
public static void notify_user(Context context, BaseAccount account, Intent intent, Bitmap icon, NotifType notifType, String title, String message) {
|
||||
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// prepare intent which is triggered if the user click on the notification
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
|
@ -1440,14 +1445,11 @@ public class Helper {
|
|||
channelTitle = context.getString(R.string.channel_notif_boost);
|
||||
}
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId)
|
||||
.setSmallIcon(R.drawable.ic_notification).setTicker(message)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setAutoCancel(true);
|
||||
.setSmallIcon(R.drawable.ic_notification).setTicker(message);
|
||||
if (notifType == NotifType.MENTION) {
|
||||
if (message.length() > 500) {
|
||||
message = message.substring(0, 499) + "…";
|
||||
}
|
||||
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
|
||||
}
|
||||
notificationBuilder.setGroup(account.mastodon_account.acct + "@" + account.instance)
|
||||
.setContentIntent(pIntent)
|
||||
|
@ -1515,19 +1517,28 @@ public class Helper {
|
|||
}
|
||||
notificationBuilder.setContentTitle(title);
|
||||
notificationBuilder.setLargeIcon(icon);
|
||||
notificationManager.notify(notificationId, notificationBuilder.build());
|
||||
|
||||
Notification summaryNotification =
|
||||
new NotificationCompat.Builder(context, channelId)
|
||||
.setContentTitle(title)
|
||||
.setContentText(channelTitle)
|
||||
.setContentIntent(pIntent)
|
||||
.setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setGroup(account.mastodon_account.acct + "@" + account.instance)
|
||||
.setGroupSummary(true)
|
||||
.build();
|
||||
notificationManager.notify(notificationId, summaryNotification);
|
||||
|
||||
Notification summaryNotification = null;
|
||||
|
||||
if (!present.contains(account.mastodon_account.acct + "@" + account.instance)) {
|
||||
summaryNotification = new NotificationCompat.Builder(context, channelId)
|
||||
.setContentTitle(title)
|
||||
.setContentText(channelTitle)
|
||||
.setContentIntent(pIntent)
|
||||
.setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
|
||||
.setGroup(account.mastodon_account.acct + "@" + account.instance)
|
||||
.setGroupSummary(true)
|
||||
.build();
|
||||
present.add(account.mastodon_account.acct + "@" + account.instance);
|
||||
}
|
||||
|
||||
notificationManager.notify(notificationId++, notificationBuilder.build());
|
||||
if (summaryNotification != null) {
|
||||
notificationManager.notify(0, summaryNotification);
|
||||
}
|
||||
}
|
||||
|
||||
public static void transfertIfExist(Context context) {
|
||||
|
|
|
@ -163,7 +163,7 @@ public class MediaHelper {
|
|||
Uri uri = Uri.fromFile(backupFile);
|
||||
intent.setDataAndType(uri, mime);
|
||||
if (!share) {
|
||||
notify_user(context, Helper.NOTIFICATION_MEDIA, currentAccount, intent, BitmapFactory.decodeResource(context.getResources(),
|
||||
notify_user(context, currentAccount, intent, BitmapFactory.decodeResource(context.getResources(),
|
||||
R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
|
||||
Toasty.success(context, context.getString(R.string.save_over), Toasty.LENGTH_LONG).show();
|
||||
} else {
|
||||
|
|
|
@ -317,7 +317,7 @@ public class NotificationsHelper {
|
|||
since_ids.put(account.user_id + "@" + account.instance, lastNotif);
|
||||
editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
||||
editor.apply();
|
||||
notify_user(context, Helper.NOTIFICATION_USER_NOTIF, account, intent, BitmapFactory.decodeResource(context.getResources(),
|
||||
notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
|
||||
R.mipmap.ic_launcher), finalNotifType, finalTitle, finalMessage);
|
||||
}
|
||||
return false;
|
||||
|
@ -332,7 +332,7 @@ public class NotificationsHelper {
|
|||
editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
||||
editor.apply();
|
||||
since_ids.put(account.user_id + "@" + account.instance, lastNotif);
|
||||
notify_user(context, Helper.NOTIFICATION_USER_NOTIF, account, intent, resource, finalNotifType, finalTitle, finalMessage);
|
||||
notify_user(context, account, intent, resource, finalNotifType, finalTitle, finalMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -571,7 +571,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
|
|||
Uri uri = Uri.parse("file://" + fullPath);
|
||||
intentOpen.setDataAndType(uri, "text/csv");
|
||||
String title = getString(R.string.data_export_theme);
|
||||
Helper.notify_user(getActivity(), Helper.NOTIFICATION_THEMING, currentAccount, intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(),
|
||||
Helper.notify_user(getActivity(), currentAccount, intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(),
|
||||
R.mipmap.ic_launcher), Helper.NotifType.BACKUP, title, message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -14,8 +14,6 @@ package app.fedilab.android.ui.fragment.timeline;
|
|||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -32,7 +30,6 @@ import app.fedilab.android.BaseMainActivity;
|
|||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.client.entities.api.Announcement;
|
||||
import app.fedilab.android.databinding.FragmentPaginationBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.ThemeHelper;
|
||||
import app.fedilab.android.ui.drawer.AnnouncementAdapter;
|
||||
import app.fedilab.android.viewmodel.mastodon.AnnouncementsVM;
|
||||
|
@ -43,7 +40,6 @@ public class FragmentMastodonAnnouncement extends Fragment {
|
|||
|
||||
private FragmentPaginationBinding binding;
|
||||
private AnnouncementsVM announcementsVM;
|
||||
private AnnouncementAdapter announcementAdapter;
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
|
@ -65,13 +61,6 @@ public class FragmentMastodonAnnouncement extends Fragment {
|
|||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
NotificationManager notificationManager = (NotificationManager) requireActivity().getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(Helper.NOTIFICATION_USER_NOTIF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intialize the view for announcements
|
||||
*
|
||||
|
@ -92,7 +81,7 @@ public class FragmentMastodonAnnouncement extends Fragment {
|
|||
}
|
||||
|
||||
|
||||
announcementAdapter = new AnnouncementAdapter(announcements);
|
||||
AnnouncementAdapter announcementAdapter = new AnnouncementAdapter(announcements);
|
||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
|
||||
binding.recyclerView.setLayoutManager(mLayoutManager);
|
||||
binding.recyclerView.setAdapter(announcementAdapter);
|
||||
|
|
Loading…
Reference in New Issue