Skip to content

Commit

Permalink
Merge branch 'develop' into list-control
Browse files Browse the repository at this point in the history
  • Loading branch information
BB9z authored Dec 5, 2023
2 parents fdeea3b + 33d4062 commit ae39c70
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 218 deletions.
2 changes: 1 addition & 1 deletion App/Assets/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@
"link.huggingChat.privacy" = "https://huggingface.co/chat/privacy";
"link.openai.privacy" = "https://openai.com/policies/privacy-policy";
"link.openai.tos" = "https://openai.com/policies/terms-of-use";
"link.openai.api-keys" = "https://platform.openai.com/account/api-keys";
"link.openai.api-keys" = "https://platform.openai.com/api-keys";
"link.openai.known-proxy" = "";
"link.feedback" = "https://github.com/b9software/B9ChatAI/discussions";
4 changes: 2 additions & 2 deletions App/Assets/Generated/L10n.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ internal enum L10n {
internal static let privacy = L10n.tr("Localizable", "link.huggingChat.privacy", fallback: "https://huggingface.co/chat/privacy")
}
internal enum Openai {
/// https://platform.openai.com/account/api-keys
internal static let apiKeys = L10n.tr("Localizable", "link.openai.api-keys", fallback: "https://platform.openai.com/account/api-keys")
/// https://platform.openai.com/api-keys
internal static let apiKeys = L10n.tr("Localizable", "link.openai.api-keys", fallback: "https://platform.openai.com/api-keys")
///
internal static let knownProxy = L10n.tr("Localizable", "link.openai.known-proxy", fallback: "")
/// https://openai.com/policies/privacy-policy
Expand Down
116 changes: 116 additions & 0 deletions App/General/List/MBCollectionViewColumnLayout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
MBCollectionViewColumnLayout

Copyright © 2018-2021 BB9z.
Copyright © 2014-2015 Beijing ZhiYun ZhiYuan Information Technology Co., Ltd.
https://github.com/BB9z/iOS-Project-Template

The MIT License
https://opensource.org/licenses/MIT
*/

/**
按列布局,根据列数等比例调整 cell 的大小并保持 cell 的间距不变

可以指定一个固定列数或一个 cell 的参考大小自动调整列数

不支持通过 delegate 设置 itemSize。如果 delegate 返回了 itemSize,则列设置将失效。
多 section 将根据第一个 section 的尺寸进行布局,不支持多 section 有不同的 itemSize。
*/
class MBCollectionViewColumnLayout: UICollectionViewFlowLayout {

/**
根据宽度自适应调整列数

开启时,外部设置的 columnCount 失效,将根据 itemSize 决定列数,能显示几列就显示几列。
但跟原始的 UICollectionViewFlowLayout 不同之处在于会等比拉大 cell 保持最小间隙。

默认 NO
*/
@IBInspectable var autoColumnDecideOnItemMinimumWidth: Bool = false

/// 列数量,默认 3
@IBInspectable var columnCount: Int = 3 {
didSet {
if oldValue == columnCount { return }
if !autoColumnDecideOnItemMinimumWidth {
invalidateLayout()
}
}
}

/**
布局的参考 item size,这个类会修改实际 itemSize

从 nib 里载入后会吧 itemSize 复制给这个属性,如果手动更新该属性需要手动调用重新布局的方法
*/
@IBInspectable var referenceItemSize: CGSize = .zero

/**
仅宽度自适应,保持高度
*/
@IBInspectable var onlyAdjustWidth: Bool = false

override func awakeFromNib() {
super.awakeFromNib()
referenceItemSize = itemSize
}

override func prepare() {
super.prepare()
guard let list = collectionView else { return }
let layoutChanged = updateLayout(bounds: list.bounds)
if layoutChanged {
list.invalidateIntrinsicContentSize()
}
}

override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
if newBounds.width != collectionView?.bounds.width {
updateLayout(bounds: newBounds)
return true
}
return super.shouldInvalidateLayout(forBoundsChange: newBounds)
}

/// 返回是否更新了布局
@discardableResult private func updateLayout(bounds: CGRect) -> Bool {
if (collectionView?.numberOfSections ?? 0) == 0 { return false }
let size = itemSize(for: bounds)
if itemSize == size { return false }
itemSize = size
return true
}

// MARK: - 布局计算

private var delegateRefrence: UICollectionViewDelegateFlowLayout? {
collectionView?.delegate as? UICollectionViewDelegateFlowLayout
}

private func itemSize(for bounds: CGRect) -> CGSize {
let reference = referenceItemSize
if autoColumnDecideOnItemMinimumWidth {
let width = innerLayoutWidth(section: 0, bounds: bounds)
columnCount = Int(width / reference.width)
}
let width = itemWidth(section: 0, bounds: bounds)
let height = onlyAdjustWidth ? reference.height : width / reference.width * reference.height
return CGSize(width: width, height: height)
}

private func itemWidth(section: Int, bounds: CGRect) -> CGFloat {
let width = innerLayoutWidth(section: section, bounds: bounds)
let column = CGFloat(max(1, columnCount))
return ((width - (column - 1) * minimumInteritemSpacing) / column).rounded(.down)
}

private func innerLayoutWidth(section: Int, bounds: CGRect) -> CGFloat {
var inset = sectionInset
if let list = collectionView,
let dInset = delegateRefrence?.collectionView?(list, layout: self, insetForSectionAt: section) {
inset = dInset
}
return bounds.width - inset.left - inset.right
}
}

