2021-04-17 11:04:46 +02:00
|
|
|
import 'package:event_bus/event_bus.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-04-17 11:04:46 +02:00
|
|
|
import 'package:kiwi/kiwi.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/account.dart';
|
2021-07-25 07:00:38 +02:00
|
|
|
import 'package:nc_photos/app_localizations.dart';
|
2021-04-17 11:04:46 +02:00
|
|
|
import 'package:nc_photos/event/event.dart';
|
2021-09-08 10:18:55 +02:00
|
|
|
import 'package:nc_photos/help_utils.dart' as help_utils;
|
2021-04-17 11:04:46 +02:00
|
|
|
import 'package:nc_photos/pref.dart';
|
2021-04-17 10:59:16 +02:00
|
|
|
import 'package:nc_photos/theme.dart';
|
2022-07-08 11:38:24 +02:00
|
|
|
import 'package:nc_photos/url_launcher_util.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/widget/account_picker_dialog.dart';
|
2022-11-12 10:55:33 +01:00
|
|
|
import 'package:nc_photos/widget/app_bar_title_container.dart';
|
2022-11-24 14:50:08 +01:00
|
|
|
import 'package:nc_photos/widget/cloud_progress_indicator.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/widget/settings.dart';
|
2022-11-12 12:29:32 +01:00
|
|
|
import 'package:nc_photos/widget/translucent_sliver_app_bar.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
/// AppBar for home screens
|
|
|
|
class HomeSliverAppBar extends StatelessWidget {
|
2021-09-15 08:58:06 +02:00
|
|
|
const HomeSliverAppBar({
|
2021-07-23 22:05:57 +02:00
|
|
|
Key? key,
|
|
|
|
required this.account,
|
2021-04-10 06:28:12 +02:00
|
|
|
this.actions,
|
|
|
|
this.menuActions,
|
|
|
|
this.onSelectedMenuActions,
|
2022-11-12 11:45:29 +01:00
|
|
|
this.isShowProgressIcon = false,
|
2021-04-10 06:28:12 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
2022-07-10 17:53:24 +02:00
|
|
|
final accountLabel = AccountPref.of(account).getAccountLabel();
|
2022-11-12 12:29:32 +01:00
|
|
|
return TranslucentSliverAppBar(
|
2021-04-10 06:28:12 +02:00
|
|
|
title: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (_) => AccountPickerDialog(
|
|
|
|
account: account,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2022-11-12 10:55:33 +01:00
|
|
|
child: AppBarTitleContainer(
|
|
|
|
title: Text(accountLabel ?? account.address),
|
|
|
|
subtitle: accountLabel == null ? Text(account.username2) : null,
|
2022-11-12 11:45:29 +01:00
|
|
|
icon: isShowProgressIcon
|
2022-11-24 14:50:08 +01:00
|
|
|
? const CloudProgressIndicator(size: 36)
|
2022-11-12 11:45:29 +01:00
|
|
|
: (account.scheme == "http"
|
|
|
|
? Icon(
|
|
|
|
Icons.no_encryption_outlined,
|
|
|
|
color: Theme.of(context).colorScheme.error,
|
|
|
|
)
|
|
|
|
: Icon(
|
|
|
|
Icons.https,
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
)),
|
2021-04-10 06:28:12 +02:00
|
|
|
),
|
|
|
|
),
|
2022-11-12 12:29:32 +01:00
|
|
|
scrolledUnderBackgroundColor:
|
|
|
|
Theme.of(context).homeNavigationBarBackgroundColor,
|
2021-04-10 06:28:12 +02:00
|
|
|
floating: true,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
actions: (actions ?? []) +
|
|
|
|
[
|
2021-10-27 22:40:54 +02:00
|
|
|
if (!Pref().isFollowSystemThemeOr(false))
|
2022-11-12 10:55:33 +01:00
|
|
|
_DarkModeSwitch(
|
2021-08-30 18:57:45 +02:00
|
|
|
onChanged: _onDarkModeChanged,
|
|
|
|
),
|
2021-07-23 22:05:57 +02:00
|
|
|
PopupMenuButton<int>(
|
2021-04-10 06:28:12 +02:00
|
|
|
tooltip: MaterialLocalizations.of(context).moreButtonTooltip,
|
|
|
|
itemBuilder: (context) =>
|
|
|
|
(menuActions ?? []) +
|
|
|
|
[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: _menuValueAbout,
|
2021-08-29 13:51:43 +02:00
|
|
|
child: Text(L10n.global().settingsMenuLabel),
|
2021-04-10 06:28:12 +02:00
|
|
|
),
|
2021-08-18 06:24:50 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: _menuValueHelp,
|
2021-08-29 13:51:43 +02:00
|
|
|
child: Text(L10n.global().helpTooltip),
|
2021-08-18 06:24:50 +02:00
|
|
|
),
|
2021-04-10 06:28:12 +02:00
|
|
|
],
|
|
|
|
onSelected: (option) {
|
|
|
|
if (option >= 0) {
|
|
|
|
onSelectedMenuActions?.call(option);
|
|
|
|
} else {
|
|
|
|
if (option == _menuValueAbout) {
|
|
|
|
Navigator.of(context).pushNamed(Settings.routeName,
|
|
|
|
arguments: SettingsArguments(account));
|
2021-08-18 06:24:50 +02:00
|
|
|
} else if (option == _menuValueHelp) {
|
2021-09-08 10:18:55 +02:00
|
|
|
launch(help_utils.mainUrl);
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-17 11:04:46 +02:00
|
|
|
void _onDarkModeChanged(bool value) {
|
2021-10-27 22:40:54 +02:00
|
|
|
Pref().setDarkTheme(value).then((_) {
|
2021-04-17 11:04:46 +02:00
|
|
|
KiwiContainer().resolve<EventBus>().fire(ThemeChangedEvent());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-10 06:28:12 +02:00
|
|
|
final Account account;
|
|
|
|
|
|
|
|
/// Screen specific action buttons
|
2021-07-23 22:05:57 +02:00
|
|
|
final List<Widget>? actions;
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
/// Screen specific actions under the overflow menu. The value of each item
|
|
|
|
/// much >= 0
|
2021-07-23 22:05:57 +02:00
|
|
|
final List<PopupMenuEntry<int>>? menuActions;
|
|
|
|
final void Function(int)? onSelectedMenuActions;
|
2022-11-12 11:45:29 +01:00
|
|
|
final bool isShowProgressIcon;
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
static const _menuValueAbout = -1;
|
2021-08-18 06:24:50 +02:00
|
|
|
static const _menuValueHelp = -2;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
2022-11-12 10:55:33 +01:00
|
|
|
|
|
|
|
class _DarkModeSwitch extends StatelessWidget {
|
|
|
|
const _DarkModeSwitch({
|
|
|
|
this.onChanged,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Theme(
|
|
|
|
data: buildDarkModeSwitchTheme(context),
|
|
|
|
child: Switch(
|
|
|
|
value: Theme.of(context).brightness == Brightness.dark,
|
|
|
|
onChanged: onChanged,
|
|
|
|
activeThumbImage:
|
|
|
|
const AssetImage("assets/ic_dark_mode_switch_24dp.png"),
|
|
|
|
inactiveThumbImage:
|
|
|
|
const AssetImage("assets/ic_dark_mode_switch_24dp.png"),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final ValueChanged<bool>? onChanged;
|
|
|
|
}
|