Skip to content

Commit

Permalink
添加上传自定义铃声UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Mar 29, 2024
1 parent e8f33bc commit d2f1340
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 27 deletions.
4 changes: 4 additions & 0 deletions Bark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
0661A54D204FDA4100965E4E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */; };
0667D192247D162C005DE2ED /* MessageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0667D191247D162C005DE2ED /* MessageTableViewCell.swift */; };
0667D194247D1BA0005DE2ED /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0667D193247D1BA0005DE2ED /* Date+Extension.swift */; };
066E0C8C2BB6AC9A00873838 /* AddSoundCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 066E0C8B2BB6AC9A00873838 /* AddSoundCell.swift */; };
0672CB06256903F700570C9D /* MessageListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0672CB05256903F700570C9D /* MessageListViewModel.swift */; };
06787C392A710568008ABDD7 /* GesturePassTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06787C382A710568008ABDD7 /* GesturePassTextView.swift */; };
06787C3B2AB82BDB008ABDD7 /* CrashReportViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06787C3A2AB82BDB008ABDD7 /* CrashReportViewController.swift */; };
Expand Down Expand Up @@ -267,6 +268,7 @@
0661A54E204FDA4100965E4E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0667D191247D162C005DE2ED /* MessageTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageTableViewCell.swift; sourceTree = "<group>"; };
0667D193247D1BA0005DE2ED /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.swift"; sourceTree = "<group>"; };
066E0C8B2BB6AC9A00873838 /* AddSoundCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddSoundCell.swift; sourceTree = "<group>"; };
0672CB05256903F700570C9D /* MessageListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewModel.swift; sourceTree = "<group>"; };
06787C382A710568008ABDD7 /* GesturePassTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GesturePassTextView.swift; sourceTree = "<group>"; };
06787C3A2AB82BDB008ABDD7 /* CrashReportViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashReportViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -405,6 +407,7 @@
06BBB8BB2567B3AD0076F63E /* ArchiveSettingCellViewModel.swift */,
060481EF250F51CA00BC9799 /* SoundCell.swift */,
065BE44F2563D939002A8CA4 /* SoundCellViewModel.swift */,
066E0C8B2BB6AC9A00873838 /* AddSoundCell.swift */,
062B98C2251B2762004562E7 /* BKButton.swift */,
06C595352481160F006B98F3 /* BKLabel.swift */,
062B98C7251B27AE004562E7 /* UINavigationItem+Extension.swift */,
Expand Down Expand Up @@ -952,6 +955,7 @@
068EC15A27ED99E700D5D11E /* ServerListViewModel.swift in Sources */,
06172FDC27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift in Sources */,
061894C729A75BEA00E001C2 /* Algorithm.swift in Sources */,
066E0C8C2BB6AC9A00873838 /* AddSoundCell.swift in Sources */,
065BE4502563D939002A8CA4 /* SoundCellViewModel.swift in Sources */,
06F08EA729B1DDFE006AB9CA /* Error+Extension.swift in Sources */,
06B1158F247BB1FB006D91FB /* Message.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"symbols" : [
{
"filename" : "music_note-music_note_symbol.svg",
"idiom" : "universal"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Bark/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ Email: to@day.app
Telegram: https://t.me/joinchat/OsCbLzovUAE0YjY1
Github Issue: https://github.com/Finb/Bark/issues
";

uploadSound = "Upload Sound";
customSounds = "Custom Sounds";
defaultSounds = "Default Sounds";
4 changes: 4 additions & 0 deletions Bark/tr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ Email: to@day.app
Telegram: https://t.me/joinchat/OsCbLzovUAE0YjY1
Github Issue: https://github.com/Finb/Bark/issues
";

uploadSound = "Upload Sound";
customSounds = "Custom Sounds";
defaultSounds = "Default Sounds";
4 changes: 4 additions & 0 deletions Bark/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ https://bark.day.app/#/faq
Telegram: https://t.me/joinchat/OsCbLzov
Github Issue: https://github.com/Finb/Bark/issues
";

uploadSound = "上传铃声";
customSounds = "自定义铃声";
defaultSounds = "默认铃声";
68 changes: 50 additions & 18 deletions Controller/SoundsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,55 @@ import RxSwift

class SoundsViewController: BaseViewController<SoundsViewModel> {
let tableView: UITableView = {
let tableView = UITableView()
let tableView = UITableView(frame: CGRect.zero, style: .insetGrouped)
tableView.backgroundColor = BKColor.background.primary
tableView.register(SoundCell.self, forCellReuseIdentifier: "\(SoundCell.self)")
tableView.register(AddSoundCell.self, forCellReuseIdentifier: "\(AddSoundCell.self)")
return tableView
}()

override func makeUI() {
self.title = NSLocalizedString("notificationSound")

self.view.addSubview(self.tableView)
self.tableView.delegate = self
self.tableView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}

self.tableView.tableHeaderView = {
let header = UILabel()
header.fontSize = 12
header.text = " \(NSLocalizedString("previewSound"))"
header.textColor = BKColor.grey.darken1
header.frame = CGRect(x: 0, y: 0, width: 0, height: 40)
return header
}()
}

override func bindViewModel() {
let output = viewModel.transform(
input: SoundsViewModel.Input(soundSelected: self.tableView.rx
.modelSelected(SoundCellViewModel.self)
.modelSelected(SoundItem.self)
.asDriver()))

let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, SoundCellViewModel>> { _, tableView, _, item -> UITableViewCell in
guard let cell = tableView.dequeueReusableCell(withIdentifier: "\(SoundCell.self)") as? SoundCell else {
return UITableViewCell()
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, SoundItem>> { _, tableView, _, item -> UITableViewCell in
switch item {
case .sound(let model):
guard let cell = tableView.dequeueReusableCell(withIdentifier: "\(SoundCell.self)") as? SoundCell else {
return UITableViewCell()
}
cell.bindViewModel(model: model)
return cell
case .addSound:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "\(AddSoundCell.self)") else {
return UITableViewCell()
}
return cell
}
cell.bindViewModel(model: item)
return cell

} titleForHeaderInSection: { dataSource, section in
return dataSource[section].model
}

output.audios
.bind(to: tableView.rx.items(dataSource: dataSource))
.disposed(by: rx.disposeBag)

output.copyNameAction.drive(onNext: { [weak self] name in
output.copyNameAction.drive(onNext: { [unowned self] name in
UIPasteboard.general.string = name.trimmingCharacters(in: .whitespacesAndNewlines)
self?.navigationController?.showSnackbar(text: NSLocalizedString("Copy"))
self.navigationController?.showSnackbar(text: NSLocalizedString("Copy"))
}).disposed(by: rx.disposeBag)

output.playAction.drive(onNext: { url in
Expand All @@ -71,5 +75,33 @@ class SoundsViewController: BaseViewController<SoundsViewModel> {
AudioServicesDisposeSystemSoundID(soundID)
}
}).disposed(by: rx.disposeBag)

output.pickerFile.drive(onNext: { [unowned self] _ in

}).disposed(by: rx.disposeBag)
}
}

extension SoundsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let sectionTitle = tableView.dataSource?.tableView?(tableView, titleForHeaderInSection: section) ?? ""

let view = UIView()

let label = UILabel()
label.text = NSLocalizedString(sectionTitle)
label.fontSize = 14
label.textColor = BKColor.grey.darken3
view.addSubview(label)
label.snp.makeConstraints { make in
make.left.equalTo(12)
make.centerY.equalToSuperview()
}

return view
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
}
Loading

0 comments on commit d2f1340

Please sign in to comment.