Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
enzevalos_iphone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
enzevalos
enzevalos_iphone
Commits
5dd39db5
Commit
5dd39db5
authored
4 years ago
by
wieseoli
Browse files
Options
Downloads
Plain Diff
Merge branch '292-add-comments-to-attachmentviewmain-swift' into 'dev'
Resolve "Add comments to: AttachmentViewMain.swift" Closes
#292
See merge request
!79
parents
952cf19e
7150ad6f
Branches
Branches containing commit
No related tags found
1 merge request
!79
Resolve "Add comments to: AttachmentViewMain.swift"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
enzevalos_iphone/SwiftUI/Read/ReadMainView.swift
+1
-1
1 addition, 1 deletion
enzevalos_iphone/SwiftUI/Read/ReadMainView.swift
enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift
+174
-114
174 additions, 114 deletions
...phone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift
with
175 additions
and
115 deletions
enzevalos_iphone/SwiftUI/Read/ReadMainView.swift
+
1
−
1
View file @
5dd39db5
...
...
@@ -66,7 +66,7 @@ struct ReadMainView <M: DisplayMail>: View {
tab
:
ReadPart
.
Attachments
.
value
,
image
:
Image
(
systemName
:
"rectangle.and.paperclip"
),
description
:
"Tab.Label.Attachments"
,
content
:
AnyView
(
AttachmentsViewMain
(
attachments
:
model
.
mail
.
displayAttachments
,
d
l
All
:
true
))
content
:
AnyView
(
AttachmentsViewMain
(
attachments
:
model
.
mail
.
displayAttachments
,
d
ownload
All
:
true
))
)
]
}
...
...
This diff is collapsed.
Click to expand it.
enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift
+
174
−
114
View file @
5dd39db5
...
...
@@ -15,29 +15,40 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/// a file that preview the attachments of incoming mails
// currently this view only previews a ProxyAttachment
import
SwiftUI
struct
AttachmentsViewMain
:
View
{
// TODO: Refactor to model?
//a list that contains all the attachment files
@State
var
attachments
:
[
DisplayAttachment
]
// Whether the Download all button was clicked
@State
var
d
l
All
=
true
;
@State
var
d
ownload
All
=
true
;
var
body
:
some
View
{
VStack
{
Spacer
()
// TODO: Add link section
//
check
if there
even
are attachments to be displayed
//
default view
if there are
no
attachments to be displayed
if
attachments
.
count
==
0
{
noAttachments
}
// otherwise preview the attachments
else
{
attachmentsView
}
}
}
/// default view if there are no attachments to be displayed
var
noAttachments
:
some
View
{
return
Text
(
NSLocalizedString
(
"ReadView.Attachments.No"
,
comment
:
""
))
.
font
(
.
footnote
)
.
padding
(
30
)
}
/// a view that previews all the attachment files
var
attachmentsView
:
some
View
{
return
VStack
(
alignment
:
.
leading
,
spacing
:
5
){
// headline
...
...
@@ -54,7 +65,7 @@ struct AttachmentsViewMain: View {
ForEach
(
0
..<
attachments
.
count
)
{
i
in
AttPrev
(
attachment
:
self
.
attachments
[
i
],
pre
load
:
self
.
d
l
All
shouldBeDown
load
ed
:
self
.
d
ownload
All
)
}
}
...
...
@@ -63,34 +74,39 @@ struct AttachmentsViewMain: View {
.
padding
(
.
top
,
30
)
.
padding
(
.
bottom
,
10
)
}
var
noAttachments
:
some
View
{
return
Text
(
NSLocalizedString
(
"ReadView.Attachments.No"
,
comment
:
""
))
.
font
(
.
footnote
)
.
padding
(
30
)
}
}
struct
AttachmentsViewMain_Previews
:
PreviewProvider
{
static
var
previews
:
some
View
{
// here we call the view with a single ProxyAttachment() for
// demonstration purposes
AttachmentsViewMain
(
attachments
:
[
ProxyAttachment
()])
}
}
//
MARK:
one
A
ttachment
Preview
//
/ a view that previews
one
a
ttachment
file
struct
AttPrev
:
View
{
// the attachment that is going to be previewed
var
attachment
:
DisplayAttachment
var
preload
=
false
// by default false
var
shouldBeDownloaded
=
false
// whether this attachment is already downloaded to the documents directory
@State
var
isDownloaded
:
Bool
=
false
// used togehter with 'open' button to
// open a fullScreenView of a file
@State
var
isFullScreen
:
Bool
=
false
func
download
(){
func
getDocumentsDirectory
()
->
URL
{
let
paths
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)
return
paths
[
0
]
}
/// a func to find the documents directory
func
getDocumentsDirectory
()
->
URL
{
let
paths
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)
return
paths
[
0
]
}
/// a func that downloads the attachment into the documents directory
func
download
()
{
let
filename
=
getDocumentsDirectory
()
.
appendingPathComponent
(
self
.
attachment
.
myName
)
do
{
...
...
@@ -101,123 +117,167 @@ struct AttPrev:View{
self
.
isDownloaded
=
true
}
//is the file already downloaded?
/// a func that checks if an attachment is downloaded into the documents directory or not
/// updates the 'isDownloaded' property accordingly
func
getDownloadedState
(){
func
getDocumentsDirectory
()
->
URL
{
let
paths
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)
return
paths
[
0
]
}
let
filename
=
getDocumentsDirectory
()
.
appendingPathComponent
(
self
.
attachment
.
myName
)
if
FileManager
.
default
.
fileExists
(
atPath
:
filename
.
path
){
self
.
isDownloaded
=
true
}
}
var
body
:
some
View
{
if
preload
{
self
.
download
()}
if
shouldBeDownloaded
{
self
.
download
()
}
//this QuickLookView has to be defined here so it reloads on every state-change
// QuickLookView creates the preview of the file
// it has to be defined here to update correctly
let
QLV
=
QuickLookView
(
name
:
self
.
attachment
.
myName
,
data
:
self
.
attachment
.
myData
,
shallDL
:
self
.
isDownloaded
)
return
VStack
{
Group
{
CardV
(
title
:
self
.
attachment
.
myName
,
Group
{
CardV
(
title
:
self
.
attachment
.
myName
,
//those are the actions visable under the cklicked preview
actions
:
self
.
isDownloaded
||
self
.
preload
?
[
/*
self.ActionView(NSLocalizedString("delete", comment: ""),
icon: AnyView(Image(systemName: "trash")),
onClick: {
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
// these buttons are visable under the preview
// when users click on the preview
actions
:
self
.
isDownloaded
||
self
.
shouldBeDownloaded
?
// different combination of buttons
// according to downloading status
[
// anyViewDeleteButton
anyViewOpenButton
,
anyViewShareButton
]
:
[
anyViewDownloadButton
,
// both lists need same length
// to make appearance the same
AnyView
(
EmptyView
()),
AnyView
(
EmptyView
())
]
){
QLV
/*TODO:
.allowsHitTesting(false).disabled(true)*/
//this should make the whole view scrollable averywhere not just on the title
}
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.name!)
do {
try FileManager.default.removeItem(at: filename)
} catch let error as NSError {
print("Error: \(error)")
}
self.isDownloaded = false
}
), */
self
.
ActionView
(
NSLocalizedString
(
"open"
,
comment
:
""
),
icon
:
AnyView
(
Image
(
systemName
:
"arrow.up.and.down"
)
.
rotationEffect
(
.
degrees
(
45
))),
onClick
:
{
self
.
isFullScreen
.
toggle
()}
),
AnyView
(
VStack
{
shareButton
Text
(
NSLocalizedString
(
"share"
,
comment
:
""
))
.
font
(
.
system
(
size
:
12
))
.
foregroundColor
(
.
blue
)
})
]
:
[
self
.
ActionView
(
NSLocalizedString
(
"download"
,
comment
:
""
),
icon
:
AnyView
(
Image
(
systemName
:
"arrow.down.circle"
)),
onClick
:
{
self
.
download
()
}
),
//odd but both lists need same length
AnyView
(
EmptyView
()),
AnyView
(
EmptyView
())
]
){
QLV
/*TODO:
.allowsHitTesting(false).disabled(true)*/
//this should make the whole view scrollable averywhere not just on the title
}
}
}
// preview should resemble the look of A4 format
.
aspectRatio
(
100
/
141
,
contentMode
:
.
fit
)
.
frame
(
width
:
UIScreen
.
main
.
bounds
.
width
*
2
/3)//
,
maxHeight
:
500
)
//an invisable NavigationLink to open the preview in fullscreen
NavigationLink
(
destination
:
QuickLookView
(
name
:
self
.
attachment
.
myName
,
data
:
self
.
attachment
.
myData
)
.
navigationBarItems
(
trailing
:
shareButton
),
isActive
:
self
.
$isFullScreen
){
Text
(
"loi"
)}
.
hidden
()
}
.
onAppear
(
perform
:
{
self
.
getDownloadedState
()
//a hidden NavigationLink to open the preview in fullscreen
// seems not to work currently
NavigationLink
(
destination
:
QuickLookView
(
name
:
self
.
attachment
.
myName
,
data
:
self
.
attachment
.
myData
)
.
navigationBarItems
(
trailing
:
anyViewShareButton
),
isActive
:
self
.
$isFullScreen
)
{
Text
(
"loi"
)}
.
hidden
()}
.
onAppear
(
perform
:
{
self
.
getDownloadedState
()
//download all functionality
if
self
.
preload
{
self
.
isDownloaded
=
true
;
self
.
download
()}
})
.
onDisappear
(
perform
:
{
func
getDocumentsDirectory
()
->
URL
{
let
paths
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)
return
paths
[
0
]
}
let
filename
=
getDocumentsDirectory
()
.
appendingPathComponent
(
self
.
attachment
.
myName
)
//download all functionality
if
self
.
shouldBeDownloaded
{
self
.
isDownloaded
=
true
;
self
.
download
()}
}
)
// remove file from documents directory
.
onDisappear
(
perform
:
{
let
filename
=
getDocumentsDirectory
()
.
appendingPathComponent
(
self
.
attachment
.
myName
)
do
{
try
FileManager
.
default
.
removeItem
(
at
:
filename
)
}
catch
let
error
as
NSError
{
print
(
"Error:
\(
error
)
"
)
}
self
.
isDownloaded
=
false
print
(
"======== Attachment DISAPPEAR -> REMOVE FILES ========"
)
})
do
{
try
FileManager
.
default
.
removeItem
(
at
:
filename
)
}
catch
let
error
as
NSError
{
print
(
"Error:
\(
error
)
"
)}
self
.
isDownloaded
=
false
print
(
"======== Attachment DISAPPEAR -> REMOVE FILES ========"
)
}
)
}
// an open button converted into an AnyView
// should open the view fullscreen
var
anyViewOpenButton
:
AnyView
{
AnyView
(
Button
(
action
:
{
self
.
isFullScreen
.
toggle
()
},
label
:
{
VStack
{
Image
(
systemName
:
"arrow.up.and.down"
)
.
rotationEffect
(
.
degrees
(
45
))
Text
(
"open"
)
.
font
(
.
system
(
size
:
12
))
}
}
)
)
}
var
shareButton
:
some
View
{
return
Button
(
action
:{
//popover the standart apple sharing stuff
/* if let coord = AppDelegate.getAppDelegate().readViewCoordinator {
coord.shareData(self.attachment.myData as NSData)
}*/
}){
Image
(
systemName
:
"square.and.arrow.up"
)
}
// a share button converted into an AnyView
var
anyViewShareButton
:
AnyView
{
AnyView
(
Button
(
action
:
{
// TODO
//popover the standard apple sharing stuff
/* if let coord = AppDelegate.getAppDelegate().readViewCoordinator {
coord.shareData(self.attachment.myData as NSData)
}*/
},
label
:
{
VStack
{
Image
(
systemName
:
"square.and.arrow.up"
)
Text
(
"share"
)
.
font
(
.
system
(
size
:
12
))
}
}
)
)
}
// a delete button converted into an AnyView
var
anyViewDeleteButton
:
AnyView
{
AnyView
(
Button
(
action
:
{
// TODO
/*
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName)
do {
try FileManager.default.removeItem(at: filename)
} catch let error as NSError {
print("Error: \(error)")
}
self.isDownloaded = false
*/
},
label
:
{
VStack
{
Image
(
systemName
:
"trash"
)
Text
(
"delete"
)
.
font
(
.
system
(
size
:
12
))
}
}
)
)
}
//each of those buttons under the card
func
ActionView
(
_
text
:
String
,
icon
:
AnyView
,
onClick
:
@escaping
()
->
Void
=
{})
->
AnyView
{
return
AnyView
(
Button
(
action
:
onClick
){
VStack
{
icon
Text
(
text
)
.
font
(
.
system
(
size
:
12
))
}})
// a download button converted into an AnyView
// dowloads the file into the documents directory
var
anyViewDownloadButton
:
AnyView
{
AnyView
(
Button
(
action
:
{
self
.
download
()
},
label
:
{
VStack
{
Image
(
systemName
:
"arrow.down.circle"
)
Text
(
"download"
)
.
font
(
.
system
(
size
:
12
))
}
}
)
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment