Add favorite repository to store session ids
MODIFY
frontend/ios/DroidKaigi 2019.xcodeproj/project.pbxproj
frontend/ios/DroidKaigi 2019.xcodeproj/project.pbxproj
3672C2DD21F7392900ACB910 /* Kingfisher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3672C2DC21F7392900ACB910 /* Kingfisher.framework */; };
3672C2DF21F73A9400ACB910 /* SpeakerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3672C2DE21F73A9400ACB910 /* SpeakerCell.swift */; };
36D1FA2721F5CF6600ADBBDE /* StoryboardInstantiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36D1FA2621F5CF6600ADBBDE /* StoryboardInstantiable.swift */; };
+ 43DC80C12200A0F600A3F710 /* FavoriteRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43DC80C02200A0F600A3F710 /* FavoriteRepository.swift */; };
5917BCA621FA19B8005BEAF2 /* SessionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5917BCA521FA19B8005BEAF2 /* SessionHeaderView.swift */; };
59D30FC921F8B1BD003A937C /* SessionByStartTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59D30FC821F8B1BD003A937C /* SessionByStartTime.swift */; };
63F34E1B21EB43CE00B2EC48 /* SessionRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F34E1A21EB43CE00B2EC48 /* SessionRepository.swift */; };
3672C2DC21F7392900ACB910 /* Kingfisher.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Kingfisher.framework; path = Carthage/Build/iOS/Kingfisher.framework; sourceTree = "<group>"; };
3672C2DE21F73A9400ACB910 /* SpeakerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeakerCell.swift; sourceTree = "<group>"; };
36D1FA2621F5CF6600ADBBDE /* StoryboardInstantiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryboardInstantiable.swift; sourceTree = "<group>"; };
+ 43DC80C02200A0F600A3F710 /* FavoriteRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteRepository.swift; sourceTree = "<group>"; };
5917BCA521FA19B8005BEAF2 /* SessionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionHeaderView.swift; sourceTree = "<group>"; };
59D30FC821F8B1BD003A937C /* SessionByStartTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionByStartTime.swift; sourceTree = "<group>"; };
63F34E1A21EB43CE00B2EC48 /* SessionRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionRepository.swift; sourceTree = "<group>"; };
isa = PBXGroup;
children = (
2159CC5621FE186800DBD016 /* Day.swift */,
- 63F34E1A21EB43CE00B2EC48 /* SessionRepository.swift */,
+ 43DC80C02200A0F600A3F710 /* FavoriteRepository.swift */,
59D30FC821F8B1BD003A937C /* SessionByStartTime.swift */,
+ 63F34E1A21EB43CE00B2EC48 /* SessionRepository.swift */,
363E6AF321FD536A00EBC698 /* TagContent.swift */,
);
path = data;
366B060721F751C400C912AD /* TagsLeftAlignedCollectionViewFlowLayout.swift in Sources */,
3672C2D121F6033200ACB910 /* NibLoadable.swift in Sources */,
3672C2CD21F6024B00ACB910 /* Reusable.swift in Sources */,
+ 43DC80C12200A0F600A3F710 /* FavoriteRepository.swift in Sources */,
366B060E21F7652D00C912AD /* PaddingLabel.swift in Sources */,
5917BCA621FA19B8005BEAF2 /* SessionHeaderView.swift in Sources */,
36D1FA2721F5CF6600ADBBDE /* StoryboardInstantiable.swift in Sources */,

MODIFY
frontend/ios/DroidKaigi 2019/Scenes/Session/SessionsViewModel.swift
frontend/ios/DroidKaigi 2019/Scenes/Session/SessionsViewModel.swift
@@ -12,7 +12,8 @@ import RxCocoa
final class SessionsViewModel {
- private let repository = SessionRepository()
+ private let sessionRepository = SessionRepository()
+ private let favoriteRepository = FavoriteRepository()
private let bag = DisposeBag()
private let day: Day
init(day: Day) {
@@ -36,7 +37,7 @@ extension SessionsViewModel {
let sessionContents = input.viewWillAppear
.flatMap { [weak self] (_) -> Observable<SessionContents> in
guard let `self` = self else { return Observable.empty() }
- return self.repository.fetch()
+ return self.sessionRepository.fetch()
.asObservable()
.catchError { error in
self._error.accept(error.localizedDescription)
@@ -44,6 +45,10 @@ extension SessionsViewModel {
}
}
+ let favoriteSessionIds = favoriteRepository.sessionIdsDidChanged
+
+ favoriteSessionIds.subscribe { print($0) }.disposed(by: bag)
+
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(identifier: "Asia/Tokyo")
dateFormatter.locale = NSLocale.current

ADD
frontend/ios/DroidKaigi 2019/data/FavoriteRepository.swift
+//
+// FavoriteRepository.swift
+// DroidKaigi 2019
+//
+// Created by woxtu on 2019/01/29.
+//
+
+import Foundation
+import RxSwift
+
+final class FavoriteRepository {
+ private let key = "favoriteSessionIds"
+
+ var sessionIdsDidChanged: Observable<[String]> {
+ return UserDefaults.standard.rx
+ .observe([String].self, key, options: [.initial, .new])
+ .map { $0 ?? [] }
+ }
+
+ func toggle(sessionId: String) {
+ var favorites = UserDefaults.standard.object(forKey: key) as? [String] ?? []
+ if favorites.contains(sessionId) {
+ favorites.removeAll { $0 == sessionId }
+ } else {
+ favorites.append(sessionId)
+ }
+ UserDefaults.standard.setValue(favorites, forKey: key)
+ UserDefaults.standard.synchronize()
+ }
+}

Add favorite repository to store session ids