Skip to content

Commit

Permalink
feat: custom Fyx cache is optional #413
Browse files Browse the repository at this point in the history
  • Loading branch information
lucien144 committed Dec 9, 2023
1 parent eccaa60 commit d64da98
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/components/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:fyx/libs/fyx_image_cache_manager.dart';
import 'package:fyx/model/MainRepository.dart';
import 'package:fyx/theme/skin/Skin.dart';
import 'package:fyx/theme/skin/SkinColors.dart';

Expand Down Expand Up @@ -34,7 +35,7 @@ class Avatar extends StatelessWidget {
errorWidget: (context, url, error) => Icon(Icons.error),
width: width,
height: height,
cacheManager: FyxImageCacheManager(),
cacheManager: MainRepository().settings.useFyxImageCache ? FyxImageCacheManager() : null,
),
)),
);
Expand Down
3 changes: 2 additions & 1 deletion lib/components/post/post_hero_attachment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:fyx/components/post/post_hero_attachment_box.dart';
import 'package:fyx/controllers/SettingsProvider.dart';
import 'package:fyx/controllers/log_service.dart';
import 'package:fyx/libs/fyx_image_cache_manager.dart';
import 'package:fyx/model/MainRepository.dart';
import 'package:fyx/model/post/Image.dart' as model;
import 'package:fyx/model/post/Link.dart';
import 'package:fyx/model/post/Video.dart';
Expand Down Expand Up @@ -74,7 +75,7 @@ class PostHeroAttachment extends StatelessWidget {
width: _crop ? size.width : null,
height: _crop ? size.height : null,
memCacheWidth: (MediaQuery.of(context).size.width * 0.5 * MediaQuery.of(context).devicePixelRatio).toInt(),
cacheManager: FyxImageCacheManager(),
cacheManager: MainRepository().settings.useFyxImageCache ? FyxImageCacheManager() : null,
),
if (blur) Positioned.fill(child: T.nsfwMask())
],
Expand Down
7 changes: 7 additions & 0 deletions lib/controllers/SettingsProvider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class SettingsProvider {
_settings.quickRating = mode;
}

bool get useFyxImageCache => _settings.useFyxImageCache;
set useFyxImageCache(bool mode) {
_box.put('useFyxImageCache', mode);
_settings.useFyxImageCache = mode;
}

bool get useAutocorrect => _settings.useAutocorrect;
set useAutocorrect(bool autocorrect) {
_box.put('useAutocorrect', autocorrect);
Expand Down Expand Up @@ -111,6 +117,7 @@ class SettingsProvider {
_settings.defaultView = _box.get('defaultView', defaultValue: Settings().defaultView);
_settings.latestView = _box.get('latestView', defaultValue: Settings().latestView);
_settings.quickRating = _box.get('quickRating', defaultValue: Settings().quickRating);
_settings.useFyxImageCache = _box.get('useFyxImageCache', defaultValue: Settings().useFyxImageCache);
_settings.useCompactMode = _box.get('useCompactMode', defaultValue: Settings().useCompactMode);
_settings.useAutocorrect = _box.get('useAutocorrect', defaultValue: Settings().useAutocorrect);
_settings.firstUnread = _box.get('firstUnread', defaultValue: Settings().firstUnread);
Expand Down
1 change: 1 addition & 0 deletions lib/model/Settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Settings {
bool useCompactMode = false;
bool useAutocorrect = true;
bool quickRating = true;
bool useFyxImageCache = false; // Wheter to use internal image case or not. May fix crashes on big images. #413
// Settings -> what is the default view when app restart?
DefaultView defaultView = DefaultView.history;
// Save the last screen view
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/GalleryPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:fyx/controllers/AnalyticsProvider.dart';
import 'package:fyx/controllers/log_service.dart';
import 'package:fyx/exceptions/UnsupportedDownloadFormatException.dart';
import 'package:fyx/libs/fyx_image_cache_manager.dart';
import 'package:fyx/model/MainRepository.dart';
import 'package:fyx/theme/Helpers.dart';
import 'package:fyx/theme/L.dart';
import 'package:fyx/theme/T.dart';
Expand Down Expand Up @@ -113,7 +114,7 @@ class _GalleryPageState extends State<GalleryPage> {
),
imageUrl: _arguments!.images[index].image,
memCacheWidth: (MediaQuery.of(context).size.width * MediaQuery.of(context).devicePixelRatio).toInt(),
cacheManager: FyxImageCacheManager()),
cacheManager: MainRepository().settings.useFyxImageCache ? FyxImageCacheManager() : null),
));
},
itemCount: _arguments!.images.length,
Expand Down
14 changes: 12 additions & 2 deletions lib/pages/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ class SettingsScreen extends StatefulWidget {
_SettingsScreenState createState() => _SettingsScreenState();
}

enum CacheKeys {images, gifs, videos, other}
enum CacheKeys { images, gifs, videos, other }

class _SettingsScreenState extends State<SettingsScreen> {
Map cacheUsage = {CacheKeys.images: 0.0, CacheKeys.gifs: 0.0, CacheKeys.videos: 0.0, CacheKeys.other: 0.0};

bool _compactMode = false;
bool _autocorrect = false;
bool _quickRating = true;
bool _useFyxImageCache = false;
bool _emptyingCache = false;
Future<Map<CacheKeys, double>> _cacheSize = Future.value({});
DefaultView _defaultView = DefaultView.latest;
Expand All @@ -53,6 +54,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_firstUnread = MainRepository().settings.firstUnread;
_linksMode = MainRepository().settings.linksMode;
_quickRating = MainRepository().settings.quickRating;
_useFyxImageCache = MainRepository().settings.useFyxImageCache;
_cacheSize = _getCacheSize();
AnalyticsProvider().setScreen('Settings', 'SettingsPage');
}
Expand Down Expand Up @@ -218,6 +220,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
SettingsSection(
title: Text('Paměť'),
tiles: <SettingsTile>[
SettingsTile.switchTile(
onToggle: (bool value) {
setState(() => _useFyxImageCache = value);
MainRepository().settings.useFyxImageCache = value;
},
initialValue: _useFyxImageCache,
title: Text('Zmenšovat obrázky')),
SettingsTile(
title: Text('Blokovaných uživatelů'),
trailing: ValueListenableBuilder(
Expand Down Expand Up @@ -269,7 +278,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
MainRepository().settings.resetNsfwDiscussion();
T.success(L.SETTINGS_CACHE_RESET, bg: colors.success);
AnalyticsProvider().logEvent('resetBlockedContent');
}),
},
description: Text('Zmenšovat obrázky - zmenšuje obrázky před stažením a předchází tak pádům aplikavce. V určitých případech ale může snižovat FPS.')),
],
),
CustomSettingsSection(
Expand Down

0 comments on commit d64da98

Please sign in to comment.