NotificationHelper: add a way to test legacy notification channels on new devices
This commit is contained in:
parent
a6e1eaebd8
commit
98cad637c9
|
@ -35,6 +35,7 @@ import com.keylesspalace.tusky.entity.Filter
|
||||||
import com.keylesspalace.tusky.entity.Status
|
import com.keylesspalace.tusky.entity.Status
|
||||||
import com.keylesspalace.tusky.network.MastodonApi
|
import com.keylesspalace.tusky.network.MastodonApi
|
||||||
import com.keylesspalace.tusky.util.ThemeUtils
|
import com.keylesspalace.tusky.util.ThemeUtils
|
||||||
|
import com.keylesspalace.tusky.util.NotificationHelper
|
||||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial
|
||||||
import com.mikepenz.iconics.IconicsDrawable
|
import com.mikepenz.iconics.IconicsDrawable
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
|
@ -171,7 +172,7 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(),
|
||||||
|
|
||||||
return when (preference) {
|
return when (preference) {
|
||||||
notificationPreference -> {
|
notificationPreference -> {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NotificationHelper.NOTIFICATION_USE_CHANNELS) {
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
intent.action = "android.settings.APP_NOTIFICATION_SETTINGS"
|
intent.action = "android.settings.APP_NOTIFICATION_SETTINGS"
|
||||||
intent.putExtra("android.provider.extra.APP_PACKAGE", BuildConfig.APPLICATION_ID)
|
intent.putExtra("android.provider.extra.APP_PACKAGE", BuildConfig.APPLICATION_ID)
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.keylesspalace.tusky.entity.NewStatus
|
||||||
import com.keylesspalace.tusky.entity.Status
|
import com.keylesspalace.tusky.entity.Status
|
||||||
import com.keylesspalace.tusky.network.MastodonApi
|
import com.keylesspalace.tusky.network.MastodonApi
|
||||||
import com.keylesspalace.tusky.util.SaveTootHelper
|
import com.keylesspalace.tusky.util.SaveTootHelper
|
||||||
|
import com.keylesspalace.tusky.util.NotificationHelper
|
||||||
import dagger.android.AndroidInjection
|
import dagger.android.AndroidInjection
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
|
@ -72,10 +73,9 @@ class SendTootService : Service(), Injectable {
|
||||||
val tootToSend = intent.getParcelableExtra<TootToSend>(KEY_TOOT)
|
val tootToSend = intent.getParcelableExtra<TootToSend>(KEY_TOOT)
|
||||||
?: throw IllegalStateException("SendTootService started without $KEY_TOOT extra")
|
?: throw IllegalStateException("SendTootService started without $KEY_TOOT extra")
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NotificationHelper.NOTIFICATION_USE_CHANNELS) {
|
||||||
val channel = NotificationChannel(CHANNEL_ID, getString(R.string.send_toot_notification_channel_name), NotificationManager.IMPORTANCE_LOW)
|
val channel = NotificationChannel(CHANNEL_ID, getString(R.string.send_toot_notification_channel_name), NotificationManager.IMPORTANCE_LOW)
|
||||||
notificationManager.createNotificationChannel(channel)
|
notificationManager.createNotificationChannel(channel)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var notificationText = tootToSend.warningText
|
var notificationText = tootToSend.warningText
|
||||||
|
|
|
@ -124,6 +124,12 @@ public class NotificationHelper {
|
||||||
*/
|
*/
|
||||||
private static final int NOTIFICATION_CHECK_INTERVAL_MINUTES = 15;
|
private static final int NOTIFICATION_CHECK_INTERVAL_MINUTES = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* by setting this as false, it's possible to test legacy notification channels on newer devices
|
||||||
|
*/
|
||||||
|
//public static final boolean NOTIFICATION_USE_CHANNELS = false;
|
||||||
|
public static final boolean NOTIFICATION_USE_CHANNELS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a given Mastodon notification and either creates a new Android notification or updates
|
* Takes a given Mastodon notification and either creates a new Android notification or updates
|
||||||
|
@ -353,7 +359,7 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createNotificationChannelsForAccount(@NonNull AccountEntity account, @NonNull Context context) {
|
public static void createNotificationChannelsForAccount(@NonNull AccountEntity account, @NonNull Context context) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NOTIFICATION_USE_CHANNELS) {
|
||||||
|
|
||||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
@ -411,7 +417,7 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteNotificationChannelsForAccount(@NonNull AccountEntity account, @NonNull Context context) {
|
public static void deleteNotificationChannelsForAccount(@NonNull AccountEntity account, @NonNull Context context) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NOTIFICATION_USE_CHANNELS) {
|
||||||
|
|
||||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
@ -422,7 +428,7 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteLegacyNotificationChannels(@NonNull Context context, @NonNull AccountManager accountManager) {
|
public static void deleteLegacyNotificationChannels(@NonNull Context context, @NonNull AccountManager accountManager) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NOTIFICATION_USE_CHANNELS) {
|
||||||
|
|
||||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
@ -441,7 +447,7 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean areNotificationsEnabled(@NonNull Context context, @NonNull AccountManager accountManager) {
|
public static boolean areNotificationsEnabled(@NonNull Context context, @NonNull AccountManager accountManager) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NOTIFICATION_USE_CHANNELS) {
|
||||||
|
|
||||||
// on Android >= O, notifications are enabled, if at least one channel is enabled
|
// on Android >= O, notifications are enabled, if at least one channel is enabled
|
||||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
@ -505,7 +511,7 @@ public class NotificationHelper {
|
||||||
private static boolean filterNotification(AccountEntity account, Notification notification,
|
private static boolean filterNotification(AccountEntity account, Notification notification,
|
||||||
Context context) {
|
Context context) {
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NOTIFICATION_USE_CHANNELS) {
|
||||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
String channelId = getChannelId(account, notification);
|
String channelId = getChannelId(account, notification);
|
||||||
|
@ -559,7 +565,7 @@ public class NotificationHelper {
|
||||||
private static void setupPreferences(AccountEntity account,
|
private static void setupPreferences(AccountEntity account,
|
||||||
NotificationCompat.Builder builder) {
|
NotificationCompat.Builder builder) {
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (NOTIFICATION_USE_CHANNELS) {
|
||||||
return; //do nothing on Android O or newer, the system uses the channel settings anyway
|
return; //do nothing on Android O or newer, the system uses the channel settings anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ public abstract class StatusViewData {
|
||||||
boolean isUserMuted, boolean isThreadMutedOnBackend, int conversationId, @Nullable List<EmojiReaction> emojiReactions) {
|
boolean isUserMuted, boolean isThreadMutedOnBackend, int conversationId, @Nullable List<EmojiReaction> emojiReactions) {
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
if (Build.VERSION.SDK_INT == 23) {
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
||||||
// https://github.com/tuskyapp/Tusky/issues/563
|
// https://github.com/tuskyapp/Tusky/issues/563
|
||||||
this.content = replaceCrashingCharacters(content);
|
this.content = replaceCrashingCharacters(content);
|
||||||
this.spoilerText = spoilerText == null ? null : replaceCrashingCharacters(spoilerText).toString();
|
this.spoilerText = spoilerText == null ? null : replaceCrashingCharacters(spoilerText).toString();
|
||||||
|
|
Loading…
Reference in New Issue