Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 iPad 支持 #246

Merged
merged 7 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Bark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
06802E5320ECC40C00767047 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; };
06840DBB272298FB001B3193 /* BKColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06840DBA272298FB001B3193 /* BKColor.swift */; };
06885EB6247FB9880004A303 /* MessageSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */; };
0689CF4C2C7484A7007203A6 /* BarkTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */; };
068EC15827ED99C900D5D11E /* ServerListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15727ED99C900D5D11E /* ServerListViewController.swift */; };
068EC15A27ED99E700D5D11E /* ServerListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15927ED99E700D5D11E /* ServerListViewModel.swift */; };
068F66B3247BD84C00DAD25A /* MessageListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068F66B2247BD84C00DAD25A /* MessageListViewController.swift */; };
Expand Down Expand Up @@ -184,6 +185,9 @@
06F11E7727D9D5FB00F00298 /* QRScannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F11E7627D9D5FB00F00298 /* QRScannerViewController.swift */; };
06FB04042C53575400F3A213 /* SharedDefines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FB04032C53575400F3A213 /* SharedDefines.swift */; };
06FB04052C53575400F3A213 /* SharedDefines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FB04032C53575400F3A213 /* SharedDefines.swift */; };
1E73F99E2C282822002BF649 /* SectionViewController-iPad.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E73F99D2C282822002BF649 /* SectionViewController-iPad.swift */; };
1EFB545D2C314A6800B8E51B /* BarkSplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EFB545C2C314A6800B8E51B /* BarkSplitViewController.swift */; };
1EFB545F2C32514000B8E51B /* SectionViewModel-iPad.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EFB545E2C32514000B8E51B /* SectionViewModel-iPad.swift */; };
3428272069AFAFE2C683FEB0 /* libPods-Bark.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CCC722470308049D180876C7 /* libPods-Bark.a */; };
879AE4D4178855A9672009E4 /* libPods-NotificationServiceExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B7F8BDFAA047451561798F58 /* libPods-NotificationServiceExtension.a */; };
B963F7D5BA7AC2571E71EF66 /* libPods-BarkTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 76381A752CCCD4DA6BB2A566 /* libPods-BarkTests.a */; };
Expand Down Expand Up @@ -324,6 +328,7 @@
0683487220510FB20024B6DA /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; };
06840DBA272298FB001B3193 /* BKColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BKColor.swift; sourceTree = "<group>"; };
06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSettingsViewController.swift; sourceTree = "<group>"; };
0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarkTabBarController.swift; sourceTree = "<group>"; };
068EC15727ED99C900D5D11E /* ServerListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewController.swift; sourceTree = "<group>"; };
068EC15927ED99E700D5D11E /* ServerListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewModel.swift; sourceTree = "<group>"; };
068F66B2247BD84C00DAD25A /* MessageListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -375,6 +380,9 @@
06FB04032C53575400F3A213 /* SharedDefines.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedDefines.swift; sourceTree = "<group>"; };
121D9B1ED4E8D26F345BC5C0 /* Pods-BarkTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BarkTests.release.xcconfig"; path = "Target Support Files/Pods-BarkTests/Pods-BarkTests.release.xcconfig"; sourceTree = "<group>"; };
138CE8CB688587E893BC5C44 /* Pods-Bark.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Bark.debug.xcconfig"; path = "Target Support Files/Pods-Bark/Pods-Bark.debug.xcconfig"; sourceTree = "<group>"; };
1E73F99D2C282822002BF649 /* SectionViewController-iPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SectionViewController-iPad.swift"; sourceTree = "<group>"; };
1EFB545C2C314A6800B8E51B /* BarkSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarkSplitViewController.swift; sourceTree = "<group>"; };
1EFB545E2C32514000B8E51B /* SectionViewModel-iPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SectionViewModel-iPad.swift"; sourceTree = "<group>"; };
519481D715B40109627E1B49 /* Pods-NotificationServiceExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationServiceExtension.release.xcconfig"; path = "Target Support Files/Pods-NotificationServiceExtension/Pods-NotificationServiceExtension.release.xcconfig"; sourceTree = "<group>"; };
76381A752CCCD4DA6BB2A566 /* libPods-BarkTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BarkTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A69B47DA6DB3B168D5770B45 /* Pods-Bark.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Bark.release.xcconfig"; path = "Target Support Files/Pods-Bark/Pods-Bark.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -447,6 +455,10 @@
06EEF332291CCFF400CA228A /* CryptoSettingController.swift */,
06EEF334291CD00000CA228A /* CryptoSettingViewModel.swift */,
06787C3A2AB82BDB008ABDD7 /* CrashReportViewController.swift */,
1E73F99D2C282822002BF649 /* SectionViewController-iPad.swift */,
1EFB545E2C32514000B8E51B /* SectionViewModel-iPad.swift */,
1EFB545C2C314A6800B8E51B /* BarkSplitViewController.swift */,
0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -1098,6 +1110,7 @@
06840DBB272298FB001B3193 /* BKColor.swift in Sources */,
06C2CF232685B88D0034B127 /* TextCell.swift in Sources */,
06BBB896256518760076F63E /* NewServerViewModel.swift in Sources */,
1EFB545D2C314A6800B8E51B /* BarkSplitViewController.swift in Sources */,
06BBB8C92567B6730076F63E /* Operators.swift in Sources */,
0603706920E1F89500F4CA05 /* PreviewCardCell.swift in Sources */,
0627DABB298B6EA2002F3F69 /* DropBoxView.swift in Sources */,
Expand Down Expand Up @@ -1161,12 +1174,15 @@
06C2CF252685BDB80034B127 /* SpacerCell.swift in Sources */,
06BBB8BC2567B3AD0076F63E /* ArchiveSettingCellViewModel.swift in Sources */,
0642B55A27EB13F100453D91 /* MutableTextCell.swift in Sources */,
1EFB545F2C32514000B8E51B /* SectionViewModel-iPad.swift in Sources */,
06EEF335291CD00000CA228A /* CryptoSettingViewModel.swift in Sources */,
0637FA8020E0981E00E80174 /* BarkSettings.swift in Sources */,
065BE4402563D649002A8CA4 /* SoundsViewModel.swift in Sources */,
065BE4462563D7E5002A8CA4 /* ViewModelType.swift in Sources */,
0603706B20E20A7C00F4CA05 /* String+Extension.swift in Sources */,
068F66B3247BD84C00DAD25A /* MessageListViewController.swift in Sources */,
1E73F99E2C282822002BF649 /* SectionViewController-iPad.swift in Sources */,
0689CF4C2C7484A7007203A6 /* BarkTabBarController.swift in Sources */,
06BBB8B72567AC140076F63E /* MessageSettingsViewModel.swift in Sources */,
06BBB8C12567B3EF0076F63E /* BaseTableViewCell.swift in Sources */,
0661A543204FDA4100965E4E /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -1433,8 +1449,10 @@
PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "match Development me.fin.bark";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -1455,8 +1473,10 @@
PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "match AppStore me.fin.bark";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
28 changes: 8 additions & 20 deletions Bark/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import CloudKit
import CrashReporter
import IQKeyboardManagerSwift
import Material
import UIKit
import UserNotifications

