Files
bundesmessenger-ios/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/View/UserOtherSessionsToolbar.swift
T
Frank Rotermund 67df1a3e95 chore: FOSS Merge 1.27.11 (MESSENGER-7276)
Merge commit 'af0b6d4be985d9f26e5111d3fa01389c7321949f' into feature/7276_FOSS_Merge_1_27_11

# Conflicts:
#	Config/AppVersion.xcconfig
#	Gemfile.lock
#	IDETemplateMacros.plist
#	Podfile
#	Podfile.lock
#	README.md
#	Riot/Modules/Authentication/AuthenticationCoordinator.swift
#	Riot/Modules/Room/CellData/RoomBubbleCellData.m
#	Riot/target.yml
#	RiotNSE/NotificationService.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionModels.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionViewModel.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/Coordinator/AuthenticationServerSelectionCoordinator.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/View/AuthenticationServerSelectionScreen.swift
#	RiotSwiftUI/Modules/Room/CompletionSuggestion/Service/CompletionSuggestionService.swift
#	fastlane/Fastfile
2025-05-16 14:06:20 +02:00

116 lines
4.0 KiB
Swift

//
// Copyright 2022-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
struct UserOtherSessionsToolbar: ToolbarContent {
@Environment(\.theme) private var theme
@Binding var isEditModeEnabled: Bool
@Binding var filter: UserOtherSessionsFilter
@Binding var isShowLocationEnabled: Bool
let allItemsSelected: Bool
let sessionCount: Int
let showDeviceLogout: Bool
let onToggleSelection: () -> Void
let onSignOut: () -> Void
var body: some ToolbarContent {
navigationBarLeading()
navigationBarTrailing()
}
private func navigationBarLeading() -> some ToolbarContent {
ToolbarItemGroup(placement: .navigationBarLeading) {
if isEditModeEnabled {
Button {
onToggleSelection()
} label: {
Text(allItemsSelected ? VectorL10n.deselectAll : VectorL10n.selectAll)
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
}
}
}
}
private func navigationBarTrailing() -> some ToolbarContent {
ToolbarItemGroup(placement: .navigationBarTrailing) {
if isEditModeEnabled {
cancelButton()
} else {
filterMenuButton()
.offset(x: 12)
optionsMenu()
}
}
}
private func cancelButton() -> some View {
Button {
isEditModeEnabled = false
} label: {
Text(VectorL10n.cancel)
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
}
.font(theme.fonts.bodySB)
}
private func filterMenuButton() -> some View {
Button { } label: {
Menu {
Picker("", selection: $filter) {
ForEach(UserOtherSessionsFilter.allCases) { filter in
Text(filter.menuLocalizedName).tag(filter)
}
}
.labelsHidden()
} label: {
Image(filter == .all ? Asset.Images.userOtherSessionsFilter.name : Asset.Images.userOtherSessionsFilterSelected.name)
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
}
.accessibilityLabel(VectorL10n.userOtherSessionFilter)
}
}
private func optionsMenu() -> some View {
Button { } label: {
Menu {
if showDeviceLogout { // As you can only sign out the selected sessions, we don't allow selection when you're unable to sign out devices.
Button {
isEditModeEnabled = true
} label: {
Label(VectorL10n.userOtherSessionMenuSelectSessions, systemImage: "checkmark.circle")
}
.disabled(sessionCount == 0)
}
if BWIBuildSettings.shared.deviceManagerShowIPAddress {
Button {
isShowLocationEnabled.toggle()
} label: {
Label(showLocationInfo: isShowLocationEnabled)
}
}
if sessionCount > 0, showDeviceLogout {
DestructiveButton {
onSignOut()
} label: {
Label(VectorL10n.userOtherSessionMenuSignOutSessions(String(sessionCount)), systemImage: "rectangle.portrait.and.arrow.forward.fill")
}
}
} label: {
Image(systemName: "ellipsis.circle")
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
.padding(.horizontal, 4)
.padding(.vertical, 12)
}
}
.accessibilityIdentifier("More")
}
}