Add support for post edit notifications (#2431)

* Add support for post edit notifications

* Update notification icon
This commit is contained in:
Levi Bard 2022-04-19 11:10:13 +02:00 committed by GitHub
commit dff039e123
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 885 additions and 23 deletions

View file

@ -32,6 +32,8 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
@ -201,7 +203,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
holder.setUsername(status.getAccount().getUsername());
holder.setCreatedAt(status.getCreatedAt());
if (concreteNotificaton.getType() == Notification.Type.STATUS) {
if (concreteNotificaton.getType() == Notification.Type.STATUS ||
concreteNotificaton.getType() == Notification.Type.UPDATE) {
holder.setAvatar(status.getAccount().getAvatar(), status.getAccount().getBot());
} else {
holder.setAvatars(status.getAccount().getAvatar(),
@ -280,7 +283,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
}
case STATUS:
case FAVOURITE:
case REBLOG: {
case REBLOG:
case UPDATE: {
return VIEW_TYPE_STATUS_NOTIFICATION;
}
case FOLLOW:
@ -474,6 +478,14 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
}
}
Drawable getIconWithColor(Context context, @DrawableRes int drawable, @ColorRes int color) {
Drawable icon = ContextCompat.getDrawable(context, drawable);
if (icon != null) {
icon.setColorFilter(ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_ATOP);
}
return icon;
}
void setMessage(NotificationViewData.Concrete notificationViewData, LinkListener listener) {
this.statusViewData = notificationViewData.getStatusViewData();
@ -486,35 +498,25 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
switch (type) {
default:
case FAVOURITE: {
icon = ContextCompat.getDrawable(context, R.drawable.ic_star_24dp);
if (icon != null) {
icon.setColorFilter(ContextCompat.getColor(context,
R.color.tusky_orange), PorterDuff.Mode.SRC_ATOP);
}
icon = getIconWithColor(context, R.drawable.ic_star_24dp, R.color.tusky_orange);
format = context.getString(R.string.notification_favourite_format);
break;
}
case REBLOG: {
icon = ContextCompat.getDrawable(context, R.drawable.ic_repeat_24dp);
if (icon != null) {
icon.setColorFilter(ContextCompat.getColor(context,
R.color.tusky_blue), PorterDuff.Mode.SRC_ATOP);
}
icon = getIconWithColor(context, R.drawable.ic_repeat_24dp, R.color.tusky_blue);
format = context.getString(R.string.notification_reblog_format);
break;
}
case STATUS: {
icon = ContextCompat.getDrawable(context, R.drawable.ic_home_24dp);
if (icon != null) {
icon.setColorFilter(ContextCompat.getColor(context,
R.color.tusky_blue), PorterDuff.Mode.SRC_ATOP);
}
icon = getIconWithColor(context, R.drawable.ic_home_24dp, R.color.tusky_blue);
format = context.getString(R.string.notification_subscription_format);
break;
}
case UPDATE: {
icon = getIconWithColor(context, R.drawable.ic_edit_24dp, R.color.tusky_blue);
format = context.getString(R.string.notification_update_format);
break;
}
}
message.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
String wholeMessage = String.format(format, displayName);

View file

@ -118,6 +118,7 @@ public class NotificationHelper {
public static final String CHANNEL_POLL = "CHANNEL_POLL";
public static final String CHANNEL_SUBSCRIPTIONS = "CHANNEL_SUBSCRIPTIONS";
public static final String CHANNEL_SIGN_UP = "CHANNEL_SIGN_UP";
public static final String CHANNEL_UPDATES = "CHANNEL_UPDATES";
/**
* WorkManager Tag
@ -395,6 +396,7 @@ public class NotificationHelper {
CHANNEL_POLL + account.getIdentifier(),
CHANNEL_SUBSCRIPTIONS + account.getIdentifier(),
CHANNEL_SIGN_UP + account.getIdentifier(),
CHANNEL_UPDATES + account.getIdentifier(),
};
int[] channelNames = {
R.string.notification_mention_name,
@ -405,6 +407,7 @@ public class NotificationHelper {
R.string.notification_poll_name,
R.string.notification_subscription_name,
R.string.notification_sign_up_name,
R.string.notification_update_name,
};
int[] channelDescriptions = {
R.string.notification_mention_descriptions,
@ -415,6 +418,7 @@ public class NotificationHelper {
R.string.notification_poll_description,
R.string.notification_subscription_description,
R.string.notification_sign_up_description,
R.string.notification_update_description,
};
List<NotificationChannel> channels = new ArrayList<>(6);
@ -567,6 +571,8 @@ public class NotificationHelper {
return account.getNotificationsPolls();
case SIGN_UP:
return account.getNotificationsSignUps();
case UPDATE:
return account.getNotificationsUpdates();
default:
return false;
}
@ -674,6 +680,8 @@ public class NotificationHelper {
}
case SIGN_UP:
return String.format(context.getString(R.string.notification_sign_up_format), accountName);
case UPDATE:
return String.format(context.getString(R.string.notification_update_format), accountName);
}
return null;
}

View file

@ -133,6 +133,17 @@ class NotificationPreferencesFragment : PreferenceFragmentCompat(), Injectable {
true
}
}
switchPreference {
setTitle(R.string.pref_title_notification_filter_updates)
key = PrefKeys.NOTIFICATION_FILTER_UPDATES
isIconSpaceReserved = false
isChecked = activeAccount.notificationsUpdates
setOnPreferenceChangeListener { _, newValue ->
updateAccount { it.notificationsUpdates = newValue as Boolean }
true
}
}
}
preferenceCategory(R.string.pref_title_notification_alerts) { category ->

View file

@ -51,6 +51,7 @@ data class AccountEntity(
var notificationsPolls: Boolean = true,
var notificationsSubscriptions: Boolean = true,
var notificationsSignUps: Boolean = true,
var notificationsUpdates: Boolean = true,
var notificationSound: Boolean = true,
var notificationVibration: Boolean = true,
var notificationLight: Boolean = true,

View file

@ -31,7 +31,7 @@ import java.io.File;
*/
@Database(entities = { DraftEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class,
TimelineAccountEntity.class, ConversationEntity.class
}, version = 33)
}, version = 34)
public abstract class AppDatabase extends RoomDatabase {
public abstract AccountDao accountDao();
@ -527,4 +527,11 @@ public abstract class AppDatabase extends RoomDatabase {
"PRIMARY KEY(`id`, `accountId`))");
}
};
public static final Migration MIGRATION_33_34 = new Migration(33, 34) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE `AccountEntity` ADD COLUMN `notificationsUpdates` INTEGER NOT NULL DEFAULT 1");
}
};
}

