ente/lib/services/storage_bonus_service.dart

38 lines
1.2 KiB
Dart
Raw Normal View History

import "package:photos/core/network/network.dart";
import "package:photos/gateways/storage_bonus_gw.dart";
import "package:shared_preferences/shared_preferences.dart";
class StorageBonusService {
late StorageBonusGateway gateway;
late SharedPreferences prefs;
2023-02-23 04:42:03 +00:00
final int minTapCountBeforeHidingBanner = 5;
final String _showStorageBonusTapCount = "showStorageBonus.tap_count";
2023-02-17 08:49:11 +00:00
void init(SharedPreferences preferences) {
prefs = preferences;
gateway = StorageBonusGateway(NetworkClient.instance.enteDio);
}
StorageBonusService._privateConstructor();
static StorageBonusService instance =
StorageBonusService._privateConstructor();
2023-02-15 16:47:40 +00:00
2023-02-23 04:42:03 +00:00
// returns true if _showStorageBonusTapCount value is less than minTapCountBeforeHidingBanner
2023-02-17 08:49:11 +00:00
bool shouldShowStorageBonus() {
2023-02-23 04:42:03 +00:00
final tapCount = prefs.getInt(_showStorageBonusTapCount) ?? 0;
return tapCount <= minTapCountBeforeHidingBanner;
2023-02-17 08:49:11 +00:00
}
void markStorageBonusAsDone() {
2023-02-23 04:42:03 +00:00
final tapCount = prefs.getInt(_showStorageBonusTapCount) ?? 0;
prefs.setInt(_showStorageBonusTapCount, tapCount + 1).ignore();
2023-02-17 08:49:11 +00:00
}
2023-02-15 16:47:40 +00:00
// getter for gateway
StorageBonusGateway getGateway() {
return gateway;
}
}