mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Show a subtle donation snackbar
This commit is contained in:
parent
c6a21ee606
commit
41e9b6214a
4 changed files with 79 additions and 0 deletions
|
@ -118,6 +118,8 @@ enum PrefKey implements PrefKeyInterface {
|
||||||
viewerAppBarButtons,
|
viewerAppBarButtons,
|
||||||
viewerBottomAppBarButtons,
|
viewerBottomAppBarButtons,
|
||||||
homeCollectionsNavBarButtons,
|
homeCollectionsNavBarButtons,
|
||||||
|
lastDonationDialogTime,
|
||||||
|
shouldRemindDonationLater,
|
||||||
;
|
;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -218,6 +220,10 @@ enum PrefKey implements PrefKeyInterface {
|
||||||
return "viewerBottomAppBarButtons";
|
return "viewerBottomAppBarButtons";
|
||||||
case PrefKey.homeCollectionsNavBarButtons:
|
case PrefKey.homeCollectionsNavBarButtons:
|
||||||
return "homeCollectionsNavBarButtons";
|
return "homeCollectionsNavBarButtons";
|
||||||
|
case PrefKey.lastDonationDialogTime:
|
||||||
|
return "lastDonationDialogTime";
|
||||||
|
case PrefKey.shouldRemindDonationLater:
|
||||||
|
return "shouldRemindDonationLater";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,24 @@ extension PrefExtension on Pref {
|
||||||
(key, value) => provider.setBool(key, value));
|
(key, value) => provider.setBool(key, value));
|
||||||
|
|
||||||
bool? isNewHttpEngine() => provider.getBool(PrefKey.isNewHttpEngine);
|
bool? isNewHttpEngine() => provider.getBool(PrefKey.isNewHttpEngine);
|
||||||
|
|
||||||
|
int? getLastDonationDialogTime() =>
|
||||||
|
provider.getInt(PrefKey.lastDonationDialogTime);
|
||||||
|
int getLastDonationDialogTimeOr(int def) =>
|
||||||
|
getLastDonationDialogTime() ?? def;
|
||||||
|
Future<bool> setLastDonationDialogTime(int value) => _set<int>(
|
||||||
|
PrefKey.lastDonationDialogTime,
|
||||||
|
value,
|
||||||
|
(key, value) => provider.setInt(key, value));
|
||||||
|
|
||||||
|
bool? shouldRemindDonationLater() =>
|
||||||
|
provider.getBool(PrefKey.shouldRemindDonationLater);
|
||||||
|
bool shouldRemindDonationLaterOr([bool def = false]) =>
|
||||||
|
shouldRemindDonationLater() ?? def;
|
||||||
|
Future<bool> setShouldRemindDonationLater(bool value) => _set<bool>(
|
||||||
|
PrefKey.shouldRemindDonationLater,
|
||||||
|
value,
|
||||||
|
(key, value) => provider.setBool(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AccountPrefExtension on AccountPref {
|
extension AccountPrefExtension on AccountPref {
|
||||||
|
|
50
app/lib/widget/donation_dialog.dart
Normal file
50
app/lib/widget/donation_dialog.dart
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import 'package:clock/clock.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:nc_photos/app_localizations.dart';
|
||||||
|
import 'package:nc_photos/controller/pref_controller.dart';
|
||||||
|
import 'package:nc_photos/entity/pref.dart';
|
||||||
|
import 'package:nc_photos/k.dart' as k;
|
||||||
|
import 'package:nc_photos/snack_bar_manager.dart';
|
||||||
|
|
||||||
|
class DonationDialogHandler {
|
||||||
|
Future<void> showIfNeeded(BuildContext context) async {
|
||||||
|
final prefController = context.read<PrefController>();
|
||||||
|
final lastMs = Pref().getLastDonationDialogTime();
|
||||||
|
if (lastMs == null) {
|
||||||
|
// first time
|
||||||
|
final firstRun = prefController.firstRunTimeValue ?? clock.now().toUtc();
|
||||||
|
final now = clock.now().toUtc();
|
||||||
|
if (now.isAfter(firstRun) &&
|
||||||
|
now.difference(firstRun) < const Duration(days: 7)) {
|
||||||
|
// unnecessary
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
return _show(context);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final last = DateTime.fromMillisecondsSinceEpoch(lastMs, isUtc: true);
|
||||||
|
final now = clock.now().toUtc();
|
||||||
|
if (now.isAfter(last) &&
|
||||||
|
now.difference(last) < const Duration(days: 365)) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// 1 year later...
|
||||||
|
return _show(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _show(BuildContext context) async {
|
||||||
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
|
content: Text(L10n.global().donationShortMessage),
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: L10n.global().donationButtonLabel,
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
duration: k.snackBarDurationNormal,
|
||||||
|
));
|
||||||
|
await Pref()
|
||||||
|
.setLastDonationDialogTime(clock.now().toUtc().millisecondsSinceEpoch);
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,6 +46,7 @@ import 'package:nc_photos/theme/dimension.dart';
|
||||||
import 'package:nc_photos/url_launcher_util.dart';
|
import 'package:nc_photos/url_launcher_util.dart';
|
||||||
import 'package:nc_photos/widget/collection_browser.dart';
|
import 'package:nc_photos/widget/collection_browser.dart';
|
||||||
import 'package:nc_photos/widget/collection_picker.dart';
|
import 'package:nc_photos/widget/collection_picker.dart';
|
||||||
|
import 'package:nc_photos/widget/donation_dialog.dart';
|
||||||
import 'package:nc_photos/widget/double_tap_exit_container/double_tap_exit_container.dart';
|
import 'package:nc_photos/widget/double_tap_exit_container/double_tap_exit_container.dart';
|
||||||
import 'package:nc_photos/widget/file_sharer_dialog.dart';
|
import 'package:nc_photos/widget/file_sharer_dialog.dart';
|
||||||
import 'package:nc_photos/widget/finger_listener.dart';
|
import 'package:nc_photos/widget/finger_listener.dart';
|
||||||
|
@ -288,6 +289,10 @@ class _BodyState extends State<_Body> {
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_onBackToTopListener.begin();
|
_onBackToTopListener.begin();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
DonationDialogHandler().showIfNeeded(context);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue