Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions LoopFollow/Remote/Settings/RemoteSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ struct RemoteSettingsView: View {

if device.value == "Trio" {
HStack {
Text("Max Protein")
Text("Max Fat")
Spacer()
TextFieldWithToolBar(
quantity: $viewModel.maxProtein,
quantity: $viewModel.maxFat,
maxLength: 4,
unit: HKUnit.gram(),
allowDecimalSeparator: true,
Expand All @@ -469,10 +469,10 @@ struct RemoteSettingsView: View {
}

HStack {
Text("Max Fat")
Text("Max Protein")
Spacer()
TextFieldWithToolBar(
quantity: $viewModel.maxFat,
quantity: $viewModel.maxProtein,
maxLength: 4,
unit: HKUnit.gram(),
allowDecimalSeparator: true,
Expand Down
39 changes: 31 additions & 8 deletions LoopFollow/Remote/TRC/MealView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct MealView: View {
@State private var statusMessage: String? = nil
@State private var selectedTime: Date? = nil
@State private var isScheduling: Bool = false
@State private var showFatProteinOrderBanner = false

enum AlertType {
case confirmMeal
Expand All @@ -46,6 +47,24 @@ struct MealView: View {
VStack {
Form {
Section(header: Text("Meal Data")) {
// TODO: This banner can be deleted in March 2027. Check the commit for other places to cleanup.
if showFatProteinOrderBanner {
HStack {
Image(systemName: "arrow.left.arrow.right")
Text("The order of Fat and Protein inputs has changed.").font(.callout)
Spacer()
Button {
Storage.shared.hasSeenFatProteinOrderChange.value = true
withAnimation { showFatProteinOrderBanner = false }
} label: {
Image(systemName: "xmark.circle.fill")
}
.buttonStyle(.plain)
}
.listRowBackground(Color.orange.opacity(0.75))
.transition(.opacity)
}

HKQuantityInputView(
label: "Carbs",
quantity: $carbs,
Expand All @@ -61,26 +80,26 @@ struct MealView: View {

if mealWithFatProtein.value {
HKQuantityInputView(
label: "Protein",
quantity: $protein,
label: "Fat",
quantity: $fat,
unit: .gram(),
maxLength: 4,
minValue: HKQuantity(unit: .gram(), doubleValue: 0),
maxValue: maxProtein.value,
isFocused: $proteinFieldIsFocused,
maxValue: maxFat.value,
isFocused: $fatFieldIsFocused,
onValidationError: { message in
handleValidationError(message)
}
)

HKQuantityInputView(
label: "Fat",
quantity: $fat,
label: "Protein",
quantity: $protein,
unit: .gram(),
maxLength: 4,
minValue: HKQuantity(unit: .gram(), doubleValue: 0),
maxValue: maxFat.value,
isFocused: $fatFieldIsFocused,
maxValue: maxProtein.value,
isFocused: $proteinFieldIsFocused,
onValidationError: { message in
handleValidationError(message)
}
Expand Down Expand Up @@ -153,6 +172,10 @@ struct MealView: View {
.onAppear {
selectedTime = nil
isScheduling = false

if !Storage.shared.hasSeenFatProteinOrderChange.value {
showFatProteinOrderBanner = true
}
}
.alert(isPresented: $showAlert) {
switch alertType {
Expand Down
3 changes: 3 additions & 0 deletions LoopFollow/Storage/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Storage {
var mealWithBolus = StorageValue<Bool>(key: "mealWithBolus", defaultValue: false)
var mealWithFatProtein = StorageValue<Bool>(key: "mealWithFatProtein", defaultValue: false)

// TODO: This flag can be deleted in March 2027. Check the commit for other places to cleanup.
var hasSeenFatProteinOrderChange = StorageValue<Bool>(key: "hasSeenFatProteinOrderChange", defaultValue: false)

var cachedJWT = StorageValue<String?>(key: "cachedJWT", defaultValue: nil)
var jwtExpirationDate = StorageValue<Date?>(key: "jwtExpirationDate", defaultValue: nil)

Expand Down
11 changes: 11 additions & 0 deletions LoopFollow/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele

loadDebugData()

// Capture before migrations run: true for existing users, false for fresh installs.
let isExistingUser = Storage.shared.migrationStep.exists

if Storage.shared.migrationStep.value < 1 {
Storage.shared.migrateStep1()
Storage.shared.migrationStep.value = 1
Expand All @@ -152,6 +155,14 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
Storage.shared.migrationStep.value = 3
}

// TODO: This migration step can be deleted in March 2027. Check the commit for other places to cleanup.
if Storage.shared.migrationStep.value < 4 {
// Existing users need to see the fat/protein order change banner.
// New users never saw the old order, so mark it as already seen.
Storage.shared.hasSeenFatProteinOrderChange.value = !isExistingUser
Storage.shared.migrationStep.value = 4
}

// Synchronize info types to ensure arrays are the correct size
synchronizeInfoTypes()

Expand Down