forked from Blendman974/faceclaw
Phone UI: show the glasses, charging case and R1 battery levels
A line under the mirror lists each device whose level is known, e.g. "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging), in portrait and landscape. The case level joins the shell's battery state beside the glasses and R1 (it is not drawn in the glasses' top bar) and reaches the page through the dashboard snapshot. Like the glasses level it is kept across disconnects: the case only reports while the glasses are docked and only drains while charging them.
This commit is contained in:
1 parent
acfcf79787
commit
9c0535014a
6 files changed
+70
-6
No files matched your search
@@ -19,7 +19,7 @@
|
||||
</ActionBar>
|
||||
|
||||
<GridLayout>
|
||||
<GridLayout rows="auto,*" visibility="{{ portraitLayoutVisibility }}">
|
||||
<GridLayout rows="auto,auto,*" visibility="{{ portraitLayoutVisibility }}">
|
||||
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
|
||||
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}"
|
||||
tap="{{ onMirrorTap }}" doubleTap="{{ onMirrorDoubleTap }}" longPress="{{ onMirrorLongPress }}" swipe="{{ onMirrorSwipe }}" />
|
||||
@@ -31,9 +31,10 @@
|
||||
visibility="{{ displayPreviewMessageVisibility }}">
|
||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
<Label row="1" text="{{ batteryLine }}" visibility="{{ batteryLineVisibility }}" class="battery-line" />
|
||||
<!-- The controls get the whole star row so the active tab's
|
||||
content can center in the leftover height. -->
|
||||
<GridLayout row="1" rows="*,auto" class="p-20">
|
||||
<GridLayout row="2" rows="*,auto" class="p-20">
|
||||
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
|
||||
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||
</GridLayout>
|
||||
@@ -60,9 +61,10 @@
|
||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
<GridLayout col="1" rows="*,auto">
|
||||
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
|
||||
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||
<GridLayout col="1" rows="auto,*,auto">
|
||||
<Label row="0" text="{{ batteryLine }}" visibility="{{ batteryLineVisibility }}" class="battery-line" />
|
||||
<rc:remote-controls row="1" visibility="{{ controlsVisibility }}" />
|
||||
<Button row="2" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
type TouchGestureEventData,
|
||||
type View,
|
||||
} from "@nativescript/core";
|
||||
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
|
||||
import { dashboardController, type DashboardSnapshot, type MirrorTouchKind } from "../g2/dashboard-controller";
|
||||
import {
|
||||
mirrorTouchSetting,
|
||||
onAnySettingChanged,
|
||||
@@ -32,8 +32,26 @@ const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
|
||||
|
||||
type LayoutOrientation = "portrait" | "landscape";
|
||||
|
||||
/**
|
||||
* The line under the mirror: each device whose level is known, e.g.
|
||||
* "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging). The case level is the last
|
||||
* one the glasses relayed; it only reports while they are docked.
|
||||
*/
|
||||
function formatBatteryLine(levels: DashboardSnapshot["batteries"]): string {
|
||||
const devices: Array<[string, number | null, boolean | null]> = [
|
||||
["G2", levels.headset, levels.headsetCharging],
|
||||
["Case", levels.case, levels.caseCharging],
|
||||
["R1", levels.ring, levels.ringCharging],
|
||||
];
|
||||
return devices
|
||||
.filter(([, level]) => level !== null)
|
||||
.map(([label, level, charging]) => `${label} ${level}%${charging ? " ⚡" : ""}`)
|
||||
.join(" · ");
|
||||
}
|
||||
|
||||
export class MainViewModel extends RemoteControlsViewModel {
|
||||
private _status = "Disconnected.";
|
||||
private _batteryLine = "";
|
||||
private _displayPreview: ImageSource | null = null;
|
||||
private _displayPreviewMessage = "";
|
||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||
@@ -90,6 +108,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.phase = snapshot.phase;
|
||||
this.batteryLine = formatBatteryLine(snapshot.batteries);
|
||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
||||
@@ -149,6 +168,21 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
* (which can be a sentence, e.g. a failure reason) stays available by
|
||||
* tapping the indicator.
|
||||
*/
|
||||
get batteryLine(): string {
|
||||
return this._batteryLine;
|
||||
}
|
||||
|
||||
set batteryLine(value: string) {
|
||||
if (this._batteryLine === value) return;
|
||||
this._batteryLine = value;
|
||||
this.notifyPropertyChange("batteryLine", value);
|
||||
this.notifyPropertyChange("batteryLineVisibility", this.batteryLineVisibility);
|
||||
}
|
||||
|
||||
get batteryLineVisibility(): "visible" | "collapse" {
|
||||
return this._batteryLine ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get connectionStatusLabel(): string {
|
||||
switch (this._phase) {
|
||||
case "connected":
|
||||
|
||||
Reference in new issue
Block a user