Group notifications
This commit is contained in:
parent
95614fa69c
commit
ea3bed1c7f
|
@ -1944,7 +1944,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_boost_new");
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_boost");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -1954,7 +1954,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_fav_new");
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_fav");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -1964,7 +1964,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_follow_new");
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_follow");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -1974,7 +1974,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_mention_new");
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_mention");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -1984,7 +1984,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_poll_new");
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_poll");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -1994,7 +1994,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_backup_new");
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_backup");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -2004,7 +2004,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_store_new");
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_store");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -34,7 +34,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.app.DownloadManager;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -1144,39 +1145,39 @@ public class Helper {
|
|||
|
||||
switch (notifType) {
|
||||
case BOOST:
|
||||
channelId = "channel_boost_new" + account.getAcct() + "@" + account.getInstance();
|
||||
channelId = "channel_boost" + account.getAcct() + "@" + account.getInstance();
|
||||
channelTitle = context.getString(R.string.channel_notif_boost);
|
||||
break;
|
||||
case FAV:
|
||||
channelId = "channel_fav_new";
|
||||
channelId = "channel_fav";
|
||||
channelTitle = context.getString(R.string.channel_notif_fav);
|
||||
break;
|
||||
case FOLLLOW:
|
||||
channelId = "channel_follow_new";
|
||||
channelId = "channel_follow";
|
||||
channelTitle = context.getString(R.string.channel_notif_follow);
|
||||
break;
|
||||
case MENTION:
|
||||
channelId = "channel_mention_new";
|
||||
channelId = "channel_mention";
|
||||
channelTitle = context.getString(R.string.channel_notif_mention);
|
||||
break;
|
||||
case POLL:
|
||||
channelId = "channel_poll_new";
|
||||
channelId = "channel_poll";
|
||||
channelTitle = context.getString(R.string.channel_notif_poll);
|
||||
break;
|
||||
case BACKUP:
|
||||
channelId = "channel_backup_new";
|
||||
channelId = "channel_backup";
|
||||
channelTitle = context.getString(R.string.channel_notif_backup);
|
||||
break;
|
||||
case STORE:
|
||||
channelId = "channel_store_new";
|
||||
channelId = "channel_store";
|
||||
channelTitle = context.getString(R.string.channel_notif_media);
|
||||
break;
|
||||
case TOOT:
|
||||
channelId = "channel_toot_new";
|
||||
channelId = "channel_toot";
|
||||
channelTitle = context.getString(R.string.channel_notif_toot);
|
||||
break;
|
||||
default:
|
||||
channelId = "channel_boost_new";
|
||||
channelId = "channel_boost";
|
||||
channelTitle = context.getString(R.string.channel_notif_boost);
|
||||
}
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId)
|
||||
|
@ -1250,6 +1251,16 @@ public class Helper {
|
|||
notificationBuilder.setContentTitle(title);
|
||||
notificationBuilder.setLargeIcon(icon);
|
||||
notificationManager.notify(notificationId, notificationBuilder.build());
|
||||
|
||||
Notification summaryNotification =
|
||||
new NotificationCompat.Builder(context, channelId)
|
||||
.setContentTitle(account.getAcct()+"@"+account.getInstance())
|
||||
.setContentText(channelTitle)
|
||||
.setSmallIcon(getNotificationIcon(context))
|
||||
.setGroup(account.getAcct() + "@" + account.getInstance())
|
||||
.setGroupSummary(true)
|
||||
.build();
|
||||
notificationManager.notify(0, summaryNotification);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ import java.lang.ref.WeakReference;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
|
@ -87,9 +89,11 @@ public class LiveNotificationDelayedService extends Service {
|
|||
public static int eventsCount = 0;
|
||||
public static HashMap<String, String> since_ids = new HashMap<>();
|
||||
private boolean fetch;
|
||||
private LiveNotificationDelayedService liveNotificationDelayedService;
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
liveNotificationDelayedService = this;
|
||||
}
|
||||
|
||||
private void startStream() {
|
||||
|
@ -99,20 +103,25 @@ public class LiveNotificationDelayedService extends Service {
|
|||
List<Account> accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccountCrossAction();
|
||||
if (accountStreams != null) {
|
||||
fetch = true;
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
Timer t = new Timer();
|
||||
t.scheduleAtFixedRate(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (final Account accountStream : accountStreams) {
|
||||
if (accountStream.getSocial() == null || accountStream.getSocial().equals("MASTODON") || accountStream.getSocial().equals("PLEROMA")) {
|
||||
new Fetch(new WeakReference<>(getApplicationContext()), accountStream).execute();
|
||||
new Fetch(new WeakReference<>(liveNotificationDelayedService), accountStream).execute();
|
||||
}
|
||||
}
|
||||
fetch = (Helper.liveNotifType(getApplicationContext()) == Helper.NOTIF_DELAYED);
|
||||
if( !fetch){
|
||||
handler.removeMessages(0);
|
||||
t.cancel();
|
||||
}
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
},
|
||||
0,
|
||||
30000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,9 +131,9 @@ public class LiveNotificationDelayedService extends Service {
|
|||
|
||||
private Account accountFetch;
|
||||
private String key, last_notifid;
|
||||
private WeakReference<Context> contextWeakReference;
|
||||
private WeakReference<LiveNotificationDelayedService> contextWeakReference;
|
||||
|
||||
Fetch(WeakReference<Context> contextWeakReference, Account account){
|
||||
Fetch(WeakReference<LiveNotificationDelayedService> contextWeakReference, Account account){
|
||||
this.accountFetch = account;
|
||||
this.contextWeakReference =contextWeakReference;
|
||||
key = account.getAcct() + "@" + account.getInstance();
|
||||
|
@ -136,11 +145,13 @@ public class LiveNotificationDelayedService extends Service {
|
|||
|
||||
@Override
|
||||
protected APIResponse doInBackground(Void... params) {
|
||||
|
||||
return new API(this.contextWeakReference.get(), accountFetch.getInstance(), accountFetch.getToken()).getNotificationsSince(DisplayNotificationsFragment.Type.ALL, last_notifid, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(APIResponse apiResponse) {
|
||||
|
||||
if( apiResponse.getNotifications() != null && apiResponse.getNotifications().size() > 0){
|
||||
since_ids.put(key, apiResponse.getNotifications().get(0).getId());
|
||||
for (Notification notification : apiResponse.getNotifications()) {
|
||||
|
@ -161,7 +172,7 @@ public class LiveNotificationDelayedService extends Service {
|
|||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.setShowBadge(false);
|
||||
|
||||
((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Account> accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccountCrossAction();
|
||||
|
@ -214,7 +225,7 @@ public class LiveNotificationDelayedService extends Service {
|
|||
}
|
||||
|
||||
|
||||
private static void onRetrieveStreaming(WeakReference<Context> contextWeakReference, Account account, Notification notification) {
|
||||
private static void onRetrieveStreaming(WeakReference<LiveNotificationDelayedService> contextWeakReference, Account account, Notification notification) {
|
||||
|
||||
Bundle b = new Bundle();
|
||||
boolean canSendBroadCast = true;
|
||||
|
@ -227,7 +238,6 @@ public class LiveNotificationDelayedService extends Service {
|
|||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.setShowBadge(false);
|
||||
((NotificationManager) Objects.requireNonNull(contextWeakReference.get().getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
|
||||
android.app.Notification notificationChannel = new NotificationCompat.Builder(contextWeakReference.get(), CHANNEL_ID)
|
||||
.setContentTitle(contextWeakReference.get().getString(R.string.top_notification))
|
||||
|
@ -336,11 +346,7 @@ public class LiveNotificationDelayedService extends Service {
|
|||
intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
|
||||
}
|
||||
final String finalMessage = message;
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Helper.NotifType finalNotifType = notifType;
|
||||
Runnable myRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (finalMessage != null) {
|
||||
Glide.with(contextWeakReference.get())
|
||||
.asBitmap()
|
||||
|
@ -367,9 +373,6 @@ public class LiveNotificationDelayedService extends Service {
|
|||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
if (canSendBroadCast) {
|
||||
|
@ -384,6 +387,7 @@ public class LiveNotificationDelayedService extends Service {
|
|||
editor.apply();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.setShowBadge(false);
|
||||
|
||||
((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Account> accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccountCrossAction();
|
||||
|
@ -301,7 +301,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.setShowBadge(false);
|
||||
((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
|
||||
android.app.Notification notificationChannel = new NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
.setContentTitle(getString(R.string.top_notification))
|
||||
|
|
Loading…
Reference in New Issue