Deleting account & something like pull to refresh
This commit is contained in:
parent
535406b9a2
commit
eac913fbfe
16 changed files with 143 additions and 41 deletions
|
@ -13,7 +13,7 @@ let package = Package(
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// Dependencies declare other packages that this package depends on.
|
// Dependencies declare other packages that this package depends on.
|
||||||
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess.git", from: "4.2.2"),
|
//.package(url: "https://github.com/kishikawakatsumi/KeychainAccess.git", from: "4.2.2"),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class Sdk {
|
||||||
let saveAccount = """
|
let saveAccount = """
|
||||||
{
|
{
|
||||||
"actualStudent": "0",
|
"actualStudent": "0",
|
||||||
"customUsername": "null",
|
"customUsername": "",
|
||||||
"privateKeyString": "\(privateKeyStringString)",
|
"privateKeyString": "\(privateKeyStringString)",
|
||||||
"fingerprint": "\(fingerprint)",
|
"fingerprint": "\(fingerprint)",
|
||||||
"deviceModel": "\(deviceModel)",
|
"deviceModel": "\(deviceModel)",
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
5C0B2AFD25F78A6A009EABEC /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 5C0B2AFC25F78A6A009EABEC /* KeychainAccess */; };
|
5C0B2AFD25F78A6A009EABEC /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 5C0B2AFC25F78A6A009EABEC /* KeychainAccess */; };
|
||||||
|
5C0ED1E3260D2704000DE4C6 /* PullToRefresh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C0ED1E2260D2704000DE4C6 /* PullToRefresh.swift */; };
|
||||||
5C1794B425E8FDFB007AD91A /* messages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794B325E8FDFB007AD91A /* messages.swift */; };
|
5C1794B425E8FDFB007AD91A /* messages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794B325E8FDFB007AD91A /* messages.swift */; };
|
||||||
5C1794B825E8FE08007AD91A /* notes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794B725E8FE08007AD91A /* notes.swift */; };
|
5C1794B825E8FE08007AD91A /* notes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794B725E8FE08007AD91A /* notes.swift */; };
|
||||||
5C1794BC25E8FE19007AD91A /* settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794BB25E8FE19007AD91A /* settings.swift */; };
|
5C1794BC25E8FE19007AD91A /* settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794BB25E8FE19007AD91A /* settings.swift */; };
|
||||||
|
@ -83,6 +84,7 @@
|
||||||
/* End PBXCopyFilesBuildPhase section */
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
5C0ED1E2260D2704000DE4C6 /* PullToRefresh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PullToRefresh.swift; sourceTree = "<group>"; };
|
||||||
5C1794B325E8FDFB007AD91A /* messages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = messages.swift; sourceTree = "<group>"; };
|
5C1794B325E8FDFB007AD91A /* messages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = messages.swift; sourceTree = "<group>"; };
|
||||||
5C1794B725E8FE08007AD91A /* notes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = notes.swift; sourceTree = "<group>"; };
|
5C1794B725E8FE08007AD91A /* notes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = notes.swift; sourceTree = "<group>"; };
|
||||||
5C1794BB25E8FE19007AD91A /* settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = settings.swift; sourceTree = "<group>"; };
|
5C1794BB25E8FE19007AD91A /* settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = settings.swift; sourceTree = "<group>"; };
|
||||||
|
@ -169,6 +171,7 @@
|
||||||
5CC2EAA325E516DD00B6183E /* Content */,
|
5CC2EAA325E516DD00B6183E /* Content */,
|
||||||
5C1B849F25E1B7A30074F29D /* Login */,
|
5C1B849F25E1B7A30074F29D /* Login */,
|
||||||
5C1CFA7925EA32AE0047286F /* ghImage.swift */,
|
5C1CFA7925EA32AE0047286F /* ghImage.swift */,
|
||||||
|
5C0ED1E2260D2704000DE4C6 /* PullToRefresh.swift */,
|
||||||
);
|
);
|
||||||
path = Views;
|
path = Views;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -465,6 +468,7 @@
|
||||||
5C84E04A25FAC5520088FD47 /* residenceInfo.swift in Sources */,
|
5C84E04A25FAC5520088FD47 /* residenceInfo.swift in Sources */,
|
||||||
5C84E05225FAC5700088FD47 /* family.swift in Sources */,
|
5C84E05225FAC5700088FD47 /* family.swift in Sources */,
|
||||||
5CC2EAAE25E526B500B6183E /* navigation.swift in Sources */,
|
5CC2EAAE25E526B500B6183E /* navigation.swift in Sources */,
|
||||||
|
5C0ED1E3260D2704000DE4C6 /* PullToRefresh.swift in Sources */,
|
||||||
5C5162D825F0DCDE00EF0777 /* more.swift in Sources */,
|
5C5162D825F0DCDE00EF0777 /* more.swift in Sources */,
|
||||||
5CF095AD25F053B10068F2C6 /* accountManager.swift in Sources */,
|
5CF095AD25F053B10068F2C6 /* accountManager.swift in Sources */,
|
||||||
5C84E04E25FAC5670088FD47 /* contact.swift in Sources */,
|
5C84E04E25FAC5670088FD47 /* contact.swift in Sources */,
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
"color-space" : "srgb",
|
"color-space" : "srgb",
|
||||||
"components" : {
|
"components" : {
|
||||||
"alpha" : "1.000",
|
"alpha" : "1.000",
|
||||||
"blue" : "0x2E",
|
"blue" : "0.180",
|
||||||
"green" : "0x2E",
|
"green" : "0.180",
|
||||||
"red" : "0xD2"
|
"red" : "0.824"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"idiom" : "universal"
|
"idiom" : "universal"
|
|
@ -5,9 +5,9 @@
|
||||||
"color-space" : "srgb",
|
"color-space" : "srgb",
|
||||||
"components" : {
|
"components" : {
|
||||||
"alpha" : "1.000",
|
"alpha" : "1.000",
|
||||||
"blue" : "0x2E",
|
"blue" : "0.180",
|
||||||
"green" : "0x2E",
|
"green" : "0.180",
|
||||||
"red" : "0xD2"
|
"red" : "0.824"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"idiom" : "universal"
|
"idiom" : "universal"
|
||||||
|
@ -23,9 +23,9 @@
|
||||||
"color-space" : "srgb",
|
"color-space" : "srgb",
|
||||||
"components" : {
|
"components" : {
|
||||||
"alpha" : "1.000",
|
"alpha" : "1.000",
|
||||||
"blue" : "0x2E",
|
"blue" : "0.180",
|
||||||
"green" : "0x2E",
|
"green" : "0.180",
|
||||||
"red" : "0xD2"
|
"red" : "0.824"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"idiom" : "universal"
|
"idiom" : "universal"
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"info" : {
|
|
||||||
"author" : "xcode",
|
|
||||||
"version" : 1
|
|
||||||
},
|
|
||||||
"properties" : {
|
|
||||||
"compression-type" : "automatic"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -115,7 +115,7 @@ struct AccountCardView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getUsername() {
|
private func getUsername() {
|
||||||
if("\(account["customUsername"])" == "null") {
|
if("\(account["customUsername"])".isEmpty) {
|
||||||
username = "\(account["account"]["UserName"])"
|
username = "\(account["account"]["UserName"])"
|
||||||
} else {
|
} else {
|
||||||
username = "\(account["customUsername"])"
|
username = "\(account["customUsername"])"
|
||||||
|
|
|
@ -16,6 +16,8 @@ struct AccountManagerView: View {
|
||||||
@AppStorage("isLogged") private var isLogged: Bool = false
|
@AppStorage("isLogged") private var isLogged: Bool = false
|
||||||
@State private var accounts: [String] = [""]
|
@State private var accounts: [String] = [""]
|
||||||
@State private var actualId: String = "0"
|
@State private var actualId: String = "0"
|
||||||
|
@State private var showingDeleteAlert = false
|
||||||
|
@State private var deletingAccount = "0"
|
||||||
|
|
||||||
private func getStudentsNames() -> [String] {
|
private func getStudentsNames() -> [String] {
|
||||||
//getting all accounts
|
//getting all accounts
|
||||||
|
@ -24,6 +26,7 @@ struct AccountManagerView: View {
|
||||||
|
|
||||||
//parsing allAccounts to array
|
//parsing allAccounts to array
|
||||||
var allAccountsArray: [String] = []
|
var allAccountsArray: [String] = []
|
||||||
|
print(allAccountsArray)
|
||||||
if(allAccounts != "[]"){
|
if(allAccounts != "[]"){
|
||||||
let data = Data(allAccounts.utf8)
|
let data = Data(allAccounts.utf8)
|
||||||
do {
|
do {
|
||||||
|
@ -86,8 +89,21 @@ struct AccountManagerView: View {
|
||||||
accounts = getStudentsNames()
|
accounts = getStudentsNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func deleteAccount() {
|
||||||
|
let keychain = Keychain()
|
||||||
|
var ids = getStudentsNames()
|
||||||
|
let id: Set<String> = [deletingAccount]
|
||||||
|
ids.removeAll(where: { id.contains($0) })
|
||||||
|
if(ids == []) {
|
||||||
|
isLogged = false
|
||||||
|
}
|
||||||
|
keychain["allAccounts"] = "\(ids)"
|
||||||
|
|
||||||
|
keychain["\(deletingAccount)"] = nil
|
||||||
|
}
|
||||||
|
|
||||||
private func getUsername(student: JSON) -> String {
|
private func getUsername(student: JSON) -> String {
|
||||||
if("\(student["customUsername"])" == "null") {
|
if("\(student["customUsername"])".isEmpty) {
|
||||||
return "\(student["account"]["UserName"])"
|
return "\(student["account"]["UserName"])"
|
||||||
} else {
|
} else {
|
||||||
return "\(student["customUsername"])"
|
return "\(student["customUsername"])"
|
||||||
|
@ -116,14 +132,24 @@ struct AccountManagerView: View {
|
||||||
.foregroundColor(.green)
|
.foregroundColor(.green)
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
let image = Image(uiImage: UIImage(systemName: "ellipsis")!)
|
let cardImage = Image(uiImage: UIImage(systemName: "ellipsis")!)
|
||||||
.renderingMode(.template)
|
.renderingMode(.template)
|
||||||
|
|
||||||
Button("\(image)") { openEditAccount(id: student) }
|
Button("\(cardImage)") { openEditAccount(id: student) }
|
||||||
|
.foregroundColor(Color("customControlColor"))
|
||||||
|
.padding(.horizontal)
|
||||||
.sheet(isPresented: $showEditAccountModal, onDismiss: {
|
.sheet(isPresented: $showEditAccountModal, onDismiss: {
|
||||||
}) {
|
}) {
|
||||||
AccountCardView()
|
AccountCardView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let trashImage = Image(uiImage: UIImage(systemName: "trash")!)
|
||||||
|
.renderingMode(.template)
|
||||||
|
|
||||||
|
Button("\(trashImage)") {
|
||||||
|
showingDeleteAlert = true
|
||||||
|
deletingAccount = student
|
||||||
|
}
|
||||||
}.buttonStyle(BorderlessButtonStyle())
|
}.buttonStyle(BorderlessButtonStyle())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +159,12 @@ struct AccountManagerView: View {
|
||||||
self.accounts = getStudentsNames()
|
self.accounts = getStudentsNames()
|
||||||
self.actualId = "\(keychain["actualAccountId"] ?? "0")"
|
self.actualId = "\(keychain["actualAccountId"] ?? "0")"
|
||||||
}
|
}
|
||||||
|
.alert(isPresented: $showingDeleteAlert) {
|
||||||
|
Alert(title: Text("Do you want to delete this account?"),
|
||||||
|
message: Text("You cannot undo this action"),
|
||||||
|
primaryButton: .destructive(Text("Delete"), action: deleteAccount),
|
||||||
|
secondaryButton: .cancel(Text("Cancel")))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Spacer()
|
Spacer()
|
||||||
Text("No accounts added")
|
Text("No accounts added")
|
||||||
|
|
|
@ -12,18 +12,25 @@ struct AttendanceView: View {
|
||||||
@AppStorage("isLogged") private var isLogged: Bool = false
|
@AppStorage("isLogged") private var isLogged: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if(isLogged == false){
|
NavigationView {
|
||||||
VStack {
|
if(isLogged == false){
|
||||||
Text("You are not logged in")
|
VStack {
|
||||||
Button("Log in") {self.showModal = true}
|
Text("You are not logged in")
|
||||||
.sheet(isPresented: $showModal, onDismiss: {
|
Button("Log in") {self.showModal = true}
|
||||||
print(self.showModal)
|
.sheet(isPresented: $showModal, onDismiss: {
|
||||||
}) {
|
print(self.showModal)
|
||||||
LoginView()
|
}) {
|
||||||
}
|
LoginView()
|
||||||
}.padding()
|
}
|
||||||
} else {
|
}.padding()
|
||||||
Text("Here is attendance (in my imagination)")
|
} else {
|
||||||
|
ScrollView {
|
||||||
|
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
|
||||||
|
print("Refreshing..")
|
||||||
|
}
|
||||||
|
Text("Here is attendance (in my imagination)")
|
||||||
|
}.coordinateSpace(name: "pullToRefresh")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,12 @@ struct CalendarView: View {
|
||||||
}
|
}
|
||||||
}.padding()
|
}.padding()
|
||||||
} else {
|
} else {
|
||||||
Text("Here is calendar (in my imagination)")
|
ScrollView {
|
||||||
|
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
|
||||||
|
print("Refreshing..")
|
||||||
|
}
|
||||||
|
Text("Here is calendar (in my imagination)")
|
||||||
|
}.coordinateSpace(name: "pullToRefresh")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,12 @@ struct DashboardView: View {
|
||||||
}
|
}
|
||||||
}.padding()
|
}.padding()
|
||||||
} else {
|
} else {
|
||||||
Text("Here is dashboard (in my imagination)")
|
ScrollView {
|
||||||
|
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
|
||||||
|
print("Refreshing..")
|
||||||
|
}
|
||||||
|
Text("Here is dashboard (in my imagination)")
|
||||||
|
}.coordinateSpace(name: "pullToRefresh")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,12 @@ struct GradesView: View {
|
||||||
}
|
}
|
||||||
}.padding()
|
}.padding()
|
||||||
} else {
|
} else {
|
||||||
Text("Here is grades (in my imagination)")
|
ScrollView {
|
||||||
|
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
|
||||||
|
print("Refreshing..")
|
||||||
|
}
|
||||||
|
Text("Here is grades (in my imagination)")
|
||||||
|
}.coordinateSpace(name: "pullToRefresh")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,12 @@ struct MessagesView: View {
|
||||||
}
|
}
|
||||||
}.padding()
|
}.padding()
|
||||||
} else {
|
} else {
|
||||||
Text("Here is messages (in my imagination)")
|
ScrollView {
|
||||||
|
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
|
||||||
|
print("Refreshing..")
|
||||||
|
}
|
||||||
|
Text("Here is messages (in my imagination)")
|
||||||
|
}.coordinateSpace(name: "pullToRefresh")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,12 @@ struct NotesView: View {
|
||||||
}
|
}
|
||||||
}.padding()
|
}.padding()
|
||||||
} else {
|
} else {
|
||||||
Text("Here is notes (in my imagination)")
|
ScrollView {
|
||||||
|
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
|
||||||
|
print("Refreshing..")
|
||||||
|
}
|
||||||
|
Text("Here is notes (in my imagination)")
|
||||||
|
}.coordinateSpace(name: "pullToRefresh")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
43
wulkanowy/Views/PullToRefresh.swift
Normal file
43
wulkanowy/Views/PullToRefresh.swift
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
//
|
||||||
|
// PullToRefresh.swift
|
||||||
|
// wulkanowy
|
||||||
|
//
|
||||||
|
// Created by Tomasz on 25/03/2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct PullToRefresh: View {
|
||||||
|
|
||||||
|
var coordinateSpaceName: String
|
||||||
|
var onRefresh: ()->Void
|
||||||
|
|
||||||
|
@State var needRefresh: Bool = false
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
GeometryReader { geo in
|
||||||
|
if (geo.frame(in: .named(coordinateSpaceName)).midY > 50) {
|
||||||
|
Spacer()
|
||||||
|
.onAppear {
|
||||||
|
needRefresh = true
|
||||||
|
}
|
||||||
|
} else if (geo.frame(in: .named(coordinateSpaceName)).maxY < 10) {
|
||||||
|
Spacer()
|
||||||
|
.onAppear {
|
||||||
|
if needRefresh {
|
||||||
|
needRefresh = false
|
||||||
|
onRefresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
if needRefresh {
|
||||||
|
ProgressView()
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}.padding(.top, -50)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue