Skip to content

Commit

Permalink
Merge pull request #44 from AKORA-Studios/toasts-#2
Browse files Browse the repository at this point in the history
Toasts #2
  • Loading branch information
DragonCat4012 authored Jul 16, 2023
2 parents a3227ba + b575831 commit c2aff1c
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Calq.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
F192DD29299D2DF40077B905 /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F192DD27299D2DEC0077B905 /* ViewExtension.swift */; };
F19B10A529AF84C000B11C82 /* OverviewVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = F19B10A429AF84C000B11C82 /* OverviewVM.swift */; };
F19F8E4229F18E03006142B4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F19F8E4429F18E03006142B4 /* Localizable.strings */; };
F1A05C5F2A642670003734F2 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A05C5E2A642670003734F2 /* StringExtension.swift */; };
F1A53D002A196BFF0045C5B0 /* ListBackgroundModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A53CFF2A196BFF0045C5B0 /* ListBackgroundModifier.swift */; };
F1A53D032A196C220045C5B0 /* WeightViewmodel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A53D022A196C220045C5B0 /* WeightViewmodel.swift */; };
F1A59A3E2A6347880039C95E /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A59A3D2A6347880039C95E /* ToastView.swift */; };
Expand Down Expand Up @@ -172,6 +173,7 @@
F19F8E4329F18E03006142B4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
F19F8E4529F18E0D006142B4 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
F19F8E4629F18E0D006142B4 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
F1A05C5E2A642670003734F2 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
F1A53CFF2A196BFF0045C5B0 /* ListBackgroundModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListBackgroundModifier.swift; sourceTree = "<group>"; };
F1A53D022A196C220045C5B0 /* WeightViewmodel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeightViewmodel.swift; sourceTree = "<group>"; };
F1A59A3D2A6347880039C95E /* ToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -317,6 +319,7 @@
F1A53CFF2A196BFF0045C5B0 /* ListBackgroundModifier.swift */,
F1A7102C2A43757D00255F10 /* CardView.swift */,
F14140472A476408007E4648 /* AppStoreRating.swift */,
F1A05C5E2A642670003734F2 /* StringExtension.swift */,
);
path = lib;
sourceTree = "<group>";
Expand Down Expand Up @@ -697,6 +700,7 @@
F17F444A298C4EE7000A3993 /* SubjectListScreen.swift in Sources */,
DD81F6832759091600B4A43B /* JSONUtil.swift in Sources */,
F1A772112A17947A004B8DCC /* Model.xcdatamodeld in Sources */,
F1A05C5F2A642670003734F2 /* StringExtension.swift in Sources */,
DD8813792764D58B00EB6BD8 /* BarChart.swift in Sources */,
F10CA6B6298DB4AB008F3FE9 /* SubjectDetailScreen.swift in Sources */,
F1A53D032A196C220045C5B0 /* WeightViewmodel.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Calq/Screens/ExamScreen/BlockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct RoundProgressBar: View {
let barProgressWidth = (CGFloat(max != 0 ? (value * 100 / max) : 0) * geo.size.width)/100
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 8)
.foregroundColor(.gray)
.foregroundColor(Color(.systemGray4))

HStack(spacing: 0) {
if barProgressWidth + 10 < geo.size.width && barProgressWidth - 5 > 0 {
Expand Down
6 changes: 6 additions & 0 deletions Calq/Screens/NewGradeScreen/NewGradeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ struct NewGradeScreen: View {
struct NewGradeView: View {
@Environment(\.presentationMode) var presentationMode
@EnvironmentObject var vm: NewGradeVM
@EnvironmentObject var toastControl: ToastControl

var body: some View {
ScrollView(showsIndicators: false) {
if vm.selectedSubject != nil {
let color = getSubjectColor(vm.selectedSubject)

VStack {
CardContainer {
VStack(alignment: .leading) {
Expand All @@ -63,6 +66,7 @@ struct NewGradeView: View {
Text(type.name).tag(type.id)
}
}.pickerStyle(.segmented)
.colorMultiply(color)
}
}

Expand All @@ -75,6 +79,7 @@ struct NewGradeView: View {
Text("3").tag(3)
Text("4").tag(4)
}.pickerStyle(.segmented)
.colorMultiply(color)

HStack {
DatePicker("gradeDate", selection: $vm.date, displayedComponents: [.date])
Expand All @@ -98,6 +103,7 @@ struct NewGradeView: View {

Button("gradeNewAdd") {
vm.saveGrade()
toastControl.show("gradeNewToastSuccess", .success)
}.buttonStyle(PrimaryStyle())
.padding(.top, 20)
}
Expand Down
29 changes: 17 additions & 12 deletions Calq/Screens/SubjectInfoScreens/GradeListScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,10 @@ struct GradeListScreen: View {
deleteAlert = true
})
}

ForEach(0...3, id: \.self) {i in
Section(header: Text("\(i + 1). ") + Text("gradeHalfyear")) {
let tests = years[i]
ForEach(tests) {test in
let color = getSubjectColor(subject)

NavigationLink {
EditGradeScreen(test: test, color: color)
} label: {
gradeIcon(test: test, color: color)
}
}
let tests = years[i]
if !tests.isEmpty {
halfyearSection(i)
}
}

Expand All @@ -56,6 +47,20 @@ struct GradeListScreen: View {
}
}

func halfyearSection(_ i: Int) -> some View {
Section(header: Text("\(i + 1). ") + Text("gradeHalfyear")) {
ForEach(years[i]) {test in
let color = getSubjectColor(subject)

NavigationLink {
EditGradeScreen(test: test, color: color)
} label: {
gradeIcon(test: test, color: color)
}
}
}
}

func dismissSheet() {
self.presentationMode.wrappedValue.dismiss()
}
Expand Down
74 changes: 59 additions & 15 deletions Calq/ToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@

import SwiftUI

enum ToastStyles: String {
case success
case error
case info
}

class ToastControl: ObservableObject {
@Published var isPresented = false

@Published var message = "SomeMessage"
@Published var color = Color.accentColor
@Published var type: ToastStyles = .info

init(isPresented: Bool = false) {
self.isPresented = isPresented
Expand All @@ -21,34 +27,72 @@ class ToastControl: ObservableObject {
isPresented = false
}

func show(_ message: String = "SomeMessage", _ color: Color = .accentColor) {
self.message = message
self.color = color
func show(_ message: String = "SomeMessage", _ type: ToastStyles = .info) {
self.message = message.localized
self.type = type
isPresented = true

DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [self] in
isPresented = false
}
}

func color() -> Color {
switch type {
case .info:
return Color.accentColor
case .success:
return Color.green
case .error:
return Color.red
}
}
}

struct ToastView: View {
@EnvironmentObject var toastControl: ToastControl

var body: some View {
ZStack {
if toastControl.isPresented {
RoundedRectangle(cornerRadius: 8).fill(toastControl.color)
.frame(height: 50)
.padding()
.shadow(radius: 40)
Text(toastControl.message)
}
if toastControl.isPresented {

bodyView()
} else {
EmptyView()
}
.onTapGesture {
toastControl.hide()
}

func bodyView() -> some View {
VStack(alignment: .leading) {
HStack(alignment: .top) {
VStack(alignment: .leading) {
Text(toastControl.message)
.font(.system(size: 12))
.foregroundColor(Color.black.opacity(0.6))
}

Spacer(minLength: 10)

Button {
toastControl.hide()
} label: {
Image(systemName: "xmark")
.foregroundColor(Color.black)
}
}
.padding()
}

.background(Color.white)
.overlay(
Rectangle()
.fill(toastControl.color())
.frame(width: 6)
.clipped()
, alignment: .leading
)
.frame(minWidth: 0, maxWidth: .infinity)
.cornerRadius(8)
.shadow(color: Color.black.opacity(0.25), radius: 4, x: 0, y: 1)
.padding(.horizontal, 16)
}
}

Expand Down
1 change: 1 addition & 0 deletions Calq/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"gradeNewAdd"="Note hinzufügen";
"gradeInvalidName"="Ungültiger Name";
"gradeInvalidNameDesc"="Der Name darf keine Sonderzeichen enthalten und nicht leer sein";
"gradeNewToastSuccess"="Neue Note hinzugefügt";

"subjectListTitle"="Kursliste";
"subjectListTable"="Notentabelle";
Expand Down
1 change: 1 addition & 0 deletions Calq/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"gradeNewAdd"="Add Grade";
"gradeInvalidName"="Invalid Name";
"gradeInvalidNameDesc"="Name cannot include special characters or be empty";
"gradeNewToastSuccess"="New Grade added";

"subjectListTitle"="Subjectlist";
"subjectListTable"="Gradetable";
Expand Down
14 changes: 14 additions & 0 deletions Calq/lib/StringExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// StringExtension.swift
// Calq
//
// Created by Kiara on 16.07.23.
//

import Foundation

extension String {
var localized: String {
return NSLocalizedString(self, comment: "")
}
}

0 comments on commit c2aff1c

Please sign in to comment.