Deleting account & something like pull to refresh

This commit is contained in:
Pengwius 2021-03-25 23:21:40 +01:00
parent 535406b9a2
commit eac913fbfe
16 changed files with 143 additions and 41 deletions

View file

@ -13,7 +13,7 @@ let package = Package(
],
dependencies: [
// 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 are the basic building blocks of a package. A target can define a module or a test suite.

View file

@ -181,7 +181,7 @@ public class Sdk {
let saveAccount = """
{
"actualStudent": "0",
"customUsername": "null",
"customUsername": "",
"privateKeyString": "\(privateKeyStringString)",
"fingerprint": "\(fingerprint)",
"deviceModel": "\(deviceModel)",

View file

@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
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 */; };
5C1794B825E8FE08007AD91A /* notes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794B725E8FE08007AD91A /* notes.swift */; };
5C1794BC25E8FE19007AD91A /* settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1794BB25E8FE19007AD91A /* settings.swift */; };
@ -83,6 +84,7 @@
/* End PBXCopyFilesBuildPhase 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>"; };
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>"; };
@ -169,6 +171,7 @@
5CC2EAA325E516DD00B6183E /* Content */,
5C1B849F25E1B7A30074F29D /* Login */,
5C1CFA7925EA32AE0047286F /* ghImage.swift */,
5C0ED1E2260D2704000DE4C6 /* PullToRefresh.swift */,
);
path = Views;
sourceTree = "<group>";
@ -465,6 +468,7 @@
5C84E04A25FAC5520088FD47 /* residenceInfo.swift in Sources */,
5C84E05225FAC5700088FD47 /* family.swift in Sources */,
5CC2EAAE25E526B500B6183E /* navigation.swift in Sources */,
5C0ED1E3260D2704000DE4C6 /* PullToRefresh.swift in Sources */,
5C5162D825F0DCDE00EF0777 /* more.swift in Sources */,
5CF095AD25F053B10068F2C6 /* accountManager.swift in Sources */,
5C84E04E25FAC5670088FD47 /* contact.swift in Sources */,

View file

@ -23,9 +23,9 @@
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x2E",
"green" : "0x2E",
"red" : "0xD2"
"blue" : "0.180",
"green" : "0.180",
"red" : "0.824"
}
},
"idiom" : "universal"

View file

@ -5,9 +5,9 @@
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x2E",
"green" : "0x2E",
"red" : "0xD2"
"blue" : "0.180",
"green" : "0.180",
"red" : "0.824"
}
},
"idiom" : "universal"
@ -23,9 +23,9 @@
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x2E",
"green" : "0x2E",
"red" : "0xD2"
"blue" : "0.180",
"green" : "0.180",
"red" : "0.824"
}
},
"idiom" : "universal"

View file

@ -1,9 +0,0 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"compression-type" : "automatic"
}
}

View file

@ -115,7 +115,7 @@ struct AccountCardView: View {
}
private func getUsername() {
if("\(account["customUsername"])" == "null") {
if("\(account["customUsername"])".isEmpty) {
username = "\(account["account"]["UserName"])"
} else {
username = "\(account["customUsername"])"

View file

@ -16,6 +16,8 @@ struct AccountManagerView: View {
@AppStorage("isLogged") private var isLogged: Bool = false
@State private var accounts: [String] = [""]
@State private var actualId: String = "0"
@State private var showingDeleteAlert = false
@State private var deletingAccount = "0"
private func getStudentsNames() -> [String] {
//getting all accounts
@ -24,6 +26,7 @@ struct AccountManagerView: View {
//parsing allAccounts to array
var allAccountsArray: [String] = []
print(allAccountsArray)
if(allAccounts != "[]"){
let data = Data(allAccounts.utf8)
do {
@ -86,8 +89,21 @@ struct AccountManagerView: View {
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 {
if("\(student["customUsername"])" == "null") {
if("\(student["customUsername"])".isEmpty) {
return "\(student["account"]["UserName"])"
} else {
return "\(student["customUsername"])"
@ -116,14 +132,24 @@ struct AccountManagerView: View {
.foregroundColor(.green)
}
Spacer()
let image = Image(uiImage: UIImage(systemName: "ellipsis")!)
let cardImage = Image(uiImage: UIImage(systemName: "ellipsis")!)
.renderingMode(.template)
Button("\(image)") { openEditAccount(id: student) }
Button("\(cardImage)") { openEditAccount(id: student) }
.foregroundColor(Color("customControlColor"))
.padding(.horizontal)
.sheet(isPresented: $showEditAccountModal, onDismiss: {
}) {
AccountCardView()
}
let trashImage = Image(uiImage: UIImage(systemName: "trash")!)
.renderingMode(.template)
Button("\(trashImage)") {
showingDeleteAlert = true
deletingAccount = student
}
}.buttonStyle(BorderlessButtonStyle())
}
}
@ -133,6 +159,12 @@ struct AccountManagerView: View {
self.accounts = getStudentsNames()
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 {
Spacer()
Text("No accounts added")

View file

@ -12,18 +12,25 @@ struct AttendanceView: View {
@AppStorage("isLogged") private var isLogged: Bool = false
var body: some View {
if(isLogged == false){
VStack {
Text("You are not logged in")
Button("Log in") {self.showModal = true}
.sheet(isPresented: $showModal, onDismiss: {
print(self.showModal)
}) {
LoginView()
}
}.padding()
} else {
Text("Here is attendance (in my imagination)")
NavigationView {
if(isLogged == false){
VStack {
Text("You are not logged in")
Button("Log in") {self.showModal = true}
.sheet(isPresented: $showModal, onDismiss: {
print(self.showModal)
}) {
LoginView()
}
}.padding()
} else {
ScrollView {
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
print("Refreshing..")
}
Text("Here is attendance (in my imagination)")
}.coordinateSpace(name: "pullToRefresh")
}
}
}
}

View file

@ -25,7 +25,12 @@ struct CalendarView: View {
}
}.padding()
} else {
Text("Here is calendar (in my imagination)")
ScrollView {
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
print("Refreshing..")
}
Text("Here is calendar (in my imagination)")
}.coordinateSpace(name: "pullToRefresh")
}
}
}

View file

@ -34,7 +34,12 @@ struct DashboardView: View {
}
}.padding()
} else {
Text("Here is dashboard (in my imagination)")
ScrollView {
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
print("Refreshing..")
}
Text("Here is dashboard (in my imagination)")
}.coordinateSpace(name: "pullToRefresh")
}
}
}

View file

@ -25,7 +25,12 @@ struct GradesView: View {
}
}.padding()
} else {
Text("Here is grades (in my imagination)")
ScrollView {
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
print("Refreshing..")
}
Text("Here is grades (in my imagination)")
}.coordinateSpace(name: "pullToRefresh")
}
}
}

View file

@ -23,7 +23,12 @@ struct MessagesView: View {
}
}.padding()
} else {
Text("Here is messages (in my imagination)")
ScrollView {
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
print("Refreshing..")
}
Text("Here is messages (in my imagination)")
}.coordinateSpace(name: "pullToRefresh")
}
}
}

View file

@ -24,7 +24,12 @@ struct NotesView: View {
}
}.padding()
} else {
Text("Here is notes (in my imagination)")
ScrollView {
PullToRefresh(coordinateSpaceName: "pullToRefresh") {
print("Refreshing..")
}
Text("Here is notes (in my imagination)")
}.coordinateSpace(name: "pullToRefresh")
}
}
}

View 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)
}
}