Skip to content

Commit

Permalink
Refactor Search scene model objects and presentation (#19)
Browse files Browse the repository at this point in the history
* Refactor Search scene model objects and presentation to match the updated diagrams.
  • Loading branch information
sitomani committed Oct 9, 2023
1 parent f3344cd commit bdb2d09
Show file tree
Hide file tree
Showing 21 changed files with 250 additions and 233 deletions.
8 changes: 4 additions & 4 deletions 4champ.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
451B6AA52204B6CC001848FA /* LocalInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451B6A9F2204B6CC001848FA /* LocalInteractor.swift */; };
451B6AA72204BBBB001848FA /* ModuleStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451B6AA62204BBBB001848FA /* ModuleStorage.swift */; };
451ED0A6241E6AA6006CE4E8 /* SwiftUITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451ED0A5241E6AA6006CE4E8 /* SwiftUITest.swift */; };
451ED0AD241E8A83006CE4E8 /* PlaylistPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451ED0A7241E8A83006CE4E8 /* PlaylistPresenter.swift */; };
451ED0AF241E8A83006CE4E8 /* PlaylistRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451ED0A9241E8A83006CE4E8 /* PlaylistRouter.swift */; };
451ED0B0241E8A83006CE4E8 /* PlaylistModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451ED0AA241E8A83006CE4E8 /* PlaylistModels.swift */; };
451ED0B1241E8A83006CE4E8 /* PlaylistStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451ED0AB241E8A83006CE4E8 /* PlaylistStore.swift */; };
Expand Down Expand Up @@ -97,6 +96,7 @@
7397C1E629091D9D002D5CDB /* uade_ios.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7397C1E129091BC3002D5CDB /* uade_ios.xcframework */; };
7397C1E729091D9D002D5CDB /* uade_ios.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7397C1E129091BC3002D5CDB /* uade_ios.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
739B4BF42720850200C2D69F /* RadioSessionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739B4BF32720850200C2D69F /* RadioSessionCell.swift */; };
73CE92E52AAF03D1000BFC1C /* PlaylistPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73CE92E42AAF03D1000BFC1C /* PlaylistPresenter.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -131,7 +131,6 @@
451B6A9F2204B6CC001848FA /* LocalInteractor.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = LocalInteractor.swift; sourceTree = "<group>"; tabWidth = 2; };
451B6AA62204BBBB001848FA /* ModuleStorage.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = ModuleStorage.swift; sourceTree = "<group>"; tabWidth = 2; };
451ED0A5241E6AA6006CE4E8 /* SwiftUITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUITest.swift; sourceTree = "<group>"; };
451ED0A7241E8A83006CE4E8 /* PlaylistPresenter.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = PlaylistPresenter.swift; sourceTree = "<group>"; tabWidth = 2; };
451ED0A9241E8A83006CE4E8 /* PlaylistRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistRouter.swift; sourceTree = "<group>"; };
451ED0AA241E8A83006CE4E8 /* PlaylistModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistModels.swift; sourceTree = "<group>"; };
451ED0AB241E8A83006CE4E8 /* PlaylistStore.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = PlaylistStore.swift; sourceTree = "<group>"; tabWidth = 2; };
Expand Down Expand Up @@ -228,6 +227,7 @@
7397C1DC29091504002D5CDB /* UADEReplayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UADEReplayer.m; sourceTree = "<group>"; };
7397C1E129091BC3002D5CDB /* uade_ios.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = uade_ios.xcframework; path = "../uade-ios/uade_ios.xcframework"; sourceTree = "<group>"; };
739B4BF32720850200C2D69F /* RadioSessionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSessionCell.swift; sourceTree = "<group>"; };
73CE92E42AAF03D1000BFC1C /* PlaylistPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlaylistPresenter.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -366,9 +366,9 @@
456E6F2A2409BC2C0034BDA2 /* Playlists */ = {
isa = PBXGroup;
children = (
73CE92E42AAF03D1000BFC1C /* PlaylistPresenter.swift */,
456E6F2D240A5FAF0034BDA2 /* PlaylistView.swift */,
45CEA1E02415005E00930A72 /* SelectPlaylistView.swift */,
451ED0A7241E8A83006CE4E8 /* PlaylistPresenter.swift */,
451ED0A9241E8A83006CE4E8 /* PlaylistRouter.swift */,
451ED0AA241E8A83006CE4E8 /* PlaylistModels.swift */,
451ED0AB241E8A83006CE4E8 /* PlaylistStore.swift */,
Expand Down Expand Up @@ -671,14 +671,14 @@
450E506721879347008FB155 /* SettingsModels.swift in Sources */,
45D61F5120E1647300869814 /* RadioPresenter.swift in Sources */,
453D9BBC241BF286002EEBAB /* PlaylistSelectorStore.swift in Sources */,
451ED0AD241E8A83006CE4E8 /* PlaylistPresenter.swift in Sources */,
4535A4662114BB2D005FBB8B /* SearchRouter.swift in Sources */,
4535A4642114BB2D005FBB8B /* SearchPresenter.swift in Sources */,
45855FCD2444AC6B0079C767 /* ModuleSharing.swift in Sources */,
450E506621879347008FB155 /* SettingsRouter.swift in Sources */,
4509EA48226251EF0031408D /* ModuleInfo+CoreDataProperties.swift in Sources */,
451B6AA42204B6CC001848FA /* LocalViewController.swift in Sources */,
454F5205215D20F3007011F3 /* ModuleFetcher.swift in Sources */,
73CE92E52AAF03D1000BFC1C /* PlaylistPresenter.swift in Sources */,
451ED0B2241E8A83006CE4E8 /* PlaylistInteractor.swift in Sources */,
45D61F5320E1647300869814 /* RadioRouter.swift in Sources */,
453D9BBA241BF286002EEBAB /* PlaylistSelectorRouter.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
{
"object": {
"pins": [
{
"package": "Alamofire",
"repositoryURL": "https://github.com/Alamofire/Alamofire",
"state": {
"branch": null,
"revision": "f96b619bcb2383b43d898402283924b80e2c4bae",
"version": "5.4.3"
}
},
{
"package": "Gzip",
"repositoryURL": "https://github.com/1024jp/GzipSwift",
"state": {
"branch": null,
"revision": "ba0b6cb51cc6202f896e469b87d2889a46b10d1b",
"version": "5.1.1"
}
},
{
"package": "SwiftyBeaver",
"repositoryURL": "https://github.com/SwiftyBeaver/SwiftyBeaver",
"state": {
"branch": null,
"revision": "5cfd6888447adcc49b80b625281b6177104f011f",
"version": "1.9.4"
}
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "f96b619bcb2383b43d898402283924b80e2c4bae",
"version" : "5.4.3"
}
]
},
"version": 1
},
{
"identity" : "gzipswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/1024jp/GzipSwift",
"state" : {
"revision" : "ba0b6cb51cc6202f896e469b87d2889a46b10d1b",
"version" : "5.1.1"
}
},
{
"identity" : "swiftybeaver",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SwiftyBeaver/SwiftyBeaver",
"state" : {
"revision" : "5cfd6888447adcc49b80b625281b6177104f011f",
"version" : "1.9.4"
}
}
],
"version" : 2
}
16 changes: 9 additions & 7 deletions 4champ/Data/Structs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ struct Notifications {
static let badgeUpdate = Notification.Name("badge_update")
}

struct MMD: Identifiable {
struct MMD: Identifiable, NameComparable {

init() {
name = ""
}

static let supportedTypes: [String] = Replay.supportedFormats
Expand All @@ -42,9 +44,9 @@ struct MMD: Identifiable {
if let path = cdi.modLocalPath {
self.localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(path)
} else {
log.error("Module \(cdi.modName ?? "noname") file not available")
log.error("Module \(cdi.modName ?? "") file not available")
}
self.name = cdi.modName
self.name = cdi.modName ?? ""
self.size = cdi.modSize?.intValue
self.type = cdi.modType
self.serviceId = ModuleService.init(rawValue: cdi.serviceId?.intValue ?? 1) ?? .amp
Expand All @@ -63,15 +65,15 @@ struct MMD: Identifiable {
if let modNameParts = components.last?.components(separatedBy: ".") {
type = modNameParts.first ?? "MOD"
name = modNameParts[1...modNameParts.count - 2].joined(separator: ".")
name = name?.replacingOccurrences(of: "%", with: "%25") // replace percent signs with encoding
name = name?.removingPercentEncoding // before removing the encoding
localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(name!).appendingPathExtension(type!)
name = name.replacingOccurrences(of: "%", with: "%25") // replace percent signs with encoding
name = name.removingPercentEncoding ?? "" // before removing the encoding
localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(name).appendingPathExtension(type!)
}
}
}

var id: Int?
var name: String?
var name: String
var type: String?
var composer: String?
var size: Int?
Expand Down
4 changes: 2 additions & 2 deletions 4champ/Networking/ModuleFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ class ModuleFetcher {
// store to file and make sure it's not writing over an existing mod
var numberExt = 0
var localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.last!.appendingPathComponent(mmd.name!).appendingPathExtension(mmd.type!)
.last!.appendingPathComponent(mmd.name).appendingPathExtension(mmd.type!)
while FileManager.default.fileExists(atPath: localPath.path) {
numberExt += 1
let filename = mmd.name! + "_\(numberExt)"
let filename = mmd.name + "_\(numberExt)"
localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.last!.appendingPathComponent(filename).appendingPathExtension(mmd.type!)
}
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Replay/ModulePlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ModulePlayer: NSObject {
didSet {
if let mod = currentModule {
let author = mod.composer
let songName = mod.name!
let songName = mod.name
let playlistName = "LockScreen_Radio".l13n()

let artwork = MPMediaItemArtwork.init(boundsSize: mpImage.size, requestHandler: { (_) -> UIImage in
Expand Down
37 changes: 17 additions & 20 deletions 4champ/Scenes/DownloadView/DownloadHostingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,10 @@ class DownloadController: NSObject, ObservableObject {
}

private func buildSummary(mod: MMD) -> String {
if let name = mod.name, let composer = mod.composer, composer.count > 0 {
return "\(name) by \(composer)"
if let composer = mod.composer, composer.trimmingCharacters(in: CharacterSet.whitespaces).count > 0 {
return "\(mod.name) by \(composer)"
}
if let name = mod.name {
return name
}
return "..."
return mod.name
}

func showImport(for urls: [URL]) {
Expand Down Expand Up @@ -157,18 +154,18 @@ class DownloadController: NSObject, ObservableObject {

var summaryItems: [String] = []

if imported > 0 {
if alreadyImported > 0 || unknown > 0 {
summaryItems.append(String.init(format: "Local_Import_Imported".l13n(), "\(imported)"))
} else {
let names: [String] = model.importIds.compactMap {
if let mod = moduleStorage.getModuleById($0), let name = mod.name {
return name
if imported > 0 {
if alreadyImported > 0 || unknown > 0 {
summaryItems.append(String.init(format: "Local_Import_Imported".l13n(), "\(imported)"))
} else {
let names: [String] = model.importIds.compactMap {
if let mod = moduleStorage.getModuleById($0) {
return mod.name
}
return nil
}
return nil
}
if names.count > 10 {
summaryItems.append(names.joined(separator: ", ") + ", ...")
if names.count > 10 {
summaryItems.append(names.joined(separator: ", ") + ", ...")

} else {
summaryItems.append(names.joined(separator: ", "))
Expand Down Expand Up @@ -321,11 +318,11 @@ class DownloadController: NSObject, ObservableObject {

private func copyFileToDocumentsDirectory(from url: URL, with mmd: inout MMD, status: inout ImportResultType?) -> URL? {
var numberExt = 0
var localPath = FileManager.default.urls(for: .documentDirectory,
in: .userDomainMask).last!.appendingPathComponent(mmd.name!).appendingPathExtension(mmd.type!)
var localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.last!.appendingPathComponent(mmd.name).appendingPathExtension(mmd.type!)
while FileManager.default.fileExists(atPath: localPath.path) {
numberExt += 1
let filename = mmd.name! + "_\(numberExt)"
let filename = mmd.name + "_\(numberExt)"
localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.last!.appendingPathComponent(filename).appendingPathExtension(mmd.type!)
}
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Scenes/Local/LocalInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class LocalInteractor: NSObject, LocalBusinessLogic, LocalDataStore {
if let path = mi.modLocalPath {
module.localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(path)
} else {
log.error("file not available for module \(module.name ?? "no name available")")
log.error("file not available for module \(module.name)")
}
module.name = mi.modName ?? ""
module.size = mi.modSize?.intValue ?? 0
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Scenes/Local/ModuleStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ModuleStorage: NSObject {
super.init()
var _ = persistentStoreCoordinator
let name = managedObjectContext.name
log.info(name ?? "noname")
log.info(name ?? "managedObjectContext does not have name")

setCurrentPlaylist(playlist: getDefaultPlaylist())
}
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Scenes/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class MainViewController: UITabBarController {

extension MainViewController: ModulePlayerObserver {
func moduleChanged(module: MMD, previous: MMD?) {
log.info("\(module.name!) (\(module.type!))")
log.info("\(module.name) (\(module.type!))")
DispatchQueue.main.async {
self.npView.setModule(module)
}
Expand Down
4 changes: 2 additions & 2 deletions 4champ/Scenes/NowPlayingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class NowPlayingView: UIView {
@IBOutlet weak var shareButton: UIButton?

func setModule(_ module: MMD) {
titleLabel?.text = "\(module.name!) (\(module.type!))"
composerLabel?.text = module.composer!
titleLabel?.text = "\(module.name) (\(module.type!))"
composerLabel?.text = (module.composer?.trimmingCharacters(in: .whitespaces).count ?? 0) > 0 ? module.composer : " "
saveButton?.isHidden = module.hasBeenSaved()
faveButton?.isSelected = module.favorite
// For now, hide the share button (sharing through the long-tap menu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class PlaylistSelectorPresenter: PlaylistSelectorPresentationLogic {
}
}

var moduleName = response.module.name ?? ""
if let mName = response.module.name, let cName = response.module.composer, cName.count > 0 {
moduleName = String.init(format: "LockScreen_Playing".l13n(), mName, cName)
var moduleName = response.module.name
if let cName = response.module.composer, cName.count > 0 {
moduleName = String.init(format: "LockScreen_Playing".l13n(), moduleName, cName)
}

let status: DownloadStatus = response.module.hasBeenSaved() ? .complete : .unknown
Expand Down
70 changes: 35 additions & 35 deletions 4champ/Scenes/Playlists/PlaylistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@ import UIKit
import SwiftUI

struct SUIModule: View {
let module: MMD
let faveCallback: ((MMD) -> Void)?
var body: some View {
VStack {
HStack {
ZStack {
Image(uiImage: UIImage.init(named: "modicon")!).resizable().frame(width: 50, height: 50)
Text(module.type?.uppercased() ?? "MOD")
.foregroundColor(Color.black)
.font(.system(size: 12))
.offset(y: 13)
if module.supported() == false {
Image(uiImage: UIImage.init(named: "stopicon")!)
.resizable()
.frame(width: 30, height: 30).offset(x: -15)
}
}.padding(EdgeInsets(top: 10, leading: 10, bottom: 3, trailing: 0))
VStack(alignment: .leading) {
Text("\(module.name ?? "no name")")
.font(.system(size: 18))
.foregroundColor(.white)
if let composer = module.composer, composer.count > 0 {
Text(module.composer ?? "no name").font(.system(size: 12))
.foregroundColor(.white)
}
Text("\(module.size ?? 0) kb").font(.system(size: 12))
.foregroundColor(.white)
let module: MMD
let faveCallback: ((MMD) -> Void)?
var body: some View {
VStack {
HStack {
ZStack {
Image(uiImage: UIImage.init(named: "modicon")!).resizable().frame(width: 50, height: 50)
Text(module.type?.uppercased() ?? "MOD")
.foregroundColor(Color.black)
.font(.system(size: 12))
.offset(y: 13)
if module.supported() == false {
Image(uiImage: UIImage.init(named: "stopicon")!)
.resizable()
.frame(width: 30, height: 30).offset(x: -15)
}
}.padding(EdgeInsets(top: 10, leading: 10, bottom: 3, trailing: 0))
VStack(alignment: .leading) {
Text("\(module.name)")
.font(.system(size: 18))
.foregroundColor(.white)
if let composer = module.composer, composer.count > 0 {
Text(module.composer ?? "no name").font(.system(size: 12))
.foregroundColor(.white)
}
Text("\(module.size ?? 0) kb").font(.system(size: 12))
.foregroundColor(.white)
}
Spacer()
Image(module.favorite ? "favestar-yellow" : "favestar-grey").padding(8).onTapGesture {
self.faveCallback?(self.module)
}.padding(7)
}
Spacer()
Image(module.favorite ? "favestar-yellow" : "favestar-grey").padding(8).onTapGesture {
self.faveCallback?(self.module)
}.padding(7)
}
Divider().background(Color(Appearance.separatorColor))
}.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
}
Divider().background(Color(Appearance.separatorColor))
}.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
}
}

struct PlaylistView: View {
Expand Down
4 changes: 1 addition & 3 deletions 4champ/Scenes/Radio/RadioPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class RadioPresenter: RadioPresentationLogic {
log.debug("")
var nextUp: String?
if buffer.count > 1 {
nextUp = "Radio_NextUp".l13n() + " " + String.init(format: "Radio_NByN".l13n(),
buffer[1].name ?? "G_untitled".l13n(),
buffer[1].composer ?? "G_untitled".l13n() )
nextUp = "Radio_NextUp".l13n() + " " + String.init(format: "Radio_NByN".l13n(), buffer[1].name, buffer[1].composer ?? "G_untitled".l13n() )
}

let canStepBack = history.count > 0 && buffer.first != history.last
Expand Down
Loading

0 comments on commit bdb2d09

Please sign in to comment.