mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-16 06:28:27 +02:00
112 lines
4.4 KiB
Swift
112 lines
4.4 KiB
Swift
//
|
|
/*
|
|
* Copyright (c) 2021 BWI GmbH
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import SwiftUI
|
|
|
|
/// Helper class for making our SwiftUI view available to ObjectiveC
|
|
@objcMembers class DeveloperSettingsViewController: NSObject {
|
|
|
|
@available(iOS 14.0, *)
|
|
class func makeViewController(session: MXSession) -> UIViewController {
|
|
return UIHostingController(rootView: DeveloperSettingsView(session: session))
|
|
}
|
|
}
|
|
|
|
@available(iOS 14.0, *)
|
|
struct DeveloperSettingsView: View {
|
|
let session: MXSession?
|
|
|
|
@State private var showAlert = false
|
|
|
|
var body: some View {
|
|
List {
|
|
Button(action: { showAlert = createNewPersonalNotesRoom(mxSession: session) }) {
|
|
Text(NSLocalizedString("bwi_settings_developer_create_new_personal_notes_room", tableName: "Vector", comment: ""))
|
|
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
|
.font(.system(size: 17))
|
|
}
|
|
.alert(isPresented: $showAlert) {
|
|
Alert(title: Text(NSLocalizedString("bwi_settings_developer", tableName: "Vector", comment: "")), message: Text(NSLocalizedString("bwi_settings_developer_new_personal_notes_room_created", tableName: "Vector", comment: "")), dismissButton: .default(Text("Ok")))
|
|
}
|
|
|
|
Button(action: { showAlert = resetMatomoInfoScreen() }) {
|
|
Text(NSLocalizedString("bwi_settings_developer_reset_matomo_info", tableName: "Vector", comment: ""))
|
|
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
|
.font(.system(size: 17))
|
|
}
|
|
.alert(isPresented: $showAlert) {
|
|
Alert(title: Text(NSLocalizedString("bwi_settings_developer", tableName: "Vector", comment: "")), message: Text(NSLocalizedString("bwi_settings_developer_show_matomo_privacy_notes_resetted", tableName: "Vector", comment: "")), dismissButton: .default(Text("Ok")))
|
|
}
|
|
Button(action: { _ = restrictUser(mxSession: session) }) {
|
|
Text(NSLocalizedString("bwi_settings_developer_restrict_user", tableName: "Bwi", comment: ""))
|
|
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
|
.font(.system(size: 17))
|
|
}
|
|
Button(action: { _ = unrestrictUser(mxSession: session) }) {
|
|
Text(NSLocalizedString("bwi_settings_developer_unrestrict_user", tableName: "Bwi", comment: ""))
|
|
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
|
.font(.system(size: 17))
|
|
}
|
|
}
|
|
.navigationTitle(NSLocalizedString("bwi_settings_developer", tableName: "Vector", comment: ""))
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
}
|
|
|
|
}
|
|
|
|
@available(iOS 14.0, *)
|
|
struct DeveloperSettingsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
DeveloperSettingsView(session: nil)
|
|
}
|
|
}
|
|
|
|
// MARK: - Button Actions
|
|
|
|
fileprivate func createNewPersonalNotesRoom(mxSession: MXSession?) -> Bool {
|
|
guard let mxSession = mxSession else {
|
|
return false
|
|
}
|
|
|
|
let service = PersonalNotesDefaultService(mxSession: mxSession)
|
|
service.resetPersonalNotesRoom()
|
|
service.createPersonalNotesRoomIfNeeded()
|
|
return true
|
|
}
|
|
|
|
fileprivate func resetMatomoInfoScreen() -> Bool {
|
|
UserDefaults.standard.set(false, forKey: "bwi_matomo_info_screen_shown")
|
|
return true
|
|
}
|
|
|
|
fileprivate func restrictUser(mxSession: MXSession?) -> Bool {
|
|
guard let mxSession = mxSession else {
|
|
return false
|
|
}
|
|
AccountRestrictionService(mxSession: mxSession).updateRestriction(roomAccess: true, addressListAccess: true)
|
|
|
|
return true
|
|
}
|
|
|
|
fileprivate func unrestrictUser(mxSession: MXSession?) -> Bool {
|
|
guard let mxSession = mxSession else {
|
|
return false
|
|
}
|
|
AccountRestrictionService(mxSession: mxSession).updateRestriction(roomAccess: false, addressListAccess: false)
|
|
return true
|
|
}
|