Commit d59d269a authored by  Joel  Oksanen's avatar Joel Oksanen

Cleaned up frontend code

parent f66016af
{
"images" : [
{
"idiom" : "universal",
"filename" : "star_border.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "star_fill.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
//
// Product.swift
// ProductInfo.swift
// ADAbot
//
// Created by Joel Oksanen on 23.2.2020.
......
......@@ -22,7 +22,7 @@ struct ProductView: View {
VStack {
Spacer()
HStack(alignment: .top) {
VStack {
VStack(alignment: .leading) {
Text(connectionManager.product.name)
.font(Font.custom("Helvetica Neue", size: 14))
.foregroundColor(Color.gray)
......@@ -40,6 +40,6 @@ struct ProductView: View {
.frame(height: height)
}
}
}
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "11A410FC-B942-445D-A528-1528513D8B56"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "1F83A6A4-50AC-4AC0-BAB3-7B81A2CFDDAE"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ADAgraph/AppDelegate.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
landmarkName = "application(_:didFinishLaunchingWithOptions:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
......@@ -11,8 +11,6 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
......
......@@ -7,3 +7,42 @@
//
import Foundation
import SwiftUI
struct Argument: Decodable, Equatable {
let text: String
let polarity: Polarity
let supporters: [Argument]
let attackers: [Argument]
let phrase: String
let size: CGFloat
static func == (lhs: Argument, rhs: Argument) -> Bool {
return lhs.text == rhs.text
}
func children() -> [Argument] {
return supporters + attackers
}
func hasChild() -> Bool {
return children().count > 0
}
func color() -> Color {
return polarity == .POS ? Color(red: 121/255, green: 197/255, blue: 88/255) : Color(red: 220/255, green: 86/255, blue: 72/255)
}
func strokeColor() -> Color {
return polarity == .POS ? Color(red: 90/255, green: 150/255, blue: 60/255) : Color(red: 180/255, green: 65/255, blue: 56/255)
}
}
enum Polarity: String, Decodable {
case POS
case NEG
}
......@@ -6,4 +6,53 @@
// Copyright © 2020 Joel Oksanen. All rights reserved.
//
import Foundation
import SwiftUI
class ConnectionManager: ObservableObject {
@Published var graph: Graph!
@Published var product: Product!
private let ip = "192.168.1.104"
private let port = "8000"
init() {
requestArguments(id: "B0000TIKK8")
}
private func requestArguments(id: String) {
let url = URL(string: "http://" + ip + ":" + port + "/ios_server/arguments?id=" + id)!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
do {
let resp = try JSONDecoder().decode(ProductData.self, from: data)
DispatchQueue.main.async {
self.graph = Graph.fromRoot(resp.root)
print(resp)
self.requestImage(for: resp.info)
}
} catch let parseError {
print(parseError)
DispatchQueue.main.async {
// Handle error in UI
}
}
}
task.resume()
}
private func requestImage(for productInfo: ProductInfo) {
let url = URL(string: productInfo.imageURL)!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
if let image = UIImage(data: data) {
DispatchQueue.main.async {
self.product = Product(id: productInfo.id, name: productInfo.name, starRating: productInfo.starRating, image: image)
}
}
}
task.resume()
}
}
......@@ -9,13 +9,16 @@
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
@ObservedObject var connectionManager: ConnectionManager
@ObservedObject var selection: SelectionHandler
var body: some View {
VStack {
if connectionManager.graph != nil && connectionManager.product != nil {
SurfaceView(graph: connectionManager.graph, selection: selection, connectionManager: connectionManager)
} else {
Text("Loading arguments...")
}
}
}
}
......@@ -7,3 +7,10 @@
//
import Foundation
struct ProductData: Decodable {
let root: Argument
let info: ProductInfo
}
......@@ -13,6 +13,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
@Published var connectionManager = ConnectionManager()
@Published var selection = SelectionHandler()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
......@@ -20,7 +22,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
let contentView = ContentView(connectionManager: connectionManager, selection: selection)
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment