Skip to content

Commit 2ebfb96

Browse files
committed
Add streakDescription for habit detail
1 parent cc44388 commit 2ebfb96

File tree

7 files changed

+49
-35
lines changed

7 files changed

+49
-35
lines changed

LongevityMaster.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
376376
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
377377
CODE_SIGN_STYLE = Automatic;
378-
CURRENT_PROJECT_VERSION = 1.1.0.1;
378+
CURRENT_PROJECT_VERSION = 1.2.0.1;
379379
DEVELOPMENT_ASSET_PATHS = "\"LongevityMaster/Preview Content\"";
380380
DEVELOPMENT_TEAM = F694X76A5X;
381381
ENABLE_PREVIEWS = YES;
@@ -392,7 +392,7 @@
392392
"$(inherited)",
393393
"@executable_path/Frameworks",
394394
);
395-
MARKETING_VERSION = 1.1.0;
395+
MARKETING_VERSION = 1.2.0;
396396
PRODUCT_BUNDLE_IDENTIFIER = com.appsbayarea.longevityMaster;
397397
PRODUCT_NAME = "$(TARGET_NAME)";
398398
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -409,7 +409,7 @@
409409
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
410410
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
411411
CODE_SIGN_STYLE = Automatic;
412-
CURRENT_PROJECT_VERSION = 1.1.0.1;
412+
CURRENT_PROJECT_VERSION = 1.2.0.1;
413413
DEVELOPMENT_ASSET_PATHS = "\"LongevityMaster/Preview Content\"";
414414
DEVELOPMENT_TEAM = F694X76A5X;
415415
ENABLE_PREVIEWS = YES;
@@ -426,7 +426,7 @@
426426
"$(inherited)",
427427
"@executable_path/Frameworks",
428428
);
429-
MARKETING_VERSION = 1.1.0;
429+
MARKETING_VERSION = 1.2.0;
430430
PRODUCT_BUNDLE_IDENTIFIER = com.appsbayarea.longevityMaster;
431431
PRODUCT_NAME = "$(TARGET_NAME)";
432432
SWIFT_EMIT_LOC_STRINGS = YES;

