mirror of
https://github.com/ente-io/ente.git
synced 2025-07-24 12:52:01 +00:00
feat: add video streaming setting
This commit is contained in:
parent
6176ec6cb9
commit
6468fe9637
5
mobile/lib/events/video_streaming_changed.dart
Normal file
5
mobile/lib/events/video_streaming_changed.dart
Normal file
@ -0,0 +1,5 @@
|
||||
import "package:photos/events/event.dart";
|
||||
|
||||
// todo: consider removing this once we opt for riverpod or similar state management
|
||||
// solution
|
||||
class VideoStreamingChanged extends Event {}
|
@ -286,7 +286,7 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
|
||||
});
|
||||
}
|
||||
_logger.info("PushService/HomeWidget done $tlog");
|
||||
PreviewVideoStore.instance.init();
|
||||
PreviewVideoStore.instance.init(preferences);
|
||||
unawaited(SemanticSearchService.instance.init());
|
||||
unawaited(MLService.instance.init());
|
||||
await PersonService.init(
|
||||
|
@ -13,16 +13,18 @@ import "package:logging/logging.dart";
|
||||
import "package:path_provider/path_provider.dart";
|
||||
import "package:photos/core/cache/video_cache_manager.dart";
|
||||
import "package:photos/core/configuration.dart";
|
||||
import "package:photos/core/event_bus.dart";
|
||||
import "package:photos/core/network/network.dart";
|
||||
import "package:photos/events/video_streaming_changed.dart";
|
||||
import "package:photos/models/base/id.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import "package:photos/models/file/file_type.dart";
|
||||
import "package:photos/service_locator.dart";
|
||||
import "package:photos/services/filedata/filedata_service.dart";
|
||||
import "package:photos/utils/file_key.dart";
|
||||
import "package:photos/utils/file_util.dart";
|
||||
import "package:photos/utils/gzip.dart";
|
||||
import "package:photos/utils/toast_util.dart";
|
||||
import "package:shared_preferences/shared_preferences.dart";
|
||||
|
||||
class PreviewVideoStore {
|
||||
PreviewVideoStore._privateConstructor();
|
||||
@ -38,10 +40,37 @@ class PreviewVideoStore {
|
||||
bool isUploading = false;
|
||||
|
||||
final _dio = NetworkClient.instance.enteDio;
|
||||
void init() {}
|
||||
|
||||
void init(SharedPreferences prefs) {
|
||||
_prefs = prefs;
|
||||
}
|
||||
|
||||
late final SharedPreferences _prefs;
|
||||
static const String _videoStreamingEnabled = "videoStreamingEnabled";
|
||||
static const String _videoStreamingCutoff = "videoStreamingCutoff";
|
||||
|
||||
bool get isVideoStreamingEnabled {
|
||||
return _prefs.getBool(_videoStreamingEnabled) ?? true;
|
||||
}
|
||||
|
||||
Future<void> setIsVideoStreamingEnabled(bool value) async {
|
||||
final oneMonthBack = DateTime.now().subtract(const Duration(days: 30));
|
||||
await _prefs.setBool(_videoStreamingEnabled, value);
|
||||
await _prefs.setInt(
|
||||
_videoStreamingCutoff,
|
||||
oneMonthBack.millisecondsSinceEpoch,
|
||||
);
|
||||
Bus.instance.fire(VideoStreamingChanged());
|
||||
}
|
||||
|
||||
Future<DateTime?> get videoStreamingCutoff async {
|
||||
final milliseconds = _prefs.getInt(_videoStreamingCutoff);
|
||||
if (milliseconds == null) return null;
|
||||
return DateTime.fromMillisecondsSinceEpoch(milliseconds);
|
||||
}
|
||||
|
||||
Future<void> chunkAndUploadVideo(BuildContext? ctx, EnteFile enteFile) async {
|
||||
if (!enteFile.isUploaded || !flagService.internalUser) return;
|
||||
if (!enteFile.isUploaded || !isVideoStreamingEnabled) return;
|
||||
final file = await getFile(enteFile, isOrigin: true);
|
||||
if (file == null) return;
|
||||
try {
|
||||
|
@ -19,6 +19,7 @@ class UserRemoteFlagService {
|
||||
static const String recoveryVerificationFlag = "recoveryKeyVerified";
|
||||
static const String mapEnabled = "mapEnabled";
|
||||
static const String mlEnabled = "faceSearchEnabled";
|
||||
static const String videoStreamingEnabled = "videoStreamingEnabled";
|
||||
static const String needRecoveryKeyVerification =
|
||||
"needRecoveryKeyVerification";
|
||||
|
||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import "package:photos/core/error-reporting/super_logging.dart";
|
||||
import "package:photos/generated/l10n.dart";
|
||||
import "package:photos/service_locator.dart";
|
||||
import "package:photos/services/preview_video_store.dart";
|
||||
import "package:photos/services/user_remote_flag_service.dart";
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/components/buttons/icon_button_widget.dart';
|
||||
@ -116,6 +117,28 @@ class AdvancedSettingsScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
),
|
||||
if (flagService.internalUser) ...[
|
||||
const SizedBox(height: 24),
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: S.of(context).videoStreaming,
|
||||
),
|
||||
menuItemColor: colorScheme.fillFaint,
|
||||
singleBorderRadius: 8,
|
||||
alignCaptionedTextToLeft: true,
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () => PreviewVideoStore
|
||||
.instance.isVideoStreamingEnabled,
|
||||
onChanged: () async {
|
||||
final isEnabled = PreviewVideoStore
|
||||
.instance.isVideoStreamingEnabled;
|
||||
|
||||
await PreviewVideoStore.instance
|
||||
.setIsVideoStreamingEnabled(!isEnabled);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user