Better update dialog (#1707)
This commit is contained in:
commit
1b370e68c6
3 changed files with 50 additions and 42 deletions
|
@ -73,30 +73,39 @@ class UpdateService {
|
|||
return _latestVersion;
|
||||
}
|
||||
|
||||
Future<void> showUpdateNotification() async {
|
||||
if (!isIndependent()) {
|
||||
return;
|
||||
}
|
||||
Future<bool> shouldShowUpdateNoification() async {
|
||||
final shouldUpdate = await this.shouldUpdate();
|
||||
|
||||
final lastNotificationShownTime =
|
||||
_prefs.getInt(kUpdateAvailableShownTimeKey) ?? 0;
|
||||
final now = DateTime.now().microsecondsSinceEpoch;
|
||||
final hasBeen3DaysSinceLastNotification =
|
||||
(now - lastNotificationShownTime) > (3 * microSecondsInDay);
|
||||
if (shouldUpdate &&
|
||||
hasBeen3DaysSinceLastNotification &&
|
||||
_latestVersion!.shouldNotify) {
|
||||
final hasBeenThresholdDaysSinceLastNotification =
|
||||
(now - lastNotificationShownTime) >
|
||||
((_latestVersion!.shouldNotify ? 1 : 3) * microSecondsInDay);
|
||||
|
||||
return shouldUpdate && hasBeenThresholdDaysSinceLastNotification;
|
||||
}
|
||||
|
||||
Future<void> showUpdateNotification() async {
|
||||
if (await shouldShowUpdateNoification()) {
|
||||
// ignore: unawaited_futures
|
||||
NotificationService.instance.showNotification(
|
||||
"Update available",
|
||||
"Click to install our best version yet",
|
||||
);
|
||||
await _prefs.setInt(kUpdateAvailableShownTimeKey, now);
|
||||
await resetUpdateAvailableShownTime();
|
||||
} else {
|
||||
_logger.info("Debouncing notification");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resetUpdateAvailableShownTime() {
|
||||
return _prefs.setInt(
|
||||
kUpdateAvailableShownTimeKey,
|
||||
DateTime.now().microsecondsSinceEpoch,
|
||||
);
|
||||
}
|
||||
|
||||
Future<LatestVersionInfo> _getLatestVersionInfo() async {
|
||||
final response = await NetworkClient.instance
|
||||
.getDio()
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
// import 'package:open_file/open_file.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/network/network.dart';
|
||||
import 'package:photos/ente_theme_data.dart';
|
||||
import "package:photos/generated/l10n.dart";
|
||||
import 'package:photos/services/update_service.dart';
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import "package:photos/ui/components/buttons/button_widget.dart";
|
||||
import "package:photos/ui/components/models/button_type.dart";
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class AppUpdateDialog extends StatefulWidget {
|
||||
|
@ -63,32 +64,28 @@ class _AppUpdateDialogState extends State<AppUpdateDialog> {
|
|||
children: changelog,
|
||||
),
|
||||
const Padding(padding: EdgeInsets.all(8)),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
child: OutlinedButton(
|
||||
style: Theme.of(context).outlinedButtonTheme.style!.copyWith(
|
||||
textStyle: MaterialStateProperty.resolveWith<TextStyle>(
|
||||
(Set<MaterialState> states) {
|
||||
return enteTextTheme.bodyBold;
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
// ignore: unawaited_futures
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ApkDownloaderDialog(widget.latestVersionInfo);
|
||||
},
|
||||
barrierDismissible: false,
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
S.of(context).update,
|
||||
),
|
||||
),
|
||||
ButtonWidget(
|
||||
buttonType: ButtonType.primary,
|
||||
labelText: S.of(context).update,
|
||||
onTap: () async {
|
||||
Navigator.pop(context);
|
||||
// ignore: unawaited_futures
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ApkDownloaderDialog(widget.latestVersionInfo);
|
||||
},
|
||||
barrierDismissible: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
ButtonWidget(
|
||||
buttonType: ButtonType.secondary,
|
||||
labelText: S.of(context).cancel,
|
||||
onTap: () async {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
const Padding(padding: EdgeInsets.all(8)),
|
||||
Center(
|
||||
|
|
|
@ -194,9 +194,9 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
},
|
||||
);
|
||||
_initDeepLinks();
|
||||
UpdateService.instance.shouldUpdate().then((shouldUpdate) {
|
||||
if (shouldUpdate) {
|
||||
Future.delayed(Duration.zero, () {
|
||||
UpdateService.instance.shouldShowUpdateNoification().then((value) {
|
||||
Future.delayed(Duration.zero, () {
|
||||
if (value) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
@ -206,9 +206,11 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
},
|
||||
barrierColor: Colors.black.withOpacity(0.85),
|
||||
);
|
||||
});
|
||||
}
|
||||
UpdateService.instance.resetUpdateAvailableShownTime();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// For sharing images coming from outside the app
|
||||
_initMediaShareSubscription();
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
|
|
Loading…
Add table
Reference in a new issue