Skip to content
Merged
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
14 changes: 7 additions & 7 deletions Blink/Blink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
4F5F12F424B63DBD00A7D9E7 /* Views */ = {
isa = PBXGroup;
children = (
A418231B24B39DDF0082962F /* MenuView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -190,6 +191,7 @@
4F5F12F724B63DF700A7D9E7 /* Views */ = {
isa = PBXGroup;
children = (
A43323D124B4F3620027B909 /* BrainstormView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -214,6 +216,7 @@
4F5F12FA24B63E2200A7D9E7 /* Views */ = {
isa = PBXGroup;
children = (
A4CC2B2B24B635CC00C1B165 /* VotingView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -328,13 +331,10 @@
4F5F12FC24B63E8200A7D9E7 /* Multipeer.swift */,
A4CC2B2F24B6491700C1B165 /* Grid */,
A418231924B39DDF0082962F /* AppDelegate.swift */,
A418231B24B39DDF0082962F /* MenuView.swift */,
A418231D24B39DE10082962F /* Assets.xcassets */,
A418232224B39DE10082962F /* LaunchScreen.storyboard */,
A418232524B39DE10082962F /* Info.plist */,
A418231F24B39DE10082962F /* Preview Content */,
A43323D124B4F3620027B909 /* BrainstormView.swift */,
A4CC2B2B24B635CC00C1B165 /* VotingView.swift */,
A4CC2B2D24B63AD300C1B165 /* RankingView.swift */,
);
path = Blink;
Expand Down Expand Up @@ -612,7 +612,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"Blink_iOS/Preview Content\"";
DEVELOPMENT_TEAM = 93JG72P729;
DEVELOPMENT_TEAM = 4LXC4A87QZ;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Blink_iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
Expand All @@ -634,7 +634,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"Blink_iOS/Preview Content\"";
DEVELOPMENT_TEAM = 93JG72P729;
DEVELOPMENT_TEAM = 4LXC4A87QZ;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Blink_iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
Expand Down Expand Up @@ -816,7 +816,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"Blink/Preview Content\"";
DEVELOPMENT_TEAM = L76X5KFZD9;
DEVELOPMENT_TEAM = 4LXC4A87QZ;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Blink/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -836,7 +836,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"Blink/Preview Content\"";
DEVELOPMENT_TEAM = L76X5KFZD9;
DEVELOPMENT_TEAM = 4LXC4A87QZ;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Blink/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
2 changes: 1 addition & 1 deletion Blink/Blink/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// Create the SwiftUI view that provides the window contents.
let contentView = MenuView()
let contentView = BrainstormView()

// Use a UIHostingController as window root view controller.
let window = UIWindow(frame: UIScreen.main.bounds)
Expand Down
34 changes: 32 additions & 2 deletions Blink/Blink/Brainstorming/ViewModels/BrainstormingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,45 @@
import Foundation
import MultipeerConnectivity

class BrainstormingViewModel: NSObject, MCSessionDelegate {
class BrainstormingViewModel: NSObject, ObservableObject {

/// Shared instance of the Multipeer Class.
let multipeerConnection = Multipeer.shared

/// Published variable of the idea Matrix.
/// Any changes that occur in this variable will make the view update.
@Published var ideasMatrix: [[String]] = [[String]]()

/// String array variable to store ideas.
/// When an idea is sent through P2P connection,
/// It will be stored in this array.
var ideas: [String]

/// Initialization of the Brainstorm ViewModel.
override init() {
ideas = []
super.init()
multipeerConnection.delegate = self
}

/// Internal functional that converts the idea String array
/// in an idea 2D String matrix with 3 columns and N rows.
/// This function is called with the following parameters:
/// - Parameter ideas: The String array that contains the ideas sent through P2P connection.
func convertIdeasArrayInMatrix(ideas: [String]) -> [[String]] {
var matrixIdeas: [[String]] = [[String]]()
var colIndex: Int = 0
var rowIndex: Int = 0
for idea in ideas {
if colIndex == 3 {
colIndex = 0
}
matrixIdeas[rowIndex].append(idea)
rowIndex += 1
colIndex += 1
}
return matrixIdeas
}
}

extension BrainstormingViewModel: MCSessionDelegate {
Expand All @@ -38,9 +66,11 @@ extension BrainstormingViewModel: MCSessionDelegate {

func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
if let text = String(data: data, encoding: .utf8) {
DispatchQueue.main.async {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if !self.ideas.contains(text) {
self.ideas.append(text)
self.ideasMatrix = self.convertIdeasArrayInMatrix(ideas: self.ideas)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,25 @@ import SwiftUI

/// Representation of the brainstorming screen.
struct BrainstormView: View {
/// The 2D matrix containing the ideas as Strings.
var ideas: [[String]]


/// Observed ViewModel so BrainstormView can get its data.
@ObservedObject var brainstormVM = BrainstormingViewModel()

/// The topic set for the session.
var topic: String

/// The timer set for the session.
var timer: String

/// Initialize a new instance of this type.
/// - Parameter ideas: 2D matrix containing the ideas as Strings. Empty by default.
/// - Parameter topic: The topic set for the session. Empty by default.
/// - Parameter timer: The timer set for the sessiion. Empty by default.
init(ideas: [[String]] = [[String]](),
topic: String = "",
init(topic: String = "",
timer: String = "") {
self.ideas = ideas
self.topic = topic
self.timer = timer
}

/// The body of a `BrainstormingView`
var body: some View {
VStack {
Expand All @@ -44,14 +42,15 @@ struct BrainstormView: View {
Spacer()
Text(timer).font(.title)
Spacer()
Text("\(ideas.reduce(0) { $0 + $1.count })").font(.headline)
Text("\(brainstormVM.ideasMatrix.reduce(0) { $0 + $1.count })").font(.headline)
Spacer()
}
Spacer()


/// The `GridView` used to layout the ideas in a
/// 3-column grid.
GridView(items: ideas)
GridView(items: self.brainstormVM.ideasMatrix)
Spacer()

/// The HStack containing the buttons for
Expand Down Expand Up @@ -79,3 +78,9 @@ struct BrainstormView: View {
}
}


struct BrainstormView_Previews: PreviewProvider {
static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/
}
}
2 changes: 1 addition & 1 deletion Blink/Blink/Menu/ViewModels/MenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import MultipeerConnectivity

class MenuViewModel: NSObject, MCSessionDelegate {
class MenuViewModel: NSObject {

let multipeerConnection = Multipeer.shared

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ struct VotingView: View {
}
}
}

struct VotingView_Previews: PreviewProvider {
static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/
}
}