Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug setting to customize image dimension timeout value #1462

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/core/enums/local_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ enum LocalSettings {
combineNavAndFab(name: 'setting_combine_nav_and_fab', key: 'combineNavAndFab', category: LocalSettingsCategories.general, subCategory: LocalSettingsSubCategories.comments),

enableExperimentalFeatures(name: 'setting_enable_experimental_features', key: 'enableExperimentalFeatures', category: LocalSettingsCategories.debug),
imageDimensionTimeout(name: 'setting_image_dimension_timeout', key: 'imageDimensionTimeout', category: LocalSettingsCategories.debug),

draftsCache(name: 'drafts_cache', key: ''),

Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,10 @@
"@imageCachingModeRelaxedShort": {
"description": "Short description for relaxed image caching mode"
},
"imageDimensionTimeout": "Image Dimension Timeout",
"@imageDimensionTimeout": {
"description": "Setting for how long to wait for the image dimensions to be fetched"
},
"importDatabase": "Import Database",
"@importDatabase": {
"description": "Name of setting for importing the db"
Expand Down
5 changes: 4 additions & 1 deletion lib/post/utils/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ Future<PostViewMedia> parsePostView(PostView postView, bool fetchImageDimensions
Size result = Size(MediaQuery.of(GlobalContext.context).size.width, 200);

try {
result = await retrieveImageDimensions(imageUrl: media.thumbnailUrl ?? media.mediaUrl).timeout(const Duration(seconds: 2));
SharedPreferences prefs = (await UserPreferences.instance).sharedPreferences;
int imageDimensionTimeout = prefs.getInt(LocalSettings.imageDimensionTimeout.name) ?? 2;

result = await retrieveImageDimensions(imageUrl: media.thumbnailUrl ?? media.mediaUrl).timeout(Duration(seconds: imageDimensionTimeout));
} catch (e) {
debugPrint('${media.thumbnailUrl ?? media.originalUrl} - $e: Falling back to default image size');
}
Expand Down
32 changes: 32 additions & 0 deletions lib/settings/pages/debug_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import 'package:thunder/notification/enums/notification_type.dart';
import 'package:thunder/notification/shared/android_notification.dart';
import 'package:thunder/notification/shared/notification_server.dart';
import 'package:thunder/notification/utils/local_notifications.dart';
import 'package:thunder/settings/widgets/list_option.dart';
import 'package:thunder/settings/widgets/toggle_option.dart';

import 'package:thunder/shared/dialogs.dart';
import 'package:thunder/shared/divider.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/settings/widgets/settings_list_tile.dart';
import 'package:thunder/utils/bottom_sheet_list_picker.dart';
import 'package:thunder/utils/cache.dart';
import 'package:thunder/utils/constants.dart';
import 'package:unifiedpush/unifiedpush.dart';
Expand Down Expand Up @@ -58,6 +60,12 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
/// Enable experimental features in the app.
bool enableExperimentalFeatures = false;

/// The maximum amount of time in seconds to fetch the image dimensions.
int imageDimensionTimeout = 2;

/// The available timeout values for image dimensions in seconds.
List<int> imageDimensionTimeouts = List.generate(10, (index) => index + 1);

Future<void> setPreferences(attribute, value) async {
final prefs = (await UserPreferences.instance).sharedPreferences;

Expand All @@ -66,6 +74,10 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
await prefs.setBool(LocalSettings.enableExperimentalFeatures.name, value);
setState(() => enableExperimentalFeatures = value);
break;
case LocalSettings.imageDimensionTimeout:
await prefs.setInt(LocalSettings.imageDimensionTimeout.name, value);
setState(() => imageDimensionTimeout = value);
break;
}
}

Expand Down Expand Up @@ -123,6 +135,7 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {

setState(() {
enableExperimentalFeatures = prefs.getBool(LocalSettings.enableExperimentalFeatures.name) ?? false;
imageDimensionTimeout = prefs.getInt(LocalSettings.imageDimensionTimeout.name) ?? 2;
});

if (widget.settingToHighlight != null) {
Expand Down Expand Up @@ -566,6 +579,25 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
highlightedSetting: settingToHighlight,
),
),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0),
child: Text(l10n.feed, style: theme.textTheme.titleMedium),
),
),
const SliverToBoxAdapter(child: SizedBox(height: 8.0)),
SliverToBoxAdapter(
child: ListOption(
description: l10n.imageDimensionTimeout,
value: ListPickerItem(label: '${imageDimensionTimeout}s', icon: Icons.timelapse, payload: imageDimensionTimeout),
options: imageDimensionTimeouts.map((value) => ListPickerItem(icon: Icons.timelapse, label: '${value}s', payload: value)).toList(),
icon: Icons.timelapse,
onChanged: (value) async => setPreferences(LocalSettings.imageDimensionTimeout, value.payload),
highlightKey: settingToHighlightKey,
setting: LocalSettings.imageDimensionTimeout,
highlightedSetting: settingToHighlight,
),
),
const SliverToBoxAdapter(child: SizedBox(height: 48)),
],
),
Expand Down
Loading