Skip to content

Commit

Permalink
ui: Show the waiting image in the UPL.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin42 committed Jan 24, 2025
1 parent 8831ec8 commit 5653bce
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 67 deletions.
8 changes: 8 additions & 0 deletions osx/PhotoBook/PhotoBook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@
73AC4FF92D3BAFE5001E19C8 /* FrontendImageResources.mm in Sources */ = {isa = PBXBuildFile; fileRef = 73AC4FF82D3BAFDC001E19C8 /* FrontendImageResources.mm */; };
73AC4FFF2D3BB3BC001E19C8 /* UnstagedImagesRepo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 73AC4FFE2D3BB3B9001E19C8 /* UnstagedImagesRepo.mm */; };
73AC50022D3BB43E001E19C8 /* StagedImagesView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 73AC50012D3BB437001E19C8 /* StagedImagesView.mm */; };
73AC500E2D403D7C001E19C8 /* UnstagedPhotoLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73AC500D2D403D75001E19C8 /* UnstagedPhotoLine.swift */; };
73AC50102D4040FF001E19C8 /* MediaList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73AC500F2D4040F9001E19C8 /* MediaList.swift */; };
73C4ECA22AA0C0E1006C4108 /* PhotoBookApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C4ECA12AA0C0E1006C4108 /* PhotoBookApp.swift */; };
73C4ECA42AA0C0E1006C4108 /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C4ECA32AA0C0E1006C4108 /* DashboardView.swift */; };
73C4ECA62AA0C0E3006C4108 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 73C4ECA52AA0C0E3006C4108 /* Assets.xcassets */; };
Expand Down Expand Up @@ -837,6 +839,8 @@
73AC4FFE2D3BB3B9001E19C8 /* UnstagedImagesRepo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UnstagedImagesRepo.mm; sourceTree = "<group>"; };
73AC50002D3BB42B001E19C8 /* StagedImagesView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StagedImagesView.h; sourceTree = "<group>"; };
73AC50012D3BB437001E19C8 /* StagedImagesView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = StagedImagesView.mm; sourceTree = "<group>"; };
73AC500D2D403D75001E19C8 /* UnstagedPhotoLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnstagedPhotoLine.swift; sourceTree = "<group>"; };
73AC500F2D4040F9001E19C8 /* MediaList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaList.swift; sourceTree = "<group>"; };
73C4EC9E2AA0C0E1006C4108 /* PhotoBook.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PhotoBook.app; sourceTree = BUILT_PRODUCTS_DIR; };
73C4ECA12AA0C0E1006C4108 /* PhotoBookApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoBookApp.swift; sourceTree = "<group>"; };
73C4ECA32AA0C0E1006C4108 /* DashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1651,6 +1655,8 @@
73C4ECA02AA0C0E1006C4108 /* PhotoBook */ = {
isa = PBXGroup;
children = (
73AC500F2D4040F9001E19C8 /* MediaList.swift */,
73AC500D2D403D75001E19C8 /* UnstagedPhotoLine.swift */,
73AC50012D3BB437001E19C8 /* StagedImagesView.mm */,
73AC50002D3BB42B001E19C8 /* StagedImagesView.h */,
73AC4FFE2D3BB3B9001E19C8 /* UnstagedImagesRepo.mm */,
Expand Down Expand Up @@ -1873,6 +1879,7 @@
73D02E5C2D18A2C50090476A /* ProjectManagementService.mm in Sources */,
73049E212C160EA9009EA667 /* PhotoBook-Bridging-Header.m in Sources */,
732A622C2D1CBC550012CB8A /* NewProjectDialog.swift in Sources */,
73AC50102D4040FF001E19C8 /* MediaList.swift in Sources */,
732A62282D1CBBDF0012CB8A /* DeleteProjectDialog.swift in Sources */,
73AC4FEC2D3B84C9001E19C8 /* MediaItem.swift in Sources */,
7356B06B2D16D12A0019FAEB /* NoirUIListener.swift in Sources */,
Expand All @@ -1884,6 +1891,7 @@
73AC4FF92D3BAFE5001E19C8 /* FrontendImageResources.mm in Sources */,
73AC4FFF2D3BB3BC001E19C8 /* UnstagedImagesRepo.mm in Sources */,
73C4ECA22AA0C0E1006C4108 /* PhotoBookApp.swift in Sources */,
73AC500E2D403D7C001E19C8 /* UnstagedPhotoLine.swift in Sources */,
73769A1E2AEEFA6400E9B5C2 /* TableContentView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 1 addition & 0 deletions osx/PhotoBook/PhotoBook/FrontendImageResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@property NSString* full;
@property NSString* medium;
@property NSString* small;
@property NSImage* smallImage;
@end

#endif /* FrontendImageResources_h */
64 changes: 64 additions & 0 deletions osx/PhotoBook/PhotoBook/MediaList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// MediaList.swift
// PhotoBook
//
// Created by Cosmin Mihai on 21.01.2025.
//

import SwiftUI

class MediaListModel: ObservableObject
{
@Published public var list: [MediaItem] = []
@Published public var selectedItem: MediaItem? = nil

@State var photobook: Photobook

init(photobook: Photobook)
{
_photobook = State(initialValue: photobook)
}

public func removeSelected()
{
if let index = list.firstIndex(where: {$0.path == selectedItem?.path})
{
list.remove(at: index)
self.photobook.removeImportFolder(selectedItem?.path)
}
}
}

struct MediaList: View
{
@State private var frameSize:CGSize
@ObservedObject var model: MediaListModel

private var tabViewRatio = 0.5

init(frameSize: CGSize, model: MediaListModel)
{
self.frameSize = frameSize
self.model = model
}

var body: some View {
VStack
{
List(model.list, id: \.self, selection: $model.selectedItem) { item in
HStack
{
Text("\(item.displayName)")
.listRowBackground(Color.PrimaryColor)
.font(.title)
}
.frame(height: 36)
}
.frame(width: frameSize.width * tabViewRatio)
.scrollIndicators(.hidden)
}
.frame(alignment:.leading)
.tag(0)
.scrollIndicators(.hidden)
}
}
107 changes: 40 additions & 67 deletions osx/PhotoBook/PhotoBook/TableContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ struct TableContentView: View, PhotobookUIListener {
@State var photobook: Photobook
@Binding var navigationPath: [String]

@State private var mediaList: [MediaItem] = []

@State var tabViewRatio = 0.5
@State var selectedTab: Int = 0

@State private var showImportMediaPicker = false

@State private var selectedMediaItem: MediaItem? = nil
@State private var uplModel:UnstagedPhotoLineModel = UnstagedPhotoLineModel()

@State private var mediaListModel:MediaListModel

@State private var uplList: [FrontendImage] = []

init(navigationPath:Binding<[String]>, photobook: Photobook)
{
_photobook = State(initialValue: photobook)
_navigationPath = navigationPath

mediaListModel = MediaListModel(photobook: photobook)
}

var body: some View {
Expand All @@ -53,11 +53,7 @@ struct TableContentView: View, PhotobookUIListener {
// Remove media button
Button(action: {
print("Remove media tapped")
if let index = mediaList.firstIndex(where: {$0.path == selectedMediaItem?.path})
{
mediaList.remove(at: index)
self.photobook.removeImportFolder(selectedMediaItem?.path)
}
mediaListModel.removeSelected()
}) {
Image(systemName: "trash")
.scaledToFit()
Expand All @@ -68,7 +64,7 @@ struct TableContentView: View, PhotobookUIListener {
.frame(alignment: .leading)
.background(Color.PrimaryColor)
.buttonStyle(PlainButtonStyle())
.disabled(mediaList.isEmpty)
.disabled(mediaListModel.list.isEmpty)

Button(action: {
print("Save tapped")
Expand Down Expand Up @@ -176,23 +172,38 @@ struct TableContentView: View, PhotobookUIListener {
.background(Color.PrimaryColor)
TabView(selection: $selectedTab) {
// Media list
VStack
MediaList(frameSize: geometry.size, model: self.mediaListModel)
.onReceive(mediaListModel.$selectedItem)
{
List(mediaList, id: \.self, selection: $selectedMediaItem) { item in
HStack
newValue in
if let newValue = newValue {
if let rowIndex = mediaListModel.list.firstIndex(where: {$0.path == newValue.path})
{
Text("\(item.displayName)")
.listRowBackground(Color.PrimaryColor)
.font(.title)
let rowSize:UInt32 = self.photobook.projectManagementService().unstagedImagesRepo().rowSize(UInt32(rowIndex))
for i in 0..<rowSize {
let image = self.photobook.projectManagementService().unstagedImagesRepo().image(UInt32(rowIndex), index:i)
if let unwrappedImage = image
{
if i >= self.uplModel.list.count
{
print(unwrappedImage.resources().small)
self.uplModel.list.append(unwrappedImage)
}
else
{
self.uplModel.list[Int(i)] = unwrappedImage
}
}
}
if (rowSize < uplModel.list.count)
{
uplModel.list.removeLast(Int(UInt32(uplModel.list.count) - UInt32(rowSize)))
}
}
.frame(height: 36)
} else {
self.uplModel.list.removeAll()
}
.frame(width: geometry.size.width * tabViewRatio)
.scrollIndicators(.hidden)
}
.frame(alignment:.leading)
.tag(0)
.scrollIndicators(.hidden)

VStack{
List(0..<20, id: \.self) { item in
Expand Down Expand Up @@ -252,20 +263,9 @@ struct TableContentView: View, PhotobookUIListener {
}
.padding(.horizontal)
}
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(self.uplList, id: \.self) { item in
RoundedRectangle(cornerRadius: 8)
.fill(Color.blue)
.frame(width: 80, height: 80)
.overlay(
Text("Item")
.foregroundColor(.white)
)
}
}
.padding(.horizontal)
}

UnstagedPhotoLine(model: uplModel)

}
.frame(height: geometry.size.height * 0.3)
.border(Color.BorderColor, width: 1)
Expand All @@ -283,43 +283,16 @@ struct TableContentView: View, PhotobookUIListener {
}
.foregroundColor(Color.MainFontColor)
.background(Color.PrimaryColor)
.onChange(of: selectedMediaItem) { newValue in
if let newValue = newValue {
if let rowIndex = mediaList.firstIndex(where: {$0.path == newValue.path})
{
let rowSize:UInt32 = self.photobook.projectManagementService().unstagedImagesRepo().rowSize(UInt32(rowIndex))
for i in 0..<rowSize {
let image = self.photobook.projectManagementService().unstagedImagesRepo().image(UInt32(rowIndex), index:i)
if let unwrappedImage = image
{
if i >= self.uplList.count
{
self.uplList.append(unwrappedImage)
}
else
{
self.uplList[Int(i)] = unwrappedImage
}
}
}
if (rowSize < uplList.count)
{
uplList.removeLast(Int(UInt32(uplList.count) - UInt32(rowSize)))
}
}
} else {
self.uplList.removeAll()
}
}

}

func onProjectRead(){}
func onMetadataUpdated(focusedName: String){}

func onMappingFinished(root: String){
let url = URL(fileURLWithPath: root)
self.mediaList.append(MediaItem(path:root, displayName: url.lastPathComponent))
selectedMediaItem = self.mediaList.last
self.mediaListModel.list.append(MediaItem(path:root, displayName: url.lastPathComponent))
self.mediaListModel.selectedItem = self.mediaListModel.list.last
}
}

56 changes: 56 additions & 0 deletions osx/PhotoBook/PhotoBook/UnstagedPhotoLine.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// UnstagedPhotoLine.swift
// PhotoBook
//
// Created by Cosmin Mihai on 21.01.2025.
//

import SwiftUI

class UnstagedPhotoLineModel: ObservableObject
{
@Published public var list: [FrontendImage] = []
}

struct UnstagedPhotoLine: View
{
@ObservedObject var model: UnstagedPhotoLineModel

init(model: UnstagedPhotoLineModel)
{
self.model = model
}

var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(self.model.list, id: \.self) { item in
if let fileName = item.resources().small
{
if let nsImage = NSImage(contentsOfFile: fileName) {
Image(nsImage: nsImage)
.frame(width: 80, height: 80)
} else {
Text("Image not found")
}
}
}
}
.padding(.horizontal)
}
}

func getImagePath(fileName: String) -> String? {
let fileManager = FileManager.default
do {
let documentsURL = try fileManager.url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false)
return documentsURL.appendingPathComponent(fileName).path
} catch {
print("Error getting documents directory: \(error)")
return nil
}
}
}

0 comments on commit 5653bce

Please sign in to comment.