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
063636f8
Commit
063636f8
authored
4 years ago
by
hannes
Browse files
Options
Downloads
Patches
Plain Diff
added function to persistentdataprovider
parent
79bd4aa5
Branches
Branches containing commit
No related tags found
1 merge request
!85
Thesis Hannes Staging
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
enzevalos_iphone/SwiftUI/Contact/SimpleMailRowView.swift
+2
-1
2 additions, 1 deletion
enzevalos_iphone/SwiftUI/Contact/SimpleMailRowView.swift
enzevalos_iphone/persistentData/PersistentDataProvider.swift
+86
-0
86 additions, 0 deletions
enzevalos_iphone/persistentData/PersistentDataProvider.swift
with
88 additions
and
1 deletion
enzevalos_iphone/SwiftUI/Contact/SimpleMailRowView.swift
+
2
−
1
View file @
063636f8
...
...
@@ -53,8 +53,9 @@ struct SimpleMailRowView <M: DisplayMail>: View {
}
}
/*
struct SimpleMailRow_Previews: PreviewProvider {
static var previews: some View {
SimpleMailRowView(mail: ProxyData.PlainMail)
}
}
}
*/
This diff is collapsed.
Click to expand it.
enzevalos_iphone/persistentData/PersistentDataProvider.swift
+
86
−
0
View file @
063636f8
...
...
@@ -420,6 +420,53 @@ class PersistentDataProvider {
}
}
func
setCategoryOpenability
(
category
:
CategoryIDType
,
filter
:
@escaping
MailFilter
)
throws
{
var
performError
:
Error
?
=
nil
let
queue
=
DispatchQueue
(
label
:
"AddCategoryEntriesToDatabase"
,
qos
:
.
userInitiated
)
queue
.
async
{
let
predicate
=
NSPredicate
(
format
:
//filter for mails not categorized by this category (no entry in inCategory for this category)
"SUBQUERY(inCategory, $category, $category.categoryName == %@ AND $category.openability > -1).@count == 0"
,
category
)
let
taskContext
=
self
.
newTaskContext
()
let
sortDescriptors
=
[
NSSortDescriptor
(
key
:
"date"
,
ascending
:
true
)]
if
let
unclassifiedMailRecords
=
self
.
generateFetchResultController
(
enitityName
:
MailRecord
.
entityName
,
sortDescriptors
:
sortDescriptors
,
predicate
:
predicate
,
propertiesToFetch
:
nil
,
fetchLimit
:
PersistentDataProvider
.
FETCHLIMIT
,
inViewContext
:
false
,
context
:
taskContext
)
.
fetchedObjects
as?
[
MailRecord
]{
taskContext
.
performAndWait
{
for
mail
in
unclassifiedMailRecords
{
let
categoryRec
=
CategoryRecord
(
context
:
taskContext
)
categoryRec
.
categoryName
=
category
categoryRec
.
openability
=
filter
(
mail
)
.
rawValue
mail
.
addToInCategory
(
categoryRec
)
}
//save
do
{
try
self
.
save
(
taskContext
:
taskContext
)}
catch
{
performError
=
error
}
}
}
else
{
performError
=
PersistentDataError
.
missingData
}
}
if
let
error
=
performError
{
throw
error
}
}
func
save
(
taskContext
:
NSManagedObjectContext
)
throws
->
()
{
// Save all insertions and deletions from the context to the store.
if
taskContext
.
hasChanges
{
...
...
@@ -681,6 +728,45 @@ class PersistentDataProvider {
return
controller
}
func
generateNoMailsController
()
->
NSFetchedResultsController
<
MailRecord
>
{
let
sortDescriptors
=
[
NSSortDescriptor
(
key
:
"date"
,
ascending
:
true
)]
return
generateFetchResultController
(
enitityName
:
MailRecord
.
entityName
,
sortDescriptors
:
sortDescriptors
,
predicate
:
nil
,
propertiesToFetch
:
nil
,
fetchLimit
:
PersistentDataProvider
.
FETCHLIMIT
,
inViewContext
:
true
,
context
:
nil
)
}
func
generateFetchedMailsInFolderAndCategoryResultsController
(
folderpath
:
String
,
category
:
String
,
andPredicate
:
NSPredicate
=
NSPredicate
(
value
:
true
),
important
:
Bool
=
false
)
->
NSFetchedResultsController
<
MailRecord
>
{
let
sortDescriptors
=
[
NSSortDescriptor
(
key
:
"date"
,
ascending
:
false
)]
let
mustOpenPredicate
=
NSPredicate
(
format
:
//filter for mails that must be opened by this category
"SUBQUERY(inCategory, $category, $category.categoryName == %@ AND $category.openability == 3).@count > 0"
,
category
)
let
openablePredicate
=
NSPredicate
(
format
:
//filter for mails beeing openable by this category (at least .canOpen (= 1))
"SUBQUERY(inCategory, $category, $category.categoryName == %@ AND $category.openability >
\(
important
?
1
:
0
)
).@count > 0 "
+
//where no other categories have a .mustOpen (= 3)
"AND SUBQUERY(inCategory, $category, $category.categoryName != %@ AND $category.openability == 3).@count == 0"
,
category
)
//an eMail is in this category if it must open it OR it can open it and no other kategory mustOPen
let
inCategoryPredicate
=
NSCompoundPredicate
(
type
:
.
or
,
subpredicates
:
[
mustOpenPredicate
,
openablePredicate
])
let
inFolderPredicate
=
NSPredicate
(
format
:
"inFolder.path == %@"
,
folderpath
)
//it also has to be in this folder (folders have higher rank than categories)
let
predicate
=
NSCompoundPredicate
(
type
:
.
and
,
subpredicates
:
[
inCategoryPredicate
,
inFolderPredicate
,
andPredicate
])
return
generateFetchResultController
(
enitityName
:
MailRecord
.
entityName
,
sortDescriptors
:
sortDescriptors
,
predicate
:
predicate
,
propertiesToFetch
:
nil
,
fetchLimit
:
PersistentDataProvider
.
FETCHLIMIT
,
inViewContext
:
true
,
context
:
nil
)
}
func
generateFetchedMailsInFolderResultsController
(
folderpath
:
String
)
->
NSFetchedResultsController
<
MailRecord
>
{
let
sortDescriptors
=
[
NSSortDescriptor
(
key
:
"date"
,
ascending
:
true
)]
let
predicate
=
NSPredicate
(
format
:
"inFolder.path == %@"
,
folderpath
)
...
...
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