Skip to content

Commit

Permalink
Apply code style
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyu committed May 7, 2022
1 parent c08b7d4 commit bf1d08f
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 242 deletions.
47 changes: 12 additions & 35 deletions Mixin.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Mixin/Assets.xcassets/ic_photo_unselected.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class PhotoInputGridCell: UICollectionViewCell {
@IBOutlet weak var imageWrapperView: UIView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var mediaTypeView: MediaTypeOverlayView!
@IBOutlet weak var badge: BadgeView!
@IBOutlet weak var statusImageView: UIImageView!
@IBOutlet weak var indexLabel: UILabel!
@IBOutlet weak var overlayView: UIView!

let cornerRadius: CGFloat = 8
Expand All @@ -20,8 +21,6 @@ class PhotoInputGridCell: UICollectionViewCell {
contentView.layer.shadowColor = UIColor.shadow.cgColor
contentView.layer.shadowOpacity = 0.29
contentView.layer.shadowRadius = 5
badge.cornerRadius = 10
badge.textColor = .white
}

override func layoutSubviews() {
Expand All @@ -32,21 +31,18 @@ class PhotoInputGridCell: UICollectionViewCell {
override func prepareForReuse() {
super.prepareForReuse()
imageView.image = nil
overlayView.isHidden = true
}

func updateBadge(with index: Int?) {
if let index = index {
badge.text = "\(index + 1)"
badge.borderWidth = 0
badge.borderColor = .clear
badge.badgeColor = .theme
indexLabel.text = "\(index + 1)"
statusImageView.backgroundColor = .theme
statusImageView.image = nil
overlayView.isHidden = false
} else {
badge.text = nil
badge.borderWidth = 1
badge.borderColor = .white
badge.badgeColor = .black.withAlphaComponent(0.16)
indexLabel.text = nil
statusImageView.backgroundColor = .clear
statusImageView.image = R.image.ic_photo_unselected_narrow()
overlayView.isHidden = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import MixinServices

class SelectedMediaCell: UICollectionViewCell {

@IBOutlet weak var imageView: SDAnimatedImageView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var mediaTypeView: MediaTypeOverlayView!

var deselectAsset: (() -> Void)?

private var requestId: PHImageRequestID?
private lazy var imageRequestOptions: PHImageRequestOptions = {
let options = PHImageRequestOptions()
options.version = .current
Expand All @@ -22,6 +23,9 @@ class SelectedMediaCell: UICollectionViewCell {
override func prepareForReuse() {
super.prepareForReuse()
imageView.image = nil
if let id = requestId {
PHCachingImageManager.default().cancelImageRequest(id)
}
}

func load(asset: PHAsset, size: CGSize) {
Expand All @@ -34,7 +38,7 @@ class SelectedMediaCell: UICollectionViewCell {
mediaTypeView.style = .hidden
}
}
PHImageManager.default().requestImage(for: asset, targetSize: size * UIScreen.main.scale, contentMode: .aspectFill, options: imageRequestOptions) { [weak self] (image, info) in
requestId = PHImageManager.default().requestImage(for: asset, targetSize: size * UIScreen.main.scale, contentMode: .aspectFill, options: imageRequestOptions) { [weak self] (image, info) in
guard let self = self, let image = image else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class ConversationInputViewController: UIViewController {
if minimize {
setPreferredContentHeightAnimated(.minimized)
}
photoViewController.dismissMediasPreviewControllerIfNeeded()
photoViewController.dismissSelectedPhotoInputItemsViewControllerIfNeeded()
UIView.animate(withDuration: 0.5, delay: 0, options: .overdampedCurve) {
self.customInputContainerView.alpha = 0
} completion: { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ extension PhotoInputGridViewController: UICollectionViewDataSource {
cell.imageView.image = R.image.conversation.ic_camera()
cell.imageView.backgroundColor = R.color.camera_background()
cell.mediaTypeView.style = .hidden
cell.badge.isHidden = true
cell.indexLabel.isHidden = true
cell.statusImageView.isHidden = true
} else if let asset = asset(at: indexPath) {
cell.identifier = asset.localIdentifier
cell.imageView.contentMode = .scaleAspectFill
cell.imageView.backgroundColor = .background
cell.badge.isHidden = false
cell.indexLabel.isHidden = false
cell.statusImageView.isHidden = false
cell.updateBadge(with: selectedAssets.firstIndex(of: asset))
imageManager.requestImage(for: asset, targetSize: thumbnailSize, contentMode: .aspectFill, options: imageRequestOptions) { [weak cell] (image, _) in
guard let cell = cell, cell.identifier == asset.localIdentifier else {
Expand Down
114 changes: 57 additions & 57 deletions Mixin/UserInterface/Controllers/Chat/PhotoInputViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class PhotoInputViewController: UIViewController, ConversationInputAccessible {
}
}

private weak var mediasPreviewControllerIfLoaded: MediasPreviewViewController?
private lazy var mediasPreviewController: MediasPreviewViewController = {
let controller = R.storyboard.chat.selected_medias()!
private weak var selectedPhotoInputItemsViewControllerIfLoaded: SelectedPhotoInputItemsViewController?
private lazy var selectedPhotoInputItemsViewController: SelectedPhotoInputItemsViewController = {
let controller = R.storyboard.chat.selected_photo_input_items()!
controller.delegate = self
mediasPreviewControllerIfLoaded = controller
selectedPhotoInputItemsViewControllerIfLoaded = controller
return controller
}()
private var allPhotos: PHFetchResult<PHAsset>?
Expand Down Expand Up @@ -190,7 +190,7 @@ extension PhotoInputViewController: PHPhotoLibraryChangeObserver {

func photoLibraryDidChange(_ changeInstance: PHChange) {
DispatchQueue.main.sync {
self.dismissMediasPreviewControllerIfNeeded()
self.dismissSelectedPhotoInputItemsViewControllerIfNeeded()
if let allPhotos = self.allPhotos, let changeDetails = changeInstance.changeDetails(for: allPhotos) {
self.allPhotos = changeDetails.fetchResultAfterChanges
}
Expand Down Expand Up @@ -233,70 +233,70 @@ extension PhotoInputViewController: PhotoInputGridViewControllerDelegate {

func photoInputGridViewController(_ controller: PhotoInputGridViewController, didSelect asset: PHAsset) {
if !controller.selectedAssets.isEmpty {
presentMediasPreviewControllerAnimated()
presentSelectedPhotoInputItemsViewControllerAnimated()
}
mediasPreviewController.add(asset)
selectedPhotoInputItemsViewController.add(asset)
}

func photoInputGridViewController(_ controller: PhotoInputGridViewController, didDeselect asset: PHAsset) {
if controller.selectedAssets.isEmpty {
dismissMediasPreviewControllerAnimated()
dismissSelectedPhotoInputItemsViewControllerAnimated()
} else {
mediasPreviewController.remove(asset)
selectedPhotoInputItemsViewController.remove(asset)
}
}

func photoInputGridViewControllerDidTapCamera(_ controller: PhotoInputGridViewController) {
dismissMediasPreviewControllerIfNeeded()
dismissSelectedPhotoInputItemsViewControllerIfNeeded()
}

}

extension PhotoInputViewController: MediasPreviewViewControllerDelegate {
extension PhotoInputViewController: SelectedPhotoInputItemsViewControllerDelegate {

func mediasPreviewViewController(_ controller: MediasPreviewViewController, didSend assets: [PHAsset]) {
func selectedPhotoInputItemsViewController(_ controller: SelectedPhotoInputItemsViewController, didSend assets: [PHAsset]) {
sendItems(assets: assets)
}

func mediasPreviewViewController(_ controller: MediasPreviewViewController, didCancelSend assets: [PHAsset]) {
func selectedPhotoInputItemsViewController(_ controller: SelectedPhotoInputItemsViewController, didCancelSend assets: [PHAsset]) {
conversationInputViewController?.dismiss()
}

func mediasPreviewViewController(_ controller: MediasPreviewViewController, didRemove asset: PHAsset) {
func selectedPhotoInputItemsViewController(_ controller: SelectedPhotoInputItemsViewController, didDeselect asset: PHAsset) {
gridViewController.deselect(asset)
if gridViewController.selectedAssets.isEmpty {
dismissMediasPreviewControllerAnimated()
dismissSelectedPhotoInputItemsViewControllerAnimated()
}
}

func mediasPreviewViewController(_ controller: MediasPreviewViewController, didSelectAssetAt index: Int) {
func selectedPhotoInputItemsViewController(_ controller: SelectedPhotoInputItemsViewController, didSelectAssetAt index: Int) {
conversationInputViewController?.setPreferredContentHeightAnimated(.regular)
let assets = gridViewController.selectedAssets
let window = MediasPreviewWindow.instance()
let window = SelectedPhotoInputItemsPreviewWindow.instance()
window.load(assets: assets, initIndex: index)
window.delegate = self
window.presentPopupControllerAnimated()
}

}

extension PhotoInputViewController: MediasPreviewWindowDelegate {
extension PhotoInputViewController: SelectedPhotoInputItemsPreviewWindowDelegate {

func mediasPreviewWindow(_ window: MediasPreviewWindow, willDismissWindow assets: [PHAsset]) {
func selectedPhotoInputItemsPreviewWindow(_ window: SelectedPhotoInputItemsPreviewWindow, willDismissWindow assets: [PHAsset]) {
if assets.isEmpty {
gridViewController.deselectAll()
dismissMediasPreviewControllerAnimated()
dismissSelectedPhotoInputItemsViewControllerAnimated()
} else {
gridViewController.updateSelectdAssets(assets)
mediasPreviewController.updateAssets(assets)
selectedPhotoInputItemsViewController.updateAssets(assets)
}
}

func mediasPreviewWindow(_ window: MediasPreviewWindow, didTapSendItems assets: [PHAsset]) {
func selectedPhotoInputItemsPreviewWindow(_ window: SelectedPhotoInputItemsPreviewWindow, didTapSendItems assets: [PHAsset]) {
sendItems(assets: assets)
}

func mediasPreviewWindow(_ window: MediasPreviewWindow, didTapSendFiles assets: [PHAsset]) {
func selectedPhotoInputItemsPreviewWindow(_ window: SelectedPhotoInputItemsPreviewWindow, didTapSendFiles assets: [PHAsset]) {
sendAsFiles(assets: assets)
}

Expand All @@ -310,7 +310,7 @@ extension PhotoInputViewController {
}
assets.forEach(controller.send(asset:))
gridViewController.deselectAll()
dismissMediasPreviewControllerAnimated()
dismissSelectedPhotoInputItemsViewControllerAnimated()
}

private func sendAsFiles(assets: [PHAsset]) {
Expand All @@ -326,86 +326,86 @@ extension PhotoInputViewController {
}
urls.forEach(controller.sendFile(url:))
self.gridViewController.deselectAll()
self.dismissMediasPreviewControllerAnimated()
self.dismissSelectedPhotoInputItemsViewControllerAnimated()
}
}

func dismissMediasPreviewControllerIfNeeded() {
guard let previewController = mediasPreviewControllerIfLoaded, previewController.parent != nil else {
func dismissSelectedPhotoInputItemsViewControllerIfNeeded() {
guard let controller = selectedPhotoInputItemsViewControllerIfLoaded, controller.parent != nil else {
return
}
gridViewController.view.isUserInteractionEnabled = false
gridViewController.deselectAll()
previewController.removeAllAssets()
previewController.view.removeFromSuperview()
previewController.removeFromParent()
previewController.view.snp.removeConstraints()
controller.removeAllAssets()
controller.view.removeFromSuperview()
controller.removeFromParent()
controller.view.snp.removeConstraints()
gridViewController.view.isUserInteractionEnabled = true
}

private func presentMediasPreviewControllerAnimated() {
private func presentSelectedPhotoInputItemsViewControllerAnimated() {
guard
mediasPreviewController.parent == nil,
selectedPhotoInputItemsViewController.parent == nil,
let conversationInputViewController = conversationInputViewController,
let inputBarView = conversationInputViewController.inputBarView,
let conversationViewController = conversationInputViewController.parent
else {
return
}
gridViewController.view.isUserInteractionEnabled = false
let previewController = mediasPreviewController
let previewViewHeight = mediasPreviewController.viewHeight
addChild(previewController)
view.insertSubview(previewController.view, at: 0)
previewController.view.snp.makeConstraints({ (make) in
let controller = selectedPhotoInputItemsViewController
let viewHeight = selectedPhotoInputItemsViewController.viewHeight
addChild(controller)
view.insertSubview(controller.view, at: 0)
controller.view.snp.makeConstraints({ (make) in
make.left.right.equalToSuperview()
make.top.equalTo(inputBarView.snp.bottom).offset(0)
})
view.layoutIfNeeded()
previewController.view.snp.updateConstraints { make in
make.top.equalTo(inputBarView.snp.bottom).offset(-previewViewHeight)
controller.view.snp.updateConstraints { make in
make.top.equalTo(inputBarView.snp.bottom).offset(-viewHeight)
}
UIView.animate(withDuration: 0.3, delay: 0, options: .overdampedCurve) {
self.view.layoutIfNeeded()
} completion: { _ in
conversationViewController.addChild(previewController)
conversationViewController.view.addSubview(previewController.view)
previewController.view.snp.remakeConstraints({ (make) in
conversationViewController.addChild(controller)
conversationViewController.view.addSubview(controller.view)
controller.view.snp.remakeConstraints({ (make) in
make.left.right.equalToSuperview()
make.top.equalTo(inputBarView.snp.bottom).offset(-previewViewHeight)
make.top.equalTo(inputBarView.snp.bottom).offset(-viewHeight)
})
self.gridViewController.view.isUserInteractionEnabled = true
}
}

private func dismissMediasPreviewControllerAnimated() {
private func dismissSelectedPhotoInputItemsViewControllerAnimated() {
guard
mediasPreviewController.parent != nil,
selectedPhotoInputItemsViewController.parent != nil,
let conversationInputViewController = conversationInputViewController,
let inputBarView = conversationInputViewController.inputBarView
else {
return
}
gridViewController.view.isUserInteractionEnabled = false
let previewController = mediasPreviewController
let previewViewHeight = mediasPreviewController.viewHeight
addChild(previewController)
view.insertSubview(previewController.view, at: 0)
previewController.view.snp.remakeConstraints({ (make) in
let controller = selectedPhotoInputItemsViewController
let viewHeight = selectedPhotoInputItemsViewController.viewHeight
addChild(controller)
view.insertSubview(controller.view, at: 0)
controller.view.snp.remakeConstraints({ (make) in
make.left.right.equalToSuperview()
make.top.equalTo(inputBarView.snp.bottom).offset(-previewViewHeight)
make.top.equalTo(inputBarView.snp.bottom).offset(-viewHeight)
})
view.layoutIfNeeded()
previewController.view.snp.updateConstraints { make in
controller.view.snp.updateConstraints { make in
make.top.equalTo(inputBarView.snp.bottom).offset(0)
}
UIView.animate(withDuration: 0.3, delay: 0, options: .overdampedCurve) {
self.view.layoutIfNeeded()
} completion: { _ in
previewController.removeAllAssets()
previewController.view.removeFromSuperview()
previewController.removeFromParent()
previewController.view.snp.removeConstraints()
controller.removeAllAssets()
controller.view.removeFromSuperview()
controller.removeFromParent()
controller.view.snp.removeConstraints()
self.gridViewController.view.isUserInteractionEnabled = true
}
}
Expand Down
Loading

0 comments on commit bf1d08f

Please sign in to comment.