-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4850 bring leaving space experience in line with web (#6062)
* Bring leaving space experience in line with Web #4850 - Done
- Loading branch information
Showing
23 changed files
with
537 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Copyright 2022 New Vector Ltd | ||
// | ||
// 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 | ||
|
||
@available(iOS 14.0, *) | ||
struct RadioButton: View { | ||
|
||
// MARK: - Properties | ||
|
||
var title: String | ||
var selected: Bool | ||
let action: () -> Void | ||
|
||
// MARK: Private | ||
|
||
@Environment(\.theme) private var theme: ThemeSwiftUI | ||
|
||
// MARK: Public | ||
|
||
var body: some View { | ||
Button(action: action, label: { | ||
HStack { | ||
Image(systemName: selected ? "largecircle.fill.circle" : "circle") | ||
.renderingMode(.template) | ||
.resizable().frame(width: 20, height: 20) | ||
.foregroundColor(selected ? theme.colors.accent : theme.colors.tertiaryContent) | ||
Text(title) | ||
.font(theme.fonts.callout) | ||
.foregroundColor(theme.colors.primaryContent) | ||
Spacer() | ||
} | ||
.padding(EdgeInsets(top: 3, leading: 3, bottom: 3, trailing: 3)) | ||
.background(Color.clear) | ||
}) | ||
} | ||
} | ||
|
||
// MARK: - Previews | ||
|
||
@available(iOS 14.0, *) | ||
struct RadioButton_Previews: PreviewProvider { | ||
static var previews: some View { | ||
Group { | ||
buttonGroup.theme(.light) | ||
buttonGroup.theme(.dark).preferredColorScheme(.dark) | ||
} | ||
.padding() | ||
} | ||
|
||
static var buttonGroup: some View { | ||
VStack { | ||
RadioButton(title: "A title", selected: false, action: {}) | ||
RadioButton(title: "A title", selected: true, action: {}) | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
RiotSwiftUI/Modules/Spaces/LeaveSpace/Coordinator/LeaveSpaceViewProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// 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 | ||
|
||
class LeaveSpaceViewProvider: MatrixItemChooserCoordinatorViewProvider { | ||
|
||
private let navTitle: String? | ||
|
||
init(navTitle: String?) { | ||
self.navTitle = navTitle | ||
} | ||
|
||
@available(iOS 14, *) | ||
func view(with viewModel: MatrixItemChooserViewModelType.Context) -> AnyView { | ||
return AnyView(LeaveSpace(viewModel: viewModel, navTitle: navTitle)) | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
RiotSwiftUI/Modules/Spaces/LeaveSpace/Service/MatrixSDK/LeaveSpaceItemsProcessor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// 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 Foundation | ||
import MatrixSDK | ||
|
||
class LeaveSpaceItemsProcessor: MatrixItemChooserProcessorProtocol { | ||
|
||
// MARK: Private | ||
|
||
private let spaceId: String | ||
private let session: MXSession | ||
|
||
// MARK: Setup | ||
|
||
init(spaceId: String, session: MXSession) { | ||
self.spaceId = spaceId | ||
self.session = session | ||
self.dataSource = MatrixItemChooserDirectChildrenDataSource(parentId: spaceId) | ||
} | ||
|
||
// MARK: MatrixItemChooserSelectionProcessorProtocol | ||
|
||
private(set) var dataSource: MatrixItemChooserDataSource | ||
|
||
var loadingText: String? { | ||
VectorL10n.roomAccessSettingsScreenSettingRoomAccess | ||
} | ||
|
||
func computeSelection(withIds itemsIds: [String], completion: @escaping (Result<Void, Error>) -> Void) { | ||
guard let space = self.session.spaceService.getSpace(withId: self.spaceId) else { | ||
return | ||
} | ||
|
||
self.leaveAllRooms(from: itemsIds, at: 0) { [weak self] result in | ||
guard let self = self else { return } | ||
|
||
switch result { | ||
case .success: | ||
self.leaveSpace(space, completion: completion) | ||
case .failure(let error): | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool { | ||
return true | ||
} | ||
|
||
// MARK: Private | ||
|
||
/// Leave room with room ID from `roomIds` at `index`. | ||
/// Recurse to the next index once done. | ||
private func leaveAllRooms(from roomIds: [String], at index: Int, completion: @escaping (Result<Void, Error>) -> Void) { | ||
guard index < roomIds.count else { | ||
completion(.success(())) | ||
return | ||
} | ||
|
||
guard let room = self.session.room(withRoomId: roomIds[index]), !room.isDirect else { | ||
self.leaveAllRooms(from: roomIds, at: index+1, completion: completion) | ||
return | ||
} | ||
|
||
MXLog.debug("[LeaveSpaceItemsProcessor] leaving room \(room.displayName ?? room.roomId)") | ||
room.leave { [weak self] response in | ||
guard let self = self else { return } | ||
|
||
switch response { | ||
case .success: | ||
self.leaveAllRooms(from: roomIds, at: index+1, completion: completion) | ||
case .failure(let error): | ||
MXLog.error("[LeaveSpaceItemsProcessor] failed to leave room with error: \(error)") | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
private func leaveSpace(_ space: MXSpace, completion: @escaping (Result<Void, Error>) -> Void) { | ||
MXLog.debug("[LeaveSpaceItemsProcessor] leaving space") | ||
space.room?.leave(completion: { response in | ||
switch response { | ||
case .success: | ||
completion(.success(())) | ||
case .failure(let error): | ||
MXLog.error("[LeaveSpaceItemsProcessor] failed to leave space with error: \(error)") | ||
completion(.failure(error)) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.