Channel notifications per account

This commit is contained in:
tom79 2019-08-01 18:15:11 +02:00
parent 92f7d65403
commit e0934f94e9
7 changed files with 39 additions and 71 deletions

View File

@ -1620,9 +1620,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
if( account != null) { intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_boost");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_boost" + account.getAcct() + "@" + account.getInstance());
}
startActivity(intent); startActivity(intent);
} }
}); });
@ -1632,9 +1630,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
if( account != null) { intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_fav");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_fav" + account.getAcct() + "@" + account.getInstance());
}
startActivity(intent); startActivity(intent);
} }
}); });
@ -1644,9 +1640,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
if( account != null) { intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_follow");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_follow" + account.getAcct() + "@" + account.getInstance());
}
startActivity(intent); startActivity(intent);
} }
}); });
@ -1656,9 +1650,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
if( account != null) { intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_mention");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_mention" + account.getAcct() + "@" + account.getInstance());
}
startActivity(intent); startActivity(intent);
} }
}); });
@ -1668,9 +1660,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
if( account != null) { intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_poll");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_poll" + account.getAcct() + "@" + account.getInstance());
}
startActivity(intent); startActivity(intent);
} }
}); });
@ -1680,9 +1670,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
if( account != null) { intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_backup");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_backup" + account.getAcct() + "@" + account.getInstance());
}
startActivity(intent); startActivity(intent);
} }
}); });
@ -1692,9 +1680,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
if( account != null) { intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_store");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_store" + account.getAcct() + "@" + account.getInstance());
}
startActivity(intent); startActivity(intent);
} }
}); });

View File

@ -1058,63 +1058,66 @@ public class Helper {
* Sends notification with intent * Sends notification with intent
* @param context Context * @param context Context
* @param intent Intent associated to the notifcation * @param intent Intent associated to the notifcation
* @param notificationId int id of the notification
* @param icon Bitmap profile picture * @param icon Bitmap profile picture
* @param title String title of the notification * @param title String title of the notification
* @param message String message for the notification * @param message String message for the notification
*/ */
public static void notify_user(Context context, Account account, Intent intent, int notificationId, Bitmap icon, NotifType notifType, String title, String message ) { public static void notify_user(Context context, Account account, Intent intent, Bitmap icon, NotifType notifType, String title, String message ) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
// prepare intent which is triggered if the user click on the notification // prepare intent which is triggered if the user click on the notification
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
int notificationId = Integer.parseInt(account.getId());
PendingIntent pIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_ONE_SHOT); PendingIntent pIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// build notification // build notification
String channelId; String channelId;
String channelTitle; String channelTitle;
switch(notifType){ switch(notifType){
case BOOST: case BOOST:
channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance();
channelTitle = context.getString(R.string.channel_notif_boost); channelTitle = context.getString(R.string.channel_notif_boost);
break; break;
case FAV: case FAV:
channelId = "channel_fav"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_fav";
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_fav); channelTitle = context.getString(R.string.channel_notif_fav);
break; break;
case FOLLLOW: case FOLLLOW:
channelId = "channel_follow"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_follow";
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_follow); channelTitle = context.getString(R.string.channel_notif_follow);
break; break;
case MENTION: case MENTION:
channelId = "channel_mention"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_mention";
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_mention); channelTitle = context.getString(R.string.channel_notif_mention);
break; break;
case POLL: case POLL:
channelId = "channel_poll"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_poll";
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_poll); channelTitle = context.getString(R.string.channel_notif_poll);
break; break;
case BACKUP: case BACKUP:
channelId = "channel_backup"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_backup";
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_backup); channelTitle = context.getString(R.string.channel_notif_backup);
break; break;
case STORE: case STORE:
channelId = "channel_store"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_store";
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_media); channelTitle = context.getString(R.string.channel_notif_media);
break; break;
case TOOT: case TOOT:
channelId = "channel_toot"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_toot";
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_toot); channelTitle = context.getString(R.string.channel_notif_toot);
break; break;
default: default:
channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance(); channelId = "channel_boost";
channelTitle =account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_boost); channelTitle = context.getString(R.string.channel_notif_boost);
} }
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId) NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.fedilab_notification_icon) .setSmallIcon(R.drawable.fedilab_notification_icon)
.setTicker(message) .setTicker(message)
.setWhen(System.currentTimeMillis()) .setWhen(System.currentTimeMillis())
.setAutoCancel(true) .setAutoCancel(true)
.setGroup(account.getAcct()+"@"+account.getInstance())
.setContentIntent(pIntent) .setContentIntent(pIntent)
.setContentText(message); .setContentText(message);
int ledColour = Color.BLUE; int ledColour = Color.BLUE;
@ -1212,8 +1215,6 @@ public class Helper {
copy(fileVideo, fileVideoTargeded); copy(fileVideo, fileVideoTargeded);
file = fileVideoTargeded; file = fileVideoTargeded;
} }
Random r = new Random();
final int notificationIdTmp = r.nextInt(10000);
// prepare intent which is triggered if the // prepare intent which is triggered if the
// notification is selected // notification is selected
final Intent intent = new Intent(); final Intent intent = new Intent();
@ -1238,7 +1239,7 @@ public class Helper {
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
notify_user(context, account, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher), NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); R.mipmap.ic_launcher), NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show();
return false; return false;
@ -1251,7 +1252,7 @@ public class Helper {
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
notify_user(context, account, intent, notificationIdTmp, resource, NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); notify_user(context, account, intent, resource, NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show();
} }
}); });
@ -4102,8 +4103,6 @@ public class Helper {
String mime = Helper.getMimeType(url); String mime = Helper.getMimeType(url);
File file = new File(download.getFileUri().getPath()); File file = new File(download.getFileUri().getPath());
final Intent intent = new Intent(); final Intent intent = new Intent();
Random r = new Random();
final int notificationIdTmp = r.nextInt(10000);
intent.setAction(android.content.Intent.ACTION_VIEW); intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + file.getAbsolutePath() ); Uri uri = Uri.parse("file://" + file.getAbsolutePath() );
intent.setDataAndType(uri, mime); intent.setDataAndType(uri, mime);
@ -4111,7 +4110,7 @@ public class Helper {
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
Helper.notify_user(context, account, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), Helper.notify_user(context, account, 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)); R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
} }
} }
@ -4304,8 +4303,6 @@ public class Helper {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
final Intent intent = new Intent(); final Intent intent = new Intent();
Random r = new Random();
final int notificationIdTmp = r.nextInt(10000);
intent.setAction(android.content.Intent.ACTION_VIEW); intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(filename)); Uri uri = Uri.fromFile(new File(filename));
intent.setDataAndType(uri, "text/csv"); intent.setDataAndType(uri, "text/csv");
@ -4313,7 +4310,7 @@ public class Helper {
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
Helper.notify_user(context, account,intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), Helper.notify_user(context, account,intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.muted_instance_exported), context.getString(R.string.download_from, backupDBPath)); R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.muted_instance_exported), context.getString(R.string.download_from, backupDBPath));
} }
}.start(); }.start();

