Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/Threema/MyProfile/RevocationsView/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 6 kB image not shown  

Quelle  RevokeView.swift   Sprache: JAVA

 

import SwiftUI
import ThreemaFramework
import ThreemaMacros

struct RevokeView: View {
    private let identity = MyIdentityStore.shared().identity!
    
    @Binding var tabSelection: Int
    @Binding var successViewType: SuccessViewType
    
    @State private var isDeleting = false
    @State private var textIsSameAsID = false
    @State private var enteredText = ""
    
    // Workaround: TextField has the wrong color
    @State private var textFieldColor: Color = .white
    
    var body: some View {
        GeometryReader { proxy in
            ScrollView {
                VStack {
                    Text(#localize("my_profile_revoke_identity_view_title"))
                        .bold()
                        .font(.title2)
                    
                    GroupBox {
                        VStack(alignment: .leading) {
                            BulletText(string: String.localizedStringWithFormat(
                                #localize("my_profile_delete_bullet_id"),
                                TargetManager.localizedAppName
                            ))
                            BulletText(string: String.localizedStringWithFormat(
                                #localize("my_profile_delete_bullet_safe"),
                                TargetManager.localizedAppName
                            ))
                            BulletText(string: #localize("my_profile_delete_bullet_linked"))
                        }
                        .padding(.leading, 24.0)
                        .padding(.top, 1)
                        
                        VStack(alignment: .leading) {
                            Text(
                                String
                                    .localizedStringWithFormat(
                                        #localize("my_profile_revoke_identity_view_enter_id"),
                                        TargetManager.localizedAppName,
                                        identity
                                    )
                            )
                            
                            TextField(
                                String
                                    .localizedStringWithFormat(
                                        #localize("my_profile_revoke_identity_view_placeholder"),
                                        TargetManager.localizedAppName
                                    ),
                                text: $enteredText
                            )
                            .foregroundStyle(textFieldColor)
                            .textFieldStyle(.roundedBorder)
                            .textCase(.uppercase)
                            .textInputAutocapitalization(.characters)
                            .onChange(of: enteredText) {
                                // Workaround: TextField has the wrong color
                                textFieldColor = .white
                                textIsSameAsID = enteredText == identity
                            }
                        }
                        .padding(.top)
                    } label: {
                        Label(
                            String.localizedStringWithFormat(
                                #localize("my_profile_revoke_info_delete"),
                                TargetManager.appName,
                                TargetManager.appName
                            ),
                            systemImage: "trash.circle.fill"
                        )
                    }
                    .groupBoxStyle(.info)
                    
                    GroupBox {
                        Label {
                            Text(String.localizedStringWithFormat(
                                #localize("my_profile_delete_info_revoke"),
                                TargetManager.localizedAppName
                            ))
                            .foregroundColor(textIsSameAsID ? .red : .white)
                        } icon: {
                            Image(systemName: "exclamationmark.triangle.fill")
                                .foregroundStyle(
                                    .white,
                                    textIsSameAsID ? .red : .orange
                                )
                        }
                    } label: {
                        EmptyView()
                    }
                    .groupBoxStyle(.info)
                    
                    Spacer()
                    
                    VStack(spacing: 12) {
                        ThreemaButton(
                            title: #localize("my_profile_revoke_identity_view_button_revoke"),
                            role: .destructive,
                            style: .bordered,
                            size: .fullWidth
                        ) {
                            revokePressed()
                        }
                        .disabled(isDeleting)
                        .disabled(!textIsSameAsID)
                        
                        ThreemaButton(
                            title: #localize("back"),
                            style: .borderedProminent,
                            size: .fullWidth,
                            action: {
                                tabSelection = 0
                            }
                        )
                        .disabled(isDeleting)
                    }
                    .padding(.horizontal)
                }
                .frame(maxHeight: .infinity)
                .frame(minHeight: proxy.size.height)
            }
        }
        .opacity(tabSelection != 2 || successViewType == .revoke ? 1.0 : 0.0)
        .onTapGesture {
            UIApplication.shared.sendAction(
                #selector(UIResponder.resignFirstResponder),
                to: nil,
                from: nil,
                for: nil
            )
        }
    }
    
    private func revokePressed() {
        isDeleting = true
        Task { @MainActor in
            do {
                try await DeleteRevokeIdentityManager.revokeIdentity()
                DeleteRevokeIdentityManager.deleteBackups()
                await DeleteRevokeIdentityManager.deleteLocalData()
                successViewType = .revoke
                tabSelection = 2
            }
            catch {
                NotificationPresenterWrapper.shared.present(type: .revocationFailed)
                isDeleting = false
                enteredText = ""
            }
        }
    }
}

#Preview {
    RevokeView(tabSelection: .constant(1), successViewType: .constant(.revoke))
        .preferredColorScheme(.dark)
}

Messung
CHZG
879710094

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.