Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kloenk's changes #301

Draft
wants to merge 11 commits into
base: swift-5.5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Pods/CocoaPodsKeys
fastlane/Appfile
Configs/LocalConfig.xcconfig
.DS_Store
17 changes: 10 additions & 7 deletions Configs/GlobalConfig.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
// NIO_NAMESPACE = com.example.nio
// DEVELOPMENT_TEAM = Z123456789

NIO_NAMESPACE = com.example.nio
DEVELOPMENT_TEAM = Z123456789
NIO_NAMESPACE = com.example.nio
DEVELOPMENT_TEAM = Z123456789

APPGROUP = $(NIO_NAMESPACE)
PRODUCT_BUNDLE_IDENTIFIER = $(NIO_NAMESPACE).iOS
MAC_PRODUCT_BUNDLE_IDENTIFIER = $(NIO_NAMESPACE).mio
SHARE_EXTENSION_PRODUCT_BUNDLE_IDENTIFIER = $(PRODUCT_BUNDLE_IDENTIFIER).NioShareExtension
CODE_SIGN_STYLE = Manual
APPGROUP = $(NIO_NAMESPACE)
PRODUCT_BUNDLE_IDENTIFIER = $(NIO_NAMESPACE).iOS
MAC_PRODUCT_BUNDLE_IDENTIFIER = $(NIO_NAMESPACE).mio
SHARE_EXTENSION_PRODUCT_BUNDLE_IDENTIFIER = $(PRODUCT_BUNDLE_IDENTIFIER).NioShareExtension
INTENTS_EXTENSION_PRODUCT_BUNDLE_IDENTIFIER = $(PRODUCT_BUNDLE_IDENTIFIER).NioIntents
INTENTSUI_EXTENSION_PRODUCT_BUNDLE_IDENTIFIER = $(PRODUCT_BUNDLE_IDENTIFIER).NioIntentsUI
NOTIFICATIONS_EXTENSION_PRODUCT_BUNDLE_IDENTIFIER = $(PRODUCT_BUNDLE_IDENTIFIER).NioNotificationExtension
CODE_SIGN_STYLE = Manual

#include? "LocalConfig.xcconfig"
69 changes: 69 additions & 0 deletions Mio/Conversations/RecentRoomsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// RecentRoomsView.swift
// Mio
//
// Created by Finn Behrens on 13.06.21.
// Copyright © 2021 Kilian Koeltzsch. All rights reserved.
//

import SwiftUI
import MatrixSDK

import NioKit

struct RecentRoomsView: View {
@EnvironmentObject var store: AccountStore

@Binding var selectedNavigationItem: SelectedNavigationItem?
@Binding var selectedRoomId: MXRoom.MXRoomId?

let rooms: [NIORoom]

private var joinedRooms: [NIORoom] {
rooms.filter {$0.room.summary.membership == .join}
}

private var invitedRooms: [NIORoom] {
rooms.filter {$0.room.summary.membership == .invite}
}

var body: some View {
NavigationView {
List {
if !invitedRooms.isEmpty {
RoomsListSection(
sectionHeader: L10n.RecentRooms.PendingInvitations.header,
rooms: invitedRooms,
onLeaveAlertTitle: L10n.RecentRooms.PendingInvitations.Leave.alertTitle,
selectedRoomId: $selectedRoomId
)
}

RoomsListSection(
sectionHeader: invitedRooms.isEmpty ? nil : L10n.RecentRooms.Rooms.header ,
rooms: joinedRooms,
onLeaveAlertTitle: L10n.RecentRooms.Leave.alertTitle,
selectedRoomId: $selectedRoomId
)

}
.listStyle(SidebarListStyle())
.navigationTitle("Mio")
.frame(minWidth: Style.minSidebarWidth)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(action: { self.selectedNavigationItem = .newConversation }) {
Label(L10n.RecentRooms.AccessibilityLabel.newConversation,
systemImage: SFSymbol.newConversation.rawValue)
}
}
}
}
}
}

struct RecentRoomsView_Previews: PreviewProvider {
static var previews: some View {
RecentRoomsView(selectedNavigationItem: .constant(nil), selectedRoomId: .constant(nil), rooms: [])
}
}
86 changes: 86 additions & 0 deletions Mio/Conversations/RoomContainerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import SwiftUI
import Combine
import MatrixSDK

import NioKit