View File

@ -266,13 +266,6 @@ public class NotificationsSyncJob extends Job {
if( targeted_account != null && notifType == Helper.NotifType.FOLLLOW) if( targeted_account != null && notifType == Helper.NotifType.FOLLLOW)
intent.putExtra(INTENT_TARGETED_ACCOUNT, targeted_account); intent.putExtra(INTENT_TARGETED_ACCOUNT, targeted_account);
intent.putExtra(PREF_INSTANCE, account.getInstance()); intent.putExtra(PREF_INSTANCE, account.getInstance());
long notif_id;
if( account.getId() != null && account.getId().matches("-?\\d+(\\.\\d+)?")){
notif_id = Long.parseLong(account.getId());
}else{
notif_id = new Random().nextLong();
}
final int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1);
if( notificationUrl != null ){ if( notificationUrl != null ){
final String finalTitle = title; final String finalTitle = title;
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
@ -294,7 +287,7 @@ public class NotificationsSyncJob extends Job {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
notify_user(getContext(), account, intent, notificationId, BitmapFactory.decodeResource(getContext().getResources(), notify_user(getContext(), account, intent, BitmapFactory.decodeResource(getContext().getResources(),
R.drawable.mastodonlogo), finalNotifType, finalTitle, message); R.drawable.mastodonlogo), finalNotifType, finalTitle, message);
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){ if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){
@ -308,7 +301,7 @@ public class NotificationsSyncJob extends Job {
.into(new SimpleTarget<Bitmap>() { .into(new SimpleTarget<Bitmap>() {
@Override @Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) { public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
notify_user(getContext(), account, intent, notificationId, resource, finalNotifType, finalTitle, message); notify_user(getContext(), account, intent, resource, finalNotifType, finalTitle, message);
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){ if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();

View File

@ -125,10 +125,8 @@ public class BackupStatusInDataBaseService extends IntentService {
message = getString(R.string.data_backup_success, String.valueOf(backupStatus.size())); message = getString(R.string.data_backup_success, String.valueOf(backupStatus.size()));
Intent mainActivity = new Intent(BackupStatusInDataBaseService.this, MainActivity.class); Intent mainActivity = new Intent(BackupStatusInDataBaseService.this, MainActivity.class);
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_INTENT); mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_INTENT);
long notif_id = Long.parseLong(account.getId());
int notificationId = ((notif_id + 4) > 2147483647) ? (int) (2147483647 - notif_id - 4) : (int) (notif_id + 4);
String title = getString(R.string.data_backup_toots, account.getAcct()); String title = getString(R.string.data_backup_toots, account.getAcct());
Helper.notify_user(getApplicationContext(),account, mainActivity, notificationId, BitmapFactory.decodeResource(getResources(), Helper.notify_user(getApplicationContext(),account, mainActivity, BitmapFactory.decodeResource(getResources(),
R.drawable.mastodonlogo), Helper.NotifType.BACKUP, title, message); R.drawable.mastodonlogo), Helper.NotifType.BACKUP, title, message);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -182,10 +182,8 @@ public class BackupStatusService extends IntentService {
intentOpen.setAction(android.content.Intent.ACTION_VIEW); intentOpen.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + fullPath); Uri uri = Uri.parse("file://" + fullPath);
intentOpen.setDataAndType(uri, "text/csv"); intentOpen.setDataAndType(uri, "text/csv");
long notif_id = Long.parseLong(account.getId());
int notificationId = ((notif_id + 3) > 2147483647) ? (int) (2147483647 - notif_id - 3) : (int) (notif_id + 3);
String title = getString(R.string.data_export_toots, account.getAcct()); String title = getString(R.string.data_export_toots, account.getAcct());
Helper.notify_user(getApplicationContext(), account, intentOpen, notificationId, BitmapFactory.decodeResource(getResources(), Helper.notify_user(getApplicationContext(), account, intentOpen, BitmapFactory.decodeResource(getResources(),
R.drawable.mastodonlogo),Helper.NotifType.BACKUP, title, message); R.drawable.mastodonlogo),Helper.NotifType.BACKUP, title, message);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -393,8 +393,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
if (targeted_account != null) { if (targeted_account != null) {
intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account); intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
} }
long notif_id = Long.parseLong(account.getId());
final int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1);
final String finalTitle = title; final String finalTitle = title;
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Helper.NotifType finalNotifType = notifType; Helper.NotifType finalNotifType = notifType;
@ -413,7 +411,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
Helper.notify_user(getApplicationContext(),account, intent, notificationId, BitmapFactory.decodeResource(getResources(), Helper.notify_user(getApplicationContext(),account, intent, BitmapFactory.decodeResource(getResources(),
R.drawable.mastodonlogo), finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance()); R.drawable.mastodonlogo), finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance());
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) {
@ -428,7 +426,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
@Override @Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) { public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
Helper.notify_user(getApplicationContext(), account,intent, notificationId, resource, finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance()); Helper.notify_user(getApplicationContext(), account,intent, resource, finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance());
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) {
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();

View File

@ -514,8 +514,6 @@ public class Sqlite extends SQLiteOpenHelper {
src.close(); src.close();
dst.close(); dst.close();
final Intent intent = new Intent(); final Intent intent = new Intent();
Random r = new Random();
final int notificationIdTmp = r.nextInt(10000);
intent.setAction(android.content.Intent.ACTION_VIEW); intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(dbDest); Uri uri = Uri.fromFile(dbDest);
intent.setDataAndType(uri, "*/*"); intent.setDataAndType(uri, "*/*");
@ -524,7 +522,7 @@ public class Sqlite extends SQLiteOpenHelper {
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
Helper.notify_user(context, account, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, backupDBPath)); R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, backupDBPath));
Toasty.success(context, context.getString(R.string.data_base_exported),Toast.LENGTH_LONG).show(); Toasty.success(context, context.getString(R.string.data_base_exported),Toast.LENGTH_LONG).show();
} }