Expand Down Expand Up @@ -78,25 +77,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
setupRealm()

IQKeyboardManager.shared.enable = true

let tabBarController = StateStorageTabBarController()
tabBarController.tabBar.tintColor = BKColor.grey.darken4

self.window?.rootViewController = BarkSnackbarController(
rootViewController: tabBarController
)

tabBarController.viewControllers = [
BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel())),
BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel())),
BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel()))
]

let tabBarItems = [UITabBarItem(title: NSLocalizedString("service"), image: UIImage(named: "baseline_gite_black_24pt"), tag: 0),
UITabBarItem(title: NSLocalizedString("historyMessage"), image: Icon.history, tag: 1),
UITabBarItem(title: NSLocalizedString("settings"), image: UIImage(named: "baseline_manage_accounts_black_24pt"), tag: 2)]
for (index, viewController) in tabBarController.viewControllers!.enumerated() {
viewController.tabBarItem = tabBarItems[index]
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
let splitViewController = BarkSplitViewController(style: .doubleColumn)
self.window?.rootViewController = BarkSnackbarController(rootViewController: splitViewController)
} else {
let tabBarController = BarkTabBarController()
self.window?.rootViewController = BarkSnackbarController(
rootViewController: tabBarController
)
}

// 需先配置好 tabBarController 的 viewControllers,显示时会默认显示上次打开的页面
Expand Down
10 changes: 5 additions & 5 deletions Common/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class Client: NSObject {
}

var currentNavigationController: UINavigationController? {
// TODO: iPad 取值不对
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
let nav = (controller?.rootViewController as? UITabBarController)?.selectedViewController as? UINavigationController
return nav
}