struct RoomContainerView: View {
@ObservedObject var room: NIORoom

@State private var showAttachmentPicker = false
@State private var showImagePicker = false
@State private var eventToReactTo: String?
@State private var showJoinAlert = false

private var roomView: RoomView {
RoomView(
events: room.events(),
isDirect: room.isDirect,
showAttachmentPicker: $showAttachmentPicker,
onCommit: { message in
asyncDetached {
await self.room.send(text: message)
}
},
onReact: { eventId in
self.eventToReactTo = eventId
},
onRedact: { eventId, reason in
self.room.redact(eventId: eventId, reason: reason)
},
onEdit: { message, eventId in
self.room.edit(text: message, eventId: eventId)
}
)
}

var body: some View {
VStack(spacing: 0) {
Divider() // TBD: This might be better done w/ toolbar styling
roomView
}
.navigationTitle(Text(room.summary.displayname ?? ""))
// TODO: action sheet
.sheet(item: $eventToReactTo) { eventId in
ReactionPicker { reaction in
self.room.react(toEventId: eventId, emoji: reaction)
self.eventToReactTo = nil
}
}
// TODO: join alert
.onAppear {
switch self.room.summary.membership {
case .invite:
self.showJoinAlert = true
case .join:
self.room.markAllAsRead()
default:
break
}
}
.environmentObject(room)
// TODO: background sheet thing
.background(Color(.textBackgroundColor))
.frame(minWidth: Style.minTimelineWidth)
}

// TODO: port me to macOS
/*
private var attachmentPickerSheet: ActionSheet {
ActionSheet(
title: Text(verbatim: L10n.Room.Attachment.selectType), buttons: [
.default(Text(verbatim: L10n.Room.Attachment.typePhoto), action: {
self.showImagePicker = true
}),
.cancel()
]
)
}*/
}


/*struct RecentRoomsContainerView_Previews: PreviewProvider {
static var previews: some View {
RecentRoomsView(selectedNavigationItem: .constant(nil), selectedRoomId: .constant(nil), rooms: [])
}
}*/
61 changes: 61 additions & 0 deletions Mio/Settings/SettingsContainerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// SettingsContainerView.swift
// Mio
//
// Created by Finn Behrens on 13.06.21.
// Copyright © 2021 Kilian Koeltzsch. All rights reserved.
//

import SwiftUI

import NioKit

struct SettingsContainerView: View {
@EnvironmentObject var store: AccountStore

var body: some View {
MacSettingsView(logoutAction: {
async {
await self.store.logout()
}
})
}
}

private struct MacSettingsView: View {
@AppStorage("accentColor") private var accentColor: Color = .purple
let logoutAction: () -> Void

var body: some View {
Form {
Section {
Picker(selection: $accentColor, label: Text(verbatim: L10n.Settings.accentColor)) {
ForEach(Color.allAccentOptions, id: \.self) { color in
HStack {
Circle()
.frame(width: 20)
.foregroundColor(color)
Text(color.description.capitalized)
}
.tag(color)
}
}
// No icon picker on macOS
}

Section {
Button(action: self.logoutAction) {
Text(verbatim: L10n.Settings.logOut)
}
}
}
.padding()
.frame(maxWidth: 320)
}
}

struct SettingsContainerView_Previews: PreviewProvider {
static var previews: some View {
SettingsContainerView()
}
}
22 changes: 22 additions & 0 deletions Mio/Shared Views/ImagePicker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ImagePicker.swift
// Mio
//
// Created by Finn Behrens on 13.06.21.
// Copyright © 2021 Kilian Koeltzsch. All rights reserved.
//

import SwiftUI

struct ImagePicker: View {

var body: some View {
Text("Sorry, no image picker on macOS yet :-/")
}
}

struct ImagePicker_Previews: PreviewProvider {
static var previews: some View {
ImagePicker()
}
}
50 changes: 50 additions & 0 deletions Mio/Shared Views/MessageTextViewWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// MessageTextViewWrapper.swift
// Mio
//
// Created by Finn Behrens on 13.06.21.
// Copyright © 2021 Kilian Koeltzsch. All rights reserved.
//

import SwiftUI
import NioKit

class MessageTextView: NSTextView {
convenience init(attributedString: NSAttributedString, linkColor: UXColor,
maxSize: CGSize)
{
self.init()
backgroundColor = .clear
textContainerInset = .zero
isEditable = false
linkTextAttributes = [
.foregroundColor: linkColor,
.underlineStyle: NSUnderlineStyle.single.rawValue,
]

self.insertText(attributedString,
replacementRange: NSRange(location: 0, length: 0))
self.maxSize = maxSize

// don't resist text wrapping across multiple lines
setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
}
}

struct MessageTextViewWrapper: NSViewRepresentable {
let attributedString: NSAttributedString
let linkColor: NSColor
let maxSize: CGSize

func makeNSView(context: Context) -> MessageTextView {
MessageTextView(attributedString: attributedString, linkColor: linkColor, maxSize: maxSize)
}

func updateNSView(_ uiView: MessageTextView, context: Context) {
// nothing to update
}

func makeCoordinator() {
// nothing to coordinate
}
}
Loading