@@ -82,6 +82,7 @@ struct FileViewer : View {
8282
8383 var body : some View {
8484 VStack {
85+ #warning("Forse dovrei creare una enum per stabilire di partenza il tipo di file, invece di fare controlli con le estensioni")
8586 if ( imageExtensions. contains ( getExtension ( self . file. path) ) ) {
8687 Image ( uiImage: UIImage ( contentsOfFile: self . file. path) !)
8788 . resizable ( )
@@ -103,6 +104,21 @@ struct FileViewer : View {
103104 }
104105}
105106
107+ func itemImage( for item: FSItem ) -> String {
108+
109+ if item. isFolder {
110+ return " folder.fill "
111+ } else if imageExtensions. contains ( getExtension ( item. lastComponent) ) {
112+ return " photo.fill "
113+ } else if listExtensions. contains ( getExtension ( item. lastComponent) ) {
114+ return " list.bullet.indent "
115+ } else if textExtensions. contains ( getExtension ( item. lastComponent) ) {
116+ return " doc.text.fill "
117+ } else {
118+ return " doc.fill "
119+ }
120+ }
121+
106122// MARK: Directory List Viewer
107123// This is the directory browser, it shows files and subdirectories of a folder in list style
108124struct DirectoryListBrowser : View {
@@ -131,20 +147,8 @@ struct DirectoryListBrowser : View {
131147 } ) { subItem in
132148 HStack {
133149 // Test for various file types and assign icons (SFSymbols, which are GREAT <3)
134- Group {
135- if subItem. isFolder {
136- Image ( systemName: " folder.fill " )
137- } else if imageExtensions. contains ( getExtension ( subItem. lastComponent) ) {
138- Image ( systemName: " photo.fill " )
139- } else if listExtensions. contains ( getExtension ( subItem. lastComponent) ) {
140- Image ( systemName: " list.bullet.indent " )
141- } else if textExtensions. contains ( getExtension ( subItem. lastComponent) ) {
142- Image ( systemName: " doc.text.fill " )
143- } else {
144- Image ( systemName: " doc.fill " )
145- }
146- }
147- . foregroundColor ( ( subItem. rootProtected) ? . orange : . green)
150+ Image ( systemName: itemImage ( for: subItem) )
151+ . foregroundColor ( ( subItem. rootProtected) ? . orange : . green)
148152
149153
150154
@@ -243,21 +247,9 @@ struct DirectoryGridBrowser : View {
243247 } ) { subItem in
244248 VStack {
245249 // Test for various file types and assign icons (SFSymbols, which are GREAT <3)
246- Group {
247- if subItem. isFolder {
248- Image ( systemName: " folder.fill " )
249- } else if imageExtensions. contains ( getExtension ( subItem. lastComponent) ) {
250- Image ( systemName: " photo.fill " )
251- } else if listExtensions. contains ( getExtension ( subItem. lastComponent) ) {
252- Image ( systemName: " list.bullet.indent " )
253- } else if textExtensions. contains ( getExtension ( subItem. lastComponent) ) {
254- Image ( systemName: " doc.text.fill " )
255- } else {
256- Image ( systemName: " doc.fill " )
257- }
258- }
259- . foregroundColor ( ( subItem. rootProtected) ? . orange : . green)
260- . padding ( . vertical, 5 )
250+ Image ( systemName: itemImage ( for: subItem) )
251+ . foregroundColor ( ( subItem. rootProtected) ? . orange : . green)
252+ . padding ( . vertical, 5 )
261253
262254
263255
@@ -287,7 +279,7 @@ struct DirectoryGridBrowser : View {
287279 Text ( subItem. lastComponent)
288280 Button ( action: {
289281 setFavorite ( name: subItem. lastComponent, path: subItem. path)
290- let newFavorite = UIMutableApplicationShortcutItem ( type: " FB_ \( subItem. lastComponent) " , localizedTitle: subItem. lastComponent, localizedSubtitle: subItem. path, icon: UIApplicationShortcutIcon ( systemImageName: subItem. isFolder ? " folder.fill " : " square.and.arrow.down.fill " ) )
282+ let newFavorite = UIMutableApplicationShortcutItem ( type: " FB_ \( subItem. lastComponent) " , localizedTitle: subItem. lastComponent, localizedSubtitle: subItem. path, icon: UIApplicationShortcutIcon ( systemImageName: itemImage ( for : subItem ) ) ) // subItem.isFolder ? "folder.fill" : "square.and.arrow.down.fill"))
291283 UIApplication . shared. shortcutItems? . append ( newFavorite)
292284 NSLog ( " Added to Favorites. " )
293285 } ) {
0 commit comments