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
f1cc460a
Commit
f1cc460a
authored
Sep 15, 2021
by
Dmitry Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Added missing UI for subscriptions
- Changed subscription verify logic
parent
8980fc87
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
289 additions
and
39 deletions
+289
-39
1Weather/AppDelegate.swift
+1
-0
1Weather/InApps/StoreManager.swift
+6
-1
1Weather/Resources/Assets.xcassets/menu/menu_crown.imageset/Contents.json
+16
-0
1Weather/Resources/Assets.xcassets/menu/menu_crown.imageset/menu_crown.pdf
+180
-0
1Weather/Resources/en.lproj/Localizable.strings
+3
-0
1Weather/UI/View controllers/Menu/Cells/MenuCellFactory.swift
+20
-20
1Weather/UI/View controllers/Menu/Header/MenuHeaderView.swift
+31
-13
1Weather/UI/View controllers/Menu/MenuViewController.swift
+19
-0
1Weather/UI/View controllers/Subscriptions/SubscriptionOverviewViewController.swift
+4
-1
1Weather/UI/View controllers/Subscriptions/SubscriptionStoreViewController.swift
+3
-1
1Weather/UI/View controllers/Subscriptions/Views/SubscriptionDescriptionView.swift
+2
-0
1Weather/UI/View controllers/Subscriptions/Views/SubscriptionProDescriptionView.swift
+2
-2
1Weather/ViewModels/SubscriptionViewModel.swift
+2
-1
No files found.
1Weather/AppDelegate.swift
View file @
f1cc460a
...
...
@@ -164,6 +164,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func
applicationDidBecomeActive
(
_
application
:
UIApplication
)
{
LocationManager
.
shared
.
updateEverythingIfNeeded
()
storeManager
.
verifySubscriptions
()
if
#available(iOS 14, *)
{
WidgetManager
.
shared
.
refreshAnalytics
()
...
...
1Weather/InApps/StoreManager.swift
View file @
f1cc460a
...
...
@@ -173,7 +173,7 @@ public class StoreManager {
public
func
purchase
(
product
:
SKProduct
,
completion
:
@escaping
(
Bool
)
->
())
{
let
log
=
self
.
log
log
.
info
(
"Purchase
\(
product
.
productIdentifier
)
start (SK)."
)
SwiftyStoreKit
.
purchaseProduct
(
product
)
{
result
in
SwiftyStoreKit
.
purchaseProduct
(
product
,
atomically
:
true
)
{
result
in
switch
result
{
case
.
success
(
let
product
):
if
product
.
needsFinishTransaction
{
...
...
@@ -196,6 +196,7 @@ public class StoreManager {
#else
service
=
.
production
#endif
let
appleValidator
=
AppleReceiptValidator
(
service
:
service
,
sharedSecret
:
StoreManager
.
sharedSecret
)
SwiftyStoreKit
.
verifyReceipt
(
using
:
appleValidator
)
{
result
in
switch
result
{
...
...
@@ -211,6 +212,7 @@ public class StoreManager {
}
case
.
expired
(
let
expiryDate
,
let
items
):
log
.
debug
(
"Subscription expired since
\(
expiryDate
)\n\(
items
)\n
"
)
self
.
hasSubscription
=
false
self
.
everHadSubscription
=
true
case
.
notPurchased
:
log
.
debug
(
"The user has never purchased a subscription."
)
...
...
@@ -219,6 +221,9 @@ public class StoreManager {
}
case
.
error
(
let
error
):
log
.
error
(
"Receipt verification failed:
\(
error
)
"
)
self
.
hasSubscription
=
false
self
.
everHadSubscription
=
false
self
.
subscriptionExpirationDate
=
nil
}
}
}
...
...
1Weather/Resources/Assets.xcassets/menu/menu_crown.imageset/Contents.json
0 → 100644
View file @
f1cc460a
{
"images"
:
[
{
"filename"
:
"menu_crown.pdf"
,
"idiom"
:
"universal"
}
],
"info"
:
{
"author"
:
"xcode"
,
"version"
:
1
},
"properties"
:
{
"preserves-vector-representation"
:
true
,
"template-rendering-intent"
:
"template"
}
}
1Weather/Resources/Assets.xcassets/menu/menu_crown.imageset/menu_crown.pdf
0 → 100644
View file @
f1cc460a
No preview for this file type
1Weather/Resources/en.lproj/Localizable.strings
View file @
f1cc460a
...
...
@@ -193,10 +193,13 @@
//Menu
"menu.goPremium" = "Go Premium";
"menu.upgradeTo" = "Upgrade to";
"menu.premiumMembership" = "Premium\nMembership";
"menu.premium.desc" = "Subcribe to 1Weather premium for a unique experience.";
"menu.tv" = "1Weather TV";
"menu.radar" = "Radar";
"menu.buyNow" = "Buy now";
"menu.upgradeNow" = "Upgrade now";
"menu.settings" = "Settings";
"menu.subscriptionOverview" = "Premium";
"menu.about" = "About us";
...
...
1Weather/UI/View controllers/Menu/Cells/MenuCellFactory.swift
View file @
f1cc460a
...
...
@@ -37,9 +37,7 @@ public enum MenuRow {
case
.
deviceId
:
return
UIImage
(
named
:
"menu_device_id"
)
case
.
subscriptionOverview
:
return
nil
#warning("Not implemented!")
//TODO: Implement!
return
UIImage
(
named
:
"menu_crown"
)
}
}
...
...
@@ -108,23 +106,7 @@ private struct SectionItem {
class
MenuCellFactory
<
T
>
:
CellFactory
{
//Private
private
let
menuViewModel
:
MenuViewModel
private
let
sections
:
[
SectionItem
]
=
{
let
infoSectionItem
:
SectionItem
if
StoreManager
.
shared
.
hasSubscription
{
infoSectionItem
=
SectionItem
(
type
:
.
info
,
rows
:
[
.
settings
,
.
subscriptionOverview
])
}
else
{
infoSectionItem
=
SectionItem
(
type
:
.
info
,
rows
:
[
.
settings
])
}
let
settingsSectionItem
=
SectionItem
(
type
:
.
settings
,
rows
:
[
.
about
,
.
ad
,
.
help
,
.
faq
,
.
privacy
,
.
deviceId
])
return
[
infoSectionItem
,
settingsSectionItem
]
}()
private
var
sections
=
[
SectionItem
]()
//Public
public
var
kSectionHeight
:
CGFloat
{
...
...
@@ -139,6 +121,24 @@ class MenuCellFactory<T>: CellFactory {
init
(
viewModel
:
MenuViewModel
)
{
self
.
menuViewModel
=
viewModel
reload
()
}
public
func
reload
()
{
let
infoSectionItem
:
SectionItem
if
StoreManager
.
shared
.
hasSubscription
{
infoSectionItem
=
SectionItem
(
type
:
.
info
,
rows
:
[
.
settings
,
.
subscriptionOverview
])
}
else
{
infoSectionItem
=
SectionItem
(
type
:
.
info
,
rows
:
[
.
settings
])
}
let
settingsSectionItem
=
SectionItem
(
type
:
.
settings
,
rows
:
[
.
about
,
.
ad
,
.
help
,
.
faq
,
.
privacy
,
.
deviceId
])
self
.
sections
=
[
infoSectionItem
,
settingsSectionItem
]
}
public
func
numberOfRows
(
inSection
section
:
Int
)
->
Int
{
...
...
1Weather/UI/View controllers/Menu/Header/MenuHeaderView.swift
View file @
f1cc460a
...
...
@@ -12,7 +12,7 @@ class MenuHeaderView: UIView {
private
let
premiumContainer
=
UIView
()
private
let
premiumHeadingLabel
=
UILabel
()
private
let
premiumDescriptionLabel
=
UILabel
()
private
let
buyButton
=
UI
Button
()
private
let
buyButton
=
SelfSizing
Button
()
private
let
premiumImageView
=
UIImageView
()
public
var
onTapBuy
:
(()
->
())?
...
...
@@ -64,36 +64,55 @@ private extension MenuHeaderView {
premiumContainer
.
addSubview
(
premiumImageView
)
premiumHeadingLabel
.
textColor
=
.
white
premiumHeadingLabel
.
font
=
AppFont
.
SFPro
.
bold
(
size
:
23
)
premiumHeadingLabel
.
text
=
"menu.goPremium"
.
localized
()
premiumHeadingLabel
.
setContentHuggingPriority
(
.
fittingSizeLevel
,
for
:
.
vertical
)
premiumContainer
.
addSubview
(
premiumHeadingLabel
)
let
descParagpraphStyle
=
NSMutableParagraphStyle
()
descParagpraphStyle
.
minimumLineHeight
=
20
let
descriptionAttrString
=
NSAttributedString
(
string
:
"menu.premium.desc"
.
localized
(),
attributes
:
[
.
foregroundColor
:
UIColor
.
white
,
.
paragraphStyle
:
descParagpraphStyle
,
.
font
:
AppFont
.
SFPro
.
regular
(
size
:
14
)])
premiumDescriptionLabel
.
lineBreakMode
=
.
byWordWrapping
premiumDescriptionLabel
.
numberOfLines
=
0
premiumDescriptionLabel
.
attributedText
=
descriptionAttrString
premiumDescriptionLabel
.
setContentHuggingPriority
(
.
defaultLow
,
for
:
.
horizontal
)
premiumContainer
.
addSubview
(
premiumDescriptionLabel
)
buyButton
.
backgroundColor
=
.
white
buyButton
.
setTitle
(
"menu.buyNow"
.
localized
(),
for
:
.
normal
)
buyButton
.
titleEdgeInsets
=
.
init
(
top
:
0
,
left
:
10
,
bottom
:
0
,
right
:
10
)
buyButton
.
setTitleColor
(
ThemeManager
.
currentTheme
.
graphTintColor
,
for
:
.
normal
)
buyButton
.
titleLabel
?
.
font
=
AppFont
.
SFPro
.
semibold
(
size
:
15
)
buyButton
.
layer
.
cornerRadius
=
4
buyButton
.
addTarget
(
self
,
action
:
#selector(
handleBuyButton
)
,
for
:
.
touchUpInside
)
premiumContainer
.
addSubview
(
buyButton
)
if
StoreManager
.
shared
.
removeAdsPurchased
{
premiumHeadingLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
16
)
premiumHeadingLabel
.
text
=
"menu.upgradeTo"
.
localized
()
let
descParagpraphStyle
=
NSMutableParagraphStyle
()
descParagpraphStyle
.
minimumLineHeight
=
20
let
descriptionAttrString
=
NSAttributedString
(
string
:
"menu.premiumMembership"
.
localized
(),
attributes
:
[
.
foregroundColor
:
UIColor
.
white
,
.
paragraphStyle
:
descParagpraphStyle
,
.
font
:
AppFont
.
SFPro
.
bold
(
size
:
24
)])
premiumDescriptionLabel
.
attributedText
=
descriptionAttrString
buyButton
.
setTitle
(
"menu.upgradeNow"
.
localized
(),
for
:
.
normal
)
}
else
{
premiumHeadingLabel
.
font
=
AppFont
.
SFPro
.
bold
(
size
:
23
)
premiumHeadingLabel
.
text
=
"menu.goPremium"
.
localized
()
let
descParagpraphStyle
=
NSMutableParagraphStyle
()
descParagpraphStyle
.
minimumLineHeight
=
20
let
descriptionAttrString
=
NSAttributedString
(
string
:
"menu.premium.desc"
.
localized
(),
attributes
:
[
.
foregroundColor
:
UIColor
.
white
,
.
paragraphStyle
:
descParagpraphStyle
,
.
font
:
AppFont
.
SFPro
.
regular
(
size
:
14
)])
premiumDescriptionLabel
.
attributedText
=
descriptionAttrString
buyButton
.
setTitle
(
"menu.buyNow"
.
localized
(),
for
:
.
normal
)
}
//Constraints
premiumContainer
.
snp
.
makeConstraints
{
(
make
)
in
make
.
top
.
equalTo
(
30
)
make
.
left
.
right
.
equalToSuperview
()
.
inset
(
18
)
.
priority
(
999
)
make
.
height
.
equalTo
(
180
)
make
.
bottom
.
equalToSuperview
()
.
inset
(
30
)
}
...
...
@@ -115,7 +134,6 @@ private extension MenuHeaderView {
}
buyButton
.
snp
.
makeConstraints
{
(
make
)
in
make
.
width
.
equalTo
(
100
)
make
.
height
.
equalTo
(
35
)
make
.
top
.
equalTo
(
premiumDescriptionLabel
.
snp
.
bottom
)
.
offset
(
18
)
.
priority
(
999
)
make
.
left
.
equalToSuperview
()
.
inset
(
18
)
...
...
1Weather/UI/View controllers/Menu/MenuViewController.swift
View file @
f1cc460a
...
...
@@ -52,12 +52,20 @@ class MenuViewController: UIViewController {
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
StoreManager
.
shared
.
add
(
observer
:
self
)
prepareController
()
prepareTableViewHeader
()
prepareTableView
()
updateUI
()
}
override
func
viewWillAppear
(
_
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
menuCellFactory
.
reload
()
tableView
.
reloadData
()
}
override
func
viewDidLayoutSubviews
()
{
super
.
viewDidLayoutSubviews
()
tableView
.
layoutTableHeaderView
()
...
...
@@ -155,6 +163,17 @@ extension MenuViewController: UITableViewDelegate {
}
}
//MARK:- StoreManager Observer
extension
MenuViewController
:
StoreManagerObserver
{
func
storeManagerUpdatedStatus
(
_
storeManager
:
StoreManager
)
{
onMain
{
self
.
menuCellFactory
.
reload
()
self
.
tableView
.
reloadData
()
}
}
}
//MARK:- MenuViewModel Delegate
extension
MenuViewController
:
MenuViewModelDelegate
{
func
viewModelDidChange
<
P
:
ViewModelProtocol
>
(
model
:
P
)
{
onMain
{
...
...
1Weather/UI/View controllers/Subscriptions/SubscriptionOverviewViewController.swift
View file @
f1cc460a
...
...
@@ -31,6 +31,9 @@ class SubscriptionOverviewViewController: UIViewController {
prepareViewController
()
prepareFooter
()
prepareScrollView
()
//Verify new subscription
StoreManager
.
shared
.
verifySubscriptions
()
}
}
...
...
@@ -54,7 +57,7 @@ extension SubscriptionOverviewViewController {
scrollViewContent
.
addSubview
(
topHeaderView
)
topHeaderView
.
snp
.
makeConstraints
{
make
in
make
.
top
.
equalToSuperview
()
make
.
left
.
right
.
equalToSuperview
()
.
inset
(
24
)
make
.
left
.
right
.
equalToSuperview
()
}
scrollViewContent
.
addSubview
(
descriptionView
)
...
...
1Weather/UI/View controllers/Subscriptions/SubscriptionStoreViewController.swift
View file @
f1cc460a
...
...
@@ -134,7 +134,9 @@ extension SubscriptionStoreViewController: SubscriptionPurchaseButtonDelegate {
extension
SubscriptionStoreViewController
:
SubscriptionViewModelDelegate
{
func
viewModel
(
_
vm
:
SubscriptionViewModel
,
finishedSubscriptionPurchaseWithResult
result
:
Bool
)
{
if
result
{
coordinator
.
openOverview
()
self
.
dismiss
(
animated
:
true
)
{
self
.
coordinator
.
openOverview
()
}
}
}
}
1Weather/UI/View controllers/Subscriptions/Views/SubscriptionDescriptionView.swift
View file @
f1cc460a
...
...
@@ -119,6 +119,7 @@ class SubscriptionDescriptionView: UIView {
let
label
=
UILabel
()
view
.
addSubview
(
label
)
label
.
textColor
=
.
black
label
.
font
=
AppFont
.
SFPro
.
semibold
(
size
:
10
)
label
.
text
=
"subscription.description.items.adFree.forever"
.
localized
()
...
...
@@ -154,6 +155,7 @@ class SubscriptionDescriptionView: UIView {
let
label
=
UILabel
()
view
.
addSubview
(
label
)
label
.
textColor
=
.
black
label
.
font
=
AppFont
.
SFPro
.
semibold
(
size
:
10
)
label
.
text
=
"subscription.description.items.comingSoon"
.
localized
()
...
...
1Weather/UI/View controllers/Subscriptions/Views/SubscriptionProDescriptionView.swift
View file @
f1cc460a
...
...
@@ -90,7 +90,7 @@ private extension SubscriptionProDescriptionView {
discountMarkerView
.
backgroundColor
=
UIColor
(
hex
:
0xffc933
)
proUsersContainer
.
addSubview
(
discountMarkerView
)
discountLabel
.
textColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
discountLabel
.
textColor
=
.
black
discountLabel
.
font
=
AppFont
.
SFPro
.
bold
(
size
:
14
)
discountLabel
.
text
=
"subscription.description.discount"
.
localizedFormat
(
"30%"
)
discountMarkerView
.
addSubview
(
discountLabel
)
...
...
@@ -278,7 +278,7 @@ private extension SubscriptionProDescriptionView {
let
label
=
UILabel
()
label
.
text
=
text
label
.
font
=
AppFont
.
SFPro
.
semibold
(
size
:
10
)
label
.
textColor
=
.
black
label
.
textColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
label
.
adjustsFontSizeToFitWidth
=
true
label
.
minimumScaleFactor
=
0.2
...
...
1Weather/ViewModels/SubscriptionViewModel.swift
View file @
f1cc460a
...
...
@@ -22,7 +22,8 @@ class SubscriptionViewModel: ViewModelProtocol {
}
public
var
isProUser
:
Bool
{
storeManager
.
removeAdsPurchased
return
true
// storeManager.removeAdsPurchased
}
public
func
purchase
(
subscription
:
SKProduct
)
{
...
...
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