This file was deleted.

36 changes: 0 additions & 36 deletions App/Model/AppError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,6 @@
// App
//

/// App 用错误
enum AppError: LocalizedError {

/// 包含一条信息的错误
case message(_ message: String)

/// Operation is cancelled
case cancel

var errorDescription: String? {
switch self {
case let .message(text):
return text
case .cancel:
return "Operation is cancelled"
}
}

/// Conveniently determine if an object is `AppError.cancel`
static func isCancel(_ err: Error?) -> Bool {
if let err = err as? AppError {
if case .cancel = err {
return true
}
return false
}
if err is CancellationError {
return true
}
if let urlError = err as? URLError {
return urlError.code == .cancelled
}
return false
}
}

enum ModelError: LocalizedError {
/// 模型验证失败
case invalid(String)
Expand Down
1 change: 1 addition & 0 deletions App/Model/CoreData/CDEngine+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright © 2023 B9Software. All rights reserved.
//

import AppFramework
import CoreData

extension CDEngine {
Expand Down
1 change: 1 addition & 0 deletions App/Model/CoreData/CDMessage+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright © 2023 B9Software. All rights reserved.
//

import AppFramework
import CoreData

public extension CDMessage {
Expand Down
1 change: 1 addition & 0 deletions App/Model/Items/Conversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright © 2023 B9Software. All rights reserved.
//

import AppFramework
import B9Action
import B9MulticastDelegate
import CoreData
Expand Down
1 change: 1 addition & 0 deletions App/Model/Items/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright © 2023 B9Software. All rights reserved.
//

import AppFramework
import CoreData
import Logging

Expand Down
1 change: 1 addition & 0 deletions App/Model/Items/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright © 2023 B9Software. All rights reserved.
//

import AppFramework
import B9Action
import B9MulticastDelegate
import CoreData
Expand Down
1 change: 1 addition & 0 deletions App/Model/OpenAI API/OANetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2023 B9Software. All rights reserved.
//

import AppFramework
import Foundation

class OANetwork {
Expand Down
10 changes: 5 additions & 5 deletions App/Scene/Base.lproj/Conversation.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="ipad7_9" orientation="portrait" layout="fullscreen" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -300,7 +300,7 @@
<outlet property="textView" destination="bh2-h6-tkH" id="pDd-Vl-PGd"/>
</connections>
</label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" placeholderIntrinsicWidth="300" placeholderIntrinsicHeight="30" textAlignment="natural" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="bh2-h6-tkH">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" placeholderIntrinsicWidth="300" placeholderIntrinsicHeight="30" textAlignment="natural" adjustsFontForContentSizeCategory="YES" layoutManager="textKit2" translatesAutoresizingMaskIntoConstraints="NO" id="bh2-h6-tkH">
<rect key="frame" x="0.0" y="0.0" width="300" height="40.5"/>
<color key="textColor" systemColor="labelColor"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
Expand Down Expand Up @@ -1773,7 +1773,7 @@
<image name="blank" width="1" height="1"/>
<image name="checkbox_off" width="18" height="18"/>
<image name="checkbox_on" width="18" height="18"/>
<image name="clipboard" catalog="system" width="103" height="128"/>
<image name="clipboard" catalog="system" width="98" height="128"/>
<image name="input_box" width="11" height="11"/>
<image name="slider.vertical.3" catalog="system" width="128" height="110"/>
<image name="xmark.circle.fill" catalog="system" width="128" height="123"/>
Expand All @@ -1796,7 +1796,7 @@
<color red="0.0" green="0.0" blue="0.0" alpha="0.60000002384185791" colorSpace="custom" customColorSpace="displayP3"/>
</namedColor>
<systemColor name="labelColor">
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down
Loading

0 comments on commit ae39c70

Please sign in to comment.