var currentTabBarController: StateStorageTabBarController? {
// TODO: iPad 取值不对
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
return controller?.rootViewController as? StateStorageTabBarController
}
Expand All @@ -49,13 +51,12 @@ class Client: NSObject {

func registerForRemoteNotifications() {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (_ granted: Bool, _: Error?) -> Void in
center.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (_ granted: Bool, _: Error?) in
if granted {
dispatch_sync_safely_main_queue {
UIApplication.shared.registerForRemoteNotifications()
}
}
else {
} else {
print("没有打开推送")
}
})
Expand All @@ -69,8 +70,7 @@ class Client: NSObject {
self.currentNavigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
}
}
}
else {
} else {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
Expand Down
50 changes: 50 additions & 0 deletions Controller/BarkSplitViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// BarkSplitViewController.swift
// Bark
//
// Created by sidguan on 2024/6/30.
// Copyright © 2024 Fin. All rights reserved.
//

import Material
import UIKit

@available(iOS 14, *)
class BarkSplitViewController: UISplitViewController {
let sectionViewController = SectionViewController_iPad(viewModel: SectionViewModel())
// Compact 下替换显示成 BarkTabBarController
let compactController = BarkTabBarController()
override func viewDidLoad() {
super.viewDidLoad()
self.preferredDisplayMode = .oneBesideSecondary
self.preferredSplitBehavior = .tile
self.delegate = self
initViewControllers()
}

func initViewControllers() {
self.setViewController(sectionViewController, for: .primary)
// 设置默认打开页面
let index: Int = Settings[.selectedViewControllerIndex] ?? 0
self.setViewController(sectionViewController.viewControllers[index], for: .secondary)
self.setViewController(compactController, for: .compact)
}
}

@available(iOS 14, *)
extension BarkSplitViewController: UISplitViewControllerDelegate {
// 同步 sectionViewController 和 compactController 当前显示页面
func splitViewControllerDidCollapse(_ svc: UISplitViewController) {
guard let index: Int = Settings[.selectedViewControllerIndex] else {
return
}
self.compactController.selectedIndex = index
}

func splitViewControllerDidExpand(_ svc: UISplitViewController) {
guard let index: Int = Settings[.selectedViewControllerIndex] else {
return
}
self.sectionViewController.tableView.selectRow(at: IndexPath(row: index, section: 0), animated: false, scrollPosition: .none)
}
}
30 changes: 30 additions & 0 deletions Controller/BarkTabBarController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// BarkTabBarController.swift
// Bark
//
// Created by huangfeng on 2024/8/20.
// Copyright © 2024 Fin. All rights reserved.
//

import Material
import UIKit

class BarkTabBarController: StateStorageTabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.tintColor = BKColor.grey.darken4

self.viewControllers = [
BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel())),
BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel())),
BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel()))
]

let tabBarItems = [UITabBarItem(title: NSLocalizedString("service"), image: UIImage(named: "baseline_gite_black_24pt"), tag: 0),
UITabBarItem(title: NSLocalizedString("historyMessage"), image: Icon.history, tag: 1),
UITabBarItem(title: NSLocalizedString("settings"), image: UIImage(named: "baseline_manage_accounts_black_24pt"), tag: 2)]
for (index, viewController) in self.viewControllers!.enumerated() {
viewController.tabBarItem = tabBarItems[index]
}
}
}
6 changes: 5 additions & 1 deletion Controller/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class BaseViewController<T>: UIViewController where T: ViewModel {

override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.largeTitleDisplayMode = .automatic
if UIDevice.current.userInterfaceIdiom == .pad {
navigationItem.largeTitleDisplayMode = .never
} else {
navigationItem.largeTitleDisplayMode = .automatic
}
makeUI()
}

Expand Down
4 changes: 2 additions & 2 deletions Controller/GroupFilterViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import RealmSwift
import RxCocoa
import RxDataSources
import RxSwift
import UIKit

struct GroupFilterModel {
var name: String?
var checked: Bool
Expand Down Expand Up @@ -43,7 +43,7 @@ class GroupFilterViewModel: ViewModel, ViewModelType {

// 点击显示所有群组或隐藏所有群组时,设置cell checked 勾选状态
input.showAllGroups.drive(onNext: { isShowAllGroups in
groupCellModels.forEach { model in
for model in groupCellModels {
model.checked.accept(isShowAllGroups)
}
}).disposed(by: rx.disposeBag)
Expand Down
Loading
Loading