public override bool Equals(object obj) { return(obj is DiscordSettings settings && BotToken == settings.BotToken && ClientID == settings.ClientID && StatusMessage == settings.StatusMessage && MonitoredChannels.SequenceEqual(settings.MonitoredChannels) && TvShowRoles.SequenceEqual(settings.TvShowRoles) && MovieRoles.SequenceEqual(settings.MovieRoles) && MovieDownloadClient == settings.MovieDownloadClient && MovieDownloadClientConfigurationHash == settings.MovieDownloadClientConfigurationHash && TvShowDownloadClient == settings.TvShowDownloadClient && TvShowDownloadClientConfigurationHash == settings.TvShowDownloadClientConfigurationHash && EnableRequestsThroughDirectMessages == settings.EnableRequestsThroughDirectMessages && AutomaticallyNotifyRequesters == settings.AutomaticallyNotifyRequesters && NotificationMode == settings.NotificationMode && NotificationChannels.SequenceEqual(settings.NotificationChannels) && AutomaticallyPurgeCommandMessages == settings.AutomaticallyPurgeCommandMessages); }
public static void Initialize(Context context, bool resetToken, bool createNotificationChannel = true, bool autoRegistration = true) { _context = context; CrossPushNotification.Current.NotificationHandler = CrossPushNotification.Current.NotificationHandler ?? new DefaultPushNotificationHandler(); FirebaseMessaging.Instance.AutoInitEnabled = autoRegistration; if (autoRegistration) { ThreadPool.QueueUserWorkItem(state => { var packageName = Application.Context.PackageManager.GetPackageInfo(Application.Context.PackageName, PackageInfoFlags.MetaData).PackageName; var versionCode = Application.Context.PackageManager.GetPackageInfo(Application.Context.PackageName, PackageInfoFlags.MetaData).VersionCode; var versionName = Application.Context.PackageManager.GetPackageInfo(Application.Context.PackageName, PackageInfoFlags.MetaData).VersionName; var prefs = Application.Context.GetSharedPreferences(KeyGroupName, FileCreationMode.Private); try { var storedVersionName = prefs.GetString(AppVersionNameKey, string.Empty); var storedVersionCode = prefs.GetString(AppVersionCodeKey, string.Empty); var storedPackageName = prefs.GetString(AppVersionPackageNameKey, string.Empty); if (resetToken || (!string.IsNullOrEmpty(storedPackageName) && (!storedPackageName.Equals(packageName, StringComparison.CurrentCultureIgnoreCase) || !storedVersionName.Equals(versionName, StringComparison.CurrentCultureIgnoreCase) || !storedVersionCode.Equals($"{versionCode}", StringComparison.CurrentCultureIgnoreCase)))) { ((PushNotificationManager)CrossPushNotification.Current).CleanUp(); } } catch (Exception ex) { _onNotificationError?.Invoke(CrossPushNotification.Current, new PushNotificationErrorEventArgs(PushNotificationErrorType.UnregistrationFailed, ex.ToString())); } finally { var editor = prefs.Edit(); editor.PutString(AppVersionNameKey, $"{versionName}"); editor.PutString(AppVersionCodeKey, $"{versionCode}"); editor.PutString(AppVersionPackageNameKey, $"{packageName}"); editor.Commit(); } CrossPushNotification.Current.RegisterForPushNotifications(); }); } if (Build.VERSION.SdkInt >= BuildVersionCodes.O && createNotificationChannel) { if (NotificationChannels == null || NotificationChannels.Count() == 0) { NotificationChannels = new List <NotificationChannelProps>() { new NotificationChannelProps(DefaultNotificationChannelId, DefaultNotificationChannelName, DefaultNotificationChannelImportance) }; } foreach (NotificationChannelProps channel in NotificationChannels) { // Create channel to show notifications. var channelId = channel.NotificationChannelId; var channelName = channel.NotificationChannelName; var channelImportance = channel.NotificationChannelImportance; var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService); var notChannel = new NotificationChannel(channelId, channelName, channelImportance); if (SoundUri != null) { try { var soundAttributes = new AudioAttributes.Builder() .SetContentType(AudioContentType.Sonification) .SetUsage(AudioUsageKind.Notification).Build(); notChannel.SetSound(SoundUri, soundAttributes); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } notificationManager.CreateNotificationChannel(notChannel); } } System.Diagnostics.Debug.WriteLine(CrossPushNotification.Current.Token); }