<commit_before>//
//  AlbumTableViewCell.swift
//  piwigo
//
//  Created by <NAME> on 1/24/15.
//  Copyright (c) 2015 bakercrew. All rights reserved.
//
//  Converted to Swift 5.4 by <NAME> on 16/01/2022
//

import UIKit
import piwigoKit

@objc
class AlbumTableViewCell: MGSwipeTableCell {
    
    @IBOutlet weak var backgroundImage: UIImageView!
    @IBOutlet weak var topCut: UIButton!
    @IBOutlet weak var bottomCut: UIButton!
    @IBOutlet weak var albumName: UILabel!
    @IBOutlet weak var albumComment: UILabel!
    @IBOutlet weak var numberOfImages: UILabel!
    @IBOutlet weak var handleButton: UIButton!
    @IBOutlet weak var recentBckg: UIImageView!
    @IBOutlet weak var recentImage: UIImageView!

    @objc
    func config(withAlbumData albumData: PiwigoAlbumData?) {
        // General settings
        backgroundColor = UIColor.piwigoColorBackground()
        contentView.backgroundColor = UIColor.piwigoColorCellBackground()
        selectionStyle = UITableViewCell.SelectionStyle.none
        topCut.backgroundColor = UIColor.piwigoColorBackground()
        bottomCut.backgroundColor = UIColor.piwigoColorBackground()

        // Album name
        albumName.text = albumData?.name ?? "—?—"
        albumName.font =  albumName.font.withSize(UIFont.fontSizeFor(label: albumName, nberLines: 2))

        // Album comment
        if let comment = albumData?.comment, comment.isEmpty == false {
            albumComment.text = comment
            albumComment.textColor = UIColor.piwigoColorText()
        }
        else {  // No comment
            if NetworkVars.hasAdminRights {
                albumComment.text = NSLocalizedString("createNewAlbumDescription_noDescription", comment: "no description")
                albumComment.textColor = UIColor.piwigoColorRightLabel()
            } else {
                albumComment.text = ""
            }
        }
        albumComment.font = albumComment.font.withSize(UIFont.fontSizeFor(label: albumComment, nberLines: 3))

        // Number of images and sub-albums
        numberOfImages.textColor = UIColor.piwigoColorText()
        let numberFormatter = NumberFormatter()
        numberFormatter.numberStyle = NumberFormatter.Style.decimal
        if albumData?.numberOfSubCategories ?? 0 == 0 {
            // There are no sub-albums
            let nberImages = numberFormatter.string(from: NSNumber(value: albumData?.numberOfImages ?? 0))
            numberOfImages.text = (albumData?.numberOfImages ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalImagesCount", comment: "%@ photos"), nberImages ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleImageCount", comment: "%@ photo"), nberImages ?? "")
        }
        else if albumData?.totalNumberOfImages ?? 0 == 0 {
            // There are no images but sub-albums
            let nberAlbums = numberFormatter.string(from: NSNumber(value: albumData?.numberOfSubCategories ?? 0))
            numberOfImages.text = (albumData?.numberOfSubCategories ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalSubAlbumsCount", comment: "%@ sub-albums"), nberAlbums ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleSubAlbumCount", comment: "%@ sub-album"), nberAlbums ?? "")
        }
        else {
            // There are images and sub-albums
            let nberImages = numberFormatter.string(from: NSNumber(value: albumData?.totalNumberOfImages ?? 0))
            var nberOfImages = (albumData?.totalNumberOfImages ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalImagesCount", comment: "%@ photos"), nberImages ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleImageCount", comment: "%@ photo"), nberImages ?? "")
            nberOfImages += ", "
            let nberAlbums = numberFormatter.string(from: NSNumber(value: albumData?.numberOfSubCategories ?? 0))
            nberOfImages += (albumData?.numberOfSubCategories ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalSubAlbumsCount", comment: "%@ sub-albums"), nberAlbums ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleSubAlbumCount", comment: "%@ sub-album"), nberAlbums ?? "")
            numberOfImages.text = nberOfImages
        }
        numberOfImages.font = numberOfImages.font.withSize(UIFont.fontSizeFor(label: numberOfImages, nberLines: 1))

        // Display placeholder when album data are unavailable
