mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-09 18:08:29 +00:00
* wip
* refactor, fix bindings
* wip
* wip
* fixes
* wip
* information map, logos
* global conditions hack
* restructure
* restructure
* texts
* text
* restructure
* wip
* restructure
* rename
* wip
* conditions for all
* comment
* onboarding wip
* onboarding wip
* fix paddings
* fix paddings
* wip
* fix padding
* onboarding wip
* nav link instead of sheet
* pretty button
* large titles
* notifications mode button style
* reenable demo operator
* Revert "reenable demo operator"
This reverts commit 42111eb333.
* padding
* reenable demo operator
* refactor (removes additional model api)
* style
* bold
* bold
* light/dark
* fix button
* comment
* wip
* remove preset
* new types
* api types
* apis
* smp and xftp servers in single view
* test operator servers, refactor
* save in main view
* better progress
* better in progress
* remove shadow
* update
* apis
* conditions view wip
* load text
* remove custom servers button from onboarding, open already conditions in nav link
* allow to continue with simplex on onboarding
* footer
* existing users notice
* fix to not show nothing on no action
* disable notice
* review later
* disable notice
* wip
* wip
* wip
* wip
* optional tag
* fix
* fix tags
* fix
* wip
* remove coding keys
* fix onboarding
* rename
* rework model wip
* wip
* wip
* wip
* fix
* wip
* wip
* delete
* simplify
* wip
* fix delete
* ios: server operators ui wip
* refactor
* edited
* save servers on dismiss/back
* ios: add address card and remove address from onboarding (#5181)
* ios: add address card and remove address from onboarding
* allow for address creation in info when open via card
* conditions interactions wip
* conditions interactions wip
* fix
* wip
* wip
* wip
* wip
* rename
* wip
* fix
* remove operator binding
* fix set enabled
* rename
* cleanup
* text
* fix info view dark mode
* update lib
* ios: operators & servers validation
* fix
* ios: align onboarding style
* ios: align onboarding style
* ios: operators info (#5207)
* ios: operators info
* update
* update texts
* texts
---------
Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
---------
Co-authored-by: Diogo <diogofncunha@gmail.com>
Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
120 lines
4.0 KiB
Swift
120 lines
4.0 KiB
Swift
//
|
|
// NotificationsModeView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 03/07/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct SetNotificationsMode: View {
|
|
@EnvironmentObject var m: ChatModel
|
|
@State private var notificationMode = NotificationsMode.instant
|
|
@State private var showAlert: NotificationAlert?
|
|
|
|
var body: some View {
|
|
GeometryReader { g in
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text("Push notifications")
|
|
.font(.largeTitle)
|
|
.bold()
|
|
.frame(maxWidth: .infinity)
|
|
|
|
Text("Send notifications:")
|
|
ForEach(NotificationsMode.values) { mode in
|
|
NtfModeSelector(mode: mode, selection: $notificationMode)
|
|
}
|
|
|
|
Spacer()
|
|
|
|
Button {
|
|
if let token = m.deviceToken {
|
|
setNotificationsMode(token, notificationMode)
|
|
} else {
|
|
AlertManager.shared.showAlertMsg(title: "No device token!")
|
|
}
|
|
onboardingStageDefault.set(.onboardingComplete)
|
|
m.onboardingStage = .onboardingComplete
|
|
} label: {
|
|
if case .off = notificationMode {
|
|
Text("Use chat")
|
|
} else {
|
|
Text("Enable notifications")
|
|
}
|
|
}
|
|
.buttonStyle(OnboardingButtonStyle())
|
|
.padding(.bottom)
|
|
}
|
|
.padding()
|
|
.frame(minHeight: g.size.height)
|
|
}
|
|
}
|
|
.frame(maxHeight: .infinity)
|
|
}
|
|
|
|
private func setNotificationsMode(_ token: DeviceToken, _ mode: NotificationsMode) {
|
|
switch mode {
|
|
case .off:
|
|
m.tokenStatus = .new
|
|
m.notificationMode = .off
|
|
default:
|
|
Task {
|
|
do {
|
|
let status = try await apiRegisterToken(token: token, notificationMode: mode)
|
|
await MainActor.run {
|
|
m.tokenStatus = status
|
|
m.notificationMode = mode
|
|
}
|
|
} catch let error {
|
|
let a = getErrorAlert(error, "Error enabling notifications")
|
|
AlertManager.shared.showAlertMsg(
|
|
title: a.title,
|
|
message: a.message
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct NtfModeSelector: View {
|
|
@EnvironmentObject var theme: AppTheme
|
|
var mode: NotificationsMode
|
|
@Binding var selection: NotificationsMode
|
|
@State private var tapped = false
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(mode.label)
|
|
.font(.headline)
|
|
.foregroundColor(selection == mode ? theme.colors.primary : theme.colors.secondary)
|
|
Text(ntfModeDescription(mode))
|
|
.lineLimit(10)
|
|
.font(.subheadline)
|
|
}
|
|
.padding(12)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.background(tapped ? Color(uiColor: .secondarySystemFill) : theme.colors.background)
|
|
.clipShape(RoundedRectangle(cornerRadius: 18))
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: 18)
|
|
.stroke(selection == mode ? theme.colors.primary : Color(uiColor: .secondarySystemFill), lineWidth: 2)
|
|
)
|
|
._onButtonGesture { down in
|
|
tapped = down
|
|
if down { selection = mode }
|
|
} perform: {}
|
|
}
|
|
}
|
|
|
|
struct NotificationsModeView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SetNotificationsMode()
|
|
}
|
|
}
|