Skip to content

Commit

Permalink
Merge pull request #25 from adisve/ui/settings
Browse files Browse the repository at this point in the history
UI/settings
  • Loading branch information
adisve authored Mar 30, 2023
2 parents 96f1451 + a6c469e commit 058b965
Show file tree
Hide file tree
Showing 90 changed files with 1,043 additions and 431 deletions.
86 changes: 66 additions & 20 deletions tumble-ios.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
7 changes: 7 additions & 0 deletions tumble-ios/App/Data/DataSource/Kronox/KronoxManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ class KronoxManager: KronoxManagerProtocol {
completion(.failure(Response.ErrorMessage(message: "Unable to convert empty response object to \(NetworkResponse.self)", statusCode: httpResponse.statusCode)))
}
}
case 202:
// Return an empty object that conforms to the expected type of NetworkResponse
if let result = Response.Empty() as? NetworkResponse {
completion(.success(result))
} else {
completion(.failure(Response.ErrorMessage(message: "Unable to convert empty response object to \(NetworkResponse.self)", statusCode: httpResponse.statusCode)))
}
case 400:
do {
let result = try self.decoder.decode(Response.ErrorMessage.self, from: data)
Expand Down
15 changes: 13 additions & 2 deletions tumble-ios/App/Data/Notifications/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class NotificationManager: NotificationManagerProtocol {
}
}