//        guard let albumData = albumData else {
//            return
//        }
        
        // Add renaming, moving and deleting capabilities when user has admin rights
        if let _ = albumData, NetworkVars.hasAdminRights {
            handleButton.isHidden = false
        }

        // Display recent icon when images have been uploaded recently
        DispatchQueue.global(qos: .userInteractive).async {
            guard let catId = albumData?.albumId,
                  let dateLast = CategoriesData.sharedInstance()
                                    .getDateLastOfCategories(inCategory: catId) else { return }
            let timeSinceLastUpload: TimeInterval = dateLast.timeIntervalSinceNow
            var indexOfPeriod: Int = AlbumVars.shared.recentPeriodIndex
            indexOfPeriod = min(indexOfPeriod, AlbumVars.shared.recentPeriodList.count - 1)
            indexOfPeriod = max(0, indexOfPeriod)
            let periodInDays: Int = AlbumVars.shared.recentPeriodList[indexOfPeriod]
            if timeSinceLastUpload > TimeInterval(-24*3600*periodInDays) {
                DispatchQueue.main.async {
                    self.recentBckg.tintColor = UIColor(white: 0, alpha: 0.3)
                    self.recentImage.tintColor = UIColor.white
                    self.recentBckg.isHidden = false<commit_msg>Removes useless code<commit_after>//
//  AlbumTableViewCell.swift
//  piwigo
//
//  Created by <NAME> on 1/24/15.
//  Copyright (c) 2015 bakercrew. All rights reserved.
//
//  Converted to Swift 5.4 by <NAME> on 16/01/2022
//

import UIKit
import piwigoKit

@objc
class AlbumTableViewCell: MGSwipeTableCell {
    
    @IBOutlet weak var backgroundImage: UIImageView!
    @IBOutlet weak var topCut: UIButton!
    @IBOutlet weak var bottomCut: UIButton!
    @IBOutlet weak var albumName: UILabel!
    @IBOutlet weak var albumComment: UILabel!
    @IBOutlet weak var numberOfImages: UILabel!
    @IBOutlet weak var handleButton: UIButton!
    @IBOutlet weak var recentBckg: UIImageView!
    @IBOutlet weak var recentImage: UIImageView!

    @objc
    func config(withAlbumData albumData: PiwigoAlbumData?) {
        // General settings
        backgroundColor = UIColor.piwigoColorBackground()
        contentView.backgroundColor = UIColor.piwigoColorCellBackground()
        selectionStyle = UITableViewCell.SelectionStyle.none
        topCut.backgroundColor = UIColor.piwigoColorBackground()
        bottomCut.backgroundColor = UIColor.piwigoColorBackground()

        // Album name
        albumName.text = albumData?.name ?? "—?—"
        albumName.font =  albumName.font.withSize(UIFont.fontSizeFor(label: albumName, nberLines: 2))

        // Album comment
        if let comment = albumData?.comment, comment.isEmpty == false {
            albumComment.text = comment
            albumComment.textColor = UIColor.piwigoColorText()
        }
        else {  // No comment
            if NetworkVars.hasAdminRights {
                albumComment.text = NSLocalizedString("createNewAlbumDescription_noDescription", comment: "no description")
                albumComment.textColor = UIColor.piwigoColorRightLabel()
            } else {
                albumComment.text = ""
            }
        }
        albumComment.font = albumComment.font.withSize(UIFont.fontSizeFor(label: albumComment, nberLines: 3))

        // Number of images and sub-albums
        numberOfImages.textColor = UIColor.piwigoColorText()
        let numberFormatter = NumberFormatter()
        numberFormatter.numberStyle = NumberFormatter.Style.decimal
        if albumData?.numberOfSubCategories ?? 0 == 0 {
            // There are no sub-albums
            let nberImages = numberFormatter.string(from: NSNumber(value: albumData?.numberOfImages ?? 0))
            numberOfImages.text = (albumData?.numberOfImages ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalImagesCount", comment: "%@ photos"), nberImages ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleImageCount", comment: "%@ photo"), nberImages ?? "")
        }
        else if albumData?.totalNumberOfImages ?? 0 == 0 {
            // There are no images but sub-albums
            let nberAlbums = numberFormatter.string(from: NSNumber(value: albumData?.numberOfSubCategories ?? 0))
            numberOfImages.text = (albumData?.numberOfSubCategories ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalSubAlbumsCount", comment: "%@ sub-albums"), nberAlbums ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleSubAlbumCount", comment: "%@ sub-album"), nberAlbums ?? "")
        }
        else {
            // There are images and sub-albums
            let nberImages = numberFormatter.string(from: NSNumber(value: albumData?.totalNumberOfImages ?? 0))
            var nberOfImages = (albumData?.totalNumberOfImages ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalImagesCount", comment: "%@ photos"), nberImages ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleImageCount", comment: "%@ photo"), nberImages ?? "")
            nberOfImages += ", "
            let nberAlbums = numberFormatter.string(from: NSNumber(value: albumData?.numberOfSubCategories ?? 0))
            nberOfImages += (albumData?.numberOfSubCategories ?? 0 > 1)
                ? String.localizedStringWithFormat(NSLocalizedString("severalSubAlbumsCount", comment: "%@ sub-albums"), nberAlbums ?? "")
                : String.localizedStringWithFormat(NSLocalizedString("singleSubAlbumCount", comment: "%@ sub-album"), nberAlbums ?? "")
            numberOfImages.text = nberOfImages
        }
        numberOfImages.font = numberOfImages.font.withSize(UIFont.fontSizeFor(label: numberOfImages, nberLines: 1))

        // Add renaming, moving and deleting capabilities when user has admin rights
        if let _ = albumData, NetworkVars.hasAdminRights {
            handleButton.isHidden = false
        }

        // Display recent icon when images have been uploaded recently
        DispatchQueue.global(qos: .userInteractive).async {
            guard let catId = albumData?.albumId,
                  let dateLast = CategoriesData.sharedInstance()
                                    .getDateLastOfCategories(inCategory: catId) else { return }
            let timeSinceLastUpload: TimeInterval = dateLast.timeIntervalSinceNow
            var indexOfPeriod: Int = AlbumVars.shared.recentPeriodIndex
            indexOfPeriod = min(indexOfPeriod, AlbumVars.shared.recentPeriodList.count - 1)
            indexOfPeriod = max(0, indexOfPeriod)
            let periodInDays: Int = AlbumVars.shared.recentPeriodList[indexOfPeriod]
            if timeSinceLastUpload > TimeInterval(-24*3600*periodInDays) {
                DispatchQueue.main.async {
                    self.recentBckg.tintColor = UIColor(white: 0, alpha: 0.3)
                    self.recentImage.tintColor = UIColor.white
                    self.recentBckg.isHidden = false
{'fraction_non_alphanumeric': 0.09732089360609432, 'fraction_numerical': 0.008388256440982624, 'mean_word_length': 2.717467387846007, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4729159', 'n_tokens_mistral': 3309, 'n_tokens_neox': 3123, 'n_words': 660}