2022-02-03 18:06:44 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-03-27 16:38:54 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/user_circle_avatar.dart';
|
2023-02-13 05:32:16 +02:00
|
|
|
import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
|
2022-02-11 04:40:11 +02:00
|
|
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
|
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/models/backup_state.model.dart';
|
2022-03-22 08:22:04 +02:00
|
|
|
import 'package:immich_mobile/shared/models/server_info_state.model.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
2022-03-22 08:22:04 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
|
2023-05-12 16:21:13 +02:00
|
|
|
class HomePageAppBar extends ConsumerWidget implements PreferredSizeWidget {
|
2023-01-24 20:23:06 +02:00
|
|
|
@override
|
|
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
|
|
|
|
|
|
const HomePageAppBar({
|
2023-02-13 05:32:16 +02:00
|
|
|
super.key,
|
2022-02-07 04:31:32 +02:00
|
|
|
this.onPopBack,
|
2023-02-13 05:32:16 +02:00
|
|
|
});
|
2022-02-03 18:06:44 +02:00
|
|
|
|
2022-02-07 04:31:32 +02:00
|
|
|
final Function? onPopBack;
|
2022-02-03 18:06:44 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-22 07:23:35 +02:00
|
|
|
final BackUpState backupState = ref.watch(backupProvider);
|
2023-03-23 17:25:58 +02:00
|
|
|
final bool isEnableAutoBackup =
|
|
|
|
backupState.backgroundBackup || backupState.autoBackup;
|
2022-06-22 07:23:35 +02:00
|
|
|
final ServerInfoState serverInfoState = ref.watch(serverInfoProvider);
|
2023-02-13 05:32:16 +02:00
|
|
|
AuthenticationState authState = ref.watch(authenticationProvider);
|
|
|
|
|
|
|
|
buildProfilePhoto() {
|
|
|
|
if (authState.profileImagePath.isEmpty) {
|
|
|
|
return IconButton(
|
|
|
|
splashRadius: 25,
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.face_outlined,
|
|
|
|
size: 30,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Scaffold.of(context).openDrawer();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Scaffold.of(context).openDrawer();
|
|
|
|
},
|
2023-03-27 16:38:54 +02:00
|
|
|
child: const UserCircleAvatar(
|
2023-02-13 05:32:16 +02:00
|
|
|
radius: 18,
|
2023-03-27 16:38:54 +02:00
|
|
|
size: 33,
|
2023-02-13 05:32:16 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 08:22:04 +02:00
|
|
|
|
2023-01-24 20:23:06 +02:00
|
|
|
return AppBar(
|
2022-08-16 01:53:30 +02:00
|
|
|
backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
|
2022-06-22 07:23:35 +02:00
|
|
|
shape: const RoundedRectangleBorder(
|
2022-11-30 18:58:07 +02:00
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(5),
|
|
|
|
),
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2022-02-11 04:40:11 +02:00
|
|
|
leading: Builder(
|
|
|
|
builder: (BuildContext context) {
|
2022-03-22 08:22:04 +02:00
|
|
|
return Stack(
|
|
|
|
children: [
|
2023-02-13 05:32:16 +02:00
|
|
|
Center(
|
|
|
|
child: buildProfilePhoto(),
|
2022-03-22 08:22:04 +02:00
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
if (serverInfoState.isVersionMismatch)
|
|
|
|
Positioned(
|
|
|
|
bottom: 12,
|
|
|
|
right: 12,
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () => Scaffold.of(context).openDrawer(),
|
|
|
|
child: Material(
|
2022-08-16 01:53:30 +02:00
|
|
|
// color: Colors.grey[200],
|
2022-07-01 03:08:49 +02:00
|
|
|
elevation: 1,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(50.0),
|
|
|
|
),
|
|
|
|
child: const Padding(
|
|
|
|
padding: EdgeInsets.all(2.0),
|
|
|
|
child: Icon(
|
|
|
|
Icons.info,
|
|
|
|
color: Color.fromARGB(255, 243, 188, 106),
|
|
|
|
size: 15,
|
2022-03-22 08:22:04 +02:00
|
|
|
),
|
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-03-22 08:22:04 +02:00
|
|
|
],
|
2022-02-11 04:40:11 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-08-16 01:53:30 +02:00
|
|
|
title: const Text(
|
2022-02-11 04:40:11 +02:00
|
|
|
'IMMICH',
|
2022-04-04 16:08:53 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontFamily: 'SnowburstOne',
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 22,
|
2022-02-03 18:06:44 +02:00
|
|
|
),
|
2022-02-11 04:40:11 +02:00
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
Stack(
|
|
|
|
alignment: AlignmentDirectional.center,
|
|
|
|
children: [
|
2022-07-01 03:08:49 +02:00
|
|
|
if (backupState.backupProgress == BackUpProgressEnum.inProgress)
|
|
|
|
Positioned(
|
|
|
|
top: 10,
|
|
|
|
right: 12,
|
|
|
|
child: SizedBox(
|
|
|
|
height: 8,
|
|
|
|
width: 8,
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
strokeWidth: 1,
|
|
|
|
valueColor: AlwaysStoppedAnimation<Color>(
|
2022-07-13 14:23:48 +02:00
|
|
|
Theme.of(context).primaryColor,
|
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-02-11 04:40:11 +02:00
|
|
|
IconButton(
|
|
|
|
splashRadius: 25,
|
|
|
|
iconSize: 30,
|
2022-06-22 07:23:35 +02:00
|
|
|
icon: isEnableAutoBackup
|
2023-02-11 22:23:32 +02:00
|
|
|
? const Icon(
|
2022-09-06 15:18:07 +02:00
|
|
|
Icons.backup_rounded,
|
|
|
|
)
|
2022-02-11 04:40:11 +02:00
|
|
|
: Badge(
|
|
|
|
padding: const EdgeInsets.all(4),
|
2023-02-11 22:23:32 +02:00
|
|
|
backgroundColor: Colors.white,
|
|
|
|
label: const Icon(
|
2022-02-11 04:40:11 +02:00
|
|
|
Icons.cloud_off_rounded,
|
|
|
|
size: 8,
|
2022-08-16 01:53:30 +02:00
|
|
|
color: Colors.indigo,
|
2022-02-03 18:06:44 +02:00
|
|
|
),
|
2022-09-06 15:18:07 +02:00
|
|
|
child: Icon(
|
|
|
|
Icons.backup_rounded,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2022-04-03 19:31:45 +02:00
|
|
|
onPressed: () async {
|
2022-06-22 07:23:35 +02:00
|
|
|
var onPop = await AutoRouter.of(context)
|
|
|
|
.push(const BackupControllerRoute());
|
2022-04-03 19:31:45 +02:00
|
|
|
|
|
|
|
if (onPop != null && onPop == true) {
|
|
|
|
onPopBack!();
|
|
|
|
}
|
2022-02-11 04:40:11 +02:00
|
|
|
},
|
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
if (backupState.backupProgress == BackUpProgressEnum.inProgress)
|
|
|
|
Positioned(
|
|
|
|
bottom: 5,
|
|
|
|
child: Text(
|
|
|
|
'${backupState.allUniqueAssets.length - backupState.selectedAlbumsBackupAssetsIds.length}',
|
|
|
|
style:
|
|
|
|
const TextStyle(fontSize: 9, fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
2022-02-11 04:40:11 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
2022-02-03 18:06:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|