Channel notifications per account
This commit is contained in:
parent
559554660a
commit
0a18f2c241
|
@ -1063,7 +1063,7 @@ public class Helper {
|
||||||
* @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, Intent intent, int notificationId, Bitmap icon, NotifType notifType, String title, String message ) {
|
public static void notify_user(Context context, Account account, Intent intent, int notificationId, 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);
|
||||||
|
@ -1075,40 +1075,40 @@ public class Helper {
|
||||||
String channelTitle;
|
String channelTitle;
|
||||||
switch(notifType){
|
switch(notifType){
|
||||||
case BOOST:
|
case BOOST:
|
||||||
channelId = "channel_boost";
|
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";
|
channelId = "channel_fav"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_fav);
|
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_fav);
|
||||||
break;
|
break;
|
||||||
case FOLLLOW:
|
case FOLLLOW:
|
||||||
channelId = "channel_follow";
|
channelId = "channel_follow"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_follow);
|
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_follow);
|
||||||
break;
|
break;
|
||||||
case MENTION:
|
case MENTION:
|
||||||
channelId = "channel_mention";
|
channelId = "channel_mention"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_mention);
|
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_mention);
|
||||||
break;
|
break;
|
||||||
case POLL:
|
case POLL:
|
||||||
channelId = "channel_poll";
|
channelId = "channel_poll"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_poll);
|
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_poll);
|
||||||
break;
|
break;
|
||||||
case BACKUP:
|
case BACKUP:
|
||||||
channelId = "channel_backup";
|
channelId = "channel_backup"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_backup);
|
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_backup);
|
||||||
break;
|
break;
|
||||||
case STORE:
|
case STORE:
|
||||||
channelId = "channel_store";
|
channelId = "channel_store"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_media);
|
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_media);
|
||||||
break;
|
break;
|
||||||
case TOOT:
|
case TOOT:
|
||||||
channelId = "channel_toot";
|
channelId = "channel_toot"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_toot);
|
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_toot);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
channelId = "channel_boost";
|
channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance();
|
||||||
channelTitle = context.getString(R.string.channel_notif_boost);
|
channelTitle =account.getAcct()+"@"+account.getInstance() + " - " + 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)
|
||||||
|
@ -1234,7 +1234,11 @@ public class Helper {
|
||||||
|
|
||||||
@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(context, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(),
|
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||||
|
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||||
|
notify_user(context, account, intent, notificationIdTmp, 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;
|
||||||
|
@ -1243,7 +1247,11 @@ public class Helper {
|
||||||
.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(context, intent, notificationIdTmp, resource, NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
|
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||||
|
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));
|
||||||
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -4099,7 +4107,11 @@ public class Helper {
|
||||||
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);
|
||||||
Helper.notify_user(context, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(),
|
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||||
|
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||||
|
Helper.notify_user(context, account, intent, notificationIdTmp, 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4297,7 +4309,11 @@ public class Helper {
|
||||||
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");
|
||||||
Helper.notify_user(context, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(),
|
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||||
|
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||||
|
Helper.notify_user(context, account,intent, notificationIdTmp, 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();
|
||||||
|
|
|
@ -294,7 +294,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(), intent, notificationId, BitmapFactory.decodeResource(getContext().getResources(),
|
notify_user(getContext(), account, intent, notificationId, 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 +308,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(), intent, notificationId, resource, finalNotifType, finalTitle, message);
|
notify_user(getContext(), account, intent, notificationId, 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();
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class BackupStatusInDataBaseService extends IntentService {
|
||||||
long notif_id = Long.parseLong(account.getId());
|
long notif_id = Long.parseLong(account.getId());
|
||||||
int notificationId = ((notif_id + 4) > 2147483647) ? (int) (2147483647 - notif_id - 4) : (int) (notif_id + 4);
|
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(), mainActivity, notificationId, BitmapFactory.decodeResource(getResources(),
|
Helper.notify_user(getApplicationContext(),account, mainActivity, notificationId, 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();
|
||||||
|
|
|
@ -185,7 +185,7 @@ public class BackupStatusService extends IntentService {
|
||||||
long notif_id = Long.parseLong(account.getId());
|
long notif_id = Long.parseLong(account.getId());
|
||||||
int notificationId = ((notif_id + 3) > 2147483647) ? (int) (2147483647 - notif_id - 3) : (int) (notif_id + 3);
|
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(), intentOpen, notificationId, BitmapFactory.decodeResource(getResources(),
|
Helper.notify_user(getApplicationContext(), account, intentOpen, notificationId, 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();
|
||||||
|
|
|
@ -413,7 +413,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(), intent, notificationId, BitmapFactory.decodeResource(getResources(),
|
Helper.notify_user(getApplicationContext(),account, intent, notificationId, 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)) {
|
||||||
|
@ -427,7 +427,8 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
||||||
.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) {
|
||||||
Helper.notify_user(getApplicationContext(), intent, notificationId, resource, finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance());
|
|
||||||
|
Helper.notify_user(getApplicationContext(), account,intent, notificationId, 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();
|
||||||
|
|
|
@ -18,6 +18,7 @@ package app.fedilab.android.sqlite;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -34,10 +35,13 @@ import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 23/04/2017.
|
* Created by Thomas on 23/04/2017.
|
||||||
* Manage the DataBase
|
* Manage the DataBase
|
||||||
|
@ -515,7 +519,12 @@ public class Sqlite extends SQLiteOpenHelper {
|
||||||
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, "*/*");
|
||||||
Helper.notify_user(context, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(),
|
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||||
|
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||||
|
Helper.notify_user(context, account, intent, notificationIdTmp, 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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue