Skip to content

Commit

Permalink
Merge pull request #98 from XKCDY/bugfix/mark-read-on-back-button
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb authored Aug 31, 2021
2 parents 9bc07e7 + 3aa82a9 commit df54845
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions XKCDY.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@
repositoryURL = "https://github.com/realm/realm-cocoa";
requirement = {
kind = exactVersion;
version = 5.4.0;
version = 5.5.1;
};
};
6A64932C24CDF2CF004BC488 /* XCRemoteSwiftPackageReference "SwiftyStoreKit" */ = {
Expand Down Expand Up @@ -1398,8 +1398,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/fermoya/SwiftUIPager.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.9.2;
kind = exactVersion;
version = 1.9.2;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
"state": {
"branch": null,
"revision": "175eeb4618b0a6ef4d69a7409b6a74ddd235a093",
"revision": "644411854d1d4e019317839573b54f8707b0044b",
"version": "5.15.0"
}
},
Expand All @@ -42,26 +42,26 @@
"repositoryURL": "https://github.com/realm/realm-cocoa",
"state": {
"branch": null,
"revision": "6310911a38d55003f0b8acca96635aa2bfc3e2c0",
"version": "5.4.0"
"revision": "7ec5df0a700ef76ad930dcedb9c63c1b354979e1",
"version": "5.5.1"
}
},
{
"package": "RealmCore",
"repositoryURL": "https://github.com/realm/realm-core",
"state": {
"branch": null,
"revision": "34d7fbcbab2a94bcad081bddf9d172961cd84659",
"version": "6.0.25"
"revision": "66d79b3c5213fb14d491c1b22193077b488d49a6",
"version": "6.2.4"
}
},
{
"package": "SwiftUIPager",
"repositoryURL": "https://github.com/fermoya/SwiftUIPager.git",
"state": {
"branch": null,
"revision": "c70dd348ee4bbdfc5af3b26c85309d4198db4f87",
"version": "1.11.0"
"revision": "d99fd8fbaa91dc5622f33a8e99a2e094179ee861",
"version": "1.9.2"
}
},
{
Expand Down
26 changes: 16 additions & 10 deletions XKCDY/Views/ComicPager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ struct ComicPager: View {
return comic.imgs?.x2 ?? comic.imgs?.x1
}

func markComicAsReadIfNecessary() {
let currentTimestamp = Date().currentTimeMillis()

if currentTimestamp > self.startedViewingAt + TIME_TO_MARK_AS_READ_MS {
let realm = try! Realm()
try! realm.write {
self.store.comic.isRead = true
}
}

self.startedViewingAt = Date().currentTimeMillis()
}

var body: some View {
GeometryReader { geometry in
ZStack {
Expand Down Expand Up @@ -143,16 +156,7 @@ struct ComicPager: View {
return
}

let currentTimestamp = Date().currentTimeMillis()

if currentTimestamp > self.startedViewingAt + TIME_TO_MARK_AS_READ_MS {
let realm = try! Realm()
try! realm.write {
self.store.comic.isRead = true
}
}

self.startedViewingAt = Date().currentTimeMillis()
self.markComicAsReadIfNecessary()

DispatchQueue.main.async {
self.store.currentComicId = self.store.filteredComics[newIndex].id
Expand Down Expand Up @@ -204,6 +208,8 @@ struct ComicPager: View {
// Make sure closing animation applies
self.offset = CGSize(width: 0.1, height: 0.1)

self.markComicAsReadIfNecessary()

self.closePager()
})
.opacity(self.offset == .zero ? 1 : 2 - Double(abs(self.offset.height) / 100))
Expand Down

0 comments on commit df54845

Please sign in to comment.