From 7e87d0ffa149a32c105b74d845af00ef42e0fe31 Mon Sep 17 00:00:00 2001 From: Anton Gustafsson Date: Mon, 16 Oct 2023 13:40:53 +0200 Subject: [PATCH] feat: remember last selected bar (#399) --- android/app/build.gradle | 4 ++-- fastlane/metadata/android/en-US/changelogs/14000.txt | 3 +++ .../dialogs/cocktail-dialog/cocktail-dialog.html | 2 +- src/domain/entities/setting-entity.ts | 1 + src/modules/user/ingredient-lists/ingredient-lists.ts | 9 ++++++--- src/modules/user/user-page.ts | 9 ++++++--- src/services/local-storage-service.ts | 9 ++++++--- 7 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/14000.txt diff --git a/android/app/build.gradle b/android/app/build.gradle index 498cd2ac..bd8dd0de 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.moimob.drinkable" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 13901 - versionName "1.39.1" + versionCode 14000 + versionName "1.40.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/fastlane/metadata/android/en-US/changelogs/14000.txt b/fastlane/metadata/android/en-US/changelogs/14000.txt new file mode 100644 index 00000000..76639d1a --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/14000.txt @@ -0,0 +1,3 @@ +• Last selected bar will now load when restaring the app + +• Updated swedish translations \ No newline at end of file diff --git a/src/components/dialogs/cocktail-dialog/cocktail-dialog.html b/src/components/dialogs/cocktail-dialog/cocktail-dialog.html index 0e61683d..ccfb80d1 100644 --- a/src/components/dialogs/cocktail-dialog/cocktail-dialog.html +++ b/src/components/dialogs/cocktail-dialog/cocktail-dialog.html @@ -245,7 +245,7 @@
Checkmark diff --git a/src/domain/entities/setting-entity.ts b/src/domain/entities/setting-entity.ts index 5f72e78d..b685a072 100644 --- a/src/domain/entities/setting-entity.ts +++ b/src/domain/entities/setting-entity.ts @@ -2,6 +2,7 @@ export class SettingEntity { language?: string; showMocktails: boolean; exploreWidgetState?: number; + lastSelectedIngredientListId?: number; constructor() { this.showMocktails = false; diff --git a/src/modules/user/ingredient-lists/ingredient-lists.ts b/src/modules/user/ingredient-lists/ingredient-lists.ts index ecfe7564..1b971a0c 100644 --- a/src/modules/user/ingredient-lists/ingredient-lists.ts +++ b/src/modules/user/ingredient-lists/ingredient-lists.ts @@ -9,7 +9,10 @@ export class IngredientLists { public ingredientLists: IngredientList[] = []; public activeIngredientListId: number; - constructor(private _dialogService: DialogService, private localStorageService: LocalStorageService) {} + constructor( + private _dialogService: DialogService, + private localStorageService: LocalStorageService + ) {} bind() { this.ingredientLists = this.localStorageService.getIngredientLists(); @@ -19,11 +22,11 @@ export class IngredientLists { openDialog(ingredientList: IngredientList) { this._dialogService .open({ viewModel: IngredientListDrawer, model: ingredientList, lock: true }) - .whenClosed(() => { + .whenClosed(async () => { this.activeIngredientListId = this.localStorageService.getIngredientLists().find(x => x.id === this.activeIngredientListId)?.id ?? 0; - this.localStorageService.setActiveIngredientListId(this.activeIngredientListId); + await this.localStorageService.setActiveIngredientListId(this.activeIngredientListId); this.bind(); }); } diff --git a/src/modules/user/user-page.ts b/src/modules/user/user-page.ts index e59e2b2c..f6323420 100644 --- a/src/modules/user/user-page.ts +++ b/src/modules/user/user-page.ts @@ -50,19 +50,22 @@ export class UserPage { @observable public selectedIngredientListId: number; public ingredientLists: IngredientList[]; - constructor(private _router: Router, private _localStorageService: LocalStorageService) {} + constructor( + private _router: Router, + private _localStorageService: LocalStorageService + ) {} activate() { this.ingredientLists = this._localStorageService.getIngredientLists(); this.selectedIngredientListId = this._localStorageService.getActiveIngredientListId(); } - selectedIngredientListIdChanged(newValue: number, oldValue: number) { + async selectedIngredientListIdChanged(newValue: number, oldValue: number) { if (oldValue === undefined) { return; } - this._localStorageService.setActiveIngredientListId(newValue); + await this._localStorageService.setActiveIngredientListId(newValue); } navigateToRoute(route: string) { diff --git a/src/services/local-storage-service.ts b/src/services/local-storage-service.ts index 318f5426..40d65e73 100644 --- a/src/services/local-storage-service.ts +++ b/src/services/local-storage-service.ts @@ -31,8 +31,6 @@ export class LocalStorageService { await this.addDefaultIngredientList([]); } - this._activeIngredientListId = this._ingredientLists[0].id; - const messuarementSystem = await this.getFromLocalStorage(StorageKey.MessuarementSystem, false); this._messuarementSystem = messuarementSystem !== null ? messuarementSystem : MessuarementSystem.Imperial; @@ -48,6 +46,8 @@ export class LocalStorageService { const settings = await this.getFromLocalStorage(StorageKey.Settings); this._settings = settings !== null ? settings : new SettingEntity(); + this._activeIngredientListId = this._settings.lastSelectedIngredientListId ?? this._ingredientLists[0].id; + const cocktailInformation = await this.getFromLocalStorage(StorageKey.CocktailInformation); this._cocktailInformation = cocktailInformation !== null ? cocktailInformation : []; @@ -247,7 +247,10 @@ export class LocalStorageService { return this._shoppingLists; } - public setActiveIngredientListId(id: number) { + public async setActiveIngredientListId(id: number) { + this._settings.lastSelectedIngredientListId = id; + await this.updateSettings(this._settings); + this._activeIngredientListId = id; }