Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
0c145ad0
Commit
0c145ad0
authored
Jun 17, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on selecting short as viewed
parent
0b2dd7b8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
4 deletions
+38
-4
1Weather/Network/ShortsManager.swift
+21
-3
1Weather/UI/View controllers/Shorts/ShortsViewController.swift
+12
-0
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
+1
-1
1Weather/ViewModels/ShortsViewModel.swift
+4
-0
No files found.
1Weather/Network/ShortsManager.swift
View file @
0c145ad0
...
@@ -59,6 +59,23 @@ class ShortsManager {
...
@@ -59,6 +59,23 @@ class ShortsManager {
}
}
}
}
func
reordering
()
{
var
reorderingArray
=
self
.
shorts
var
itemsToReorder
=
[
ShortsItem
]()
self
.
shorts
.
enumerated
()
.
forEach
{
if
$1
.
isViewed
{
itemsToReorder
.
append
(
reorderingArray
.
remove
(
at
:
$0
))
}
}
reorderingArray
.
append
(
contentsOf
:
itemsToReorder
)
self
.
shorts
=
reorderingArray
self
.
multicastDelegate
.
invoke
{
delegate
in
delegate
.
shortsDidChange
()
}
}
func
like
(
item
:
ShortsItem
)
{
func
like
(
item
:
ShortsItem
)
{
guard
let
shortsToLikeIndex
=
(
shorts
.
firstIndex
{
$0
.
id
==
item
.
id
})
else
{
guard
let
shortsToLikeIndex
=
(
shorts
.
firstIndex
{
$0
.
id
==
item
.
id
})
else
{
return
return
...
@@ -67,8 +84,9 @@ class ShortsManager {
...
@@ -67,8 +84,9 @@ class ShortsManager {
}
}
func
markAsViewed
(
item
:
ShortsItem
)
{
func
markAsViewed
(
item
:
ShortsItem
)
{
// guard let sourceIndex = (self.shorts.firstIndex{ $0.id == item.id }) else {
guard
let
sourceIndex
=
(
self
.
shorts
.
firstIndex
{
$0
.
id
==
item
.
id
})
else
{
// return
return
// }
}
self
.
shorts
[
sourceIndex
]
.
markAsViewed
()
}
}
}
}
1Weather/UI/View controllers/Shorts/ShortsViewController.swift
View file @
0c145ad0
...
@@ -22,6 +22,7 @@ class ShortsViewController: UIViewController {
...
@@ -22,6 +22,7 @@ class ShortsViewController: UIViewController {
private
let
tableView
=
UITableView
()
private
let
tableView
=
UITableView
()
private
var
averageColorCache
=
[
AnyHashable
:
UIColor
]()
private
var
averageColorCache
=
[
AnyHashable
:
UIColor
]()
private
var
lastOffset
:
CGFloat
=
0
private
var
lastOffset
:
CGFloat
=
0
private
var
visibleRow
=
0
deinit
{
deinit
{
print
(
"[ShortsViewController] deinit"
)
print
(
"[ShortsViewController] deinit"
)
...
@@ -44,6 +45,11 @@ class ShortsViewController: UIViewController {
...
@@ -44,6 +45,11 @@ class ShortsViewController: UIViewController {
prepareTableView
()
prepareTableView
()
}
}
override
func
viewWillDisappear
(
_
animated
:
Bool
)
{
super
.
viewWillDisappear
(
animated
)
print
(
"[ShortsViewController] Will disappear"
)
}
private
func
scrollTo
(
newOffset
:
CGPoint
,
velocity
:
CGPoint
)
{
private
func
scrollTo
(
newOffset
:
CGPoint
,
velocity
:
CGPoint
)
{
let
animation
=
POPBasicAnimation
(
propertyNamed
:
kPOPScrollViewContentOffset
)
let
animation
=
POPBasicAnimation
(
propertyNamed
:
kPOPScrollViewContentOffset
)
animation
?
.
timingFunction
=
CAMediaTimingFunction
(
name
:
.
easeOut
)
animation
?
.
timingFunction
=
CAMediaTimingFunction
(
name
:
.
easeOut
)
...
@@ -51,6 +57,8 @@ class ShortsViewController: UIViewController {
...
@@ -51,6 +57,8 @@ class ShortsViewController: UIViewController {
animation
?
.
toValue
=
newOffset
animation
?
.
toValue
=
newOffset
animation
?
.
fromValue
=
tableView
.
contentOffset
animation
?
.
fromValue
=
tableView
.
contentOffset
print
(
"[ShortsViewController] diff:
\(
abs
(
tableView
.
contentOffset
.
y
)
/
newOffset
.
y
)
"
)
tableView
.
pop_add
(
animation
,
forKey
:
kAnimationKey
)
tableView
.
pop_add
(
animation
,
forKey
:
kAnimationKey
)
}
}
}
}
...
@@ -97,6 +105,10 @@ extension ShortsViewController: UITableViewDelegate {
...
@@ -97,6 +105,10 @@ extension ShortsViewController: UITableViewDelegate {
return
tableView
.
bounds
.
height
return
tableView
.
bounds
.
height
}
}
func
tableView
(
_
tableView
:
UITableView
,
didEndDisplaying
cell
:
UITableViewCell
,
forRowAt
indexPath
:
IndexPath
)
{
viewModel
.
markAsViewed
(
item
:
viewModel
.
shorts
[
indexPath
.
row
])
}
func
scrollViewWillEndDragging
(
_
scrollView
:
UIScrollView
,
withVelocity
velocity
:
CGPoint
,
targetContentOffset
:
UnsafeMutablePointer
<
CGPoint
>
)
{
func
scrollViewWillEndDragging
(
_
scrollView
:
UIScrollView
,
withVelocity
velocity
:
CGPoint
,
targetContentOffset
:
UnsafeMutablePointer
<
CGPoint
>
)
{
//Get direction
//Get direction
let
direction
:
ScrollDirection
let
direction
:
ScrollDirection
...
...
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
View file @
0c145ad0
...
@@ -217,7 +217,7 @@ class TodayCellFactory: CellFactoryProtocol {
...
@@ -217,7 +217,7 @@ class TodayCellFactory: CellFactoryProtocol {
rowsToHide
.
insert
(
.
moon
)
rowsToHide
.
insert
(
.
moon
)
}
}
if
!
ShortsManager
.
shared
.
shortsAvailable
||
todayViewModel
.
shorts
.
isEmpty
{
if
!
ShortsManager
.
shared
.
shortsAvailable
{
rowsToHide
.
insert
(
.
shorts
)
rowsToHide
.
insert
(
.
shorts
)
}
}
...
...
1Weather/ViewModels/ShortsViewModel.swift
View file @
0c145ad0
...
@@ -38,6 +38,10 @@ class ShortsViewModel: ViewModelProtocol {
...
@@ -38,6 +38,10 @@ class ShortsViewModel: ViewModelProtocol {
UIApplication
.
shared
.
open
(
url
,
options
:
[:])
UIApplication
.
shared
.
open
(
url
,
options
:
[:])
}
}
}
}
func
markAsViewed
(
item
:
ShortsItem
)
{
shortsManager
.
markAsViewed
(
item
:
item
)
}
}
}
//MARK:- ShortManager Delegate
//MARK:- ShortManager Delegate
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment