Skip to content

Commit

Permalink
Added Remaining label if ETADisplay goes into count down mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Clon1998 committed Nov 15, 2023
1 parent bd05a75 commit 2cc48b4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 39 deletions.
4 changes: 3 additions & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"elapsed": "Verstrichen",
"flow": "Fluss",
"filament": "Filament",
"filament_tooltip": "{} % Filament Verwendet, dass ist {} m der vorhergesagten {} m."
"filament_tooltip": "{} % Filament Verwendet, dass ist {} m der vorhergesagten {} m.",
"eta_tooltip": "Verbleibende Zeit:\nØ: {avg}\nSlicer: {slicer}\nDatei: {file}\nFilament: {filament}",
"remaining": "Verbleibend"
},
"cam_card": {
"webcam": "Webcam",
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"flow": "Flow",
"filament": "Filament",
"filament_tooltip": "Used {} % of Filament, that is {} m of the {} m predicted.",
"eta_tooltip": "Remaining time:\nAVG: {avg}\nSlicer: {slicer}\nFile: {file}\nFilament: {filament}"
"eta_tooltip": "Remaining time:\nAVG: {avg}\nSlicer: {slicer}\nFile: {file}\nFilament: {filament}",
"remaining": "Remaining"
},
"cam_card": {
"webcam": "Webcam",
Expand Down
1 change: 1 addition & 0 deletions common/lib/service/live_activity_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class LiveActivityService {
'machine_name': machine.name,
'eta_label': tr('pages.dashboard.general.print_card.eta'),
'elapsed_label': tr('pages.dashboard.general.print_card.elapsed'),
'remaining_label': tr('pages.dashboard.general.print_card.remaining'),
};
if ({PrintState.printing, PrintState.paused, PrintState.complete, PrintState.cancelled}
.contains(printer.print.state)) {
Expand Down
25 changes: 5 additions & 20 deletions ios/MobilrakerLiveActivity/PrintingLiveActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ struct PrintingLiveActivity: Widget {

let primaryColor = sharedDefault.integer(forKey: context.attributes.prefixedKey(key:"primary_color_light"))
let machineName = sharedDefault.string(forKey: context.attributes.prefixedKey(key:"machine_name"))!
let etaLabel = sharedDefault.string(forKey: context.attributes.prefixedKey(key:"eta_label"))!
let elapsedLabel = sharedDefault.string(forKey: context.attributes.prefixedKey(key:"elapsed_label"))!


Expand All @@ -77,12 +76,7 @@ struct PrintingLiveActivity: Widget {
}

if !isPrintDone {
VStack(alignment: .leading) {
Text(etaLabel)
.font(.title2)
.fontWeight(.light)
EtaDisplayView(etaDate: etaDate)
}
EtaDisplayView(activityContext: context, etaDate: etaDate)
}

}
Expand Down Expand Up @@ -111,7 +105,6 @@ struct PrintingLiveActivity: Widget {

let primaryColor = sharedDefault.integer(forKey:context.attributes.prefixedKey(key: "primary_color_dark"))
let machineName = sharedDefault.string(forKey: context.attributes.prefixedKey(key:"machine_name"))!
let etaLabel = sharedDefault.string(forKey:context.attributes.prefixedKey(key: "eta_label"))!
let elapsedLabel = sharedDefault.string(forKey: context.attributes.prefixedKey(key:"elapsed_label"))!

return DynamicIsland {
Expand All @@ -134,30 +127,22 @@ struct PrintingLiveActivity: Widget {
VStack(alignment: .leading) {
Text(file)
if !isPrintDone {
HStack {
VStack(alignment: .leading) {
Text(etaLabel)
.font(.title2)
.fontWeight(.light)
EtaDisplayView(etaDate: etaDate)
}
.frame(maxWidth: .infinity, alignment: .leading) // Expand to fill available space
}
EtaDisplayView(activityContext: context, etaDate: etaDate)
.frame(maxWidth: .infinity, alignment: .leading) // Expand to fill available space
}
}
}
} compactLeading: {
let progress = context.state.progress ?? sharedDefault.double(forKey: context.attributes.prefixedKey(key:"progress"))
let isPrintDone = abs(progress - 1) < 0.0001

let eta = context.state.eta ?? sharedDefault.integer(forKey: context.attributes.prefixedKey(key:"eta"))
let etaDate = eta > 0 ? Date(timeIntervalSince1970: TimeInterval(eta)) : nil

if isPrintDone {
Image("mr_logo")
.resizable()
.scaledToFit()
} else {
let eta = context.state.eta ?? sharedDefault.integer(forKey: context.attributes.prefixedKey(key:"eta"))
let etaDate = eta > 0 ? Date(timeIntervalSince1970: TimeInterval(eta)) : nil
EtaDisplayViewCompact(etaDate: etaDate, width: 50)
.padding(.horizontal, 2.0)
}
Expand Down
44 changes: 27 additions & 17 deletions ios/MobilrakerLiveActivity/UI/EtaDisplayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,40 @@
//

import SwiftUI
import WidgetKit
import Foundation

struct EtaDisplayView: View {
let activityContext: ActivityViewContext<LiveActivitiesAppAttributes>
let etaDate: Date?


// Computed property for etaLabel
private var etaLabel: String {
return sharedDefault.string(forKey: activityContext.attributes.prefixedKey(key: "eta_label"))!
}

// Computed property for remainingLabel
private var remainingLabel: String {
return sharedDefault.string(forKey: activityContext.attributes.prefixedKey(key: "remaining_label"))!
}

var body: some View {
if let eta = etaDate {
if shouldShowAsTimer(eta: eta) {
TimerTextView(eta: eta)
VStack(alignment: .leading) {
Text(shouldShowAsTimer(eta: etaDate) ? remainingLabel : etaLabel)
.font(.title2)
.fontWeight(.light)

if let eta = etaDate {
if shouldShowAsTimer(eta: eta) {
TimerTextView(eta: eta)
} else {
FormattedDateTextView(eta: eta)
}
} else {
FormattedDateTextView(eta: eta)
Text("--")
.font(.title)
.fontWeight(.semibold)
}
} else {
Text("--")
.font(.title)
.fontWeight(.semibold)
}
}
}
Expand Down Expand Up @@ -105,14 +123,6 @@ struct FormattedDateTextView: View {

}


struct EtaDisplayView_Previews: PreviewProvider {
static var previews: some View {
EtaDisplayView(etaDate: Date() )
}
}


func shouldShowAsTimer(eta: Date?, delta: Int = 3) -> Bool {
guard let eta = eta else {
return false
Expand Down

0 comments on commit 2cc48b4

Please sign in to comment.