Added Data Store
This commit is contained in:
parent
18f68031b7
commit
e1c606fdda
@ -27,6 +27,8 @@
|
|||||||
F58EB2D02A5590E800E22DA6 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = F58EB2CF2A5590E800E22DA6 /* README.md */; };
|
F58EB2D02A5590E800E22DA6 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = F58EB2CF2A5590E800E22DA6 /* README.md */; };
|
||||||
F5A4B1212A5D4D1F00F5AE01 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */; };
|
F5A4B1212A5D4D1F00F5AE01 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */; };
|
||||||
F5A4B1232A5D5F8B00F5AE01 /* BTPeripheral.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */; };
|
F5A4B1232A5D5F8B00F5AE01 /* BTPeripheral.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */; };
|
||||||
|
F5A4B1252A5D7A8D00F5AE01 /* DataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1242A5D7A8D00F5AE01 /* DataStore.swift */; };
|
||||||
|
F5A4B1272A5D861E00F5AE01 /* SettingsEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1262A5D861E00F5AE01 /* SettingsEditView.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@ -70,6 +72,8 @@
|
|||||||
F58EB2CF2A5590E800E22DA6 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
F58EB2CF2A5590E800E22DA6 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||||
F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||||
F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPeripheral.swift; sourceTree = "<group>"; };
|
F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPeripheral.swift; sourceTree = "<group>"; };
|
||||||
|
F5A4B1242A5D7A8D00F5AE01 /* DataStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStore.swift; sourceTree = "<group>"; };
|
||||||
|
F5A4B1262A5D861E00F5AE01 /* SettingsEditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsEditView.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -134,6 +138,7 @@
|
|||||||
F5847B692A59AB24009E28D4 /* FeedStore.swift */,
|
F5847B692A59AB24009E28D4 /* FeedStore.swift */,
|
||||||
96BD330D2A5C254B007A6E53 /* TextApp.swift */,
|
96BD330D2A5C254B007A6E53 /* TextApp.swift */,
|
||||||
F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */,
|
F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */,
|
||||||
|
F5A4B1242A5D7A8D00F5AE01 /* DataStore.swift */,
|
||||||
);
|
);
|
||||||
path = RippleChat;
|
path = RippleChat;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -170,6 +175,7 @@
|
|||||||
96BD33122A5C400B007A6E53 /* FeedListView.swift */,
|
96BD33122A5C400B007A6E53 /* FeedListView.swift */,
|
||||||
96BD33152A5C403C007A6E53 /* PeeringView.swift */,
|
96BD33152A5C403C007A6E53 /* PeeringView.swift */,
|
||||||
F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */,
|
F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */,
|
||||||
|
F5A4B1262A5D861E00F5AE01 /* SettingsEditView.swift */,
|
||||||
);
|
);
|
||||||
path = Views;
|
path = Views;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -313,7 +319,9 @@
|
|||||||
F5847B642A599CC3009E28D4 /* LogEntry.swift in Sources */,
|
F5847B642A599CC3009E28D4 /* LogEntry.swift in Sources */,
|
||||||
96BD33102A5C27B0007A6E53 /* NewFeedEntryView.swift in Sources */,
|
96BD33102A5C27B0007A6E53 /* NewFeedEntryView.swift in Sources */,
|
||||||
F5A4B1232A5D5F8B00F5AE01 /* BTPeripheral.swift in Sources */,
|
F5A4B1232A5D5F8B00F5AE01 /* BTPeripheral.swift in Sources */,
|
||||||
|
F5A4B1252A5D7A8D00F5AE01 /* DataStore.swift in Sources */,
|
||||||
F5847B6A2A59AB24009E28D4 /* FeedStore.swift in Sources */,
|
F5847B6A2A59AB24009E28D4 /* FeedStore.swift in Sources */,
|
||||||
|
F5A4B1272A5D861E00F5AE01 /* SettingsEditView.swift in Sources */,
|
||||||
F581F59B2A5AE72F0081C383 /* BluetoothController.swift in Sources */,
|
F581F59B2A5AE72F0081C383 /* BluetoothController.swift in Sources */,
|
||||||
96454F1D2A558EBC0040BEBD /* ContentView.swift in Sources */,
|
96454F1D2A558EBC0040BEBD /* ContentView.swift in Sources */,
|
||||||
F5A4B1212A5D4D1F00F5AE01 /* SettingsView.swift in Sources */,
|
F5A4B1212A5D4D1F00F5AE01 /* SettingsView.swift in Sources */,
|
||||||
|
|||||||
@ -21,6 +21,8 @@ class BluetoothPeripheral: NSObject, ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Change variable names, etc...
|
||||||
|
|
||||||
extension BluetoothPeripheral: CBPeripheralManagerDelegate {
|
extension BluetoothPeripheral: CBPeripheralManagerDelegate {
|
||||||
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
|
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
|
||||||
switch peripheral.state {
|
switch peripheral.state {
|
||||||
@ -44,12 +46,7 @@ extension BluetoothPeripheral: CBPeripheralManagerDelegate {
|
|||||||
|
|
||||||
func addServices() {
|
func addServices() {
|
||||||
|
|
||||||
let value = Feed.sampleFeed
|
let myCharacteristic = CBMutableCharacteristic(type: BLE_CHARACTERISTIC_UUID_RX, properties: [.read, .write, .notify], value: nil, permissions: [.readable])
|
||||||
// let valueData = value(using: .utf8)
|
|
||||||
|
|
||||||
// 1. Create instance of CBMutableCharcateristic
|
|
||||||
// let myCharacteristic1 = CBMutableCharacteristic(type: CBUUID(nsuuid: UUID()), properties: [.notify, .write, .read], value: nil, permissions: [.readable, .writeable])
|
|
||||||
let myCharacteristic = CBMutableCharacteristic(type: BLE_CHARACTERISTIC_UUID_RX, properties: [.read], value: nil, permissions: [.readable])
|
|
||||||
|
|
||||||
// 2. Create instance of CBMutableService
|
// 2. Create instance of CBMutableService
|
||||||
let myService = CBMutableService(type: BLE_SERVICE_UUID, primary: true)
|
let myService = CBMutableService(type: BLE_SERVICE_UUID, primary: true)
|
||||||
@ -65,4 +62,23 @@ extension BluetoothPeripheral: CBPeripheralManagerDelegate {
|
|||||||
print("Started Advertising")
|
print("Started Advertising")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveRead request: CBATTRequest) {
|
||||||
|
//
|
||||||
|
// messageLabel.text = "Data getting Read"
|
||||||
|
// readValueLabel.text = value
|
||||||
|
//
|
||||||
|
// // Perform your additional operations here
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
|
||||||
|
//
|
||||||
|
// messageLabel.text = "Writing Data"
|
||||||
|
//
|
||||||
|
// if let value = requests.first?.value {
|
||||||
|
// writeValueLabel.text = value.hexEncodedString()
|
||||||
|
// //Perform here your additional operations on the data you get
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,16 +10,23 @@ import CoreBluetooth
|
|||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@State var currentView = 0
|
@State var currentView = 0
|
||||||
|
@EnvironmentObject var dataStore: DataStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
switch self.currentView {
|
switch self.currentView {
|
||||||
case 0: PeeringView()
|
case 0:
|
||||||
case 1: FeedListView(feeds: [])
|
PeeringView()
|
||||||
case 2: SettingsView()
|
.environmentObject(dataStore)
|
||||||
|
case 1:
|
||||||
|
FeedListView(feeds: [])
|
||||||
|
.environmentObject(dataStore)
|
||||||
|
case 2:
|
||||||
|
SettingsView()
|
||||||
|
.environmentObject(dataStore)
|
||||||
default:
|
default:
|
||||||
FeedListView(feeds: [])
|
FeedListView(feeds: [])
|
||||||
|
.environmentObject(dataStore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
@ -60,6 +67,7 @@ struct ContentView: View {
|
|||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ContentView()
|
ContentView()
|
||||||
|
.environmentObject(DataStore())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
RippleChat/DataStore.swift
Normal file
21
RippleChat/DataStore.swift
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// DataStore.swift
|
||||||
|
// RippleChat
|
||||||
|
//
|
||||||
|
// Created by Severin Memmishofer on 11.07.23.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class DataStore: ObservableObject {
|
||||||
|
@Published var personalID: String
|
||||||
|
@Published var friends: [String]
|
||||||
|
@Published var feeds: [Feed]
|
||||||
|
|
||||||
|
init(personalID: String = "", friends: [String] = [], feeds: [Feed] = []) {
|
||||||
|
self.personalID = personalID
|
||||||
|
self.friends = friends
|
||||||
|
self.feeds = feeds
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,6 +13,7 @@ struct RippleChatApp: App {
|
|||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView()
|
ContentView()
|
||||||
|
.environmentObject(DataStore())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ struct FeedListView: View {
|
|||||||
@State var feeds: [Feed]
|
@State var feeds: [Feed]
|
||||||
@StateObject var store = FeedStore(feed: Feed.sampleFeed)
|
@StateObject var store = FeedStore(feed: Feed.sampleFeed)
|
||||||
var feedStores = [FeedStore(feed: Feed.sampleFeed), FeedStore(feed: Feed.sampleFeed2)]
|
var feedStores = [FeedStore(feed: Feed.sampleFeed), FeedStore(feed: Feed.sampleFeed2)]
|
||||||
|
@EnvironmentObject var dataStore: DataStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text("FeedListView")
|
Text("FeedListView")
|
||||||
@ -29,6 +30,8 @@ struct FeedListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Spacer()
|
||||||
|
NewFeedEntryView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import SwiftUI
|
|||||||
struct PeeringView: View {
|
struct PeeringView: View {
|
||||||
@ObservedObject private var bluetoothController = BluetoothController()
|
@ObservedObject private var bluetoothController = BluetoothController()
|
||||||
@ObservedObject private var bluetoothPeripheral = BluetoothPeripheral()
|
@ObservedObject private var bluetoothPeripheral = BluetoothPeripheral()
|
||||||
|
@EnvironmentObject var dataStore: DataStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text("Peering View")
|
Text("Peering View")
|
||||||
|
|||||||
29
RippleChat/Views/SettingsEditView.swift
Normal file
29
RippleChat/Views/SettingsEditView.swift
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// SettingsEditView.swift
|
||||||
|
// RippleChat
|
||||||
|
//
|
||||||
|
// Created by Severin Memmishofer on 11.07.23.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct SettingsEditView: View {
|
||||||
|
@EnvironmentObject var dataStore: DataStore
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Form {
|
||||||
|
Section(header: Text("Personal Feed ID")) {
|
||||||
|
//TextField("FeedID", text: $scrum.title)
|
||||||
|
}
|
||||||
|
Section(header: Text("Friends")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SettingsEditView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
SettingsEditView()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,13 +8,22 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct SettingsView: View {
|
struct SettingsView: View {
|
||||||
|
@State private var newEntry: String = ""
|
||||||
|
@EnvironmentObject var dataStore: DataStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text("Hello, Settings!")
|
Section(header: Text("Personal Feed ID")) {
|
||||||
|
Text("Your FeedID is: \(dataStore.personalID)")
|
||||||
|
}
|
||||||
|
Section(header: Text("Friends")) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SettingsView_Previews: PreviewProvider {
|
struct SettingsView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SettingsView()
|
SettingsView()
|
||||||
|
.environmentObject(DataStore(personalID: "BOB"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user