Fix crash when opening notification settings.

main
Cody Henthorne 2022-12-06 13:11:22 -05:00
rodzic 260e572071
commit 1764b21214
4 zmienionych plików z 7 dodań i 6 usunięć

Wyświetl plik

@ -104,7 +104,7 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
summary = DSLSettingsText.from(R.string.preferences__change_sound_and_vibration),
isEnabled = state.messageNotificationsState.notificationsEnabled,
onClick = {
NotificationChannels.getInstance().openChannelSettings(NotificationChannels.getInstance().messagesChannel, null)
NotificationChannels.getInstance().openChannelSettings(requireActivity(), NotificationChannels.getInstance().messagesChannel, null)
}
)
} else {

Wyświetl plik

@ -91,7 +91,7 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__customize),
summary = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__change_sound_and_vibration),
isEnabled = state.controlsEnabled,
onClick = { NotificationChannels.getInstance().openChannelSettings(state.recipient!!.notificationChannel!!, ConversationUtil.getShortcutId(state.recipient)) }
onClick = { NotificationChannels.getInstance().openChannelSettings(requireActivity(), state.recipient!!.notificationChannel!!, ConversationUtil.getShortcutId(state.recipient)) }
)
} else {
clickPref(

Wyświetl plik

@ -184,7 +184,7 @@ public final class EnableCallNotificationSettingsDialog extends DialogFragment {
}
private void showNotificationChannelSettings() {
NotificationChannels.getInstance().openChannelSettings(NotificationChannels.CALLS, null);
NotificationChannels.getInstance().openChannelSettings(requireActivity(), NotificationChannels.CALLS, null);
}
private void showAppSettings() {

Wyświetl plik

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.notifications;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
@ -127,7 +128,7 @@ public class NotificationChannels {
/**
* Navigates the user to the system settings for the desired notification channel.
*/
public void openChannelSettings(@NonNull String channelId, @Nullable String conversationId) {
public void openChannelSettings(@NonNull Activity activityContext, @NonNull String channelId, @Nullable String conversationId) {
if (!supported()) {
return;
}
@ -139,10 +140,10 @@ public class NotificationChannels {
if (conversationId != null && Build.VERSION.SDK_INT >= CONVERSATION_SUPPORT_VERSION) {
intent.putExtra(Settings.EXTRA_CONVERSATION_ID, conversationId);
}
context.startActivity(intent);
activityContext.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Channel settings activity not found", e);
Toast.makeText(context, R.string.NotificationChannels__no_activity_available_to_open_notification_channel_settings, Toast.LENGTH_SHORT).show();
Toast.makeText(activityContext, R.string.NotificationChannels__no_activity_available_to_open_notification_channel_settings, Toast.LENGTH_SHORT).show();
}
}