Wallpaper_Home/wallpaper_project/Community/C/WA_RKDetailsVC.swift
2024-08-19 14:40:12 +08:00

335 lines
13 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// WA_RKDetailsVC.swift
// wallpaper_project
import UIKit
import SVProgressHUD
import AppLovinSDK
import FirebaseRemoteConfig
import MTGSDKNewInterstitial
import MTGSDKBidding
import MTGSDK
class WA_RKDetailsVC: WA_RootVC,UITextFieldDelegate {
@IBOutlet weak var tableView: UITableView!
var model: WA_RakModel?
var dataItems: [DataModel] = []
var interstitialAd: MAInterstitialAd!
var retryAttempt = 0.0
@IBOutlet weak var plBtn: UIButton!
var textField: UITextField!
let activityView = UIActivityIndicatorView()
var remoteConfig: RemoteConfig!
var isadshow:Bool = false
var bidToken:String?
var newInterstitialAdManager:MTGNewInterstitialBidAdManager?
override func viewDidLoad() {
super.viewDidLoad()
plBtn.layer.cornerRadius = 10
setTableViewCell()
if let data = model?.data {
dataItems = data
}
activityView.center = CGPoint(x: self.view.center.x, y: self.view.center.y - kSafeArea_Top - 44)
//
activityView.hidesWhenStopped = true
activityView.color = .black
activityView.style = UIActivityIndicatorView.Style.whiteLarge
self.view.addSubview(activityView)
// UITextField
textField = UITextField()
textField.backgroundColor = .lightGray
textField.isHidden = true
textField.delegate = self
textField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(textField)
//
NSLayoutConstraint.activate([
// plBtn.centerXAnchor.constraint(equalTo: view.centerXAnchor),
// plBtn.centerYAnchor.constraint(equalTo: view.centerYAnchor),
textField.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
textField.leadingAnchor.constraint(equalTo: view.leadingAnchor),
textField.trailingAnchor.constraint(equalTo: view.trailingAnchor),
textField.heightAnchor.constraint(equalToConstant: 40)
])
//
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Remote Config
remoteConfig = RemoteConfig.remoteConfig()
//
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 0
remoteConfig.configSettings = settings
// Fetch
remoteConfig.setDefaults(fromPlist: "isopen")
// Fetch
}
func setTableViewCell(){
tableView.delegate = self
tableView.dataSource = self
tableView.register(UINib(nibName: "WA_RKPLCell", bundle: nil), forCellReuseIdentifier: "WA_RKPLCell")
tableView.register(UINib(nibName: "WA_RKTopCell", bundle: nil), forCellReuseIdentifier: "WA_RKTopCell")
}
@IBAction func backbtn(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
@IBAction func plBtn(_ sender: Any) {
let issureready = newInterstitialAdManager?.isAdReady()
if self.isadshow == true{
if ((issureready) != nil) {
newInterstitialAdManager?.show(from: self)
}else{
if isLoggedIn(){
self.plBtn.isHidden = true
textField.isHidden = false
textField.becomeFirstResponder()
}else{
let vc = WA_LoginVC()
vc.type = 1
self.navigationController?.pushViewController(vc, animated: true)
}
}
}else{
if isLoggedIn(){
self.plBtn.isHidden = true
textField.isHidden = false
textField.becomeFirstResponder()
}else{
let vc = WA_LoginVC()
vc.type = 1
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
//
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect {
//
let keyboardHeight = keyboardFrame.height
// textField
self.textField.frame.origin.y = self.view.frame.height - keyboardHeight - self.textField.frame.height
//
}
}
//
@objc func keyboardWillHide(notification: NSNotification) {
textField.isHidden = true
self.plBtn.isHidden = false
textField.text = ""
}
//
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
//
print("The user clicked the confirm button")
if textField.text?.count == 0{
SVProgressHUD.showInfo(withStatus: "Please enter the comment content")
DispatchQueue.global().asyncAfter(deadline: .now() + 2.0) {
SVProgressHUD.dismiss()
}
}else{
textField.resignFirstResponder() //
self.plBtn.isHidden = false
textField.text = ""
DispatchQueue.main.asyncAfter(deadline: .now()){
self.activityView.startAnimating()
DispatchQueue.global().asyncAfter(deadline: .now() + 1.5){
DispatchQueue.main.asyncAfter(deadline: .now()){
self.activityView.stopAnimating()
SVProgressHUD.showInfo(withStatus: "Successfully sent comment, reviewing content")
DispatchQueue.global().asyncAfter(deadline: .now() + 2.0) {
SVProgressHUD.dismiss()
}
}
}
}
}
return true
}
}
extension WA_RKDetailsVC:UITableViewDataSource,UITableViewDelegate{
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 1
} else {
//
return dataItems.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0{
let cell = tableView.dequeueReusableCell(withIdentifier: "WA_RKTopCell", for: indexPath)as!WA_RKTopCell
if let imageURL = URL(string: model!.img ?? "") {
cell.countImagV.sd_setImage(with: imageURL)
}
if let headURL = URL(string: model!.head ?? "") {
cell.headImageV.sd_setImage(with: headURL)
}
cell.nameLabel.text = model?.name
cell.titleLabel.text = model?.content
cell.tlcoutlabel.text = "\(dataItems.count)Participation in topics"
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(imageTapped(_:)))
cell.countImagV.isUserInteractionEnabled = true
cell.countImagV.addGestureRecognizer(tapGesture)
return cell
}else{
let cell = tableView.dequeueReusableCell(withIdentifier: "WA_RKPLCell", for: indexPath)as!WA_RKPLCell
cell.model = dataItems[indexPath.row]
cell.reportBlcok = {
// UIAlertController
let alertController = UIAlertController(title: "report", message: "Report the content of this comment?", preferredStyle: .alert)
//
alertController.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: nil))
//
alertController.addAction(UIAlertAction(title: "report", style: .default, handler: { action in
//
// print("")
DispatchQueue.main.asyncAfter(deadline: .now()){
self.activityView.startAnimating()
DispatchQueue.global().asyncAfter(deadline: .now() + 1.5){
DispatchQueue.main.asyncAfter(deadline: .now()){
self.activityView.stopAnimating()
SVProgressHUD.showInfo(withStatus: "Successfully submitted. Thank you for your feedback. We will review this comment again in the future")
DispatchQueue.global().asyncAfter(deadline: .now() + 2.0) {
SVProgressHUD.dismiss()
}
}
}
}
}))
// present
self.present(alertController, animated: true, completion: nil)
}
cell.blackBLcok = {
// UIAlertController
let alertController = UIAlertController(title: "Block", message: "Blacklisting comment content?", preferredStyle: .alert)
//
alertController.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: nil))
//
alertController.addAction(UIAlertAction(title: "Block", style: .default, handler: { action in
//
// print("")
DispatchQueue.main.asyncAfter(deadline: .now()){
self.activityView.startAnimating()
DispatchQueue.global().asyncAfter(deadline: .now() + 1.5){
DispatchQueue.main.asyncAfter(deadline: .now()){
self.activityView.stopAnimating()
let selectedModel = self.dataItems[indexPath.row]
self.dataItems.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .fade)
SVProgressHUD.showInfo(withStatus: "Successfully submitted. Thank you for your feedback. We will review this comment again in the future")
self.tableView.reloadData()
DispatchQueue.global().asyncAfter(deadline: .now() + 2.0) {
SVProgressHUD.dismiss()
}
}
}
}
}))
// present
self.present(alertController, animated: true, completion: nil)
}
return cell
}
}
@objc func imageTapped(_ sender: UITapGestureRecognizer) {
if let imageView = sender.view as? UIImageView, let image = imageView.image {
//
let fullScreenImageView = UIImageView(image: image)
fullScreenImageView.frame = UIScreen.main.bounds
fullScreenImageView.backgroundColor = .black
fullScreenImageView.contentMode = .scaleAspectFit
fullScreenImageView.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage(_:)))
fullScreenImageView.addGestureRecognizer(tap)
if let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) {
keyWindow.addSubview(fullScreenImageView)
}
}
}
@objc func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
sender.view?.removeFromSuperview()
}
}