|
@@ -22,6 +22,7 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
var startYVisible: CGFloat!
|
|
|
var endYVisible: CGFloat!
|
|
|
var indexSelected = 0
|
|
|
+ var updateEditor: (([ImageGrouping]) -> ())?
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
@@ -33,6 +34,10 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
centeredTitleView.subtitleLabel.text = String(listGroupingImages.count) + " " + "images".localized()
|
|
|
navigationItem.titleView = centeredTitleView
|
|
|
|
|
|
+ let selectButton = UIBarButtonItem(title: "Select".localized(), style: .plain, target: self, action: #selector(selectAction))
|
|
|
+ selectButton.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)], for: .normal)
|
|
|
+ navigationItem.rightBarButtonItem = selectButton
|
|
|
+
|
|
|
tableViewImages.register(UITableViewCell.self, forCellReuseIdentifier: "cellGrupingImages")
|
|
|
tableViewImages.dataSource = self
|
|
|
tableViewImages.delegate = self
|
|
@@ -77,8 +82,13 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
content.imageProperties.tintColor = .black
|
|
|
switch indexPath.row {
|
|
|
case 0:
|
|
|
- content.image = UIImage(systemName: "star.fill")
|
|
|
- content.text = "Star".localized()
|
|
|
+ if listGroupingImages[indexSelected].dataMessage["is_stared"] as! String == "1" {
|
|
|
+ content.image = UIImage(systemName: "star.slash.fill")
|
|
|
+ content.text = "Unstar".localized()
|
|
|
+ } else {
|
|
|
+ content.image = UIImage(systemName: "star.fill")
|
|
|
+ content.text = "Star".localized()
|
|
|
+ }
|
|
|
case 1:
|
|
|
content.image = UIImage(systemName: "arrowshape.turn.up.left.fill")
|
|
|
content.text = "Reply".localized()
|
|
@@ -101,8 +111,9 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
cell.selectionStyle = .none
|
|
|
|
|
|
let containerImages = UIImageView()
|
|
|
+ containerImages.contentMode = .scaleAspectFit
|
|
|
cell.contentView.addSubview(containerImages)
|
|
|
- containerImages.anchor(top: cell.contentView.topAnchor, left: cell.contentView.leftAnchor, bottom: cell.contentView.bottomAnchor, right: cell.contentView.rightAnchor, paddingBottom: 15, height: UIScreen.main.bounds.height - 104)
|
|
|
+ containerImages.anchor(top: cell.contentView.topAnchor, left: cell.contentView.leftAnchor, bottom: cell.contentView.bottomAnchor, right: cell.contentView.rightAnchor, paddingBottom: 15, height: getImageSize(image: listGroupingImages[indexPath.row].imageId)!.height)
|
|
|
|
|
|
if !copySession && !forwardSession && !deleteSession {
|
|
|
let longPressRecognizer = LongPressImageVIew(target: self, action: #selector(handleLongPress(_:)))
|
|
@@ -128,10 +139,11 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
let containerTimeStatus = UIView()
|
|
|
containerImages.addSubview(containerTimeStatus)
|
|
|
- containerTimeStatus.anchor(bottom: containerImages.bottomAnchor, right: containerImages.rightAnchor, height: 15)
|
|
|
- let widthcontainerTimeStatus = containerTimeStatus.widthAnchor.constraint(equalToConstant: 50)
|
|
|
+ containerTimeStatus.anchor(bottom: containerImages.bottomAnchor, right: containerImages.rightAnchor, height: 20)
|
|
|
+ let widthcontainerTimeStatus = containerTimeStatus.widthAnchor.constraint(equalToConstant: 60)
|
|
|
widthcontainerTimeStatus.isActive = true
|
|
|
containerTimeStatus.layer.cornerRadius = 5.0
|
|
|
containerTimeStatus.layer.masksToBounds = true
|
|
@@ -145,12 +157,12 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
|
|
|
timeInImage.text = formatter.string(from: date as Date)
|
|
|
timeInImage.textColor = .white
|
|
|
- timeInImage.font = UIFont.systemFont(ofSize: 10, weight: .medium)
|
|
|
+ timeInImage.font = UIFont.systemFont(ofSize: 12, weight: .medium)
|
|
|
|
|
|
if isInitiator {
|
|
|
let statusInImage = UIImageView()
|
|
|
containerTimeStatus.addSubview(statusInImage)
|
|
|
- statusInImage.anchor(right: containerTimeStatus.rightAnchor, centerY: containerTimeStatus.centerYAnchor, width: 15, height: 15)
|
|
|
+ statusInImage.anchor(right: containerTimeStatus.rightAnchor, centerY: containerTimeStatus.centerYAnchor, width: 20, height: 20)
|
|
|
if listGroupingImages[indexPath.row].status == "1" || listGroupingImages[indexPath.row].status == "2" {
|
|
|
statusInImage.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: DigiX.self), with: nil)!.withTintColor(UIColor.white)
|
|
|
} else if listGroupingImages[indexPath.row].status == "3" {
|
|
@@ -160,8 +172,17 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
}
|
|
|
timeInImage.anchor(right: statusInImage.leftAnchor, centerY: containerTimeStatus.centerYAnchor, height: 15)
|
|
|
} else {
|
|
|
- timeInImage.anchor(right: containerTimeStatus.rightAnchor, paddingRight: 5, centerY: containerTimeStatus.centerYAnchor, height: 15)
|
|
|
- widthcontainerTimeStatus.constant = 40
|
|
|
+ timeInImage.anchor(right: containerTimeStatus.rightAnchor, paddingRight: 5, centerY: containerTimeStatus.centerYAnchor, height: 20)
|
|
|
+ widthcontainerTimeStatus.constant = widthcontainerTimeStatus.constant - 10
|
|
|
+ }
|
|
|
+
|
|
|
+ if listGroupingImages[indexPath.row].dataMessage["is_stared"] as! String == "1" {
|
|
|
+ let iconStar = UIImageView()
|
|
|
+ containerTimeStatus.addSubview(iconStar)
|
|
|
+ iconStar.anchor(right: timeInImage.leftAnchor, paddingRight: 2, centerY: containerTimeStatus.centerYAnchor, width: 20, height: 20)
|
|
|
+ widthcontainerTimeStatus.constant = widthcontainerTimeStatus.constant + 20
|
|
|
+ iconStar.image = UIImage(systemName: "star.fill")
|
|
|
+ iconStar.tintColor = .white
|
|
|
}
|
|
|
return cell
|
|
|
}
|
|
@@ -172,6 +193,27 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
switch indexPath.row {
|
|
|
case 0:
|
|
|
popover.dismiss()
|
|
|
+ if listGroupingImages[indexSelected].dataMessage["is_stared"] as! String == "0" {
|
|
|
+ DispatchQueue.global().async { [self] in
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "is_stared" : 1
|
|
|
+ ], _where: "message_id = '\(listGroupingImages[indexSelected].messageId)'")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ listGroupingImages[indexSelected].dataMessage["is_stared"] = "1"
|
|
|
+ } else {
|
|
|
+ DispatchQueue.global().async { [self] in
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "is_stared" : 0
|
|
|
+ ], _where: "message_id = '\(listGroupingImages[indexSelected].messageId)'")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ listGroupingImages[indexSelected].dataMessage["is_stared"] = "0"
|
|
|
+ }
|
|
|
+ tableViewImages.reloadRows(at: [IndexPath(row: indexSelected, section: 0)], with: .none)
|
|
|
+ updateEditor!(listGroupingImages)
|
|
|
case 1:
|
|
|
popover.dismiss()
|
|
|
case 2:
|
|
@@ -232,6 +274,45 @@ class ListGroupImages: UIViewController, UITableViewDataSource, UITableViewDeleg
|
|
|
UINotificationFeedbackGenerator().notificationOccurred(.success)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @objc func selectAction() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func getImageSize(image: String) -> CGSize? {
|
|
|
+ let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
+ let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
+ let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
|
+ if let dirPath = paths.first {
|
|
|
+ let imageURL = URL(fileURLWithPath: dirPath).appendingPathComponent(image)
|
|
|
+ let image = UIImage(contentsOfFile: imageURL.path)
|
|
|
+ let imageWidth = image!.size.width
|
|
|
+ let imageHeight = image!.size.height
|
|
|
+
|
|
|
+ // Calculate the aspect ratio of the image
|
|
|
+ let aspectRatio = imageWidth / imageHeight
|
|
|
+
|
|
|
+ // Get the available width and height of the screen
|
|
|
+ let screenWidth = UIScreen.main.bounds.width
|
|
|
+ let screenHeight = UIScreen.main.bounds.height
|
|
|
+
|
|
|
+ // Calculate the size to display the image while maintaining its aspect ratio
|
|
|
+ var displayWidth: CGFloat = 0.0
|
|
|
+ var displayHeight: CGFloat = 0.0
|
|
|
+
|
|
|
+ if imageWidth > imageHeight {
|
|
|
+ // Landscape image
|
|
|
+ displayWidth = screenWidth
|
|
|
+ displayHeight = screenWidth / aspectRatio
|
|
|
+ } else {
|
|
|
+ // Portrait or square image
|
|
|
+ displayHeight = screenHeight
|
|
|
+ displayWidth = screenHeight * aspectRatio
|
|
|
+ }
|
|
|
+ return CGSize(width: displayWidth, height: displayHeight)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class CenteredTitleSubtitleView: UIView {
|