diff --git a/Podfile b/Podfile index 9d2fa37..36fbfce 100644 --- a/Podfile +++ b/Podfile @@ -11,6 +11,7 @@ target 'nippohub-daily' do pod 'Firebase/Auth' pod 'Firebase/Database' pod 'LicensePlist' + pod 'XLPagerTabStrip', '~> 9.0' target 'nippohub-dailyTests' do inherit! :search_paths diff --git a/Podfile.lock b/Podfile.lock index 969f07a..f71dded 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -36,12 +36,14 @@ PODS: - nanopb/encode (= 0.3.8) - nanopb/decode (0.3.8) - nanopb/encode (0.3.8) + - XLPagerTabStrip (9.0.0) DEPENDENCIES: - Firebase/Auth - Firebase/Core - Firebase/Database - LicensePlist + - XLPagerTabStrip (~> 9.0) SPEC REPOS: https://github.com/cocoapods/specs.git: @@ -56,6 +58,7 @@ SPEC REPOS: - leveldb-library - LicensePlist - nanopb + - XLPagerTabStrip SPEC CHECKSUMS: Firebase: d6861c2059d8c32d1e6dd8932e22ada346d90a3a @@ -69,7 +72,8 @@ SPEC CHECKSUMS: leveldb-library: 08cba283675b7ed2d99629a4bc5fd052cd2bb6a5 LicensePlist: 3fda61ebe060afc8fc6d995df34a91401af5a244 nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 + XLPagerTabStrip: 61c57fd61f611ee5f01ff1495ad6fbee8bf496c5 -PODFILE CHECKSUM: adc1ddd66988b6f72eb56a6b655ee95824e860e2 +PODFILE CHECKSUM: 3dcddfea3eeb494c837e35f51f7e87acee8b1089 COCOAPODS: 1.5.3 diff --git a/nippohub-daily.xcodeproj/project.pbxproj b/nippohub-daily.xcodeproj/project.pbxproj index 583adf0..f85510b 100644 --- a/nippohub-daily.xcodeproj/project.pbxproj +++ b/nippohub-daily.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ 54408D45226BC97000DF8F7E /* AgreementsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54408D44226BC97000DF8F7E /* AgreementsViewController.swift */; }; 54408D47226BD4C000DF8F7E /* PrivacyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54408D46226BD4C000DF8F7E /* PrivacyViewController.swift */; }; 545159C22246DB80005854CE /* SignUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545159C12246DB80005854CE /* SignUpViewController.swift */; }; - 545159C4224996AB005854CE /* DailyReportIndexViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545159C3224996AB005854CE /* DailyReportIndexViewController.swift */; }; + 545159C4224996AB005854CE /* DailyReportsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545159C3224996AB005854CE /* DailyReportsTableViewController.swift */; }; 54572997224AE01F001F20CD /* DailyReportListItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54572996224AE01F001F20CD /* DailyReportListItem.xib */; }; 54572999224AE0CF001F20CD /* DailyReportListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54572998224AE0CF001F20CD /* DailyReportListItem.swift */; }; 5457299C224AE3B9001F20CD /* DailyReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5457299B224AE3B9001F20CD /* DailyReport.swift */; }; @@ -50,6 +50,7 @@ 54E6487822D01F0B00C20EF6 /* Agreements.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 54E6487722D01F0B00C20EF6 /* Agreements.storyboard */; }; 54E6487A22D01F3D00C20EF6 /* Privacy.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 54E6487922D01F3D00C20EF6 /* Privacy.storyboard */; }; 54E6487C22D01F8100C20EF6 /* Setting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 54E6487B22D01F8100C20EF6 /* Setting.storyboard */; }; + 54E6487E22D7EF6400C20EF6 /* DailyReportIndexViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E6487D22D7EF6400C20EF6 /* DailyReportIndexViewController.swift */; }; 5E99E2EDAC11B3134A51A4B2 /* Pods_nippohub_dailyUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C959E3B09DECB470B0B3AC1 /* Pods_nippohub_dailyUITests.framework */; }; 68E1A26A7BB64FCEF4C78B4A /* Pods_nippohub_daily.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3763B8884410BDF84668DF2F /* Pods_nippohub_daily.framework */; }; BEE4D3ED4041D11317B0C135 /* Pods_nippohub_dailyTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0526FC9D8890CE3F9BD45EC8 /* Pods_nippohub_dailyTests.framework */; }; @@ -84,7 +85,7 @@ 54408D44226BC97000DF8F7E /* AgreementsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgreementsViewController.swift; sourceTree = ""; }; 54408D46226BD4C000DF8F7E /* PrivacyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyViewController.swift; sourceTree = ""; }; 545159C12246DB80005854CE /* SignUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; - 545159C3224996AB005854CE /* DailyReportIndexViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyReportIndexViewController.swift; sourceTree = ""; }; + 545159C3224996AB005854CE /* DailyReportsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyReportsTableViewController.swift; sourceTree = ""; }; 54572996224AE01F001F20CD /* DailyReportListItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DailyReportListItem.xib; sourceTree = ""; }; 54572998224AE0CF001F20CD /* DailyReportListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyReportListItem.swift; sourceTree = ""; }; 5457299B224AE3B9001F20CD /* DailyReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyReport.swift; sourceTree = ""; }; @@ -125,6 +126,7 @@ 54E6487722D01F0B00C20EF6 /* Agreements.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Agreements.storyboard; sourceTree = ""; }; 54E6487922D01F3D00C20EF6 /* Privacy.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Privacy.storyboard; sourceTree = ""; }; 54E6487B22D01F8100C20EF6 /* Setting.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Setting.storyboard; sourceTree = ""; }; + 54E6487D22D7EF6400C20EF6 /* DailyReportIndexViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyReportIndexViewController.swift; sourceTree = ""; }; 6E29FA28320AE5E76C86423E /* Pods-nippohub-dailyUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-nippohub-dailyUITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-nippohub-dailyUITests/Pods-nippohub-dailyUITests.debug.xcconfig"; sourceTree = ""; }; 7C959E3B09DECB470B0B3AC1 /* Pods_nippohub_dailyUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_nippohub_dailyUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 83869DF114DC7D4A8F8FE69B /* Pods-nippohub-dailyTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-nippohub-dailyTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-nippohub-dailyTests/Pods-nippohub-dailyTests.debug.xcconfig"; sourceTree = ""; }; @@ -342,7 +344,8 @@ isa = PBXGroup; children = ( 54E6486D22D01DEE00C20EF6 /* DailyReportIndex.storyboard */, - 545159C3224996AB005854CE /* DailyReportIndexViewController.swift */, + 545159C3224996AB005854CE /* DailyReportsTableViewController.swift */, + 54E6487D22D7EF6400C20EF6 /* DailyReportIndexViewController.swift */, ); path = DailyReportIndex; sourceTree = ""; @@ -612,6 +615,7 @@ "${SRCROOT}/Pods/Target Support Files/Pods-nippohub-daily/Pods-nippohub-daily-frameworks.sh", "${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework", "${BUILT_PRODUCTS_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework", + "${BUILT_PRODUCTS_DIR}/XLPagerTabStrip/XLPagerTabStrip.framework", "${BUILT_PRODUCTS_DIR}/leveldb-library/leveldb.framework", "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework", ); @@ -619,6 +623,7 @@ outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMSessionFetcher.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleToolboxForMac.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/XLPagerTabStrip.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/leveldb.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework", ); @@ -672,6 +677,7 @@ files = ( 54CA71CE225C06DB00D09381 /* LaunchViewController.swift in Sources */, 54572999224AE0CF001F20CD /* DailyReportListItem.swift in Sources */, + 54E6487E22D7EF6400C20EF6 /* DailyReportIndexViewController.swift in Sources */, 5457299C224AE3B9001F20CD /* DailyReport.swift in Sources */, 54408D45226BC97000DF8F7E /* AgreementsViewController.swift in Sources */, 545729A2224EDFDA001F20CD /* DailyReportNewViewController.swift in Sources */, @@ -680,7 +686,7 @@ 5472CE3722504B38001158E4 /* DateConverter.swift in Sources */, 540F069E2263EAD400A9CCA1 /* AlertOnlyOK.swift in Sources */, 54E6485E22CABEBC00C20EF6 /* DailyReportRepository.swift in Sources */, - 545159C4224996AB005854CE /* DailyReportIndexViewController.swift in Sources */, + 545159C4224996AB005854CE /* DailyReportsTableViewController.swift in Sources */, 54C1FCED224444CA00AB4FC8 /* SignInViewController.swift in Sources */, 540381792265479B0077F687 /* UIView+.swift in Sources */, 5472CE3422504098001158E4 /* DailyReportEditViewController.swift in Sources */, diff --git a/nippohub-daily/ViewsControllers/DailyReportEdit/DailyReportEditViewController.swift b/nippohub-daily/ViewsControllers/DailyReportEdit/DailyReportEditViewController.swift index 4dec885..55577a9 100644 --- a/nippohub-daily/ViewsControllers/DailyReportEdit/DailyReportEditViewController.swift +++ b/nippohub-daily/ViewsControllers/DailyReportEdit/DailyReportEditViewController.swift @@ -45,7 +45,7 @@ final class DailyReportEditViewController: UIViewController { (self.navigationController?.viewControllers[self.navigationController!.viewControllers.count - 2] as! DailyReportShowViewController).dailyReport = dailyReport // TODO: nilチェックする // TODO: showで処理する - (self.navigationController!.viewControllers[self.navigationController!.viewControllers.count - 3] as! DailyReportIndexViewController).updateDailyReports(dailyReport: dailyReport) + (self.navigationController!.viewControllers[self.navigationController!.viewControllers.count - 3] as! DailyReportIndexViewController)//.updateDailyReports(dailyReport: dailyReport) self.navigationController?.popViewController(animated: true) } diff --git a/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndex.storyboard b/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndex.storyboard index f25a8d8..32597be 100644 --- a/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndex.storyboard +++ b/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndex.storyboard @@ -1,5 +1,5 @@ - + @@ -10,51 +10,85 @@ + + + + + + + + + + + + + + + + + + - + - - + + - + + + + - - + + + + + + + + + + + - - - - + + + + + + + - + - + - + - + - + - + - + + - + - + diff --git a/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndexViewController.swift b/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndexViewController.swift index c250acf..83ce0e0 100644 --- a/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndexViewController.swift +++ b/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportIndexViewController.swift @@ -1,54 +1,17 @@ // -// DailyReportIndexViewController.swift +// DailyReportIndex2ViewController.swift // nippohub-daily // -// Created by うさきち on 2019/03/26. +// Created by うさきち on 2019/07/12. // Copyright © 2019 うーぴょん. All rights reserved. // import UIKit -import Firebase +import XLPagerTabStrip -final class DailyReportIndexViewController: UIViewController { - @IBOutlet private weak var tableDailyReports: UITableView! - private var dailyReports: [DailyReport] = [] - - override func viewDidLoad() { - super.viewDidLoad() - - let currentUser = AccountRepository.instance.currentUser - let dailyReportRepository = DailyReportRepository.instance - - tableDailyReports.register(UINib(nibName: "DailyReportListItem", bundle: nil), forCellReuseIdentifier: "DailyReportListItem") - tableDailyReports.dataSource = self - tableDailyReports.delegate = self - - if let user = currentUser { - dailyReportRepository.fetch(user: user) { [unowned self] in - self.dailyReports = $0 - self.tableDailyReports.reloadData() - } - } - } - - // 日報に更新があった時日報一覧を最新にする - func updateDailyReports(dailyReport: DailyReport) { - let index = dailyReports.firstIndex { $0.id == dailyReport.id } - - if let index = index { - dailyReports[index] = dailyReport - dailyReports.sort { $0.date >= $1.date } - } else { - let indexToInsert = dailyReports.firstIndex { $0.date <= dailyReport.date } - - if let indexToInsert = indexToInsert { - dailyReports.insert(dailyReport, at: indexToInsert) - } else { - dailyReports.append(dailyReport) - } - } - - tableDailyReports.reloadData() +class DailyReportIndexViewController: ButtonBarPagerTabStripViewController { + override public func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + return [DailyReportsTableViewController(), DailyReportsTableViewController()] } @IBAction func transitToNewDailyReport() { @@ -62,29 +25,8 @@ final class DailyReportIndexViewController: UIViewController { navigationController?.pushViewController(viewController, animated: true) } - + static func instantiate() -> DailyReportIndexViewController { return UIStoryboard(name: "DailyReportIndex", bundle: nil).instantiateInitialViewController() as! DailyReportIndexViewController } } - -extension DailyReportIndexViewController: UITableViewDataSource, UITableViewDelegate { - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return dailyReports.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "DailyReportListItem") as! DailyReportListItem - let dailyReport = dailyReports[indexPath.row] - - cell.title = "\(DateConverter.converter.toString(from: dailyReport.date)) \(dailyReport.title)" // TODO: Date追加 - - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let viewController = DailyReportShowViewController.instantiate(dailyReport: dailyReports[indexPath.row]) - - navigationController?.pushViewController(viewController, animated: true) - } -} diff --git a/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportsTableViewController.swift b/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportsTableViewController.swift new file mode 100644 index 0000000..9347253 --- /dev/null +++ b/nippohub-daily/ViewsControllers/DailyReportIndex/DailyReportsTableViewController.swift @@ -0,0 +1,96 @@ +// +// DailyReportIndexViewController.swift +// nippohub-daily +// +// Created by うさきち on 2019/03/26. +// Copyright © 2019 うーぴょん. All rights reserved. +// + +import UIKit +import Firebase +import XLPagerTabStrip + +final class DailyReportsTableViewController: UITableViewController { + private var dailyReports: [DailyReport] = [] + + override func viewDidLoad() { + super.viewDidLoad() + + tableView.register(UINib(nibName: "DailyReportListItem", bundle: nil), forCellReuseIdentifier: "DailyReportListItem") + } + + override func viewDidAppear(_ animated: Bool) { + let currentUser = AccountRepository.instance.currentUser + let dailyReportRepository = DailyReportRepository.instance + + if let user = currentUser { + dailyReportRepository.fetch(user: user) { [unowned self] in + self.dailyReports = $0 + self.tableView.reloadData() + } + } + } + + // 日報に更新があった時日報一覧を最新にする + func updateDailyReports(dailyReport: DailyReport) { + let index = dailyReports.firstIndex { $0.id == dailyReport.id } + + if let index = index { + dailyReports[index] = dailyReport + dailyReports.sort { $0.date >= $1.date } + } else { + let indexToInsert = dailyReports.firstIndex { $0.date <= dailyReport.date } + + if let indexToInsert = indexToInsert { + dailyReports.insert(dailyReport, at: indexToInsert) + } else { + dailyReports.append(dailyReport) + } + } + + tableView.reloadData() + } + + @objc @IBAction func transitToNewDailyReport() { + let viewController = DailyReportNewViewController.instantiate() + + navigationController?.pushViewController(viewController, animated: true) + } + + @IBAction func transitToSettings() { + let viewController = SettingViewController.instantiate() + + navigationController?.pushViewController(viewController, animated: true) + } + + static func instantiate() -> DailyReportIndexViewController { + return UIStoryboard(name: "DailyReportIndex", bundle: nil).instantiateInitialViewController() as! DailyReportIndexViewController + } +} + +extension DailyReportsTableViewController { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return dailyReports.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "DailyReportListItem") as! DailyReportListItem + let dailyReport = dailyReports[indexPath.row] + + cell.title = "\(DateConverter.converter.toString(from: dailyReport.date)) \(dailyReport.title)" // TODO: Date追加 + + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let viewController = DailyReportShowViewController.instantiate(dailyReport: dailyReports[indexPath.row]) + + navigationController?.pushViewController(viewController, animated: true) + } +} + +extension DailyReportsTableViewController: IndicatorInfoProvider { + func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo { + return IndicatorInfo(title: "My Child title") + } +} diff --git a/nippohub-daily/ViewsControllers/DailyReportNew/DailyReportNewViewController.swift b/nippohub-daily/ViewsControllers/DailyReportNew/DailyReportNewViewController.swift index 0d8be47..02390b4 100644 --- a/nippohub-daily/ViewsControllers/DailyReportNew/DailyReportNewViewController.swift +++ b/nippohub-daily/ViewsControllers/DailyReportNew/DailyReportNewViewController.swift @@ -26,7 +26,7 @@ final class DailyReportNewViewController: UIViewController { let dailyReport = dailyReportRepository.create(user: user, date: date, title: title, content: content) // TODO: nilチェックする - (self.navigationController!.viewControllers[self.navigationController!.viewControllers.count - 2] as! DailyReportIndexViewController).updateDailyReports(dailyReport: dailyReport) + (self.navigationController!.viewControllers[self.navigationController!.viewControllers.count - 2] as! DailyReportIndexViewController)//.updateDailyReports(dailyReport: dailyReport) } self.navigationController?.popViewController(animated: true) diff --git a/nippohub-daily/ViewsControllers/SignIn/SignInViewController.swift b/nippohub-daily/ViewsControllers/SignIn/SignInViewController.swift index 300ec2b..0daed08 100644 --- a/nippohub-daily/ViewsControllers/SignIn/SignInViewController.swift +++ b/nippohub-daily/ViewsControllers/SignIn/SignInViewController.swift @@ -45,4 +45,3 @@ final class SignInViewController: UIViewController { return UIStoryboard(name: "SignIn", bundle: nil).instantiateInitialViewController() as! SignInViewController } } -