Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIA-1299: Handle logout on Account Settings #83

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PIA VPN-tvOS/Assets.xcassets/Settings/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "improve-app.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
6 changes: 3 additions & 3 deletions PIA VPN-tvOS/Dashboard/UI/DashboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ struct DashboardView: View {
@ObservedObject var viewModel: DashboardViewModel

var body: some View {
VStack {
VStack(alignment: .center) {
ConnectionStateBar(tintColor: viewModel.connectionTintColor.connectionBarTint)

Spacer()
DashboardConnectionButtonSection()
.padding(.bottom, 80)

Expand All @@ -17,7 +17,7 @@ struct DashboardView: View {

QuickConnectSection()
.frame(width: Spacing.dashboardViewWidth)

Spacer()
}
.withTopNavigationBarAndTitleView {
// View for the Title section of the Navigation bar
Expand Down
2 changes: 2 additions & 0 deletions PIA VPN-tvOS/Dashboard/UI/PIAConnectionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ struct PIAConnectionButton: View {
Button(viewModel.errorAlertCloseActionTitle, role: .cancel) {

}
// TODO: Localize
Button("Retry", role: .none) {
viewModel.toggleConnection()
}
} message: {
// TODO: Localize
Text("Please check your internet connection and try again")
}
}
Expand Down
14 changes: 10 additions & 4 deletions PIA VPN-tvOS/Dashboard/UI/QuickConnectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ struct QuickConnectView: View {

let rows = [ GridItem(.adaptive(minimum: 160, maximum: 160)) ]
var body: some View {

HStack(alignment: .top, spacing: 44) {
ForEach(viewModel.servers, id: \.regionIdentifier) { item in
DashboardFactory.makeQuickConnectButton(for: item, delegate: viewModel)
VStack (alignment: .leading) {
HStack(alignment: .top, spacing: 44) {
ForEach(viewModel.servers, id: \.regionIdentifier) { item in
DashboardFactory.makeQuickConnectButton(for: item, delegate: viewModel)
}

if viewModel.servers.count < 4 {
Spacer()
}
}
}
.frame(width: Spacing.dashboardViewWidth)
.onAppear {
viewModel.updateStatus()
}
Expand Down
34 changes: 33 additions & 1 deletion PIA VPN-tvOS/Navigation/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AppRouter: ObservableObject, AppRouterType {
pathDestinations.removeAll()
path.removeLast(path.count)
}

}


Expand All @@ -75,7 +76,7 @@ extension AppRouter {
router.navigate(to: destination)
}
}

static func == (lhs: AppRouter.Actions, rhs: AppRouter.Actions) -> Bool {
switch (lhs, rhs) {
case (.pop, .pop):
Expand Down Expand Up @@ -104,3 +105,34 @@ extension AppRouter {
}.store(in: &cancellables)
}
}

// MARK: - Destinations Navigations Actions

extension AppRouter {

private static func navigateRouterToDestinationAction(_ destination: any Destinations) -> AppRouter.Actions {
AppRouter.Actions.navigate(router: AppRouterFactory.makeAppRouter(), destination: destination)
}
}

// MARK: - Settings Navigation Actions

extension AppRouter {

static var navigateToAvailableSettingsDestinationAction: AppRouter.Actions {
navigateRouterToDestinationAction(SettingsDestinations.availableSettings)
}

static var navigateToAccountSettingsDestinationAction: AppRouter.Actions {
navigateRouterToDestinationAction(SettingsDestinations.account)
}

static var navigateToGeneralSettingsDestinationAction: AppRouter.Actions {
navigateRouterToDestinationAction(SettingsDestinations.general)
}

static var navigateToDIPSettingsDestinationAction: AppRouter.Actions {
navigateRouterToDestinationAction(SettingsDestinations.dip)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TopNavigationFactory {
}

static func makeTopNavigationViewModel() -> TopNavigationViewModel {
return topNavigationViewModelShared
return TopNavigationViewModel(appRouter: AppRouterFactory.makeAppRouter())
}


Expand Down
1 change: 0 additions & 1 deletion PIA VPN-tvOS/Navigation/Destinations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ enum RegionsDestinations: Destinations, Codable {
}
}
}

14 changes: 11 additions & 3 deletions PIA VPN-tvOS/Navigation/Presentation/TopNavigationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TopNavigationViewModel: ObservableObject {
case .locations:
appRouter.navigate(to: RegionsDestinations.serversList)
case .settings:
// TODO: Implement me
appRouter.navigate(to: SettingsDestinations.availableSettings)
break
case .help:
// TODO: Implement me
Expand All @@ -105,8 +105,16 @@ class TopNavigationViewModel: ObservableObject {
return .locations
case .home as DashboardDestinations:
return .vpn
// TODO: Add settings and help destinations when implemented
default:
case .availableSettings as SettingsDestinations:
return .settings
case .account as SettingsDestinations:
return .settings
case .general as SettingsDestinations:
return .settings
case .dip as SettingsDestinations:
return .settings
// TODO: add help destinations when implemented
default:
return .vpn
}
} else {
Expand Down
41 changes: 41 additions & 0 deletions PIA VPN-tvOS/Navigation/Routes+Settings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Routes+Settings.swift
// PIA VPN-tvOS
//
// Created by Laura S on 2/14/24.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Foundation
import SwiftUI

enum SettingsDestinations {
case availableSettings
case account
case general
case dip
}




extension View {
func withSettingsRoutes() -> some View {
self.navigationDestination(for: SettingsDestinations.self) { destination in
switch destination {
case .availableSettings:
SettingsFactory.makeAvailableSettingsView()
.withTopNavigationBar(with: "Settings")
case .account:
SettingsFactory.makeAccountSettingsView()
.withTopNavigationBar(with: "Account")
case .general:
// TODO: Implement me
EmptyView()
case .dip:
// TODO: Implement me
EmptyView()
}
}
}
}
2 changes: 1 addition & 1 deletion PIA VPN-tvOS/Navigation/UI/TopNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct TrailingNavigationView: View {
}
.focused($focusedSection, equals: section)
.buttonBorderShape(.circle)
.buttonStyle(BasicButtonStyle())
.buttonStyle(.card)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protocol RegionsFilterUseCaseType {
}

class RegionsFilterUseCase: RegionsFilterUseCaseType {

private let maxReccommendedServersCount = 12
private let serversUseCase: RegionsListUseCaseType
private let favoritesUseCase: FavoriteRegionUseCaseType
private let previouslySearchedAvailability: SearchedRegionsAvailabilityType
Expand Down Expand Up @@ -129,9 +129,9 @@ extension RegionsFilterUseCase {
}

private func getRecommended(from servers: [ServerType]) -> [ServerType] {
servers.sorted(by: {
Array(servers.sorted(by: {
$0.pingTime ?? 0 < $1.pingTime ?? 0
})
}).prefix(maxReccommendedServersCount))
}

private func getSearchResultsFrom(_ servers: [ServerType], with searchTerm: String) -> [ServerType] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class RootContainerViewModel: ObservableObject {

let onBoardingVpnProfileInstalled = vpnConfigurationAvailability.get()
let shouldShowconnectionStatsPermisson = connectionStatsPermissonType.get() == nil

switch (accountProvider.isLoggedIn, onBoardingVpnProfileInstalled) {
// logged in, vpn profile installed
case (true, true):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct UserActivatedContainerView: View {
.navigationBarHidden(true)
}
}
.withSettingsRoutes()

}

Expand Down
36 changes: 36 additions & 0 deletions PIA VPN-tvOS/Settings/CompositionRoot/SettingsFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SettingsFactory.swift
// PIA VPN-tvOS
//
// Created by Laura S on 2/14/24.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Foundation
import PIALibrary

class SettingsFactory {
private static func makeAvailableSettingsViewModel() -> AvailableSettingsViewModel {
return AvailableSettingsViewModel(onAccountSelectedAction: AppRouter.navigateToAccountSettingsDestinationAction)
}

static func makeAvailableSettingsView() -> AvailableSettingsView {
return AvailableSettingsView(viewModel: makeAvailableSettingsViewModel())
}

static func makeLogOutUseCase() -> LogOutUseCaseType {
guard let defaultAccountProvider = Client.providers.accountProvider as? DefaultAccountProvider else {
fatalError("Incorrect account provider type")
}

return LogOutUseCase(accountProvider: defaultAccountProvider, appPreferences: AppPreferences.shared, vpnConfigurationProvicer: VPNConfigurationInstallingFactory.makeVpnConfigurationProvider())
}

private static func makeAccountSettingsViewModel() -> AccountSettingsViewModel {
return AccountSettingsViewModel(logOutUseCase: makeLogOutUseCase())
}

static func makeAccountSettingsView() -> AccountSettingsView {
return AccountSettingsView(viewModel: makeAccountSettingsViewModel())
}
}
64 changes: 64 additions & 0 deletions PIA VPN-tvOS/Settings/Presentation/AccountSettingsViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// AccountSettingsViewModel.swift
// PIA VPN-tvOS
//
// Created by Laura S on 2/15/24.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Foundation

class AccountSettingsViewModel: ObservableObject {

var logOutButtonTitle: String {
L10n.Localizable.Settings.Account.LogOutButton.title
}

var logOutAlertTitle: String {
L10n.Localizable.Settings.Account.LogOutAlert.title
}

var logOutAlertMesage: String {
L10n.Localizable.Settings.Account.LogOutAlert.message
}

var logOutAlertCancelActionText: String {
L10n.Localizable.Global.cancel
}

var logOutAlertConfirmActionText: String {
L10n.Localizable.Settings.Account.LogOutButton.title
}

@Published var isLogOutAlertVisible: Bool = false
@Published var isLoading: Bool = false

let logOutUseCase: LogOutUseCaseType

init(logOutUseCase: LogOutUseCaseType) {
self.logOutUseCase = logOutUseCase
}

func logOutButtonWasTapped() {
isLogOutAlertVisible = true
}

private func setLoading(to loading: Bool) {
DispatchQueue.main.async { [weak self] in
self?.isLoading = loading
}
}

func logOutConfirmationButtonWasTapped() {
Task {
do {
setLoading(to: true)
try await logOutUseCase.logOut()
setLoading(to: false)
} catch {
setLoading(to: false)
}
}
}

}
Loading
Loading