|
@@ -25,7 +25,7 @@ import Foundation
|
|
|
import UIKit
|
|
|
import SwiftRichString
|
|
|
|
|
|
-class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate, UITableViewDataSourcePrefetching, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
|
|
+class NCActivity: UIViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
|
|
|
|
|
@IBOutlet weak var tableView: UITableView!
|
|
|
|
|
@@ -75,7 +75,7 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
|
|
|
}
|
|
|
|
|
|
func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
|
|
|
- return CCGraphics.changeThemingColorImage(UIImage.init(named: "activityNoRecord"), multiplier: 2, color: NCBrandColor.sharedInstance.graySoft)
|
|
|
+ return CCGraphics.changeThemingColorImage(UIImage.init(named: "activity"), width: 300, height: 300, color: NCBrandColor.sharedInstance.graySoft)
|
|
|
}
|
|
|
|
|
|
func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
|
|
@@ -87,47 +87,48 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
|
|
|
func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -> Bool {
|
|
|
return true
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+class activityTableViewCell: UITableViewCell {
|
|
|
|
|
|
- // MARK: TableView
|
|
|
+ private let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
|
|
|
- func loadDataSource() {
|
|
|
-
|
|
|
- sectionDate.removeAll()
|
|
|
+ @IBOutlet weak var collectionView: UICollectionView!
|
|
|
|
|
|
- activities = NCManageDatabase.sharedInstance.getActivity(predicate: NSPredicate(format: "account == %@", appDelegate.activeAccount))
|
|
|
- for tableActivity in activities {
|
|
|
- guard let date = Calendar.current.date(from: Calendar.current.dateComponents([.year, .month, .day], from: tableActivity.date as Date)) else {
|
|
|
- continue
|
|
|
- }
|
|
|
- if !sectionDate.contains(date) {
|
|
|
- sectionDate.append(date)
|
|
|
- }
|
|
|
- }
|
|
|
- tableView.reloadData()
|
|
|
- }
|
|
|
+ @IBOutlet weak var icon: UIImageView!
|
|
|
+ @IBOutlet weak var avatar: UIImageView!
|
|
|
+ @IBOutlet weak var subject: UILabel!
|
|
|
+ @IBOutlet weak var subjectTrailingConstraint: NSLayoutConstraint!
|
|
|
+ @IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint!
|
|
|
+
|
|
|
+ var idActivity: Int = 0
|
|
|
+ var account: String = ""
|
|
|
+ var activityPreviews = [tableActivityPreview]()
|
|
|
|
|
|
- func getTableActivitiesFromSection(_ section: Int) -> [tableActivity] {
|
|
|
- let startDate = sectionDate[section]
|
|
|
- let endDate: Date = {
|
|
|
- let components = DateComponents(day: 1, second: -1)
|
|
|
- return Calendar.current.date(byAdding: components, to: startDate)!
|
|
|
- }()
|
|
|
+ override func awakeFromNib() {
|
|
|
+ super.awakeFromNib()
|
|
|
|
|
|
- return NCManageDatabase.sharedInstance.getActivity(predicate: NSPredicate(format: "account == %@ && date BETWEEN %@", appDelegate.activeAccount, [startDate, endDate]))
|
|
|
- }
|
|
|
-
|
|
|
- func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
- return sectionDate.count
|
|
|
+ collectionView.delegate = self
|
|
|
+ collectionView.dataSource = self
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Table View
|
|
|
+
|
|
|
+extension NCActivity: UITableViewDelegate {
|
|
|
|
|
|
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
- return getTableActivitiesFromSection(section).count
|
|
|
+ func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
+ return 120
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
return 60
|
|
|
}
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
+ return UITableView.automaticDimension
|
|
|
+ }
|
|
|
+
|
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
|
|
|
let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 60))
|
|
@@ -148,33 +149,16 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
|
|
|
view.addSubview(label)
|
|
|
return view
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
- return 120
|
|
|
- }
|
|
|
-
|
|
|
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
- return UITableView.automaticDimension
|
|
|
- }
|
|
|
+extension NCActivity: UITableViewDataSource {
|
|
|
|
|
|
- func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
|
|
|
-
|
|
|
- let section = indexPaths.last?.section ?? 0
|
|
|
- let row = indexPaths.last?.row ?? 0
|
|
|
-
|
|
|
- let lastSection = self.sectionDate.count - 1
|
|
|
- let lastRow = getTableActivitiesFromSection(section).count - 1
|
|
|
-
|
|
|
- if section == lastSection && row > lastRow - 1 {
|
|
|
- let results = getTableActivitiesFromSection(section)
|
|
|
- let activity = results[lastRow]
|
|
|
-
|
|
|
- loadActivity(idActivity: activity.idActivity)
|
|
|
- }
|
|
|
+ func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
+ return sectionDate.count
|
|
|
}
|
|
|
|
|
|
- func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath]) {
|
|
|
- //print("cancelPrefetchingForRowsAt \(indexPaths)")
|
|
|
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
+ return getTableActivitiesFromSection(section).count
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
@@ -184,13 +168,13 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
|
|
|
let results = getTableActivitiesFromSection(indexPath.section)
|
|
|
let activity = results[indexPath.row]
|
|
|
var orderKeysId = [String]()
|
|
|
-
|
|
|
+
|
|
|
cell.idActivity = activity.idActivity
|
|
|
cell.account = activity.account
|
|
|
cell.avatar.image = nil
|
|
|
cell.avatar.isHidden = true
|
|
|
cell.subjectTrailingConstraint.constant = 10
|
|
|
-
|
|
|
+
|
|
|
// icon
|
|
|
if activity.icon.count > 0 {
|
|
|
|
|
@@ -220,7 +204,7 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// avatar
|
|
|
if activity.user.count > 0 && activity.user != appDelegate.activeUserID {
|
|
|
|
|
@@ -289,164 +273,45 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
|
|
|
cell.collectionViewHeightConstraint.constant = 60
|
|
|
}
|
|
|
cell.collectionView.reloadData()
|
|
|
-
|
|
|
+
|
|
|
return cell
|
|
|
}
|
|
|
|
|
|
return UITableViewCell()
|
|
|
}
|
|
|
-
|
|
|
- // MARK: NC API
|
|
|
-
|
|
|
- @objc func loadActivityRefreshing() {
|
|
|
- loadActivity(idActivity: 0)
|
|
|
- }
|
|
|
+}
|
|
|
|
|
|
- @objc func loadActivity(idActivity: Int) {
|
|
|
+extension NCActivity: UITableViewDataSourcePrefetching {
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
|
|
|
|
|
|
- if loadingActivity {
|
|
|
- return
|
|
|
- } else {
|
|
|
- loadingActivity = true
|
|
|
- }
|
|
|
+ let section = indexPaths.last?.section ?? 0
|
|
|
+ let row = indexPaths.last?.row ?? 0
|
|
|
|
|
|
- if idActivity > 0 {
|
|
|
- NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: 50)
|
|
|
- }
|
|
|
+ let lastSection = self.sectionDate.count - 1
|
|
|
+ let lastRow = getTableActivitiesFromSection(section).count - 1
|
|
|
|
|
|
- OCNetworking.sharedManager().getActivityWithAccount(appDelegate.activeAccount, since: idActivity, limit: 100, link: "", completion: { (account, listOfActivity, message, errorCode) in
|
|
|
-
|
|
|
- if errorCode == 0 && account == self.appDelegate.activeAccount {
|
|
|
- NCManageDatabase.sharedInstance.addActivity(listOfActivity as! [OCActivity], account: account!)
|
|
|
-
|
|
|
- self.loadDataSource()
|
|
|
- }
|
|
|
-
|
|
|
- self.refreshControl.endRefreshing()
|
|
|
- NCUtility.sharedInstance.stopActivityIndicator()
|
|
|
+ if section == lastSection && row > lastRow - 1 {
|
|
|
+ let results = getTableActivitiesFromSection(section)
|
|
|
+ let activity = results[lastRow]
|
|
|
|
|
|
- self.loadingActivity = false
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class activityTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
|
|
|
-
|
|
|
- private let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
-
|
|
|
- @IBOutlet weak var collectionView: UICollectionView!
|
|
|
-
|
|
|
- @IBOutlet weak var icon: UIImageView!
|
|
|
- @IBOutlet weak var avatar: UIImageView!
|
|
|
- @IBOutlet weak var subject: UILabel!
|
|
|
- @IBOutlet weak var subjectTrailingConstraint: NSLayoutConstraint!
|
|
|
- @IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint!
|
|
|
-
|
|
|
- var idActivity: Int = 0
|
|
|
- var account: String = ""
|
|
|
- var activityPreviews = [tableActivityPreview]()
|
|
|
-
|
|
|
- override func awakeFromNib() {
|
|
|
- super.awakeFromNib()
|
|
|
-
|
|
|
- collectionView.delegate = self
|
|
|
- collectionView.dataSource = self
|
|
|
- }
|
|
|
-
|
|
|
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
|
- return CGSize(width: 50, height: 50)
|
|
|
- }
|
|
|
-
|
|
|
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
|
|
- return 20
|
|
|
- }
|
|
|
-
|
|
|
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
|
|
|
- return UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
|
|
|
- }
|
|
|
-
|
|
|
- func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
- return 1
|
|
|
+ loadActivity(idActivity: activity.idActivity)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
- return activityPreviews.count
|
|
|
+ func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath]) {
|
|
|
+ //print("cancelPrefetchingForRowsAt \(indexPaths)")
|
|
|
}
|
|
|
-
|
|
|
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
-
|
|
|
- if let cell: activityCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as? activityCollectionViewCell {
|
|
|
-
|
|
|
- cell.imageView.image = nil
|
|
|
-
|
|
|
- let activityPreview = activityPreviews[indexPath.row]
|
|
|
- let fileID = String(activityPreview.fileId)
|
|
|
+}
|
|
|
|
|
|
- // Trashbin
|
|
|
- if activityPreview.view == "trashbin" {
|
|
|
-
|
|
|
- let source = activityPreview.source
|
|
|
-
|
|
|
- DispatchQueue.global().async {
|
|
|
- if let imageNamePath = NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false) {
|
|
|
- DispatchQueue.main.async {
|
|
|
- if let image = UIImage(contentsOfFile: imageNamePath) {
|
|
|
- cell.imageView.image = image
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- if activityPreview.isMimeTypeIcon {
|
|
|
-
|
|
|
- let source = activityPreview.source
|
|
|
+// MARK: - Collection View
|
|
|
|
|
|
- DispatchQueue.global().async {
|
|
|
- if let imageNamePath = NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false) {
|
|
|
- DispatchQueue.main.async {
|
|
|
- if let image = UIImage(contentsOfFile: imageNamePath) {
|
|
|
- cell.imageView.image = image
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- if let activitySubjectRich = NCManageDatabase.sharedInstance.getActivitySubjectRich(account: account, idActivity: idActivity, id: fileID) {
|
|
|
-
|
|
|
- let fileNamePath = CCUtility.getDirectoryUserData() + "/" + activitySubjectRich.name
|
|
|
-
|
|
|
- if FileManager.default.fileExists(atPath: fileNamePath) {
|
|
|
-
|
|
|
- if let image = UIImage(contentsOfFile: fileNamePath) {
|
|
|
- cell.imageView.image = image
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- OCNetworking.sharedManager()?.downloadPreview(withAccount: appDelegate.activeAccount, serverPath: activityPreview.source, fileNamePath: fileNamePath, completion: { (account, image, message, errorCode) in
|
|
|
- if errorCode == 0 {
|
|
|
- cell.imageView.image = image
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return cell
|
|
|
- }
|
|
|
-
|
|
|
- return UICollectionViewCell()
|
|
|
- }
|
|
|
+extension activityTableViewCell: UICollectionViewDelegate {
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
|
|
|
let activityPreview = activityPreviews[indexPath.row]
|
|
|
-
|
|
|
+
|
|
|
if activityPreview.view == "trashbin" {
|
|
|
|
|
|
var responder: UIResponder? = collectionView
|
|
@@ -457,10 +322,12 @@ class activityTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollec
|
|
|
}
|
|
|
}
|
|
|
if (responder as? UIViewController)!.navigationController != nil {
|
|
|
-
|
|
|
if let viewController = UIStoryboard.init(name: "NCTrash", bundle: nil).instantiateInitialViewController() as? NCTrash {
|
|
|
- viewController.scrollToFileID = String(activityPreview.fileId)
|
|
|
- (responder as? UIViewController)!.navigationController?.pushViewController(viewController, animated: true)
|
|
|
+ if let result = NCManageDatabase.sharedInstance.getTrashItem(fileID: String(activityPreview.fileId), account: activityPreview.account) {
|
|
|
+ viewController.scrollToFileID = result.fileID
|
|
|
+ viewController.path = result.filePath
|
|
|
+ (responder as? UIViewController)!.navigationController?.pushViewController(viewController, animated: true)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -507,7 +374,7 @@ class activityTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollec
|
|
|
OCNetworking.sharedManager()?.readFile(withAccount: activityPreview.account, serverUrl: serverUrl, fileName: fileName, completion: { (account, metadata, message, errorCode) in
|
|
|
|
|
|
NCUtility.sharedInstance.stopActivityIndicator()
|
|
|
-
|
|
|
+
|
|
|
if account == self.appDelegate.activeAccount && errorCode == 0 {
|
|
|
|
|
|
// move from id to oc:id + instanceid (fileID)
|
|
@@ -532,6 +399,84 @@ class activityTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollec
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+extension activityTableViewCell: UICollectionViewDataSource {
|
|
|
+
|
|
|
+ func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
+ return activityPreviews.count
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
+
|
|
|
+ if let cell: activityCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as? activityCollectionViewCell {
|
|
|
+
|
|
|
+ cell.imageView.image = nil
|
|
|
+
|
|
|
+ let activityPreview = activityPreviews[indexPath.row]
|
|
|
+ let fileID = String(activityPreview.fileId)
|
|
|
+
|
|
|
+ // Trashbin
|
|
|
+ if activityPreview.view == "trashbin" {
|
|
|
+
|
|
|
+ let source = activityPreview.source
|
|
|
+
|
|
|
+ NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false) { (imageNamePath) in
|
|
|
+ if imageNamePath != nil {
|
|
|
+ if let image = UIImage(contentsOfFile: imageNamePath!) {
|
|
|
+ cell.imageView.image = image
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if activityPreview.isMimeTypeIcon {
|
|
|
+
|
|
|
+ let source = activityPreview.source
|
|
|
+
|
|
|
+ NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false) { (imageNamePath) in
|
|
|
+ if imageNamePath != nil {
|
|
|
+ if let image = UIImage(contentsOfFile: imageNamePath!) {
|
|
|
+ cell.imageView.image = image
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if let activitySubjectRich = NCManageDatabase.sharedInstance.getActivitySubjectRich(account: account, idActivity: idActivity, id: fileID) {
|
|
|
+
|
|
|
+ let fileNamePath = CCUtility.getDirectoryUserData() + "/" + activitySubjectRich.name
|
|
|
+
|
|
|
+ if FileManager.default.fileExists(atPath: fileNamePath) {
|
|
|
+
|
|
|
+ if let image = UIImage(contentsOfFile: fileNamePath) {
|
|
|
+ cell.imageView.image = image
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ OCNetworking.sharedManager()?.downloadPreview(withAccount: appDelegate.activeAccount, serverPath: activityPreview.source, fileNamePath: fileNamePath, completion: { (account, image, message, errorCode) in
|
|
|
+ if errorCode == 0 {
|
|
|
+ cell.imageView.image = image
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ return UICollectionViewCell()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
class activityCollectionViewCell: UICollectionViewCell {
|
|
|
|
|
|
@IBOutlet weak var imageView: UIImageView!
|
|
@@ -540,3 +485,80 @@ class activityCollectionViewCell: UICollectionViewCell {
|
|
|
super.awakeFromNib()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension activityTableViewCell: UICollectionViewDelegateFlowLayout {
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
|
+ return CGSize(width: 50, height: 50)
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
|
|
+ return 20
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
|
|
|
+ return UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - NC API & Algorithm
|
|
|
+
|
|
|
+extension NCActivity {
|
|
|
+
|
|
|
+ func loadDataSource() {
|
|
|
+
|
|
|
+ sectionDate.removeAll()
|
|
|
+
|
|
|
+ activities = NCManageDatabase.sharedInstance.getActivity(predicate: NSPredicate(format: "account == %@", appDelegate.activeAccount))
|
|
|
+ for tableActivity in activities {
|
|
|
+ guard let date = Calendar.current.date(from: Calendar.current.dateComponents([.year, .month, .day], from: tableActivity.date as Date)) else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if !sectionDate.contains(date) {
|
|
|
+ sectionDate.append(date)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tableView.reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ func getTableActivitiesFromSection(_ section: Int) -> [tableActivity] {
|
|
|
+ let startDate = sectionDate[section]
|
|
|
+ let endDate: Date = {
|
|
|
+ let components = DateComponents(day: 1, second: -1)
|
|
|
+ return Calendar.current.date(byAdding: components, to: startDate)!
|
|
|
+ }()
|
|
|
+
|
|
|
+ return NCManageDatabase.sharedInstance.getActivity(predicate: NSPredicate(format: "account == %@ && date BETWEEN %@", appDelegate.activeAccount, [startDate, endDate]))
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func loadActivityRefreshing() {
|
|
|
+ loadActivity(idActivity: 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func loadActivity(idActivity: Int) {
|
|
|
+
|
|
|
+ if loadingActivity {
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ loadingActivity = true
|
|
|
+ }
|
|
|
+
|
|
|
+ if idActivity > 0 {
|
|
|
+ NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: 50)
|
|
|
+ }
|
|
|
+
|
|
|
+ OCNetworking.sharedManager().getActivityWithAccount(appDelegate.activeAccount, since: idActivity, limit: 100, link: "", completion: { (account, listOfActivity, message, errorCode) in
|
|
|
+
|
|
|
+ if errorCode == 0 && account == self.appDelegate.activeAccount {
|
|
|
+ NCManageDatabase.sharedInstance.addActivity(listOfActivity as! [OCActivity], account: account!)
|
|
|
+
|
|
|
+ self.loadDataSource()
|
|
|
+ }
|
|
|
+
|
|
|
+ self.refreshControl.endRefreshing()
|
|
|
+ NCUtility.sharedInstance.stopActivityIndicator()
|
|
|
+
|
|
|
+ self.loadingActivity = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|