LongevityMaster.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LongevityMaster/App/LongevityMasterApp.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ struct LongevityMasterApp: App {
1616
@Dependency(\.purchaseManager) private var purchaseManager
1717
@StateObject private var openAd = OpenAd()
1818
@Environment(\.scenePhase) private var scenePhase
19-
@State private var didShowOpenAd = false
2019

2120
init() {
2221
MobileAds.shared.start(completionHandler: nil)

LongevityMaster/Base.lproj/LaunchScreen.storyboard

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23727" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
33
<device id="retina6_12" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23721"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
77
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
88
</dependencies>
@@ -16,35 +16,17 @@
1616
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1717
<subviews>
1818
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="appIcon360" translatesAutoresizingMaskIntoConstraints="NO" id="ZYi-5Z-Gy0">
19-
<rect key="frame" x="121.66666666666669" y="276" width="150" height="180"/>
19+
<rect key="frame" x="121" y="336" width="150" height="180"/>
2020
<constraints>
2121
<constraint firstAttribute="width" constant="150" id="qrQ-a4-7kl"/>
2222
<constraint firstAttribute="height" constant="180" id="xTC-UG-mtM"/>
2323
</constraints>
2424
</imageView>
25-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="LongevityMaster" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
26-
<rect key="frame" x="0.0" y="476" width="393" height="43"/>
27-
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
28-
<color key="textColor" red="1" green="0.46999999999999997" blue="0.17999999999999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
29-
<nil key="highlightedColor"/>
30-
</label>
31-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Build Healthy Habits for Life" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="12" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
32-
<rect key="frame" x="0.0" y="529" width="393" height="21"/>
33-
<fontDescription key="fontDescription" type="system" pointSize="17"/>
34-
<color key="textColor" red="0.56000000000000005" green="0.56000000000000005" blue="0.57999999999999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
35-
<nil key="highlightedColor"/>
36-
</label>
3725
</subviews>
3826
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
3927
<color key="backgroundColor" red="1" green="0.96470588235294119" blue="0.93333333333333335" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
4028
<constraints>
41-
<constraint firstItem="obG-Y5-kRd" firstAttribute="top" secondItem="GJd-Yh-RWb" secondAttribute="bottom" constant="10" id="5cz-MP-9tL"/>
42-
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="Q3B-4B-g5h"/>
43-
<constraint firstItem="obG-Y5-kRd" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="SfN-ll-jLj"/>
44-
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="Y44-ml-fuU"/>
45-
<constraint firstItem="ZYi-5Z-Gy0" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" constant="-60" id="cJh-R0-oOg"/>
46-
<constraint firstItem="GJd-Yh-RWb" firstAttribute="top" secondItem="ZYi-5Z-Gy0" secondAttribute="bottom" constant="20" id="moa-c2-u7t"/>
47-
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="x7j-FC-K8j"/>
29+
<constraint firstItem="ZYi-5Z-Gy0" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="cJh-R0-oOg"/>
4830
<constraint firstItem="ZYi-5Z-Gy0" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="xWU-4O-h0Y"/>
4931
</constraints>
5032
</view>

LongevityMaster/Components/Habits/HabitDetail.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class HabitDetailViewModel {
4646
case monthly = "Monthly"
4747
case yearly = "Yearly"
4848
var id: String { rawValue }
49+
50+
var displayName: String {
51+
switch self {
52+
case .monthly: String(localized: "Monthly")
53+
case .yearly: String(localized: "Yearly")
54+
}
55+
}
4956
}
5057

5158
var calendarMode: CalendarMode = .monthly
@@ -71,12 +78,30 @@ class HabitDetailViewModel {
7178
}
7279

7380
var todayHabit: TodayHabit {
74-
habit.toTodayHabit(
81+
let calendar = Calendar.current
82+
let today = calendar.startOfDay(for: Date())
83+
let streak = calculateCurrentStreak(checkIns: checkIns, calendar: calendar, today: today)
84+
let streakDescription = streak > 0 ? String(localized: "🔥 \(streak)d streak") : nil
85+
return habit.toTodayHabit(
7586
isCompleted: true,
76-
streakDescription: habit.frequencyDescription
87+
streakDescription: streakDescription,
88+
frequencyDescription: habit.frequencyDescription
7789
)
7890
}
7991

92+
private func calculateCurrentStreak(checkIns: [CheckIn], calendar: Calendar, today: Date) -> Int {
93+
let sortedDates = checkIns.map { calendar.startOfDay(for: $0.date) }.sorted(by: >)
94+
var streak = 0
95+
var currentDate = today
96+
let dateSet = Set(sortedDates)
97+
while dateSet.contains(currentDate) {
98+
streak += 1
99+
guard let previousDate = calendar.date(byAdding: .day, value: -1, to: currentDate) else { break }
100+
currentDate = previousDate
101+
}
102+
return streak
103+
}
104+
80105
var reminders: [Reminder.Draft] {
81106
allReminders.filter { $0.habitID == habit.id }.map(Reminder.Draft.init)
82107
}
@@ -325,7 +350,7 @@ struct HabitDetailView: View {
325350
// Segmented control for calendar mode
326351
Picker("Mode", selection: $viewModel.calendarMode) {
327352
ForEach(HabitDetailViewModel.CalendarMode.allCases) { mode in
328-
Text(mode.rawValue).tag(mode)
353+
Text(mode.displayName).tag(mode)
329354
}
330355
}
331356
.pickerStyle(SegmentedPickerStyle())

LongevityMaster/Config/Debug.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
// https://help.apple.com/xcode/#/dev745c5c974
99

1010
GADApplicationIdentifier = ca-app-pub-3940256099942544~1458002511
11-
bannerViewAdUnitID = ca-app-pub-3940256099942544/2435281174
11+
bannerViewAdUnitID = ca-app-pub-3940256099942544/2934735716
1212
appOpenAdID = ca-app-pub-3940256099942544/5575463023

LongevityMaster/mul.lproj/LaunchScreen.xcstrings

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"strings" : {
44
"GJd-Yh-RWb.text" : {
55
"comment" : "Class = \"UILabel\"; text = \"LongevityMaster\"; ObjectID = \"GJd-Yh-RWb\";",
6-
"extractionState" : "extracted_with_value",
6+
"extractionState" : "stale",
77
"localizations" : {
88
"en" : {
99
"stringUnit" : {
@@ -21,7 +21,7 @@
2121
},
2222
"obG-Y5-kRd.text" : {
2323
"comment" : "Class = \"UILabel\"; text = \"Build Healthy Habits for Life\"; ObjectID = \"obG-Y5-kRd\";",
24-
"extractionState" : "extracted_with_value",
24+
"extractionState" : "stale",
2525
"localizations" : {
2626
"en" : {
2727
"stringUnit" : {

0 commit comments

Comments
 (0)