mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Move load indicator to app bar in home pages
This commit is contained in:
parent
eddb94a3e6
commit
10aa594057
4 changed files with 132 additions and 91 deletions
17
app/lib/widget/app_bar_circular_progress_indicator.dart
Normal file
17
app/lib/widget/app_bar_circular_progress_indicator.dart
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class AppBarCircularProgressIndicator extends StatelessWidget {
|
||||||
|
const AppBarCircularProgressIndicator({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const Center(
|
||||||
|
child: SizedBox.square(
|
||||||
|
dimension: 24,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -140,24 +140,17 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
child: Column(
|
child: SizedBox(
|
||||||
mainAxisSize: MainAxisSize.min,
|
width: double.infinity,
|
||||||
children: [
|
height: _calcBottomAppBarExtent(context),
|
||||||
if (state is ListAlbumBlocLoading)
|
child: ClipRect(
|
||||||
const LinearProgressIndicator(),
|
child: BackdropFilter(
|
||||||
SizedBox(
|
filter: ImageFilter.blur(sigmaX: 4, sigmaY: 4),
|
||||||
width: double.infinity,
|
child: const ColoredBox(
|
||||||
height: _calcBottomAppBarExtent(context),
|
color: Colors.transparent,
|
||||||
child: ClipRect(
|
|
||||||
child: BackdropFilter(
|
|
||||||
filter: ImageFilter.blur(sigmaX: 4, sigmaY: 4),
|
|
||||||
child: const ColoredBox(
|
|
||||||
color: Colors.transparent,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -193,28 +186,36 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNormalAppBar(BuildContext context) {
|
Widget _buildNormalAppBar(BuildContext context) {
|
||||||
return HomeSliverAppBar(
|
return BlocBuilder(
|
||||||
account: widget.account,
|
bloc: _bloc,
|
||||||
menuActions: [
|
buildWhen: (previous, current) =>
|
||||||
PopupMenuItem(
|
previous is ListAlbumBlocLoading != current is ListAlbumBlocLoading,
|
||||||
value: _menuValueSort,
|
builder: (context, state) {
|
||||||
child: Text(L10n.global().sortTooltip),
|
return HomeSliverAppBar(
|
||||||
),
|
account: widget.account,
|
||||||
PopupMenuItem(
|
isShowProgressIcon: state is ListAlbumBlocLoading,
|
||||||
value: _menuValueImport,
|
menuActions: [
|
||||||
child: Text(L10n.global().importFoldersTooltip),
|
PopupMenuItem(
|
||||||
),
|
value: _menuValueSort,
|
||||||
],
|
child: Text(L10n.global().sortTooltip),
|
||||||
onSelectedMenuActions: (option) {
|
),
|
||||||
switch (option) {
|
PopupMenuItem(
|
||||||
case _menuValueSort:
|
value: _menuValueImport,
|
||||||
_onSortPressed(context);
|
child: Text(L10n.global().importFoldersTooltip),
|
||||||
break;
|
),
|
||||||
|
],
|
||||||
|
onSelectedMenuActions: (option) {
|
||||||
|
switch (option) {
|
||||||
|
case _menuValueSort:
|
||||||
|
_onSortPressed(context);
|
||||||
|
break;
|
||||||
|
|
||||||
case _menuValueImport:
|
case _menuValueImport:
|
||||||
_onImportPressed(context);
|
_onImportPressed(context);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import 'package:nc_photos/pref.dart';
|
||||||
import 'package:nc_photos/theme.dart';
|
import 'package:nc_photos/theme.dart';
|
||||||
import 'package:nc_photos/url_launcher_util.dart';
|
import 'package:nc_photos/url_launcher_util.dart';
|
||||||
import 'package:nc_photos/widget/account_picker_dialog.dart';
|
import 'package:nc_photos/widget/account_picker_dialog.dart';
|
||||||
|
import 'package:nc_photos/widget/app_bar_circular_progress_indicator.dart';
|
||||||
import 'package:nc_photos/widget/app_bar_title_container.dart';
|
import 'package:nc_photos/widget/app_bar_title_container.dart';
|
||||||
import 'package:nc_photos/widget/settings.dart';
|
import 'package:nc_photos/widget/settings.dart';
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ class HomeSliverAppBar extends StatelessWidget {
|
||||||
this.actions,
|
this.actions,
|
||||||
this.menuActions,
|
this.menuActions,
|
||||||
this.onSelectedMenuActions,
|
this.onSelectedMenuActions,
|
||||||
|
this.isShowProgressIcon = false,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -38,15 +40,17 @@ class HomeSliverAppBar extends StatelessWidget {
|
||||||
child: AppBarTitleContainer(
|
child: AppBarTitleContainer(
|
||||||
title: Text(accountLabel ?? account.address),
|
title: Text(accountLabel ?? account.address),
|
||||||
subtitle: accountLabel == null ? Text(account.username2) : null,
|
subtitle: accountLabel == null ? Text(account.username2) : null,
|
||||||
icon: account.scheme == "http"
|
icon: isShowProgressIcon
|
||||||
? Icon(
|
? const AppBarCircularProgressIndicator()
|
||||||
Icons.no_encryption_outlined,
|
: (account.scheme == "http"
|
||||||
color: Theme.of(context).colorScheme.error,
|
? Icon(
|
||||||
)
|
Icons.no_encryption_outlined,
|
||||||
: Icon(
|
color: Theme.of(context).colorScheme.error,
|
||||||
Icons.https,
|
)
|
||||||
color: Theme.of(context).colorScheme.primary,
|
: Icon(
|
||||||
),
|
Icons.https,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floating: true,
|
floating: true,
|
||||||
|
@ -103,6 +107,7 @@ class HomeSliverAppBar extends StatelessWidget {
|
||||||
/// much >= 0
|
/// much >= 0
|
||||||
final List<PopupMenuEntry<int>>? menuActions;
|
final List<PopupMenuEntry<int>>? menuActions;
|
||||||
final void Function(int)? onSelectedMenuActions;
|
final void Function(int)? onSelectedMenuActions;
|
||||||
|
final bool isShowProgressIcon;
|
||||||
|
|
||||||
static const _menuValueAbout = -1;
|
static const _menuValueAbout = -1;
|
||||||
static const _menuValueHelp = -2;
|
static const _menuValueHelp = -2;
|
||||||
|
|
|
@ -205,25 +205,17 @@ class _HomePhotosState extends State<HomePhotos>
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
child: Column(
|
child: SizedBox(
|
||||||
mainAxisSize: MainAxisSize.min,
|
width: double.infinity,
|
||||||
children: [
|
height: _calcBottomAppBarExtent(context),
|
||||||
if (state is ScanAccountDirBlocLoading ||
|
child: ClipRect(
|
||||||
_buildItemQueue.isProcessing)
|
child: BackdropFilter(
|
||||||
const LinearProgressIndicator(),
|
filter: ImageFilter.blur(sigmaX: 4, sigmaY: 4),
|
||||||
SizedBox(
|
child: const ColoredBox(
|
||||||
width: double.infinity,
|
color: Colors.transparent,
|
||||||
height: _calcBottomAppBarExtent(context),
|
|
||||||
child: ClipRect(
|
|
||||||
child: BackdropFilter(
|
|
||||||
filter: ImageFilter.blur(sigmaX: 4, sigmaY: 4),
|
|
||||||
child: const ColoredBox(
|
|
||||||
color: Colors.transparent,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -287,31 +279,42 @@ class _HomePhotosState extends State<HomePhotos>
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNormalAppBar(BuildContext context) {
|
Widget _buildNormalAppBar(BuildContext context) {
|
||||||
return HomeSliverAppBar(
|
return BlocBuilder(
|
||||||
account: widget.account,
|
bloc: _bloc,
|
||||||
actions: [
|
buildWhen: (previous, current) =>
|
||||||
ZoomMenuButton(
|
previous is ScanAccountDirBlocLoading !=
|
||||||
initialZoom: _thumbZoomLevel,
|
current is ScanAccountDirBlocLoading,
|
||||||
minZoom: -1,
|
builder: (context, state) {
|
||||||
maxZoom: 2,
|
return HomeSliverAppBar(
|
||||||
onZoomChanged: (value) {
|
account: widget.account,
|
||||||
_setThumbZoomLevel(value.round());
|
isShowProgressIcon: (state is ScanAccountDirBlocLoading ||
|
||||||
Pref().setHomePhotosZoomLevel(_thumbZoomLevel);
|
_buildItemQueue.isProcessing) &&
|
||||||
|
!_isRefreshIndicatorActive,
|
||||||
|
actions: [
|
||||||
|
ZoomMenuButton(
|
||||||
|
initialZoom: _thumbZoomLevel,
|
||||||
|
minZoom: -1,
|
||||||
|
maxZoom: 2,
|
||||||
|
onZoomChanged: (value) {
|
||||||
|
_setThumbZoomLevel(value.round());
|
||||||
|
Pref().setHomePhotosZoomLevel(_thumbZoomLevel);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
menuActions: [
|
||||||
|
PopupMenuItem(
|
||||||
|
value: _menuValueRefresh,
|
||||||
|
child: Text(L10n.global().refreshMenuLabel),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
onSelectedMenuActions: (option) {
|
||||||
|
switch (option) {
|
||||||
|
case _menuValueRefresh:
|
||||||
|
_onRefreshSelected();
|
||||||
|
break;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
],
|
|
||||||
menuActions: [
|
|
||||||
PopupMenuItem(
|
|
||||||
value: _menuValueRefresh,
|
|
||||||
child: Text(L10n.global().refreshMenuLabel),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
onSelectedMenuActions: (option) {
|
|
||||||
switch (option) {
|
|
||||||
case _menuValueRefresh:
|
|
||||||
_onRefreshSelected();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -625,11 +628,25 @@ class _HomePhotosState extends State<HomePhotos>
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _waitRefresh() async {
|
Future<void> _waitRefresh() async {
|
||||||
while (true) {
|
setState(() {
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
_isRefreshIndicatorActive = true;
|
||||||
if (_bloc.state is! ScanAccountDirBlocLoading) {
|
});
|
||||||
return;
|
try {
|
||||||
|
while (true) {
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
if (_bloc.state is! ScanAccountDirBlocLoading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
// To prevent the app bar icon appearing for a very short while
|
||||||
|
unawaited(Future.delayed(const Duration(seconds: 2)).then((_) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_isRefreshIndicatorActive = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,6 +762,7 @@ class _HomePhotosState extends State<HomePhotos>
|
||||||
late final _Web? _web = platform_k.isWeb ? _Web(this) : null;
|
late final _Web? _web = platform_k.isWeb ? _Web(this) : null;
|
||||||
|
|
||||||
var _isScrollbarVisible = false;
|
var _isScrollbarVisible = false;
|
||||||
|
var _isRefreshIndicatorActive = false;
|
||||||
|
|
||||||
static final _log = Logger("widget.home_photos._HomePhotosState");
|
static final _log = Logger("widget.home_photos._HomePhotosState");
|
||||||
static const _menuValueRefresh = 0;
|
static const _menuValueRefresh = 0;
|
||||||
|
|
Loading…
Reference in a new issue