func cancelNotification(for eventId: String) {
notificationCenter.removePendingNotificationRequests(withIdentifiers: [eventId])
AppLogger.shared.info("Cancelled notifications with id -> \(eventId)")
Expand Down Expand Up @@ -74,15 +75,25 @@ class NotificationManager: NotificationManagerProtocol {
AppLogger.shared.info("Cancelled all notifications for this school")
}

func createNotificationFromEvent(event: Response.Event, color: String) -> EventNotification {
func createNotificationFromEvent(event: Response.Event, color: String) -> EventNotification? {
guard let dateComponents = event.dateComponents else { return nil }
let notification = EventNotification(
id: event.id,
color: color,
dateComponents: event.dateComponents!,
dateComponents: dateComponents,
categoryIdentifier: event.course.id, content: event.toDictionary()
)
return notification
}

func createNotificationFromBooking(booking: Response.KronoxUserBookingElement) -> BookingNotification? {
guard let dateComponents = booking.dateComponentsConfirmation else { return nil }
let notification = BookingNotification(
id: booking.resourceID,
dateComponents: dateComponents
)
return notification
}
}


Expand Down
18 changes: 3 additions & 15 deletions tumble-ios/App/Data/Repository/Preferences/PreferenceService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,13 @@ class PreferenceService: PreferenceServiceProtocol {
UserDefaults.standard.synchronize()
}

func setTheme(isDarkMode: Bool) -> Void {
UserDefaults.standard.set(isDarkMode, forKey: StoreKey.theme.rawValue)
UserDefaults.standard.set(true, forKey: StoreKey.overrideSystemTheme.rawValue)
UserDefaults.standard.synchronize()
}

func setOverrideSystemFalse() -> Void {
UserDefaults.standard.set(false, forKey: StoreKey.overrideSystemTheme.rawValue)
func setAppearance(appearance: String) -> Void {
UserDefaults.standard.set(appearance, forKey: StoreKey.appearance.rawValue)
UserDefaults.standard.synchronize()
}

func setLang(lang: String) -> Void {
UserDefaults.standard.set(lang, forKey: StoreKey.language.rawValue)
UserDefaults.standard.set(lang, forKey: StoreKey.locale.rawValue)
UserDefaults.standard.synchronize()
}

Expand All @@ -81,12 +75,6 @@ class PreferenceService: PreferenceServiceProtocol {
UserDefaults.standard.synchronize()
}

func setOverrideSystem(value: Bool) {
UserDefaults.standard.set(value, forKey: StoreKey.overrideSystemTheme.rawValue)
UserDefaults.standard.synchronize()
}


// ----------- GET -----------
func getDefault(key: String) -> Any? {
return UserDefaults.standard.object(forKey: key)
Expand Down
9 changes: 9 additions & 0 deletions tumble-ios/App/Domain/Model/Network/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ public enum Response {
case locationID = "locationId"
case showConfirmButton, showUnbookButton, confirmationOpen, confirmationClosed
}

var dateComponentsConfirmation: DateComponents? {
guard let date = isoDateFormatter.date(from: confirmationOpen) else {
return nil
}
let calendar = Calendar.current
let dateComponents = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
return dateComponents
}
}

// MARK: - KronoxEventRegistration
Expand Down
6 changes: 2 additions & 4 deletions tumble-ios/App/Domain/Model/Preferences/StoreKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ enum StoreKey: String {

case school = "school"
case bookmarks = "bookmarks"
case theme = "theme"
case language = "lang"
case appearance = "appearance"
case locale = "locale"
case notificationOffset = "notification_offset"
case autoSignup = "auto_signup"
case viewType = "view_type"
case userOnboarded = "user_onboarded"
case overrideSystemTheme = "override_theme"
case lastBookmarksUpdate = "last_bookmark_update"
case profileImage = "profile_image"

case networkSettings = "networkSettings"
Expand Down
23 changes: 20 additions & 3 deletions tumble-ios/App/Domain/Model/Presentation/Bookmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@

import Foundation

class Bookmark: Identifiable, ObservableObject {
class Bookmark: Identifiable, ObservableObject, Codable {

@Published var toggled: Bool
let id: String

init(toggled: Bool, id: String) {
self.toggled = toggled
self.id = id
}

@Published var toggled: Bool
let id: String
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
toggled = try container.decode(Bool.self, forKey: .toggled)
id = try container.decode(String.self, forKey: .id)
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(toggled, forKey: .toggled)
try container.encode(id, forKey: .id)
}

private enum CodingKeys: String, CodingKey {
case toggled
case id
}
}
13 changes: 0 additions & 13 deletions tumble-ios/App/Domain/Model/Presentation/SideBarSheetModel.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ protocol PreferenceServiceProtocol {

func setBookmarks(bookmarks: [Bookmark]) -> Void

func setTheme(isDarkMode: Bool) -> Void

func setOverrideSystemFalse() -> Void

func setAppearance(appearance: String) -> Void

func setLang(lang: String) -> Void

func setAutoSignup(autoSignup: Bool) -> Void

func setViewType(viewType: Int) -> Void

func setOverrideSystem(value: Bool) -> Void


func toggleBookmark(bookmark: String, value: Bool) -> Void

// ----------- GET -----------
Expand Down
Binary file modified tumble-ios/App/Extensions/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ extension Dictionary where Key == String, Value == Any {
}
}

extension Dictionary where Key == String, Value == Bool {
func encode() -> Data? {
try? JSONEncoder().encode(self)
}

init?(data: Data) {
guard let dictionary = try? JSONDecoder().decode(Dictionary.self, from: data) else {
return nil
}
self = dictionary
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Image {

func tabBarIcon(isSelected: Bool) -> some View {
self
.font(.system(size: 20))
.font(.system(size: 21))
.foregroundColor(isSelected ? .primary : .onSurface.opacity(0.5))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ extension Text {
}

func titleSchool() -> some View {
self.font(.system(size: 20, weight: .semibold))
self
.font(.system(size: 18, weight: .medium))
.foregroundColor(.onSurface)
}

func featureText() -> some View {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// UIApplicationExtension.swift
// tumble-ios
//
// Created by Adis Veletanlic on 2023-03-30.
//

import Foundation
import StoreKit
import UIKit

extension UIApplication {

// Override variable
private var keyWindow: UIWindow? {
// Get connected scenes
return UIApplication.shared.connectedScenes
// Keep only active scenes, onscreen and visible to the user
.filter { $0.activationState == .foregroundActive }
// Keep only the first `UIWindowScene`
.first(where: { $0 is UIWindowScene })
// Get its associated windows
.flatMap({ $0 as? UIWindowScene })?.windows
// Finally, keep only the key window
.first(where: \.isKeyWindow)
}

func requestReview() -> Void {
if let keyWindow = UIApplication.shared.keyWindow, let windowScene = keyWindow.windowScene {
SKStoreReviewController.requestReview(in: windowScene)
}
}

func shareFeedback() -> Void {
if let url = URL(string: "mailto:tumblestudios.app@gmail.com") {
UIApplication.shared.open(url)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension View {
func searchBox() -> some View {
self.padding(10)
.background(.gray.opacity(0.25))
.cornerRadius(20)
.cornerRadius(10)
.padding(.horizontal, 10)
.padding(.bottom, 15)
.padding(.top, 15)
Expand Down
8 changes: 4 additions & 4 deletions tumble-ios/App/Observables/ViewModels/ParentViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import SwiftUI
let bookmarksViewModel: BookmarksViewModel
let accountPageViewModel: AccountViewModel
let searchViewModel: SearchViewModel
let sidebarViewModel: SettingsViewModel
let settingsViewModel: SettingsViewModel


init() {
Expand All @@ -41,7 +41,7 @@ import SwiftUI
self.bookmarksViewModel = viewModelFactory.makeViewModelBookmarks()
self.accountPageViewModel = viewModelFactory.makeViewModelAccount()
self.searchViewModel = viewModelFactory.makeViewModelSearch()
self.sidebarViewModel = viewModelFactory.makeViewModelSettings()
self.settingsViewModel = viewModelFactory.makeViewModelSettings()

self.canvasUrl = preferenceService.getCanvasUrl()
self.kronoxUrl = preferenceService.getUniversityKronoxUrl()
Expand All @@ -61,7 +61,7 @@ import SwiftUI
self.universityName = preferenceService.getUniversityName()
self.searchViewModel.update()
self.bookmarksViewModel.updateViewLocals()
self.sidebarViewModel.updateViewLocals()
self.settingsViewModel.updateViewLocals()
self.bookmarksViewModel.loadBookmarkedSchedules()
self.accountPageViewModel.updateViewLocals()
self.homeViewModel.updateViewLocals()
Expand All @@ -70,7 +70,7 @@ import SwiftUI


func updateSchedulesChildView() -> Void {
sidebarViewModel.updateBookmarks()
settingsViewModel.updateBookmarks()
homeViewModel.updateViewLocals()
bookmarksViewModel.loadBookmarkedSchedules()
}
Expand Down
12 changes: 8 additions & 4 deletions tumble-ios/App/Observables/ViewModels/ResourceViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,18 @@ import Foundation
requestUrl,
refreshToken: refreshToken,
body: requestBody) {
(result: Result<Response.KronoxUserBookingElement, Response.ErrorMessage>) in
(result: Result<Response.KronoxUserBookingElement?, Response.ErrorMessage>) in
switch result {
case .success:
AppLogger.shared.info("Booked resource \(resourceId)")
completion(.success(()))
case .failure(let error):
AppLogger.shared.critical("Failed to book resource: \(error)")
completion(.failure(.internal(reason: "\(error)")))
if error.statusCode == 202 {
completion(.success(()))
} else {
AppLogger.shared.critical("Failed to book resource: \(error)")
completion(.failure(.internal(reason: "\(error)")))
}
}
}
case .failure(let error):
Expand All @@ -205,7 +209,7 @@ import Foundation
}
)
}

func unbookResource(bookingId: String, completion: @escaping (Result<Void, Error>) -> Void) -> Void {
authenticateAndExecute(
school: school,
Expand Down
Loading

0 comments on commit 058b965

Please sign in to comment.