Update based on comments from Doug

This commit is contained in:
David Langley 2021-09-09 17:00:45 +01:00
parent 158ef08eec
commit ce7f015d91
8 changed files with 42 additions and 45 deletions

View file

@ -18,7 +18,7 @@ import Foundation
/**
A protocol that any class or struct can conform to
so that it can easiy produce avatar data.
so that it can easily produce avatar data.
E.g. MXRoom, MxUser can conform to this making it
easy to grab the avatar data for display.
*/

View file

@ -19,6 +19,11 @@ import Combine
/**
XCTest utility to wait for results from publishers, so that the output can be used for assertions.
```
let collectedEvents = somePublisher.collect(3).first()
XCTAssertEqual(try xcAwait(collectedEvents), [expected, values, here])
```
*/
@available(iOS 14.0, *)
extension XCTestCase {

View file

@ -25,7 +25,7 @@ final class TemplateUserProfileCoordinator: Coordinator {
// MARK: Private
private let parameters: TemplateUserProfileCoordinatorParameters
private let templateUserProfileViewController: UIViewController
private let templateUserProfileHostingController: UIViewController
private var templateUserProfileViewModel: TemplateUserProfileViewModelProtocol
// MARK: Public
@ -43,7 +43,7 @@ final class TemplateUserProfileCoordinator: Coordinator {
let view = TemplateUserProfile(viewModel: viewModel)
.addDependency(AvatarService.instantiate(mediaManager: parameters.session.mediaManager))
templateUserProfileViewModel = viewModel
templateUserProfileViewController = VectorHostingController(rootView: view)
templateUserProfileHostingController = VectorHostingController(rootView: view)
}
// MARK: - Public
@ -59,6 +59,6 @@ final class TemplateUserProfileCoordinator: Coordinator {
}
func toPresentable() -> UIViewController {
return self.templateUserProfileViewController
return self.templateUserProfileHostingController
}
}

View file

@ -30,7 +30,7 @@ class TemplateUserProfileService: TemplateUserProfileServiceProtocol {
// MARK: Public
var userId: String {
return session.myUser.userId
session.myUser.userId
}
var displayName: String? {
@ -62,7 +62,7 @@ class TemplateUserProfileService: TemplateUserProfileServiceProtocol {
let event = event,
case .presence = MXEventType(identifier: event.eventId)
else { return }
self.presenceSubject.send(TemplateUserProfilePresence(mxPresence: self.session.myUser.presence))
self.presenceSubject.send(TemplateUserProfilePresence(mxPresence: self.session.myUser.presence))
}
// TODO: Add log back when abstract logger added to RiotSwiftUI
// if reference == nil {

View file

@ -21,9 +21,12 @@ struct TemplateUserProfile: View {
// MARK: - Properties
// MARK: Private
@Environment(\.theme) private var theme: ThemeSwiftUI
// MARK: Public
@Environment(\.theme) var theme: ThemeSwiftUI
@ObservedObject var viewModel: TemplateUserProfileViewModel
var body: some View {
@ -35,33 +38,26 @@ struct TemplateUserProfile: View {
)
Divider()
VStack{
HStack(alignment: .center){
Spacer()
Text("More great user content!")
.font(theme.fonts.title2)
.foregroundColor(theme.colors.secondaryContent)
Spacer()
}
Text("More great user content!")
.font(theme.fonts.title2)
.foregroundColor(theme.colors.secondaryContent)
}
.frame(maxHeight: .infinity)
}
.background(theme.colors.background)
.frame(maxHeight: .infinity)
.navigationTitle(viewModel.viewState.displayName ?? "")
.navigationBarItems(leading: leftButton, trailing: rightButton)
}
// MARK: Private
private var leftButton: some View {
Button(VectorL10n.cancel) {
viewModel.proccess(viewAction: .cancel)
}
}
private var rightButton: some View {
Button(VectorL10n.done) {
viewModel.proccess(viewAction: .cancel)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(VectorL10n.done) {
viewModel.process(viewAction: .cancel)
}
}
ToolbarItem(placement: .cancellationAction) {
Button(VectorL10n.cancel) {
viewModel.process(viewAction: .cancel)
}
}
}
}
}

View file

@ -21,9 +21,10 @@ struct TemplateUserProfileHeader: View {
// MARK: - Properties
// MARK: Public
// MARK: Private
@Environment(\.theme) private var theme: ThemeSwiftUI
@Environment(\.theme) var theme: ThemeSwiftUI
// MARK: Public
let avatar: AvatarInputProtocol?
let displayName: String?
let presence: TemplateUserProfilePresence
@ -31,17 +32,13 @@ struct TemplateUserProfileHeader: View {
var body: some View {
VStack {
if let avatar = avatar {
HStack{
Spacer()
AvatarImage(avatarData: avatar, size: .xxLarge)
Spacer()
}
AvatarImage(avatarData: avatar, size: .xxLarge)
.padding(.vertical)
}
VStack(spacing: 8){
Text(displayName ?? "")
.font(theme.fonts.title3)
TemplateUserProfilePresenceView(presense: presence)
TemplateUserProfilePresenceView(presence: presence)
}
}
}

View file

@ -22,25 +22,24 @@ struct TemplateUserProfilePresenceView: View {
// MARK: - Properties
// MARK: Public
let presense: TemplateUserProfilePresence
let presence: TemplateUserProfilePresence
var body: some View {
HStack {
Image(systemName: "circle.fill")
.resizable()
.frame(width: 8, height: 8)
.foregroundColor(foregroundColor)
Text(presense.title)
Text(presence.title)
.font(.subheadline)
}
.foregroundColor(foregroundColor)
.padding(0)
}
// MARK: Private
// MARK: View Components
private var foregroundColor: Color {
switch presense {
switch presence {
case .online:
return .green
case .idle:
@ -59,7 +58,7 @@ struct TemplateUserProfilePresenceView_Previews: PreviewProvider {
VStack(alignment:.leading){
Text("Presence")
ForEach(TemplateUserProfilePresence.allCases) { presence in
TemplateUserProfilePresenceView(presense: presence)
TemplateUserProfilePresenceView(presence: presence)
}
}
}

View file

@ -50,12 +50,12 @@ class TemplateUserProfileViewModel: ObservableObject, TemplateUserProfileViewMod
}
// MARK: - Public
func proccess(viewAction: TemplateUserProfileViewAction) {
func process(viewAction: TemplateUserProfileViewAction) {
switch viewAction {
case .cancel:
self.cancel()
cancel()
case .done:
self.done()
done()
}
}