mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
parent
469b234c5a
commit
54a94e8b0f
@ -14,7 +14,7 @@ let kRealmDefaultConfiguration = {
|
|||||||
let fileUrl = groupUrl?.appendingPathComponent("bark.realm")
|
let fileUrl = groupUrl?.appendingPathComponent("bark.realm")
|
||||||
let config = Realm.Configuration(
|
let config = Realm.Configuration(
|
||||||
fileURL: fileUrl,
|
fileURL: fileUrl,
|
||||||
schemaVersion: 15,
|
schemaVersion: 16,
|
||||||
migrationBlock: { migration, oldSchemaVersion in
|
migrationBlock: { migration, oldSchemaVersion in
|
||||||
switch oldSchemaVersion {
|
switch oldSchemaVersion {
|
||||||
case 0...13:
|
case 0...13:
|
||||||
|
|||||||
@ -15,6 +15,7 @@ class Message: Object {
|
|||||||
@objc dynamic var subtitle: String?
|
@objc dynamic var subtitle: String?
|
||||||
@objc dynamic var body: String?
|
@objc dynamic var body: String?
|
||||||
@objc dynamic var url: String?
|
@objc dynamic var url: String?
|
||||||
|
@objc dynamic var image: String?
|
||||||
@objc dynamic var group: String?
|
@objc dynamic var group: String?
|
||||||
@objc dynamic var createDate: Date?
|
@objc dynamic var createDate: Date?
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
// Copyright © 2024 Fin. All rights reserved.
|
// Copyright © 2024 Fin. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Kingfisher
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
enum MessageListCellDateStyle {
|
enum MessageListCellDateStyle {
|
||||||
@ -22,6 +23,8 @@ class MessageItemModel {
|
|||||||
var attributedText: NSAttributedString?
|
var attributedText: NSAttributedString?
|
||||||
var dateText: String?
|
var dateText: String?
|
||||||
|
|
||||||
|
var image: String?
|
||||||
|
|
||||||
var createDate: Date?
|
var createDate: Date?
|
||||||
var dateStyle: MessageListCellDateStyle = .relative {
|
var dateStyle: MessageListCellDateStyle = .relative {
|
||||||
didSet {
|
didSet {
|
||||||
@ -90,6 +93,7 @@ class MessageItemModel {
|
|||||||
|
|
||||||
self.attributedText = text
|
self.attributedText = text
|
||||||
self.createDate = message.createDate
|
self.createDate = message.createDate
|
||||||
|
self.image = message.image
|
||||||
defer {
|
defer {
|
||||||
self.dateStyle = .relative
|
self.dateStyle = .relative
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ class ArchiveProcessor: NotificationContentProcessor {
|
|||||||
let body = alert?["body"] as? String
|
let body = alert?["body"] as? String
|
||||||
let url = userInfo["url"] as? String
|
let url = userInfo["url"] as? String
|
||||||
let group = userInfo["group"] as? String
|
let group = userInfo["group"] as? String
|
||||||
|
let image = userInfo["image"] as? String
|
||||||
|
|
||||||
try? realm?.write {
|
try? realm?.write {
|
||||||
let message = Message()
|
let message = Message()
|
||||||
@ -37,6 +38,7 @@ class ArchiveProcessor: NotificationContentProcessor {
|
|||||||
message.subtitle = subtitle
|
message.subtitle = subtitle
|
||||||
message.body = body
|
message.body = body
|
||||||
message.url = url
|
message.url = url
|
||||||
|
message.image = image
|
||||||
message.group = group
|
message.group = group
|
||||||
message.createDate = Date()
|
message.createDate = Date()
|
||||||
realm?.add(message)
|
realm?.add(message)
|
||||||
|
|||||||
1
Podfile
1
Podfile
@ -28,6 +28,7 @@ def pods
|
|||||||
pod 'Kingfisher'
|
pod 'Kingfisher'
|
||||||
pod 'MercariQRScanner', :git => 'https://github.com/Finb/QRScanner'
|
pod 'MercariQRScanner', :git => 'https://github.com/Finb/QRScanner'
|
||||||
pod 'DropDown'
|
pod 'DropDown'
|
||||||
|
pod 'ImageViewer.swift'
|
||||||
|
|
||||||
pod 'SwiftyStoreKit'
|
pod 'SwiftyStoreKit'
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,6 +5,7 @@ PODS:
|
|||||||
- Differentiator (5.0.0)
|
- Differentiator (5.0.0)
|
||||||
- DropDown (2.3.13)
|
- DropDown (2.3.13)
|
||||||
- FDFullscreenPopGesture (1.1)
|
- FDFullscreenPopGesture (1.1)
|
||||||
|
- ImageViewer.swift (3.3.8)
|
||||||
- IQKeyboardCore (1.0.7)
|
- IQKeyboardCore (1.0.7)
|
||||||
- IQKeyboardManagerSwift/Core (8.0.0):
|
- IQKeyboardManagerSwift/Core (8.0.0):
|
||||||
- IQKeyboardNotification
|
- IQKeyboardNotification
|
||||||
@ -74,6 +75,7 @@ DEPENDENCIES:
|
|||||||
- DefaultsKit
|
- DefaultsKit
|
||||||
- DropDown
|
- DropDown
|
||||||
- FDFullscreenPopGesture
|
- FDFullscreenPopGesture
|
||||||
|
- ImageViewer.swift
|
||||||
- IQKeyboardManagerSwift/IQKeyboardToolbarManager
|
- IQKeyboardManagerSwift/IQKeyboardToolbarManager
|
||||||
- Kingfisher
|
- Kingfisher
|
||||||
- Material
|
- Material
|
||||||
@ -100,6 +102,7 @@ SPEC REPOS:
|
|||||||
- Differentiator
|
- Differentiator
|
||||||
- DropDown
|
- DropDown
|
||||||
- FDFullscreenPopGesture
|
- FDFullscreenPopGesture
|
||||||
|
- ImageViewer.swift
|
||||||
- IQKeyboardCore
|
- IQKeyboardCore
|
||||||
- IQKeyboardManagerSwift
|
- IQKeyboardManagerSwift
|
||||||
- IQKeyboardNotification
|
- IQKeyboardNotification
|
||||||
@ -141,6 +144,7 @@ SPEC CHECKSUMS:
|
|||||||
Differentiator: e8497ceab83c1b10ca233716d547b9af21b9344d
|
Differentiator: e8497ceab83c1b10ca233716d547b9af21b9344d
|
||||||
DropDown: 8a2116376c1981888557f72ec2ffc9a5e0e456ec
|
DropDown: 8a2116376c1981888557f72ec2ffc9a5e0e456ec
|
||||||
FDFullscreenPopGesture: a8a620179e3d9c40e8e00256dcee1c1a27c6d0f0
|
FDFullscreenPopGesture: a8a620179e3d9c40e8e00256dcee1c1a27c6d0f0
|
||||||
|
ImageViewer.swift: 284cd8127d31af8e5938674fb9f8e695a4cdf6c6
|
||||||
IQKeyboardCore: cb7f0a9a17dd32599569f2f478c1418dc28bcebb
|
IQKeyboardCore: cb7f0a9a17dd32599569f2f478c1418dc28bcebb
|
||||||
IQKeyboardManagerSwift: 0c6fbbaa2e60739e48d7cf59f25661471a7a3a65
|
IQKeyboardManagerSwift: 0c6fbbaa2e60739e48d7cf59f25661471a7a3a65
|
||||||
IQKeyboardNotification: d7382c4466c5a5adef92c7452ebf861b36050088
|
IQKeyboardNotification: d7382c4466c5a5adef92c7452ebf861b36050088
|
||||||
@ -167,6 +171,6 @@ SPEC CHECKSUMS:
|
|||||||
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
|
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
|
||||||
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a
|
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a
|
||||||
|
|
||||||
PODFILE CHECKSUM: a7da3cf53c17d876cd2e822046dc7499c69fe470
|
PODFILE CHECKSUM: 3d8263a3dcdc33edad82e369b6e182961d45cc98
|
||||||
|
|
||||||
COCOAPODS: 1.16.2
|
COCOAPODS: 1.16.2
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
// Copyright © 2024 Fin. All rights reserved.
|
// Copyright © 2024 Fin. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import ImageViewer_swift
|
||||||
|
import Kingfisher
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class MessageItemView: UIView {
|
class MessageItemView: UIView {
|
||||||
@ -13,6 +15,7 @@ class MessageItemView: UIView {
|
|||||||
let view = UIView()
|
let view = UIView()
|
||||||
view.layer.cornerRadius = 10
|
view.layer.cornerRadius = 10
|
||||||
view.backgroundColor = BKColor.background.secondary
|
view.backgroundColor = BKColor.background.secondary
|
||||||
|
view.clipsToBounds = true
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -33,6 +36,22 @@ class MessageItemView: UIView {
|
|||||||
return label
|
return label
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
let imageView: UIImageView = {
|
||||||
|
let imageView = UIImageView()
|
||||||
|
imageView.contentMode = .scaleAspectFill
|
||||||
|
imageView.layer.cornerRadius = 4
|
||||||
|
imageView.clipsToBounds = true
|
||||||
|
return imageView
|
||||||
|
}()
|
||||||
|
|
||||||
|
let contentStackView: UIStackView = {
|
||||||
|
let stackView = UIStackView()
|
||||||
|
stackView.axis = .vertical
|
||||||
|
stackView.spacing = 8
|
||||||
|
stackView.alignment = .fill
|
||||||
|
return stackView
|
||||||
|
}()
|
||||||
|
|
||||||
let dateLabel: UILabel = {
|
let dateLabel: UILabel = {
|
||||||
let label = BKLabel()
|
let label = BKLabel()
|
||||||
label.hitTestSlop = UIEdgeInsets(top: -5, left: -5, bottom: -5, right: -5)
|
label.hitTestSlop = UIEdgeInsets(top: -5, left: -5, bottom: -5, right: -5)
|
||||||
@ -69,13 +88,23 @@ class MessageItemView: UIView {
|
|||||||
|
|
||||||
var tapAction: ((_ message: MessageItemModel, _ sourceView: UIView) -> Void)?
|
var tapAction: ((_ message: MessageItemModel, _ sourceView: UIView) -> Void)?
|
||||||
|
|
||||||
|
/// 用于查找通知扩展缓存的图片
|
||||||
|
lazy var imageCache: ImageCache = {
|
||||||
|
let groupUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.bark")
|
||||||
|
let cache = try? ImageCache(name: "shared", cacheDirectoryURL: groupUrl)
|
||||||
|
|
||||||
|
return cache ?? KingfisherManager.shared.cache
|
||||||
|
}()
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
self.backgroundColor = BKColor.background.primary
|
self.backgroundColor = BKColor.background.primary
|
||||||
self.addSubview(panel)
|
self.addSubview(panel)
|
||||||
panel.addSubview(bodyLabel)
|
panel.addSubview(contentStackView)
|
||||||
panel.addSubview(dateLabel)
|
panel.addSubview(dateLabel)
|
||||||
panel.addSubview(blackMaskView)
|
panel.addSubview(blackMaskView)
|
||||||
|
contentStackView.addArrangedSubview(bodyLabel)
|
||||||
|
contentStackView.addArrangedSubview(imageView)
|
||||||
|
|
||||||
layoutView()
|
layoutView()
|
||||||
|
|
||||||
@ -104,17 +133,20 @@ class MessageItemView: UIView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func layoutView() {
|
func layoutView() {
|
||||||
bodyLabel.snp.makeConstraints { make in
|
contentStackView.snp.makeConstraints { make in
|
||||||
make.top.equalTo(16)
|
make.top.equalTo(16)
|
||||||
make.left.equalTo(12)
|
make.left.equalTo(12)
|
||||||
make.right.equalTo(-12)
|
make.right.equalTo(-12)
|
||||||
}
|
}
|
||||||
|
imageView.snp.makeConstraints { make in
|
||||||
|
make.width.equalTo(UIScreen.main.bounds.width - 24)
|
||||||
|
make.height.equalTo((UIScreen.main.bounds.width - 24) / 2)
|
||||||
|
}
|
||||||
dateLabel.snp.makeConstraints { make in
|
dateLabel.snp.makeConstraints { make in
|
||||||
make.left.equalTo(bodyLabel)
|
make.left.equalTo(contentStackView)
|
||||||
make.top.equalTo(bodyLabel.snp.bottom).offset(12)
|
make.top.equalTo(contentStackView.snp.bottom).offset(12)
|
||||||
make.bottom.equalTo(panel).offset(-12).priority(.medium)
|
make.bottom.equalTo(panel).offset(-12).priority(.medium)
|
||||||
}
|
}
|
||||||
|
|
||||||
panel.snp.makeConstraints { make in
|
panel.snp.makeConstraints { make in
|
||||||
make.left.equalToSuperview().offset(16)
|
make.left.equalToSuperview().offset(16)
|
||||||
make.right.equalToSuperview().offset(-16)
|
make.right.equalToSuperview().offset(-16)
|
||||||
@ -136,5 +168,15 @@ extension MessageItemView {
|
|||||||
func setMessage(message: MessageItemModel) {
|
func setMessage(message: MessageItemModel) {
|
||||||
self.bodyLabel.attributedText = message.attributedText
|
self.bodyLabel.attributedText = message.attributedText
|
||||||
self.dateLabel.text = message.dateText
|
self.dateLabel.text = message.dateText
|
||||||
|
if let image = message.image {
|
||||||
|
imageView.isHidden = false
|
||||||
|
imageView.kf.setImage(with: URL(string: image), options: [.targetCache(imageCache)]) { [weak self] _ in
|
||||||
|
// 获取系统是否是夜间模式
|
||||||
|
let isDarkMode = UIScreen.main.traitCollection.userInterfaceStyle == .dark
|
||||||
|
self?.imageView.setupImageViewer(options: [.closeIcon(UIImage(named: "back")!), .theme(isDarkMode ? .dark : .light)])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
imageView.isHidden = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user