feat: major app overhaul — API fixes, glassmorphism UI, health dashboard, notifications

API Integration:
- Fix logHabit: send "date" instead of "completed_at"
- Fix FinanceCategory: "icon" → "emoji" to match API
- Fix task priorities: remove level 4, keep 1-3 matching API
- Fix habit frequencies: map monthly/interval → "custom" for API
- Add token refresh (401 → auto retry with new token)
- Add proper error handling (remove try? in save functions, show errors in UI)
- Add date field to savings transactions
- Add MonthlyPaymentDetail and OverduePayment models
- Fix habit completedToday: compute on client from logs (API doesn't return it)
- Filter habits by day of week on client (daily/weekly/monthly/interval)

Design System (glassmorphism):
- New DesignSystem.swift: Theme colors, GlassCard modifier, GlowIcon, GlowStatCard
- Custom tab bar with per-tab glow colors (VStack layout, not ZStack overlay)
- Deep dark background #06060f across all views
- Glass cards with gradient fill + stroke throughout app
- App icon: glassmorphism style with teal glow

Health Dashboard:
- Compact ReadinessBanner with recommendation text
- 8 metric tiles: sleep, HR, HRV, steps, SpO2, respiratory rate, energy, distance
- Each tile with status indicator (good/ok/bad) and hint text
- Heart rate card (min/avg/max)
- Weekly trends card (averages)
- Recovery score (weighted: 40% sleep, 35% HRV, 25% RHR)
- Tips card with actionable recommendations
- Sleep detail view with hypnogram (step chart of phases)
- Sleep segments timeline from HealthKit (deep/rem/core/awake with exact times)
- Line chart replacing bar chart for weekly data
- Collect respiratory_rate and sleep phases with timestamps from HealthKit
- Background sync every ~30min via BGProcessingTask

Notifications:
- NotificationService for local push notifications
- Morning/evening reminders with native DatePicker (wheel)
- Payment reminders: 5 days, 1 day, and day-of for recurring savings
- Notification settings in Settings tab

UI Fixes:
- Fix color picker overflow: HStack → LazyVGrid 5 columns
- Fix sheet headers: shorter text, proper padding
- Fix task/habit toggle: separate tap zones (checkbox vs edit)
- Fix deprecated onChange syntax for iOS 17+
- Savings overview: real monthly payments and detailed overdues from API
- Settings: timezone as Menu picker, removed Telegram/server notifications sections
- All sheets use .presentationDetents([.large])

Config:
- project.yml: real DEVELOPMENT_TEAM, HealthKit + BackgroundModes capabilities
- Info.plist: BGTaskScheduler + UIBackgroundModes
- Assets.xcassets with AppIcon
- CLAUDE.md project documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-05 23:15:36 +03:00
parent 1146965bcb
commit 28fca1de89
38 changed files with 3608 additions and 1031 deletions

View File

@@ -12,13 +12,21 @@ struct SettingsView: View {
// Profile fields
@State private var telegramChatId = ""
@State private var morningNotification = true
@State private var eveningNotification = true
@State private var morningTime = "09:00"
@State private var eveningTime = "21:00"
@State private var timezone = "Europe/Moscow"
@State private var username = ""
// Local notifications
@AppStorage("notif_morning") private var morningNotif = false
@AppStorage("notif_evening") private var eveningNotif = false
@AppStorage("notif_morning_hour") private var morningHour = 8
@AppStorage("notif_morning_min") private var morningMin = 0
@AppStorage("notif_evening_hour") private var eveningHour = 21
@AppStorage("notif_evening_min") private var eveningMin = 0
@AppStorage("notif_payments") private var paymentNotif = true
@State private var notifAuthorized = false
@State private var morningDate = Calendar.current.date(from: DateComponents(hour: 8, minute: 0))!
@State private var eveningDate = Calendar.current.date(from: DateComponents(hour: 21, minute: 0))!
var isDark: Bool { colorSchemeRaw != "light" }
let timezones = [
@@ -30,7 +38,7 @@ struct SettingsView: View {
var body: some View {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
Color(hex: "06060f").ignoresSafeArea()
ScrollView {
VStack(spacing: 0) {
// Header / Avatar
@@ -74,77 +82,78 @@ struct SettingsView: View {
}
}
// MARK: Telegram
SettingsSection(title: "Telegram Бот") {
VStack(alignment: .leading, spacing: 8) {
Label("Chat ID", systemImage: "paperplane.fill")
.font(.caption).foregroundColor(Color(hex: "8888aa"))
TextField("Например: 123456789", text: $telegramChatId)
.keyboardType(.numbersAndPunctuation)
.foregroundColor(.white).padding(14)
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.07)))
HStack(spacing: 4) {
Image(systemName: "info.circle").font(.caption2).foregroundColor(Color(hex: "0D9488"))
Text("Напишите /start боту @pulse_tracking_bot, чтобы получить Chat ID")
.font(.caption2).foregroundColor(Color(hex: "8888aa"))
}
}
.padding(.horizontal, 4)
}
// MARK: Notifications
SettingsSection(title: "Уведомления") {
VStack(spacing: 12) {
SettingsToggle(icon: "sunrise.fill", title: "Утренние уведомления", color: "ffa502", isOn: morningNotification) {
morningNotification.toggle()
}
if morningNotification {
HStack {
Text("Время").font(.callout).foregroundColor(Color(hex: "8888aa"))
if !notifAuthorized {
Button(action: {
Task { notifAuthorized = await NotificationService.shared.requestPermission() }
}) {
HStack(spacing: 14) {
GlowIcon(systemName: "bell.badge.fill", color: Theme.orange, size: 36, iconSize: .subheadline)
VStack(alignment: .leading, spacing: 2) {
Text("Включить уведомления").font(.callout).foregroundColor(.white)
Text("Нажми, чтобы разрешить").font(.caption).foregroundColor(Theme.textSecondary)
}
Spacer()
TextField("09:00", text: $morningTime)
.keyboardType(.numbersAndPunctuation)
.foregroundColor(.white)
.multilineTextAlignment(.trailing)
.frame(width: 60)
Image(systemName: "arrow.right.circle.fill").foregroundColor(Theme.teal)
}
.padding(.horizontal, 4)
}
Divider().background(Color.white.opacity(0.08))
SettingsToggle(icon: "moon.stars.fill", title: "Вечерние уведомления", color: "6366f1", isOn: eveningNotification) {
eveningNotification.toggle()
}
if eveningNotification {
HStack {
Text("Время").font(.callout).foregroundColor(Color(hex: "8888aa"))
} else {
VStack(spacing: 14) {
// Morning
NotifRow(icon: "sunrise.fill", title: "Утреннее", color: Theme.orange,
isOn: $morningNotif, date: $morningDate)
Divider().background(Color.white.opacity(0.06))
// Evening
NotifRow(icon: "moon.stars.fill", title: "Вечернее", color: Theme.indigo,
isOn: $eveningNotif, date: $eveningDate)
Divider().background(Color.white.opacity(0.06))
// Payments
HStack(spacing: 14) {
GlowIcon(systemName: "creditcard.fill", color: Theme.purple, size: 36, iconSize: .subheadline)
VStack(alignment: .leading, spacing: 2) {
Text("Платежи").font(.callout).foregroundColor(.white)
Text("За 5 дн, 1 день и в день оплаты").font(.caption2).foregroundColor(Theme.textSecondary)
}
Spacer()
TextField("21:00", text: $eveningTime)
.keyboardType(.numbersAndPunctuation)
.foregroundColor(.white)
.multilineTextAlignment(.trailing)
.frame(width: 60)
Toggle("", isOn: $paymentNotif).tint(Theme.teal).labelsHidden()
}
.padding(.horizontal, 4)
}
.onChange(of: morningNotif) { applyNotifSchedule() }
.onChange(of: eveningNotif) { applyNotifSchedule() }
.onChange(of: morningDate) { saveTimes(); applyNotifSchedule() }
.onChange(of: eveningDate) { saveTimes(); applyNotifSchedule() }
.onChange(of: paymentNotif) { Task { await schedulePaymentNotifs() } }
}
}
// MARK: Timezone
SettingsSection(title: "Часовой пояс") {
VStack(alignment: .leading, spacing: 8) {
Label("Выберите часовой пояс", systemImage: "clock.fill")
.font(.caption).foregroundColor(Color(hex: "8888aa"))
Picker("Часовой пояс", selection: $timezone) {
ForEach(timezones, id: \.self) { tz in Text(tz).tag(tz) }
HStack(spacing: 14) {
GlowIcon(systemName: "clock.fill", color: Theme.blue, size: 36, iconSize: .subheadline)
VStack(alignment: .leading, spacing: 2) {
Text("Часовой пояс").font(.callout).foregroundColor(.white)
Text(timezoneDisplay(timezone)).font(.caption).foregroundColor(Theme.textSecondary)
}
Spacer()
Menu {
ForEach(timezones, id: \.self) { tz in
Button(action: { timezone = tz }) {
HStack {
Text(timezoneDisplay(tz))
if timezone == tz { Image(systemName: "checkmark") }
}
}
}
} label: {
HStack(spacing: 4) {
Text(timezoneShort(timezone)).font(.callout.bold()).foregroundColor(Theme.teal)
Image(systemName: "chevron.up.chevron.down").font(.caption2).foregroundColor(Theme.teal)
}
.padding(.horizontal, 12).padding(.vertical, 8)
.background(RoundedRectangle(cornerRadius: 10).fill(Theme.teal.opacity(0.15)))
}
.pickerStyle(.wheel)
.frame(height: 120)
.clipped()
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.04)))
}
.padding(.horizontal, 4)
}
// MARK: Save Button
@@ -186,20 +195,19 @@ struct SettingsView: View {
ChangePasswordView(isPresented: $showPasswordChange)
.presentationDetents([.medium])
.presentationDragIndicator(.visible)
.presentationBackground(Color(hex: "0a0a1a"))
.presentationBackground(Color(hex: "06060f"))
}
}
func loadProfile() async {
isLoading = true
username = authManager.userName
notifAuthorized = await NotificationService.shared.isAuthorized()
morningDate = Calendar.current.date(from: DateComponents(hour: morningHour, minute: morningMin)) ?? morningDate
eveningDate = Calendar.current.date(from: DateComponents(hour: eveningHour, minute: eveningMin)) ?? eveningDate
if let p = try? await APIService.shared.getProfile(token: authManager.token) {
profile = p
telegramChatId = p.telegramChatId ?? ""
morningNotification = p.morningNotification ?? true
eveningNotification = p.eveningNotification ?? true
morningTime = p.morningTime ?? "09:00"
eveningTime = p.eveningTime ?? "21:00"
timezone = p.timezone ?? "Europe/Moscow"
}
isLoading = false
@@ -209,10 +217,6 @@ struct SettingsView: View {
isSaving = true
let req = UpdateProfileRequest(
telegramChatId: telegramChatId.isEmpty ? nil : telegramChatId,
morningNotification: morningNotification,
eveningNotification: eveningNotification,
morningTime: morningTime,
eveningTime: eveningTime,
timezone: timezone
)
_ = try? await APIService.shared.updateProfile(token: authManager.token, request: req)
@@ -228,6 +232,51 @@ struct SettingsView: View {
}
isSaving = false
}
func applyNotifSchedule() {
let cal = Calendar.current
let mh = cal.component(.hour, from: morningDate)
let mm = cal.component(.minute, from: morningDate)
let eh = cal.component(.hour, from: eveningDate)
let em = cal.component(.minute, from: eveningDate)
NotificationService.shared.updateSchedule(
morning: morningNotif, morningTime: "\(mh):\(String(format: "%02d", mm))",
evening: eveningNotif, eveningTime: "\(eh):\(String(format: "%02d", em))"
)
}
func saveTimes() {
let cal = Calendar.current
morningHour = cal.component(.hour, from: morningDate)
morningMin = cal.component(.minute, from: morningDate)
eveningHour = cal.component(.hour, from: eveningDate)
eveningMin = cal.component(.minute, from: eveningDate)
}
func schedulePaymentNotifs() async {
guard paymentNotif else {
NotificationService.shared.cancelPaymentReminders()
return
}
let stats = try? await APIService.shared.getSavingsStats(token: authManager.token)
guard let details = stats?.monthlyPaymentDetails else { return }
NotificationService.shared.schedulePaymentReminders(payments: details)
}
func timezoneDisplay(_ tz: String) -> String {
guard let zone = TimeZone(identifier: tz) else { return tz }
let offset = zone.secondsFromGMT() / 3600
let sign = offset >= 0 ? "+" : ""
let city = tz.split(separator: "/").last?.replacingOccurrences(of: "_", with: " ") ?? tz
return "\(city) (UTC\(sign)\(offset))"
}
func timezoneShort(_ tz: String) -> String {
guard let zone = TimeZone(identifier: tz) else { return tz }
let offset = zone.secondsFromGMT() / 3600
let sign = offset >= 0 ? "+" : ""
return "UTC\(sign)\(offset)"
}
}
// MARK: - SettingsSection
@@ -242,7 +291,7 @@ struct SettingsSection<Content: View>: View {
content()
}
.padding(16)
.background(RoundedRectangle(cornerRadius: 16).fill(Color.white.opacity(0.04)))
.glassCard(cornerRadius: 16)
.padding(.horizontal)
}
}
@@ -258,14 +307,11 @@ struct SettingsToggle: View {
let onToggle: () -> Void
var body: some View {
HStack(spacing: 14) {
ZStack {
RoundedRectangle(cornerRadius: 8).fill(Color(hex: color).opacity(0.2)).frame(width: 36, height: 36)
Image(systemName: icon).foregroundColor(Color(hex: color)).font(.subheadline)
}
GlowIcon(systemName: icon, color: Color(hex: color), size: 36, iconSize: .subheadline)
Text(title).font(.callout).foregroundColor(.white)
Spacer()
Toggle("", isOn: Binding(get: { isOn }, set: { _ in onToggle() }))
.tint(Color(hex: "0D9488"))
.tint(Theme.teal)
}
}
}
@@ -280,13 +326,39 @@ struct SettingsButton: View {
var body: some View {
Button(action: action) {
HStack(spacing: 14) {
ZStack {
RoundedRectangle(cornerRadius: 8).fill(Color(hex: color).opacity(0.2)).frame(width: 36, height: 36)
Image(systemName: icon).foregroundColor(Color(hex: color)).font(.subheadline)
}
GlowIcon(systemName: icon, color: Color(hex: color), size: 36, iconSize: .subheadline)
Text(title).font(.callout).foregroundColor(.white)
Spacer()
Image(systemName: "chevron.right").foregroundColor(Color(hex: "8888aa")).font(.caption)
Image(systemName: "chevron.right").foregroundColor(Theme.textSecondary).font(.caption)
}
}
}
}
// MARK: - NotifRow
struct NotifRow: View {
let icon: String
let title: String
let color: Color
@Binding var isOn: Bool
@Binding var date: Date
var body: some View {
VStack(spacing: 8) {
HStack(spacing: 14) {
GlowIcon(systemName: icon, color: color, size: 36, iconSize: .subheadline)
Text(title).font(.callout).foregroundColor(.white)
Spacer()
Toggle("", isOn: $isOn).tint(Theme.teal).labelsHidden()
}
if isOn {
DatePicker("", selection: $date, displayedComponents: .hourAndMinute)
.datePickerStyle(.wheel)
.labelsHidden()
.frame(height: 100)
.clipped()
.environment(\.colorScheme, .dark)
}
}
}