Skip to content

Commit

Permalink
Cache unlocked features.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Mar 6, 2022
1 parent c6348ed commit f82eed8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 12 additions & 4 deletions lib/infrastructure/purchase_service.dart
Expand Up @@ -12,10 +12,11 @@ import 'package:shiori/domain/services/purchase_service.dart';
import 'package:shiori/infrastructure/secrets.dart';

class PurchaseServiceImpl implements PurchaseService {
bool _initialized = false;

final LoggingService _loggingService;

bool _initialized = false;
List<AppUnlockedFeature>? _unlockedFeatures;

@override
bool get isInitialized => _initialized;

Expand Down Expand Up @@ -129,6 +130,7 @@ class PurchaseServiceImpl implements PurchaseService {
}

try {
_unlockedFeatures = null;
final features = await _getUnlockedFeatures(entitlementIdentifier: entitlementIdentifier);
return features.isNotEmpty;
} catch (e, s) {
Expand Down Expand Up @@ -156,6 +158,10 @@ class PurchaseServiceImpl implements PurchaseService {

Future<List<AppUnlockedFeature>> _getUnlockedFeatures({String? entitlementIdentifier}) async {
try {
if (_unlockedFeatures != null){
return _unlockedFeatures!;
}

if (!await isPlatformSupported()) {
return [];
}
Expand All @@ -167,11 +173,13 @@ class PurchaseServiceImpl implements PurchaseService {
final transactions = await Purchases.restoreTransactions();
if (entitlementIdentifier.isNullEmptyOrWhitespace) {
final activeEntitlements = transactions.entitlements.active.values.any((el) => el.isActive);
return activeEntitlements ? AppUnlockedFeature.values : [];
_unlockedFeatures = activeEntitlements ? AppUnlockedFeature.values : [];
return _unlockedFeatures!;
}

final entitlement = transactions.entitlements.active.values.firstWhereOrNull((el) => el.identifier == entitlementIdentifier && el.isActive);
return entitlement != null ? AppUnlockedFeature.values : [];
_unlockedFeatures = entitlement != null ? AppUnlockedFeature.values : [];
return _unlockedFeatures!;
} catch (e) {
rethrow;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/presentation/donations/donations_bottom_sheet.dart
Expand Up @@ -177,7 +177,11 @@ class _DonationItem extends StatelessWidget {
return InkWell(
onTap: onTap,
child: Card(
color: isSelected ? theme.colorScheme.primary.withOpacity(0.5) : null,
color: isSelected
? theme.colorScheme.primary.withOpacity(0.5)
: theme.scaffoldBackgroundColor == Colors.black
? theme.cardColor.withOpacity(0.5)
: theme.cardColor,
margin: Styles.edgeInsetAll10,
child: Padding(
padding: Styles.edgeInsetAll10,
Expand Down
Expand Up @@ -56,7 +56,7 @@ extension AppThemeTypeExtensions on AppAccentColorType {
return dark;
}

const almostBlackColor = Color.fromARGB(255, 16, 16, 16);
const almostBlackColor = Color.fromARGB(255, 20, 20, 20);
return dark.copyWith(
scaffoldBackgroundColor: Colors.black,
popupMenuTheme: const PopupMenuThemeData(color: almostBlackColor),
Expand Down

0 comments on commit f82eed8

Please sign in to comment.