damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

NotificationSettingsView.swift (3402B)


      1 //
      2 //  NotificationSettings.swift
      3 //  damus
      4 //
      5 //  Created by William Casarin on 2023-04-05.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct NotificationSettingsView: View {
     11     @ObservedObject var settings: UserSettingsStore
     12     
     13     @Environment(\.dismiss) var dismiss
     14     
     15     func indicator_binding(_ val: NewEventsBits) -> Binding<Bool> {
     16         return Binding.init(get: {
     17             (settings.notification_indicators & val.rawValue) > 0
     18         }, set: { v in
     19             if v {
     20                 settings.notification_indicators |= val.rawValue
     21             } else {
     22                 settings.notification_indicators &= ~val.rawValue
     23             }
     24         })
     25     }
     26     
     27     var body: some View {
     28         Form {
     29             Section(header: Text(NSLocalizedString("Local Notifications", comment: "Section header for damus local notifications user configuration"))) {
     30                 Toggle(NSLocalizedString("Zaps", comment: "Setting to enable Zap Local Notification"), isOn: $settings.zap_notification)
     31                     .toggleStyle(.switch)
     32                 Toggle(NSLocalizedString("Mentions", comment: "Setting to enable Mention Local Notification"), isOn: $settings.mention_notification)
     33                     .toggleStyle(.switch)
     34                 Toggle(NSLocalizedString("Reposts", comment: "Setting to enable Repost Local Notification"), isOn: $settings.repost_notification)
     35                     .toggleStyle(.switch)
     36                 Toggle(NSLocalizedString("Likes", comment: "Setting to enable Like Local Notification"), isOn: $settings.like_notification)
     37                     .toggleStyle(.switch)
     38                 Toggle(NSLocalizedString("DMs", comment: "Setting to enable DM Local Notification"), isOn: $settings.dm_notification)
     39                     .toggleStyle(.switch)
     40             }
     41 
     42             Section(header: Text(NSLocalizedString("Notification Preference", comment: "Section header for Notification Preferences"))) {
     43                 Toggle(NSLocalizedString("Show only from users you follow", comment: "Setting to Show notifications only associated to users your follow"), isOn: $settings.notification_only_from_following)
     44                     .toggleStyle(.switch)
     45             }
     46             
     47             Section(header: Text(NSLocalizedString("Notification Dots", comment: "Section header for notification indicator dot settings"))) {
     48                 Toggle(NSLocalizedString("Zaps", comment: "Setting to enable Zap Local Notification"), isOn: indicator_binding(.zaps))
     49                     .toggleStyle(.switch)
     50                 Toggle(NSLocalizedString("Mentions", comment: "Setting to enable Mention Local Notification"), isOn: indicator_binding(.mentions))
     51                     .toggleStyle(.switch)
     52                 Toggle(NSLocalizedString("Reposts", comment: "Setting to enable Repost Local Notification"), isOn: indicator_binding(.reposts))
     53                     .toggleStyle(.switch)
     54                 Toggle(NSLocalizedString("Likes", comment: "Setting to enable Like Local Notification"), isOn: indicator_binding(.likes))
     55                     .toggleStyle(.switch)
     56             }
     57         }
     58         .navigationTitle("Notifications")
     59         .onReceive(handle_notify(.switched_timeline)) { _ in
     60             dismiss()
     61         }
     62     }
     63 }
     64 
     65 
     66 struct NotificationSettings_Previews: PreviewProvider {
     67     static var previews: some View {
     68         NotificationSettingsView(settings: UserSettingsStore())
     69     }
     70 }