Skip to content

Commit

Permalink
added itemImage function.
Browse files Browse the repository at this point in the history
Should probably add a type property enum to FSItem instead of comparin extensions though
  • Loading branch information
alessaba committed Jan 3, 2021
1 parent 3913fd4 commit 3b04601
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "32">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/FilippoBrowser WatchKit App">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B4BED82233531D9005E5BB1"
BuildableName = "FilippoBrowser WatchKit App.app"
BlueprintName = "FilippoBrowser WatchKit App"
ReferencedContainer = "container:FilippoBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -73,16 +75,27 @@
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "32">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/FilippoBrowser WatchKit App">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B4BED82233531D9005E5BB1"
BuildableName = "FilippoBrowser WatchKit App.app"
BlueprintName = "FilippoBrowser WatchKit App"
ReferencedContainer = "container:FilippoBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B4BED82233531D9005E5BB1"
BuildableName = "FilippoBrowser WatchKit App.app"
BlueprintName = "FilippoBrowser WatchKit App"
ReferencedContainer = "container:FilippoBrowser.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,46 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/FilippoBrowser WatchKit App">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B4BED82233531D9005E5BB1"
BuildableName = "FilippoBrowser WatchKit App.app"
BlueprintName = "FilippoBrowser WatchKit App"
ReferencedContainer = "container:FilippoBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/FilippoBrowser WatchKit App">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B4BED82233531D9005E5BB1"
BuildableName = "FilippoBrowser WatchKit App.app"
BlueprintName = "FilippoBrowser WatchKit App"
ReferencedContainer = "container:FilippoBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B4BED82233531D9005E5BB1"
BuildableName = "FilippoBrowser WatchKit App.app"
BlueprintName = "FilippoBrowser WatchKit App"
ReferencedContainer = "container:FilippoBrowser.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
52 changes: 22 additions & 30 deletions FilippoBrowser/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct FileViewer : View {

var body: some View {
VStack {
#warning("Forse dovrei creare una enum per stabilire di partenza il tipo di file, invece di fare controlli con le estensioni")
if (imageExtensions.contains(getExtension(self.file.path))){
Image(uiImage: UIImage(contentsOfFile: self.file.path)!)
.resizable()
Expand All @@ -103,6 +104,21 @@ struct FileViewer : View {
}
}

func itemImage(for item: FSItem) -> String {

if item.isFolder {
return "folder.fill"
} else if imageExtensions.contains(getExtension(item.lastComponent)) {
return "photo.fill"
} else if listExtensions.contains(getExtension(item.lastComponent)){
return "list.bullet.indent"
} else if textExtensions.contains(getExtension(item.lastComponent)) {
return "doc.text.fill"
} else {
return "doc.fill"
}
}

// MARK: Directory List Viewer
// This is the directory browser, it shows files and subdirectories of a folder in list style
struct DirectoryListBrowser : View {
Expand Down Expand Up @@ -131,20 +147,8 @@ struct DirectoryListBrowser : View {
}) { subItem in
HStack{
// Test for various file types and assign icons (SFSymbols, which are GREAT <3)
Group{
if subItem.isFolder {
Image(systemName: "folder.fill")
} else if imageExtensions.contains(getExtension(subItem.lastComponent)) {
Image(systemName: "photo.fill")
} else if listExtensions.contains(getExtension(subItem.lastComponent)){
Image(systemName: "list.bullet.indent")
} else if textExtensions.contains(getExtension(subItem.lastComponent)) {
Image(systemName: "doc.text.fill")
} else {
Image(systemName: "doc.fill")
}
}
.foregroundColor((subItem.rootProtected) ? .orange : .green)
Image(systemName: itemImage(for: subItem))
.foregroundColor((subItem.rootProtected) ? .orange : .green)



Expand Down Expand Up @@ -243,21 +247,9 @@ struct DirectoryGridBrowser : View {
}) { subItem in
VStack{
// Test for various file types and assign icons (SFSymbols, which are GREAT <3)
Group{
if subItem.isFolder {
Image(systemName: "folder.fill")
} else if imageExtensions.contains(getExtension(subItem.lastComponent)) {
Image(systemName: "photo.fill")
} else if listExtensions.contains(getExtension(subItem.lastComponent)){
Image(systemName: "list.bullet.indent")
} else if textExtensions.contains(getExtension(subItem.lastComponent)) {
Image(systemName: "doc.text.fill")
} else {
Image(systemName: "doc.fill")
}
}
.foregroundColor((subItem.rootProtected) ? .orange : .green)
.padding(.vertical, 5)
Image(systemName: itemImage(for: subItem))
.foregroundColor((subItem.rootProtected) ? .orange : .green)
.padding(.vertical, 5)



Expand Down Expand Up @@ -287,7 +279,7 @@ struct DirectoryGridBrowser : View {
Text(subItem.lastComponent)
Button(action: {
setFavorite(name: subItem.lastComponent, path: subItem.path)
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"))
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"))
UIApplication.shared.shortcutItems?.append(newFavorite)
NSLog("Added to Favorites.")
}){
Expand Down

0 comments on commit 3b04601

Please sign in to comment.