RemoveAdvertView.swift 4.75 KB
//
//  RemoveAdvertView.swift
//  browser
//
//  Created by Artem Talko on 29.09.2023.
//

import UIKit
import SnapKit

final class RemoveAdvertView: GradientView {

    private let appLogoImageView: UIImageView = {
        let obj = UIImageView()
        obj.image = .gotoweb
        obj.contentMode = .scaleAspectFit
        
        return obj
    }()
    
    let adBlockButton: AdBlockButton = {
        let obj = AdBlockButton()
        
        return obj
    }()
    
    let removeAdvertSegmentControl: UISegmentedControl = {
        let items = ["AdBlock", "Browser"]
        let obj = UISegmentedControl(items: items)
        obj.selectedSegmentIndex = 0
        obj.backgroundColor = ColorConstants.segmentControlBackground
        obj.layer.cornerRadius = 10
        obj.selectedSegmentTintColor = UIColor(red: 0.349, green: 0.565, blue: 1, alpha: 1)
        obj.setTitleTextAttributes([.foregroundColor: UIColor.black], for: .normal)
        obj.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .selected)
        
        return obj
    }()
    
    private let leftDecorativeSquareImageView: UIImageView = {
        let obj = UIImageView()
        obj.image = .leftDecorativeSquares
        
        return obj
    }()
    
    private let rightDecorativeSquareImageView: UIImageView = {
        let obj = UIImageView()
        obj.image = .rightDecorativeSquares
        
        return obj
    }()
    
    let tapActionLabel: UILabel = {
        let obj = UILabel()
        let userDefaultsAdBlockerValue = CachingManager.shared.isAdBlocking
        
        obj.text = StringConstants.turnOn
        obj.font = FontConstants.semiboldFont_24
        //ok
        if userDefaultsAdBlockerValue {
            obj.textColor = ColorConstants.SearchbarTintBlue
        } else {
            obj.textColor = ColorConstants.customPink
        }
        
        return obj
    }()
    
    private let protectFromLabel: UILabel = {
        let obj = UILabel()
        obj.text = StringConstants.adBlockProtectFrom
        obj.font = FontConstants.semiboldFont_18
        
        return obj
    }()
    
    let adBlockTableView: UITableView = {
        let obj = UITableView()
        obj.backgroundColor = .clear
        obj.isScrollEnabled = false
        obj.separatorStyle = .none
        
        return obj
    }()
    
    override init (frame: CGRect) {
        super.init(frame: frame)
        
        setup()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup() {
        addSubview(appLogoImageView)
        addSubview(adBlockButton)
        addSubview(tapActionLabel)
        addSubview(removeAdvertSegmentControl)
        addSubview(leftDecorativeSquareImageView)
        addSubview(rightDecorativeSquareImageView)
        addSubview(protectFromLabel)
        addSubview(adBlockTableView)
        
        setupConstraints()
    }
    
    private func setupConstraints() {
        leftDecorativeSquareImageView.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.leading.equalToSuperview()
        }
        
        rightDecorativeSquareImageView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.trailing.equalToSuperview()
        }
        
        appLogoImageView.snp.makeConstraints { make in
            make.top.equalTo(safeAreaLayoutGuide.snp.top).offset(24.sizeH)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(34.sizeH)
        }
        
        removeAdvertSegmentControl.snp.makeConstraints { make in
            make.top.equalTo(appLogoImageView.snp.bottom).offset(34.sizeH)
            make.leading.trailing.equalToSuperview().inset(54.sizeW)
            make.height.equalTo(34.sizeH)
        }
        
        adBlockButton.snp.makeConstraints { make in
            make.top.equalTo(removeAdvertSegmentControl.snp.bottom).offset(84.sizeH)
            make.leading.trailing.equalToSuperview().inset(47.sizeW)
            make.height.equalTo(171.sizeH)
        }
        
        tapActionLabel.snp.makeConstraints { make in
            make.top.equalTo(adBlockButton.snp.bottom).offset(45.sizeH)
            make.centerX.equalToSuperview()
        }
        
        protectFromLabel.snp.makeConstraints { make in
            make.top.equalTo(tapActionLabel.snp.bottom).offset(44.sizeH)
            make.leading.equalToSuperview().offset(44.sizeW)
        }
        
        adBlockTableView.snp.makeConstraints { make in
            make.top.equalTo(protectFromLabel.snp.bottom).offset(4.sizeH)
            make.leading.equalToSuperview().offset(44.sizeW)
            make.trailing.equalToSuperview().offset(-32.sizeW)
            make.bottom.equalToSuperview().offset(-16.sizeH)
        }
    }
}