View file

@ -63,7 +63,7 @@ class AppModule {
AppDatabase.Migration25_26(appContext.getExternalFilesDir("Tusky")),
AppDatabase.MIGRATION_26_27, AppDatabase.MIGRATION_27_28, AppDatabase.MIGRATION_28_29,
AppDatabase.MIGRATION_29_30, AppDatabase.MIGRATION_30_31, AppDatabase.MIGRATION_31_32,
AppDatabase.MIGRATION_32_33
AppDatabase.MIGRATION_32_33, AppDatabase.MIGRATION_33_34
)
.build()
}

View file

@ -39,6 +39,7 @@ data class Notification(
POLL("poll"),
STATUS("status"),
SIGN_UP("admin.sign_up"),
UPDATE("update"),
;
companion object {
@ -51,7 +52,7 @@ data class Notification(
}
return UNKNOWN
}
val asList = listOf(MENTION, REBLOG, FAVOURITE, FOLLOW, FOLLOW_REQUEST, POLL, STATUS, SIGN_UP)
val asList = listOf(MENTION, REBLOG, FAVOURITE, FOLLOW, FOLLOW_REQUEST, POLL, STATUS, SIGN_UP, UPDATE)
}
override fun toString(): String {

View file

@ -709,6 +709,8 @@ public class NotificationsFragment extends SFragment implements
return getString(R.string.notification_subscription_name);
case SIGN_UP:
return getString(R.string.notification_sign_up_name);
case UPDATE:
return getString(R.string.notification_update_name);
default:
return "Unknown";
}

View file

@ -60,6 +60,7 @@ object PrefKeys {
const val NOTIFICATIONS_FILTER_FOLLOWS = "notificationFilterFollows"
const val NOTIFICATION_FILTER_SUBSCRIPTIONS = "notificationFilterSubscriptions"
const val NOTIFICATION_FILTER_SIGN_UPS = "notificationFilterSignUps"
const val NOTIFICATION_FILTER_UPDATES = "notificationFilterUpdates"
const val TAB_FILTER_HOME_REPLIES = "tabFilterHomeReplies"
const val TAB_FILTER_HOME_BOOSTS = "tabFilterHomeBoosts"