Hide incoming shared (#1584)

This commit is contained in:
Ashil 2023-12-13 12:11:18 +05:30 committed by GitHub
commit 3ed2cae6da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 13 deletions

View file

@ -8157,6 +8157,16 @@ class S {
args: [],
);
}
/// `Archive shared albums`
String get archiveSharedAlbums {
return Intl.message(
'Archive shared albums',
name: 'archiveSharedAlbums',
desc: '',
args: [],
);
}
}
class AppLocalizationDelegate extends LocalizationsDelegate<S> {

View file

@ -1159,5 +1159,6 @@
"signOutFromOtherDevices": "Sign out from other devices",
"signOutOtherBody": "If you think someone might know your password, you can force all other devices using your account to sign out.",
"signOutOtherDevices": "Sign out other devices",
"doNotSignOut": "Do not sign out"
"doNotSignOut": "Do not sign out",
"archiveSharedAlbums": "Archive shared albums"
}

View file

@ -147,7 +147,7 @@ class CollectionsService {
);
}
await _updateDB(updatedCollections);
_prefs.setInt(_collectionsSyncTimeKey, maxUpdationTime);
await _prefs.setInt(_collectionsSyncTimeKey, maxUpdationTime);
watch.logAndReset("till DB insertion ${updatedCollections.length}");
for (final collection in fetchedCollections) {
_cacheLocalPathAndCollection(collection);
@ -222,16 +222,24 @@ class CollectionsService {
}
Set<int> archivedOrHiddenCollectionIds() {
return _collectionIDToCollections.values
.toList()
.where(
(element) =>
element.hasShareeArchived() ||
element.isHidden() ||
element.isArchived(),
)
.map((e) => e.id)
.toSet();
final bool archiveIncomingCollections =
LocalSettings.instance.archiveSharedAlbums;
final int ownerID = _config.getUserID()!;
final Set<int> result = <int>{};
for (final collection in _collectionIDToCollections.values) {
if (collection.isHidden() ||
collection.isArchived() ||
collection.hasShareeArchived()) {
result.add(collection.id);
continue;
}
if (archiveIncomingCollections) {
if (collection.owner?.id != ownerID) {
result.add(collection.id);
}
}
}
return result;
}
int getCollectionSyncTime(int collectionID) {

View file

@ -2,6 +2,8 @@ import "dart:async";
import 'package:flutter/material.dart';
import "package:photos/core/error-reporting/super_logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/force_reload_home_gallery_event.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/services/memories_service.dart";
import "package:photos/services/user_remote_flag_service.dart";
@ -119,6 +121,32 @@ class _AdvancedSettingsScreenState extends State<AdvancedSettingsScreen> {
const SizedBox(
height: 24,
),
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: S.of(context).archiveSharedAlbums,
),
menuItemColor: colorScheme.fillFaint,
singleBorderRadius: 8,
alignCaptionedTextToLeft: true,
trailingWidget: ToggleSwitchWidget(
value: () =>
LocalSettings.instance.archiveSharedAlbums,
onChanged: () async {
await LocalSettings.instance
.setArchiveSharedAlbums(
!LocalSettings.instance.archiveSharedAlbums,
);
Bus.instance.fire(
ForceReloadHomeGalleryEvent(
"Hide/show shared albums",
),
);
},
),
),
const SizedBox(
height: 24,
),
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: S.of(context).manageDeviceStorage,
@ -131,7 +159,8 @@ class _AdvancedSettingsScreenState extends State<AdvancedSettingsScreen> {
singleBorderRadius: 8,
alignCaptionedTextToLeft: true,
onTap: () async {
routeToPage(context, const AppStorageViewer());
await routeToPage(
context, const AppStorageViewer());
},
),
const SizedBox(

View file

@ -13,6 +13,7 @@ class LocalSettings {
static final LocalSettings instance = LocalSettings._privateConstructor();
static const kCollectionSortPref = "collection_sort_pref";
static const kPhotoGridSize = "photo_grid_size";
static const kArchiveSharedAlbums = "archive_shared_albums";
static const kRateUsShownCount = "rate_us_shown_count";
static const kRateUsPromptThreshold = 2;
@ -38,10 +39,18 @@ class LocalSettings {
}
}
bool get archiveSharedAlbums {
return _prefs.getBool(kArchiveSharedAlbums) ?? false;
}
Future<void> setPhotoGridSize(int value) async {
await _prefs.setInt(kPhotoGridSize, value);
}
Future<void> setArchiveSharedAlbums(bool value) async {
await _prefs.setBool(kArchiveSharedAlbums, value);
}
int getRateUsShownCount() {
if (_prefs.containsKey(kRateUsShownCount)) {
return _prefs.getInt(kRateUsShownCount)!;