Skip to content

Commit

Permalink
#907 - Make it possible to count down to save a brew automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Feb 17, 2025
1 parent 835e6d2 commit 1d4c8b1
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1156,3 +1156,7 @@ Somehow i've found out that ionic is rendering this media-tags and setting box-s


}
.toast-automatic-save-timer {
--button-color: #FFFFFF;

}
31 changes: 26 additions & 5 deletions src/app/brew/brew-add/brew-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import { REFERENCE_GRAPH_TYPE } from '../../../enums/brews/referenceGraphType';
import { ReferenceGraph } from '../../../classes/brew/referenceGraph';
import { UIHelper } from '../../../services/uiHelper';
import { Bean } from '../../../classes/bean/bean';
import { EventQueueService } from '../../../services/queueService/queue-service.service';
import { AppEventType } from '../../../enums/appEvent/appEvent';

declare var Plotly;

Expand Down Expand Up @@ -77,6 +79,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
private initialBeanData: string = '';
private disableHardwareBack;
public bluetoothSubscription: Subscription = undefined;
public automaticSaveSubscription: Subscription = undefined;
public readonly PreparationDeviceType = PreparationDeviceType;

constructor(
Expand All @@ -100,6 +103,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
private readonly changeDetectorRef: ChangeDetectorRef,
private readonly hapticService: HapticService,
private readonly uiHelper: UIHelper,
private readonly eventQueue: EventQueueService,
) {
// Initialize to standard in drop down
this.settings = this.uiSettingsStorage.getSettings();
Expand All @@ -119,6 +123,11 @@ export class BrewAddComponent implements OnInit, OnDestroy {
.getAllEntries()
.filter((e) => !e.finished)
.sort((a, b) => a.name.localeCompare(b.name))[0]?.config?.uuid;

const eventSubs = this.eventQueue.on(AppEventType.BREW_AUTOMATIC_SAVE);
this.automaticSaveSubscription = eventSubs.subscribe((event) => {
this.finish(true);
});
}
@HostListener('window:keyboardWillShow')
private hideFooter() {
Expand Down Expand Up @@ -292,7 +301,8 @@ export class BrewAddComponent implements OnInit, OnDestroy {
}
}

public async finish() {
public async finish(_automaticSave: boolean = false) {
this.deattachBrewAutoSave();
await this.uiAlert.showLoadingMessage(undefined, undefined, true);
await sleep(50);
try {
Expand Down Expand Up @@ -325,10 +335,14 @@ export class BrewAddComponent implements OnInit, OnDestroy {
await this.uiAlert.hideLoadingSpinner();
await sleep(100);

if (this.uiBrewHelper.checkIfBeanPackageIsConsumed(this.data.getBean())) {
await this.uiBrewHelper.checkIfBeanPackageIsConsumedTriggerMessageAndArchive(
this.data.getBean(),
);
if (_automaticSave === false) {
if (
this.uiBrewHelper.checkIfBeanPackageIsConsumed(this.data.getBean())
) {
await this.uiBrewHelper.checkIfBeanPackageIsConsumedTriggerMessageAndArchive(
this.data.getBean(),
);
}
}

this.uiAnalytics.trackEvent(
Expand Down Expand Up @@ -518,11 +532,18 @@ export class BrewAddComponent implements OnInit, OnDestroy {
);
}
}
public deattachBrewAutoSave() {
if (this.automaticSaveSubscription) {
this.automaticSaveSubscription.unsubscribe();
this.automaticSaveSubscription = undefined;
}
}

public ngOnDestroy() {
if (this.bluetoothSubscription) {
this.bluetoothSubscription.unsubscribe();
this.bluetoothSubscription = undefined;
}
this.deattachBrewAutoSave();
}
}
21 changes: 21 additions & 0 deletions src/app/settings/settings.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,27 @@ <h2>{{"PAGE_SETTINGS_BREW_TIMER_START_DELAY_ACTIVE" | translate}}</h2>
slot="end">{{settings.brew_timer_start_delay_time | toFixed: 1}}</div>
</ion-range>
</ion-item>

<ion-item [lines]="settings.brew_save_automatic_active?'none':'full'">
<ion-checkbox label-placement='start' (ngModelChange)="saveSettings();"
[(ngModel)]="settings.brew_save_automatic_active">
<div class='ion-label' style="white-space: normal;">
<h2>{{"PAGE_SETTINGS_BREW_TIMER_SAVE_AUTOMATIC_TITLE" | translate}}</h2>
</div>
</ion-checkbox>
</ion-item>
<ion-item lines='none' *ngIf="settings.brew_save_automatic_active">
<ion-label class="ion-margin-end">
<p>{{"PAGE_SETTINGS_BREW_TIMER_SAVE_AUTOMATIC_DESCRIPTION" | translate}}</p>
</ion-label>
</ion-item>
<ion-item *ngIf="settings.brew_save_automatic_active">
<ion-range [disabled]='isScrolling' style="padding-left:20px;padding-top:0;padding-bottom:15px;padding-right:0px;" min="1" snaps="true" max="20"
step="1" (ngModelChange)="saveSettings()" [(ngModel)]="settings.brew_save_automatic_active_delay">
<div class='ion-label'
slot="end">{{settings.brew_save_automatic_active_delay | toFixed: 1}}</div>
</ion-range>
</ion-item>
</ion-card-content>
</ion-card>

Expand Down
6 changes: 5 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1426,5 +1426,9 @@
"GRAPH_UPDATE_INTERVAL_TITLE": "Graph Update Interval",
"GRAPH_UPDATE_INTERVAL_DESCRIPTION": "Use this only if your graph lags while streaming, which mainly occurs on older tablets or phones. If you're not experiencing any issues, you can ignore this function.",
"GRAPH_UPDATE_FREQUENCY_INTERVAL_TITLE": "Graph Update Frequency Interval",
"GRAPH_UPDATE_FREQUENCY_INTERVAL_DESCRIPTION": "Refresh at the selected millisecond interval"
"GRAPH_UPDATE_FREQUENCY_INTERVAL_DESCRIPTION": "Refresh at the selected millisecond interval",
"PAGE_SETTINGS_BREW_TIMER_SAVE_AUTOMATIC_TITLE": "Save brew automatically",
"PAGE_SETTINGS_BREW_TIMER_SAVE_AUTOMATIC_DESCRIPTION": "Save the brew automatically after a specific time interval has passed. This action will be executed after you pause the brew-timer",
"SAVE_NOW": "Save now",
"SAVING_BREW_COUNTDOWN": "Saving brew in {{time}}"
}
6 changes: 6 additions & 0 deletions src/classes/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export class Settings implements ISettings {
public brew_timer_start_delay_time: number;
public brew_timer_start_delay_active: boolean;

public brew_save_automatic_active: boolean;
public brew_save_automatic_active_delay: number;

public use_numeric_keyboard_for_grind_size: boolean;

public welcome_page_showed: boolean;
Expand Down Expand Up @@ -331,6 +334,9 @@ export class Settings implements ISettings {
this.brew_timer_start_delay_time = 1;
this.brew_timer_start_delay_active = false;

this.brew_save_automatic_active = false;
this.brew_save_automatic_active_delay = 5;

this.track_caffeine_consumption = false;

this.show_roasting_section = false;
Expand Down
11 changes: 11 additions & 0 deletions src/components/brews/brew-brewing/brew-brewing.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { HapticService } from '../../../services/hapticService/haptic.service';
import { BrewFlow } from '../../../classes/brew/brewFlow';
import { Bean } from '../../../classes/bean/bean';
import { BREW_FUNCTION_PIPE_ENUM } from '../../../enums/brews/brewFunctionPipe';
import { AppEvent } from '../../../classes/appEvent/appEvent';

declare var cordova;

Expand Down Expand Up @@ -728,12 +729,22 @@ export class BrewBrewingComponent implements OnInit, AfterViewInit {

public async timerPaused(_event) {
await this.brewBrewingGraphEl.timerPaused(_event);

if (
this.settings.haptic_feedback_active &&
this.settings.haptic_feedback_brew_stopped
) {
this.hapticService.vibrate();
}
if (this.settings.brew_save_automatic_active) {
const delayTimer = this.settings.brew_save_automatic_active_delay;
const response = await this.uiToast.showAutomaticSaveTimer(delayTimer);
if (response !== 'cancel') {
this.eventQueue.dispatch(
new AppEvent(AppEventType.BREW_AUTOMATIC_SAVE, undefined),
);
}
}
}

public async tareScale(_event) {
Expand Down
1 change: 1 addition & 0 deletions src/enums/appEvent/appEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export enum AppEventType {
BLUETOOTH_REFRACTOMETER_DEVICE_DISCONNECT = 'BLUETOOTH_REFRACTOMETER_DEVICE_DISCONNECT',
PREPARATION_SELECTION_CHANGED = 'PREPARATION_SELECTION_CHANGED',
UPDATE_LOADING_SPINNER_MESSAGE = 'UPDATE_LOADING_SPINNER_MESSAGE',
BREW_AUTOMATIC_SAVE = 'BREW_AUTOMATIC_SAVE',
}
3 changes: 3 additions & 0 deletions src/interfaces/settings/iSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export interface ISettings {
brew_timer_start_delay_time: number;
brew_timer_start_delay_active: boolean;

brew_save_automatic_active: boolean;
brew_save_automatic_active_delay: number;

show_roasting_section: boolean;
show_water_section: boolean;
show_cupping_section: boolean;
Expand Down
48 changes: 47 additions & 1 deletion src/services/uiToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,55 @@ import { TranslateService } from '@ngx-translate/core';
export class UIToast {
constructor(
private readonly translate: TranslateService,
private readonly toastController: ToastController
private readonly toastController: ToastController,
) {}

public async showAutomaticSaveTimer(_seconds: number) {
let message = this.translate.instant('SAVING_BREW_COUNTDOWN', {
time: _seconds.toString(),
});

const toast = await this.toastController.create({
message: message,
duration: _seconds * 1000,
position: 'top',
animated: false,
cssClass: 'toast-automatic-save-timer',
buttons: [
{
text: this.translate.instant('CANCEL'),
role: 'cancel',
},
{
text: this.translate.instant('SAVE_NOW'),
role: 'save',
},
],
});
await toast.present();
let delayCounter = _seconds;

let delayIntv = setInterval(() => {
delayCounter = delayCounter - 1;
if (delayCounter <= 0) {
toast.message = this.translate.instant('SAVING_BREW_COUNTDOWN', {
time: delayCounter.toString(),
});
clearInterval(delayIntv);
delayIntv = undefined;
} else {
toast.message = this.translate.instant('SAVING_BREW_COUNTDOWN', {
time: delayCounter.toString(),
});
}
}, 1000);

const responseToast = await toast.onDidDismiss();
if (delayIntv) {
clearInterval(delayIntv);
}
return responseToast.role;
}
public async showInfoToast(_message: string, translate: boolean = true) {
let message = _message;
if (translate === true) {
Expand Down

0 comments on commit 1d4c8b1

Please sign in to comment.