Skip to content

Commit

Permalink
設定画面の実装 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
CH3COOH authored Aug 9, 2023
1 parent 1c8b615 commit faab88d
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 256 deletions.
30 changes: 21 additions & 9 deletions TodoNote/TodoNote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
AA1932872A830F5B002C846F /* SyncReadyTodoUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA1932842A830F5B002C846F /* SyncReadyTodoUseCase.swift */; };
AA1932882A830F5B002C846F /* SyncReadyTodoUseCaseInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA1932852A830F5B002C846F /* SyncReadyTodoUseCaseInput.swift */; };
AA1932892A830F5B002C846F /* SyncReadyTodoUseCaseResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA1932862A830F5B002C846F /* SyncReadyTodoUseCaseResult.swift */; };
AA1932902A837A11002C846F /* SignOutUseCaseResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA19328D2A837A11002C846F /* SignOutUseCaseResult.swift */; };
AA1932912A837A11002C846F /* SignOutUseCaseInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA19328E2A837A11002C846F /* SignOutUseCaseInput.swift */; };
AA1932922A837A11002C846F /* SignOutUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA19328F2A837A11002C846F /* SignOutUseCase.swift */; };
AABB4F832A80D7A5008FC467 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AABB4F822A80D7A5008FC467 /* Preview Assets.xcassets */; };
AABB4F852A80D7A5008FC467 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = AABB4F842A80D7A5008FC467 /* Persistence.swift */; };
AABB4F882A80D7A5008FC467 /* TodoNote.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = AABB4F862A80D7A5008FC467 /* TodoNote.xcdatamodeld */; };
Expand All @@ -47,9 +50,7 @@
AAE79F912A80E376009823FB /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F8A2A80E376009823FB /* SettingsView.swift */; };
AAE79F922A80E376009823FB /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F8B2A80E376009823FB /* SettingsViewModel.swift */; };
AAE79F932A80E376009823FB /* SettingsViewRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F8C2A80E376009823FB /* SettingsViewRouter.swift */; };
AAE79F942A80E376009823FB /* SettingsListSwitchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F8E2A80E376009823FB /* SettingsListSwitchView.swift */; };
AAE79F952A80E376009823FB /* SettingsListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F8F2A80E376009823FB /* SettingsListItemView.swift */; };
AAE79F962A80E376009823FB /* SettingsListAppIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F902A80E376009823FB /* SettingsListAppIconView.swift */; };
AAE79F9C2A80E4E3009823FB /* AlertItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F9B2A80E4E3009823FB /* AlertItem.swift */; };
AAE79F9E2A80E51D009823FB /* RSwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79F9D2A80E51D009823FB /* RSwiftUI.swift */; };
AAE79FA12A80E543009823FB /* ListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE79FA02A80E543009823FB /* ListItemView.swift */; };
Expand Down Expand Up @@ -118,6 +119,9 @@
AA1932842A830F5B002C846F /* SyncReadyTodoUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncReadyTodoUseCase.swift; sourceTree = "<group>"; };
AA1932852A830F5B002C846F /* SyncReadyTodoUseCaseInput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncReadyTodoUseCaseInput.swift; sourceTree = "<group>"; };
AA1932862A830F5B002C846F /* SyncReadyTodoUseCaseResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncReadyTodoUseCaseResult.swift; sourceTree = "<group>"; };
AA19328D2A837A11002C846F /* SignOutUseCaseResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignOutUseCaseResult.swift; sourceTree = "<group>"; };
AA19328E2A837A11002C846F /* SignOutUseCaseInput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignOutUseCaseInput.swift; sourceTree = "<group>"; };
AA19328F2A837A11002C846F /* SignOutUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignOutUseCase.swift; sourceTree = "<group>"; };
AABB4F782A80D7A4008FC467 /* TodoNote.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TodoNote.app; sourceTree = BUILT_PRODUCTS_DIR; };
AABB4F822A80D7A5008FC467 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
AABB4F842A80D7A5008FC467 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -145,9 +149,7 @@
AAE79F8A2A80E376009823FB /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
AAE79F8B2A80E376009823FB /* SettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewModel.swift; sourceTree = "<group>"; };
AAE79F8C2A80E376009823FB /* SettingsViewRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewRouter.swift; sourceTree = "<group>"; };
AAE79F8E2A80E376009823FB /* SettingsListSwitchView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsListSwitchView.swift; sourceTree = "<group>"; };
AAE79F8F2A80E376009823FB /* SettingsListItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsListItemView.swift; sourceTree = "<group>"; };
AAE79F902A80E376009823FB /* SettingsListAppIconView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsListAppIconView.swift; sourceTree = "<group>"; };
AAE79F9B2A80E4E3009823FB /* AlertItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertItem.swift; sourceTree = "<group>"; };
AAE79F9D2A80E51D009823FB /* RSwiftUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSwiftUI.swift; sourceTree = "<group>"; };
AAE79FA02A80E543009823FB /* ListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -270,6 +272,16 @@
path = SyncReadyTodo;
sourceTree = "<group>";
};
AA19328C2A837A11002C846F /* SignOut */ = {
isa = PBXGroup;
children = (
AA19328F2A837A11002C846F /* SignOutUseCase.swift */,
AA19328E2A837A11002C846F /* SignOutUseCaseInput.swift */,
AA19328D2A837A11002C846F /* SignOutUseCaseResult.swift */,
);
path = SignOut;
sourceTree = "<group>";
};
AABB4F6F2A80D7A4008FC467 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -320,8 +332,8 @@
AABB4F902A80D7A5008FC467 /* TodoNoteTests */ = {
isa = PBXGroup;
children = (
AA1932792A82F8F8002C846F /* Repository */,
AABB4F912A80D7A5008FC467 /* TodoNoteTests.swift */,
AA1932792A82F8F8002C846F /* Repository */,
);
path = TodoNoteTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -448,9 +460,7 @@
AAE79F8D2A80E376009823FB /* View */ = {
isa = PBXGroup;
children = (
AAE79F8E2A80E376009823FB /* SettingsListSwitchView.swift */,
AAE79F8F2A80E376009823FB /* SettingsListItemView.swift */,
AAE79F902A80E376009823FB /* SettingsListAppIconView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -499,6 +509,7 @@
children = (
AAE79FC32A80FDA6009823FB /* UseCaseProctol.swift */,
AAE79FB32A80FD2F009823FB /* Launch */,
AA19328C2A837A11002C846F /* SignOut */,
AA1932832A830F5B002C846F /* SyncReadyTodo */,
AA19327C2A830A09002C846F /* UpdateTodo */,
);
Expand Down Expand Up @@ -917,9 +928,9 @@
AAE79FAA2A80E882009823FB /* HomeView.swift in Sources */,
AAE79F732A80DEEA009823FB /* SafariUtil.swift in Sources */,
AAE79F9E2A80E51D009823FB /* RSwiftUI.swift in Sources */,
AA1932902A837A11002C846F /* SignOutUseCaseResult.swift in Sources */,
AABB4F852A80D7A5008FC467 /* Persistence.swift in Sources */,
AAE79F9C2A80E4E3009823FB /* AlertItem.swift in Sources */,
AAE79F942A80E376009823FB /* SettingsListSwitchView.swift in Sources */,
AAE79FC02A80FD2F009823FB /* CheckVersionUseCase.swift in Sources */,
AAE79FE02A81180B009823FB /* AppConstValues.swift in Sources */,
AAE79FBC2A80FD2F009823FB /* LaunchUseCaseInput.swift in Sources */,
Expand All @@ -942,6 +953,7 @@
AAE79F6C2A80DE50009823FB /* SplashView.swift in Sources */,
AA1932882A830F5B002C846F /* SyncReadyTodoUseCaseInput.swift in Sources */,
AAE79F752A80DF13009823FB /* R.generated.swift in Sources */,
AA1932922A837A11002C846F /* SignOutUseCase.swift in Sources */,
AA1932732A8248AB002C846F /* LoginViewModel.swift in Sources */,
AAE79FB22A80FAE1009823FB /* RegistrationStatus.swift in Sources */,
AA1932752A824B7C002C846F /* TodoItemView.swift in Sources */,
Expand All @@ -958,13 +970,13 @@
AA1932822A830A2F002C846F /* UpdateTodoUseCaseResult.swift in Sources */,
AAE79FC82A80FFBB009823FB /* AppTitleView.swift in Sources */,
AAE79F852A80E1BC009823FB /* ActivityIndicatorView.swift in Sources */,
AAE79F962A80E376009823FB /* SettingsListAppIconView.swift in Sources */,
AAE79FD42A810D20009823FB /* PreviewUtil.swift in Sources */,
AAE79F6E2A80DE5C009823FB /* SplashViewModel.swift in Sources */,
AAE79F772A80DF48009823FB /* FAPage.swift in Sources */,
AAE79F932A80E376009823FB /* SettingsViewRouter.swift in Sources */,
AAE79F912A80E376009823FB /* SettingsView.swift in Sources */,
AAE79F952A80E376009823FB /* SettingsListItemView.swift in Sources */,
AA1932912A837A11002C846F /* SignOutUseCaseInput.swift in Sources */,
AAE79FBF2A80FD2F009823FB /* CheckVersionUseCaseInput.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 2 additions & 0 deletions TodoNote/TodoNote/Model/FAPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import Foundation
enum FAPage: String {
case splash = "スプラッシュ"

// 設定
case settings = "設定"
case settingsFeedback = "設定/お問い合わせ"
case settingsUserPolicy = "設定/利用規約"
case settingsPrivacyPolicy = "設定/プライバシーポリシー"
case settingsPublisher = "設定/運営会社"
case settingsLicense = "設定/ライセンス情報"
}

extension FAPage {
Expand Down
24 changes: 24 additions & 0 deletions TodoNote/TodoNote/Repository/TodoRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,35 @@ class TodoRepository {
}
}

func fetch(status: RegistrationStatus) async throws -> [Todo] {
let request = TodoEntity.fetchRequest()
request.predicate = NSPredicate(format: "status == %@", status.rawValue)

return try await MainActor.run {
let result = try context.fetch(request)
return result.compactMap { $0.toModel() }
}
}

func fetchCount() throws -> Int {
let request = TodoEntity.fetchRequest()
return try context.count(for: request)
}

/// 指定したステータスのレコードをすべて削除する
func deleteAll(status: RegistrationStatus) async throws {
let request = TodoEntity.fetchRequest()
request.predicate = NSPredicate(format: "status == %@", status.rawValue)

try await MainActor.run {
let entities = try context.fetch(request)
for entity in entities {
context.delete(entity)
}
try context.save()
}
}

/// すべてのレコードを削除する
func deleteAll() async throws {
let request = TodoEntity.fetchRequest()
Expand Down
2 changes: 2 additions & 0 deletions TodoNote/TodoNote/Resource/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<false/>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>ITSAppUsesNonExemptEncryption </key>
<false/>
<key>NSUserTrackingUsageDescription</key>
<string>If allowed, it will be easier to display ads that match your preferences.</string>
<key>SKAdNetworkItems</key>
Expand Down
26 changes: 13 additions & 13 deletions TodoNote/TodoNote/Screen/Settings/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Created by KENJIWADA on 2023/03/16.
//

import SafariServices
import SwiftUI

struct SettingsView: View {
Expand Down Expand Up @@ -71,13 +70,13 @@ struct SettingsView: View {
}

Section {
Button(action: { model.onClickSignOutButton(from: viewController) }) {
HStack {
R.string.localizable.logout.text
.foregroundColor(Color.red)
.font(.system(size: 15))
}
.frame(maxWidth: .infinity)
Button(action: {
model.onClickSignOutButton(from: viewController)
}) {
R.string.localizable.logout.text
.foregroundColor(Color.red)
.font(.system(size: 15, weight: .bold))
.frame(maxWidth: .infinity)
}
}

Expand All @@ -95,21 +94,22 @@ struct SettingsView: View {
.navigationTitle(R.string.localizable.settings_title.text)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
model.update()
FAPage.settings.send()
model.onAppear(from: viewController)
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
viewController?.dismiss(animated: true)
}) {
Button(action: onClickCloseButton) {
R.string.localizable.close.text
}
}
}
.alert(item: $model.alertItem) { $0.alert }
.actionSheet(item: $model.actionSheetItem) { $0.sheet }
}

private func onClickCloseButton() {
viewController?.dismiss(animated: true)
}
}

struct SettingsView_Previews: PreviewProvider {
Expand Down
33 changes: 24 additions & 9 deletions TodoNote/TodoNote/Screen/Settings/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Created by KENJIWADA on 2023/03/18.
//

import FirebaseAuth
import SwiftUI

class SettingsViewModel: ObservableObject {
Expand All @@ -14,6 +13,8 @@ class SettingsViewModel: ObservableObject {

@Published var alertItem: AlertItem?

private let signOutUseCase = SignOutUseCase()

init() {
// アプリバージョンの取得
if let version = Bundle.main.infoDictionary?["CFBundleVersion"] as? String,
Expand All @@ -27,7 +28,9 @@ class SettingsViewModel: ObservableObject {

// MARK: -

func update() {}
func onAppear(from _: UIViewController?) {
FAPage.settings.send()
}

func onClickSignOutButton(from viewController: UIViewController?) {
actionSheetItem = ActionSheetItem(
Expand All @@ -47,14 +50,26 @@ class SettingsViewModel: ObservableObject {
// MARK: -

private func logout(viewController: UIViewController?) {
do {
try Auth.auth().signOut()

viewController?.dismiss(animated: false) {
SceneDelegate.shared?.rootViewController.switchToLoginScreen()
Task {
let result = await signOutUseCase.execute(.init())
switch result {
case .success:
await moveLoginScreen(from: viewController)
case let .failed(error):
alertItem = AlertItem(
alert: Alert(
title: R.string.localizable.error.text,
message: Text(error.localizedDescription)
)
)
}
} catch {
// TODO: エラー処理
}
}

@MainActor
private func moveLoginScreen(from viewController: UIViewController?) {
viewController?.dismiss(animated: false) {
SceneDelegate.shared?.rootViewController.switchToLoginScreen()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,12 @@ import SafariServices
import SwiftUI

struct SettingsViewRouter {
/// ストア
static func moveStore(from _: UIViewController?) {
// let vc = UIViewController.hostingController {
// StoreView(
// fromInformation: false
// )
// }
// vc.hidesBottomBarWhenPushed = true
// viewController?.navigationController?.pushViewController(vc, animated: true)
}

/// このアプリについて
static func moveAbout(from _: UIViewController?) {
// let vc = UIViewController.hostingController {
// AboutSettingsView()
// }
// vc.hidesBottomBarWhenPushed = true
// viewController?.navigationController?.pushViewController(vc, animated: true)
}

/// ライセンス
static func moveLicences(from viewController: UIViewController?) {
let vc = LicensePlistViewController(tableViewStyle: .insetGrouped)
vc.hidesBottomBarWhenPushed = true
viewController?.navigationController?.pushViewController(vc, animated: true)
// FAPage.settingsLicense.send()
FAPage.settingsLicense.send()
}

/// お問合せ
Expand Down
Loading

0 comments on commit faab88d

Please sign in to comment.