[ABANDONED] Mastodon iOS client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.1 KiB

//
// ComposeViewController.swift
// elpha-ios
//
// Created by Dwayne Harris on 11/12/18.
// Copyright © 2018 Elpha. All rights reserved.
//
import FLAnimatedImage
import UIKit
class ComposeViewController: UIViewController {
@IBOutlet var replyToView: UIView!
@IBOutlet var replyToAvatarImageView: FLAnimatedImageView!
@IBOutlet var replyToDisplayNameLabel: UILabel!
@IBOutlet var replyToUsernameLabel: UILabel!
@IBOutlet var replyToContentTextView: UITextViewFixed!
@IBOutlet var statusTextView: UITextView!
@IBOutlet var statusCharacterCountLabel: UILabel!
@IBOutlet var contentWarningTextField: UITextField!
@IBOutlet var tootButton: UIButton!
@IBOutlet var bottomConstraint: NSLayoutConstraint!
var replyToStatus: StatusMO? = nil
override func viewDidLoad() {
super.viewDidLoad()
replyToAvatarImageView.layer.cornerRadius = 10
replyToAvatarImageView.layer.masksToBounds = true
statusTextView.layer.cornerRadius = 10
statusTextView.layer.masksToBounds = true
statusTextView.delegate = self
NotificationCenter.default.addObserver(self, selector: #selector(keyboardNotification(notification:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
if let replyToStatus = replyToStatus {
replyToView.isHidden = false
if let reblog = replyToStatus.reblog {
self.setupReplyTo(status: reblog)
} else {
self.setupReplyTo(status: replyToStatus)
}
} else {
replyToView.isHidden = true
}
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
statusTextView.becomeFirstResponder()
}
func setupReplyTo(status: StatusMO) {
if let account = status.account {
replyToAvatarImageView.loadImageURL(account.avatarURL!)
replyToDisplayNameLabel.text = account.displayName
replyToUsernameLabel.text = "@\(account.acct!)"
}
replyToContentTextView.attributedText = status.content?.htmlAttributed(size: 13.0)
}
@objc func keyboardNotification(notification: NSNotification) {
if let userInfo = notification.userInfo {
let endFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
let endFrameY = endFrame?.origin.y ?? 0
if endFrameY >= UIScreen.main.bounds.size.height {
bottomConstraint.constant = 50.0
} else {
bottomConstraint.constant = endFrame?.size.height ?? 0.0
}
}
}
@IBAction func dismissTapped(_ sender: Any) {
dismiss(animated: true)
}
}
extension ComposeViewController: UITextViewDelegate {
func textViewDidChange(_ textView: UITextView) {
let characters = statusTextView.text!.count
statusCharacterCountLabel.text = String(500 - characters)
}
}