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 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);
|
||||
// prepare intent which is triggered if the user click on the notification
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
|
@ -1075,40 +1075,40 @@ public class Helper {
|
|||
String channelTitle;
|
||||
switch(notifType){
|
||||
case BOOST:
|
||||
channelId = "channel_boost";
|
||||
channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = context.getString(R.string.channel_notif_boost);
|
||||
break;
|
||||
case FAV:
|
||||
channelId = "channel_fav";
|
||||
channelTitle = context.getString(R.string.channel_notif_fav);
|
||||
channelId = "channel_fav"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_fav);
|
||||
break;
|
||||
case FOLLLOW:
|
||||
channelId = "channel_follow";
|
||||
channelTitle = context.getString(R.string.channel_notif_follow);
|
||||
channelId = "channel_follow"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_follow);
|
||||
break;
|
||||
case MENTION:
|
||||
channelId = "channel_mention";
|
||||
channelTitle = context.getString(R.string.channel_notif_mention);
|
||||
channelId = "channel_mention"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_mention);
|
||||
break;
|
||||
case POLL:
|
||||
channelId = "channel_poll";
|
||||
channelTitle = context.getString(R.string.channel_notif_poll);
|
||||
channelId = "channel_poll"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_poll);
|
||||
break;
|
||||
case BACKUP:
|
||||
channelId = "channel_backup";
|
||||
channelTitle = context.getString(R.string.channel_notif_backup);
|
||||
channelId = "channel_backup"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_backup);
|
||||
break;
|
||||
case STORE:
|
||||
channelId = "channel_store";
|
||||
channelTitle = context.getString(R.string.channel_notif_media);
|
||||
channelId = "channel_store"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_media);
|
||||
break;
|
||||
case TOOT:
|
||||
channelId = "channel_toot";
|
||||
channelTitle = context.getString(R.string.channel_notif_toot);
|
||||
channelId = "channel_toot"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_toot);
|
||||
break;
|
||||
default:
|
||||
channelId = "channel_boost";
|
||||
channelTitle = context.getString(R.string.channel_notif_boost);
|
||||
channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance();
|
||||
channelTitle =account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_boost);
|
||||
}
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId)
|
||||
.setSmallIcon(R.drawable.fedilab_notification_icon)
|
||||
|
@ -1234,7 +1234,11 @@ public class Helper {
|
|||
|
||||
@Override
|
||||
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));
|
||||
Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
|
@ -1243,7 +1247,11 @@ public class Helper {
|
|||
.into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
@ -4099,7 +4107,11 @@ public class Helper {
|
|||
intent.setAction(android.content.Intent.ACTION_VIEW);
|
||||
Uri uri = Uri.parse("file://" + file.getAbsolutePath() );
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -4297,7 +4309,11 @@ public class Helper {
|
|||
intent.setAction(android.content.Intent.ACTION_VIEW);
|
||||
Uri uri = Uri.fromFile(new File(filename));
|
||||
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));
|
||||
}
|
||||
}.start();
|
||||
|
|
|
@ -294,7 +294,7 @@ public class NotificationsSyncJob extends Job {
|
|||
|
||||
@Override
|
||||
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);
|
||||
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)){
|
||||
|
@ -308,7 +308,7 @@ public class NotificationsSyncJob extends Job {
|
|||
.into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
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);
|
||||
if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
|
|
|
@ -128,7 +128,7 @@ public class BackupStatusInDataBaseService extends IntentService {
|
|||
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());
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -185,7 +185,7 @@ public class BackupStatusService extends IntentService {
|
|||
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());
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -413,7 +413,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
|
||||
@Override
|
||||
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());
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
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>() {
|
||||
@Override
|
||||
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);
|
||||
if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
|
|
|
@ -18,6 +18,7 @@ package app.fedilab.android.sqlite;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
@ -34,10 +35,13 @@ import java.util.Date;
|
|||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import app.fedilab.android.client.Entities.Account;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import app.fedilab.android.R;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 23/04/2017.
|
||||
* Manage the DataBase
|
||||
|
@ -515,7 +519,12 @@ public class Sqlite extends SQLiteOpenHelper {
|
|||
intent.setAction(android.content.Intent.ACTION_VIEW);
|
||||
Uri uri = Uri.fromFile(dbDest);
|
||||
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));
|
||||
Toasty.success(context, context.getString(R.string.data_base_exported),Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue