1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

fix(mobile): Fix back button closing the app from multiselection in Android (#1477)

* fixes back button multiselection on android in main timeline

* back button on multiselect in album clears selection

* fixed homepage back and refactor future

* not a futureOr
This commit is contained in:
martyfuhry 2023-01-29 23:36:26 -05:00 committed by GitHub
parent f23979024a
commit 3210302ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 50 deletions

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:auto_route/auto_route.dart'; import 'package:auto_route/auto_route.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -248,32 +250,45 @@ class AlbumViewerPage extends HookConsumerWidget {
); );
} }
Future<bool> onWillPop() async {
final isMultiselectEnable = ref.read(assetSelectionProvider).selectedAssetsInAlbumViewer.isNotEmpty;
if (isMultiselectEnable) {
ref.watch(assetSelectionProvider.notifier).removeAll();
return false;
}
return true;
}
Widget buildBody(AlbumResponseDto albumInfo) { Widget buildBody(AlbumResponseDto albumInfo) {
return GestureDetector( return WillPopScope(
onTap: () { onWillPop: onWillPop,
titleFocusNode.unfocus(); child: GestureDetector(
}, onTap: () {
child: DraggableScrollbar.semicircle( titleFocusNode.unfocus();
backgroundColor: Theme.of(context).hintColor, },
controller: scrollController, child: DraggableScrollbar.semicircle(
heightScrollThumb: 48.0, backgroundColor: Theme.of(context).hintColor,
child: CustomScrollView(
controller: scrollController, controller: scrollController,
slivers: [ heightScrollThumb: 48.0,
buildHeader(albumInfo), child: CustomScrollView(
SliverPersistentHeader( controller: scrollController,
pinned: true, slivers: [
delegate: ImmichSliverPersistentAppBarDelegate( buildHeader(albumInfo),
minHeight: 50, SliverPersistentHeader(
maxHeight: 50, pinned: true,
child: Container( delegate: ImmichSliverPersistentAppBarDelegate(
color: Theme.of(context).scaffoldBackgroundColor, minHeight: 50,
child: buildControlButton(albumInfo), maxHeight: 50,
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: buildControlButton(albumInfo),
),
), ),
), ),
), buildImageGrid(albumInfo)
buildImageGrid(albumInfo) ],
], ),
), ),
), ),
); );

View File

@ -200,34 +200,46 @@ class HomePage extends HookConsumerWidget {
); );
} }
return SafeArea( Future<bool> onWillPop() async {
bottom: !multiselectEnabled.state, if (multiselectEnabled.state) {
top: true, selectionEnabledHook.value = false;
child: Stack( return false;
children: [ }
ref.watch(assetProvider).renderList == null ||
ref.watch(assetProvider).allAssets.isEmpty return true;
? buildLoadingIndicator() }
: ImmichAssetGrid(
renderList: ref.watch(assetProvider).renderList!, return WillPopScope(
allAssets: ref.watch(assetProvider).allAssets, onWillPop: onWillPop,
assetsPerRow: appSettingService child: SafeArea(
.getSetting(AppSettingsEnum.tilesPerRow), bottom: !multiselectEnabled.state,
showStorageIndicator: appSettingService top: true,
.getSetting(AppSettingsEnum.storageIndicator), child: Stack(
listener: selectionListener, children: [
selectionActive: selectionEnabledHook.value, ref.watch(assetProvider).renderList == null ||
), ref.watch(assetProvider).allAssets.isEmpty
if (selectionEnabledHook.value) ? buildLoadingIndicator()
ControlBottomAppBar( : ImmichAssetGrid(
onShare: onShareAssets, renderList: ref.watch(assetProvider).renderList!,
onDelete: onDelete, allAssets: ref.watch(assetProvider).allAssets,
onAddToAlbum: onAddToAlbum, assetsPerRow: appSettingService
albums: albums, .getSetting(AppSettingsEnum.tilesPerRow),
sharedAlbums: sharedAlbums, showStorageIndicator: appSettingService
onCreateNewAlbum: onCreateNewAlbum, .getSetting(AppSettingsEnum.storageIndicator),
), listener: selectionListener,
], selectionActive: selectionEnabledHook.value,
),
if (selectionEnabledHook.value)
ControlBottomAppBar(
onShare: onShareAssets,
onDelete: onDelete,
onAddToAlbum: onAddToAlbum,
albums: albums,
sharedAlbums: sharedAlbums,
onCreateNewAlbum: onCreateNewAlbum,
),
],
),
), ),
); );
} }