From accf1008e72fac43156fc3ed2beccc349d705acf Mon Sep 17 00:00:00 2001 From: Fin Date: Fri, 21 Feb 2025 14:15:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bark.xcodeproj/project.pbxproj | 16 ---- Bark/Localizable.xcstrings | 2 +- Controller/GroupFilterViewController.swift | 101 --------------------- Controller/GroupFilterViewModel.swift | 91 ------------------- View/GroupCellViewModel.swift | 22 ----- View/GroupTableViewCell.swift | 78 ---------------- 6 files changed, 1 insertion(+), 309 deletions(-) delete mode 100644 Controller/GroupFilterViewController.swift delete mode 100644 Controller/GroupFilterViewModel.swift delete mode 100644 View/GroupCellViewModel.swift delete mode 100644 View/GroupTableViewCell.swift diff --git a/Bark.xcodeproj/project.pbxproj b/Bark.xcodeproj/project.pbxproj index 89b9fb6..7661763 100644 --- a/Bark.xcodeproj/project.pbxproj +++ b/Bark.xcodeproj/project.pbxproj @@ -118,10 +118,6 @@ 068EC15A27ED99E700D5D11E /* ServerListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15927ED99E700D5D11E /* ServerListViewModel.swift */; }; 068F66B3247BD84C00DAD25A /* MessageListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068F66B2247BD84C00DAD25A /* MessageListViewController.swift */; }; 0699473D2D223094008D5E40 /* CustomTapTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0699473C2D223094008D5E40 /* CustomTapTextView.swift */; }; - 06AE3118266F4E2E00B39FBB /* GroupFilterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AE3117266F4E2E00B39FBB /* GroupFilterViewController.swift */; }; - 06AE311A266F4E6600B39FBB /* GroupFilterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AE3119266F4E6600B39FBB /* GroupFilterViewModel.swift */; }; - 06AE311C266F54A500B39FBB /* GroupTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AE311B266F54A500B39FBB /* GroupTableViewCell.swift */; }; - 06AE311E266F54CC00B39FBB /* GroupCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AE311D266F54CC00B39FBB /* GroupCellViewModel.swift */; }; 06B1158D247BA6D5006D91FB /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06B1158C247BA6D5006D91FB /* CloudKit.framework */; }; 06B1158F247BB1FB006D91FB /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B1158E247BB1FB006D91FB /* Message.swift */; }; 06B11591247BC132006D91FB /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B1158E247BB1FB006D91FB /* Message.swift */; }; @@ -367,10 +363,6 @@ 068EC15927ED99E700D5D11E /* ServerListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewModel.swift; sourceTree = ""; }; 068F66B2247BD84C00DAD25A /* MessageListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewController.swift; sourceTree = ""; }; 0699473C2D223094008D5E40 /* CustomTapTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTapTextView.swift; sourceTree = ""; }; - 06AE3117266F4E2E00B39FBB /* GroupFilterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupFilterViewController.swift; sourceTree = ""; }; - 06AE3119266F4E6600B39FBB /* GroupFilterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupFilterViewModel.swift; sourceTree = ""; }; - 06AE311B266F54A500B39FBB /* GroupTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupTableViewCell.swift; sourceTree = ""; }; - 06AE311D266F54CC00B39FBB /* GroupCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupCellViewModel.swift; sourceTree = ""; }; 06B1158C247BA6D5006D91FB /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; }; 06B1158E247BB1FB006D91FB /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = ""; }; 06B11590247BBC15006D91FB /* NotificationServiceExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NotificationServiceExtension.entitlements; sourceTree = ""; }; @@ -492,8 +484,6 @@ 06BBB8B62567AC140076F63E /* MessageSettingsViewModel.swift */, 060481ED250F404500BC9799 /* SoundsViewController.swift */, 065BE43F2563D649002A8CA4 /* SoundsViewModel.swift */, - 06AE3117266F4E2E00B39FBB /* GroupFilterViewController.swift */, - 06AE3119266F4E6600B39FBB /* GroupFilterViewModel.swift */, 06F11E7627D9D5FB00F00298 /* QRScannerViewController.swift */, 068EC15727ED99C900D5D11E /* ServerListViewController.swift */, 068EC15927ED99E700D5D11E /* ServerListViewModel.swift */, @@ -525,8 +515,6 @@ 062B98C2251B2762004562E7 /* BKButton.swift */, 06C595352481160F006B98F3 /* BKLabel.swift */, 062B98C7251B27AE004562E7 /* UINavigationItem+Extension.swift */, - 06AE311B266F54A500B39FBB /* GroupTableViewCell.swift */, - 06AE311D266F54CC00B39FBB /* GroupCellViewModel.swift */, 06C2CF222685B88D0034B127 /* TextCell.swift */, 06C2CF242685BDB80034B127 /* SpacerCell.swift */, 0642B55927EB13F100453D91 /* MutableTextCell.swift */, @@ -1256,7 +1244,6 @@ 0603706920E1F89500F4CA05 /* PreviewCardCell.swift in Sources */, 066890082D1946D500E106F2 /* MessageItemView.swift in Sources */, 0627DABB298B6EA2002F3F69 /* DropBoxView.swift in Sources */, - 06AE311C266F54A500B39FBB /* GroupTableViewCell.swift in Sources */, 0672CB06256903F700570C9D /* MessageListViewModel.swift in Sources */, 0627DABD2990D615002F3F69 /* BorderTextField.swift in Sources */, 06E62C112D670F62004DC82B /* PushToCurrentIntent.swift in Sources */, @@ -1268,7 +1255,6 @@ 0699473D2D223094008D5E40 /* CustomTapTextView.swift in Sources */, 06EEF333291CCFF400CA228A /* CryptoSettingController.swift in Sources */, 0603706D20E23EC000F4CA05 /* BarkSFSafariViewController.swift in Sources */, - 06AE311A266F4E6600B39FBB /* GroupFilterViewModel.swift in Sources */, 06F08EA429B098DD006AB9CA /* CryptoSettingManager.swift in Sources */, 0668900B2D19525400E106F2 /* ShowLessAndClearView.swift in Sources */, 06BD4DAA2901352E003364DB /* Object+Dictionary.swift in Sources */, @@ -1295,12 +1281,10 @@ 06C5952F248107F5006B98F3 /* iCloudStatusCell.swift in Sources */, 06BBB88725650C6C0076F63E /* ArchiveSettingManager.swift in Sources */, 065BE44B2563D8E1002A8CA4 /* Reusable.swift in Sources */, - 06AE311E266F54CC00B39FBB /* GroupCellViewModel.swift in Sources */, 0637FA8620E0AB6600E80174 /* UIColor+Extension.swift in Sources */, 0637FA8A20E0D58800E80174 /* NewServerViewController.swift in Sources */, 067B2EB525693E38008B6BE1 /* MessageSection.swift in Sources */, 0637FA8220E09C4B00E80174 /* BarkNavigationController.swift in Sources */, - 06AE3118266F4E2E00B39FBB /* GroupFilterViewController.swift in Sources */, 0637FA7A20E092B300E80174 /* Observable+Extension.swift in Sources */, 060481F0250F51CA00BC9799 /* SoundCell.swift in Sources */, 0667D194247D1BA0005DE2ED /* Date+Extension.swift in Sources */, diff --git a/Bark/Localizable.xcstrings b/Bark/Localizable.xcstrings index cf127c3..6badce5 100644 --- a/Bark/Localizable.xcstrings +++ b/Bark/Localizable.xcstrings @@ -1920,7 +1920,7 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "Groups" + "value" : "Group" } }, "ja" : { diff --git a/Controller/GroupFilterViewController.swift b/Controller/GroupFilterViewController.swift deleted file mode 100644 index 977264f..0000000 --- a/Controller/GroupFilterViewController.swift +++ /dev/null @@ -1,101 +0,0 @@ -// -// GroupFilterViewController.swift -// Bark -// -// Created by huangfeng on 2021/6/8. -// Copyright © 2021 Fin. All rights reserved. -// - -import Material -import MJRefresh -import RealmSwift -import RxCocoa -import RxDataSources -import RxSwift -import UIKit - -class GroupFilterViewController: BaseViewController { - let doneButton: BKButton = { - let btn = BKButton() - btn.setTitle(NSLocalizedString("done"), for: .normal) - btn.setTitleColor(BKColor.lightBlue.darken3, for: .normal) - btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40) - btn.fontSize = 14 - return btn - }() - - let showAllGroupsButton: BKButton = { - let btn = BKButton() - btn.setTitle(NSLocalizedString("hideAllGroups"), for: .selected) - btn.setTitle(NSLocalizedString("showAllGroups"), for: .normal) - btn.setTitleColor(Color.lightBlue.darken3, for: .normal) - btn.fontSize = 14 - return btn - }() - - let tableView: UITableView = { - let tableView = UITableView(frame: CGRect.zero, style: .insetGrouped) - tableView.separatorStyle = .singleLine - tableView.separatorColor = BKColor.grey.lighten3 - tableView.backgroundColor = BKColor.background.primary - tableView.register(GroupTableViewCell.self, forCellReuseIdentifier: "\(GroupTableViewCell.self)") - return tableView - }() - - override func makeUI() { - self.title = NSLocalizedString("group") - self.navigationItem.setRightBarButtonItem(item: UIBarButtonItem(customView: doneButton)) - - self.view.addSubview(tableView) - self.view.addSubview(showAllGroupsButton) - tableView.snp.makeConstraints { make in - make.top.equalToSuperview() - make.bottom.equalToSuperview().offset((kSafeAreaInsets.bottom + 40) * -1) - make.left.right.equalToSuperview() - } - showAllGroupsButton.snp.makeConstraints { make in - make.centerX.equalToSuperview() - make.height.equalTo(40) - make.bottom.equalToSuperview().offset(-kSafeAreaInsets.bottom) - } - - self.tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: 20)) - } - - override func bindViewModel() { - let output = viewModel.transform( - input: GroupFilterViewModel.Input( - showAllGroups: self.showAllGroupsButton.rx - .tap - .compactMap { [weak self] in - guard let strongSelf = self else { return nil } - return !strongSelf.showAllGroupsButton.isSelected - } - .asDriver(onErrorDriveWith: .empty()), - doneTap: self.doneButton.rx.tap.asDriver() - )) - - let dataSource = RxTableViewSectionedReloadDataSource> { _, tableView, _, item -> UITableViewCell in - guard let cell = tableView.dequeueReusableCell(withIdentifier: "\(GroupTableViewCell.self)") as? GroupTableViewCell else { - return UITableViewCell() - } - cell.bindViewModel(model: item) - return cell - } - - output.groups - .drive(tableView.rx.items(dataSource: dataSource)) - .disposed(by: rx.disposeBag) - - output.isShowAllGroups - .drive(self.showAllGroupsButton.rx.isSelected) - .disposed(by: rx.disposeBag) - - output.dismiss.drive(onNext: { [weak self] in - self?.dismiss(animated: true, completion: nil) - }) - .disposed(by: rx.disposeBag) - } -} - -extension GroupFilterViewController: UITableViewDelegate {} diff --git a/Controller/GroupFilterViewModel.swift b/Controller/GroupFilterViewModel.swift deleted file mode 100644 index 64b8566..0000000 --- a/Controller/GroupFilterViewModel.swift +++ /dev/null @@ -1,91 +0,0 @@ -// -// GroupFilterViewModel.swift -// Bark -// -// Created by huangfeng on 2021/6/8. -// Copyright © 2021 Fin. All rights reserved. -// - -import RealmSwift -import RxCocoa -import RxDataSources -import RxSwift - -struct GroupFilterModel { - var name: String? - var checked: Bool -} - -class GroupFilterViewModel: ViewModel, ViewModelType { - let groups: [GroupFilterModel] - init(groups: [GroupFilterModel]) { - self.groups = groups - } - - struct Input { - var showAllGroups: Driver - var doneTap: Driver - } - - struct Output { - var groups: Driver<[SectionModel]> - var isShowAllGroups: Driver - var dismiss: Driver - } - - var done = PublishRelay<[String?]>() - - func transform(input: Input) -> Output { - // 页面中的群组cellModel - let groupCellModels = self.groups.map { filterModel in - GroupCellViewModel(groupFilterModel: filterModel) - } - - // 点击显示所有群组或隐藏所有群组时,设置cell checked 勾选状态 - input.showAllGroups.drive(onNext: { isShowAllGroups in - for model in groupCellModels { - model.checked.accept(isShowAllGroups) - } - }).disposed(by: rx.disposeBag) - - // cell checked 状态改变 - let checkChanged = Observable.merge(groupCellModels.map { model in - model.checked.asObservable() - }) - - // 是否勾选了所有群组 - let isShowAllGroups = - checkChanged - .map { _ in - groupCellModels.filter { viewModel in - viewModel.checked.value - }.count >= groupCellModels.count - } - input.doneTap.map { () -> [String?] in - let isShowAllGroups = groupCellModels.filter { viewModel in - viewModel.checked.value - }.count >= groupCellModels.count - if isShowAllGroups { - return [] - } - return groupCellModels - .filter { $0.checked.value } - .map { $0.name.value } - } - .asObservable() - .bind(to: self.done) - .disposed(by: rx.disposeBag) - - let dismiss = PublishRelay() - input.doneTap.map { _ in () } - .asObservable() - .bind(to: dismiss) - .disposed(by: rx.disposeBag) - - return Output( - groups: Driver.just([SectionModel(model: "header", items: groupCellModels)]), - isShowAllGroups: isShowAllGroups.asDriver(onErrorDriveWith: .empty()), - dismiss: dismiss.asDriver(onErrorDriveWith: .empty()) - ) - } -} diff --git a/View/GroupCellViewModel.swift b/View/GroupCellViewModel.swift deleted file mode 100644 index e912ba0..0000000 --- a/View/GroupCellViewModel.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// GroupCellViewModel.swift -// Bark -// -// Created by huangfeng on 2021/6/8. -// Copyright © 2021 Fin. All rights reserved. -// - -import RxCocoa -import RxDataSources -import RxSwift -import UIKit - -class GroupCellViewModel: ViewModel { - let name = BehaviorRelay(value: nil) - let checked = BehaviorRelay(value: false) - - init(groupFilterModel: GroupFilterModel) { - self.name.accept(groupFilterModel.name) - self.checked.accept(groupFilterModel.checked) - } -} diff --git a/View/GroupTableViewCell.swift b/View/GroupTableViewCell.swift deleted file mode 100644 index 89c38a0..0000000 --- a/View/GroupTableViewCell.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -// GroupTableViewCell.swift -// Bark -// -// Created by huangfeng on 2021/6/8. -// Copyright © 2021 Fin. All rights reserved. -// - -import Material -import UIKit - -class GroupTableViewCell: BaseTableViewCell { - let nameLabel: UILabel = { - let label = UILabel() - label.fontSize = 14 - label.textColor = BKColor.grey.darken4 - return label - }() - - let checkButton: BKButton = { - let btn = BKButton() - btn.setImage(UIImage(named: "baseline_radio_button_unchecked_black_24pt"), for: .normal) - btn.setImage(UIImage(named: "baseline_check_circle_outline_black_24pt"), for: .selected) - btn.tintColor = BKColor.grey.base - btn.isUserInteractionEnabled = false - return btn - }() - - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - self.selectionStyle = .none - self.backgroundColor = BKColor.background.secondary - - self.contentView.addSubview(nameLabel) - self.contentView.addSubview(checkButton) - - checkButton.snp.makeConstraints { make in - make.width.height.equalTo(24) - make.left.equalToSuperview().offset(15) - make.centerY.equalToSuperview() - } - nameLabel.snp.makeConstraints { make in - make.left.equalTo(checkButton.snp.right).offset(15) - make.top.equalToSuperview().offset(15) - make.bottom.equalToSuperview().offset(-15) - } - let tap = UITapGestureRecognizer() - self.contentView.addGestureRecognizer(tap) - tap.rx.event.subscribe(onNext: { [weak self] _ in - self?.viewModel?.checked.accept(!self!.checkButton.isSelected) - }).disposed(by: rx.disposeBag) - } - - @available(*, unavailable) - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func bindViewModel(model: GroupCellViewModel) { - super.bindViewModel(model: model) - - model.name - .map { name in - name ?? NSLocalizedString("default") - } - .bind(to: nameLabel.rx.text) - .disposed(by: rx.reuseBag) - - model.checked - .bind(to: self.checkButton.rx.isSelected) - .disposed(by: rx.reuseBag) - - model.checked.subscribe( - onNext: { [weak self] checked in - self?.checkButton.tintColor = checked ? BKColor.lightBlue.darken3 : BKColor.grey.base - }).disposed(by: rx.reuseBag) - } -}