Merge branch 'main' into db_and_services
This commit is contained in:
commit
5f4b67b93e
7 changed files with 150 additions and 28 deletions
|
@ -156,17 +156,24 @@ class CollectionsDB {
|
|||
];
|
||||
}
|
||||
|
||||
Future<List<dynamic>> insert(List<Collection> collections) async {
|
||||
Future<void> insert(List<Collection> collections) async {
|
||||
final db = await instance.database;
|
||||
final batch = db.batch();
|
||||
var batch = db.batch();
|
||||
int batchCounter = 0;
|
||||
for (final collection in collections) {
|
||||
if (batchCounter == 400) {
|
||||
await batch.commit(noResult: true);
|
||||
batch = db.batch();
|
||||
batchCounter = 0;
|
||||
}
|
||||
batch.insert(
|
||||
table,
|
||||
_getRowForCollection(collection),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
batchCounter++;
|
||||
}
|
||||
return await batch.commit();
|
||||
await batch.commit(noResult: true);
|
||||
}
|
||||
|
||||
Future<List<Collection>> getAllCollections() async {
|
||||
|
|
|
@ -106,20 +106,15 @@ class CollectionsService {
|
|||
final updatedCollections = <Collection>[];
|
||||
int maxUpdationTime = lastCollectionUpdationTime;
|
||||
final ownerID = _config.getUserID();
|
||||
bool fireEventForCollectionDeleted = false;
|
||||
for (final collection in fetchedCollections) {
|
||||
if (collection.isDeleted) {
|
||||
await _filesDB.deleteCollection(collection.id);
|
||||
await setCollectionSyncTime(collection.id, null);
|
||||
if (_collectionIDToCollections.containsKey(collection.id)) {
|
||||
Bus.instance.fire(
|
||||
LocalPhotosUpdatedEvent(
|
||||
List<File>.empty(),
|
||||
source: "syncCollectionDeleted",
|
||||
),
|
||||
);
|
||||
fireEventForCollectionDeleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
// remove reference for incoming collections when unshared/deleted
|
||||
if (collection.isDeleted && ownerID != collection.owner?.id) {
|
||||
await _db.deleteCollection(collection.id);
|
||||
|
@ -132,6 +127,14 @@ class CollectionsService {
|
|||
? collection.updationTime
|
||||
: maxUpdationTime;
|
||||
}
|
||||
if (fireEventForCollectionDeleted) {
|
||||
Bus.instance.fire(
|
||||
LocalPhotosUpdatedEvent(
|
||||
List<File>.empty(),
|
||||
source: "syncCollectionDeleted",
|
||||
),
|
||||
);
|
||||
}
|
||||
await _updateDB(updatedCollections);
|
||||
_prefs.setInt(_collectionsSyncTimeKey, maxUpdationTime);
|
||||
watch.logAndReset("till DB insertion");
|
||||
|
@ -1116,6 +1119,7 @@ class CollectionsService {
|
|||
try {
|
||||
await _db.insert(collections);
|
||||
} catch (e) {
|
||||
_logger.severe("Failed to update collections", e);
|
||||
if (attempt < kMaximumWriteAttempts) {
|
||||
return _updateDB(collections, attempt: ++attempt);
|
||||
} else {
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:photos/ente_theme_data.dart';
|
|||
import 'package:photos/ui/components/captioned_text_widget.dart';
|
||||
import 'package:photos/ui/components/menu_item_widget.dart';
|
||||
import 'package:photos/ui/settings/common_settings.dart';
|
||||
import 'package:photos/ui/settings/inherited_settings_state.dart';
|
||||
|
||||
class ExpandableMenuItemWidget extends StatefulWidget {
|
||||
final String title;
|
||||
|
@ -37,6 +38,11 @@ class _ExpandableMenuItemWidgetState extends State<ExpandableMenuItemWidget> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isAnySectionExpanded =
|
||||
InheritedSettingsState.maybeOf(context)?.isAnySectionExpanded ?? false;
|
||||
final isCurrentSectionExpanded = expandableController.expanded;
|
||||
final isSuppressed = isAnySectionExpanded && !isCurrentSectionExpanded;
|
||||
|
||||
final enteColorScheme = Theme.of(context).colorScheme.enteTheme.colorScheme;
|
||||
final backgroundColor =
|
||||
MediaQuery.of(context).platformBrightness == Brightness.light
|
||||
|
@ -59,10 +65,19 @@ class _ExpandableMenuItemWidgetState extends State<ExpandableMenuItemWidget> {
|
|||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: widget.title,
|
||||
makeTextBold: true,
|
||||
textColor: isSuppressed
|
||||
? enteColorScheme.textMuted
|
||||
: enteColorScheme.textBase,
|
||||
),
|
||||
isExpandable: true,
|
||||
leadingIcon: widget.leadingIcon,
|
||||
leadingIconColor: isSuppressed
|
||||
? enteColorScheme.strokeMuted
|
||||
: enteColorScheme.strokeBase,
|
||||
trailingIcon: Icons.expand_more,
|
||||
trailingIconColor: isSuppressed
|
||||
? enteColorScheme.strokeMuted
|
||||
: enteColorScheme.strokeBase,
|
||||
menuItemColor: enteColorScheme.fillFaint,
|
||||
expandableController: expandableController,
|
||||
),
|
||||
|
@ -81,6 +96,12 @@ class _ExpandableMenuItemWidgetState extends State<ExpandableMenuItemWidget> {
|
|||
}
|
||||
|
||||
void _expandableControllerListener() {
|
||||
setState(() {});
|
||||
setState(() {
|
||||
if (expandableController.expanded) {
|
||||
InheritedSettingsState.of(context).increment();
|
||||
} else {
|
||||
InheritedSettingsState.of(context).decrement();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ class MenuItemWidget extends StatefulWidget {
|
|||
/// trailing icon can be passed without size as default size set by
|
||||
/// flutter is what this component expects
|
||||
final IconData? trailingIcon;
|
||||
final Color? trailingIconColor;
|
||||
final Widget? trailingWidget;
|
||||
final bool trailingIconIsMuted;
|
||||
final VoidCallback? onTap;
|
||||
|
@ -41,6 +42,7 @@ class MenuItemWidget extends StatefulWidget {
|
|||
this.leadingIconSize = 20.0,
|
||||
this.leadingIconWidget,
|
||||
this.trailingIcon,
|
||||
this.trailingIconColor,
|
||||
this.trailingWidget,
|
||||
this.trailingIconIsMuted = false,
|
||||
this.onTap,
|
||||
|
@ -167,7 +169,10 @@ class _MenuItemWidgetState extends State<MenuItemWidget> {
|
|||
switchInCurve: Curves.easeOut,
|
||||
child: isExpanded
|
||||
? const SizedBox.shrink()
|
||||
: Icon(widget.trailingIcon),
|
||||
: Icon(
|
||||
widget.trailingIcon,
|
||||
color: widget.trailingIconColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
: widget.trailingIcon != null
|
||||
|
@ -175,7 +180,7 @@ class _MenuItemWidgetState extends State<MenuItemWidget> {
|
|||
widget.trailingIcon,
|
||||
color: widget.trailingIconIsMuted
|
||||
? enteColorScheme.strokeMuted
|
||||
: null,
|
||||
: widget.trailingIconColor,
|
||||
)
|
||||
: widget.trailingWidget ?? const SizedBox.shrink(),
|
||||
],
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dots_indicator/dots_indicator.dart';
|
||||
|
@ -12,8 +10,10 @@ import 'package:photos/ui/account/email_entry_page.dart';
|
|||
import 'package:photos/ui/account/login_page.dart';
|
||||
import 'package:photos/ui/account/password_entry_page.dart';
|
||||
import 'package:photos/ui/account/password_reentry_page.dart';
|
||||
import 'package:photos/ui/common/dialogs.dart';
|
||||
import 'package:photos/ui/common/gradient_button.dart';
|
||||
import 'package:photos/ui/components/button_widget.dart';
|
||||
import 'package:photos/ui/components/dialog_widget.dart';
|
||||
import 'package:photos/ui/components/models/button_type.dart';
|
||||
import 'package:photos/ui/payment/subscription.dart';
|
||||
|
||||
class LandingPageWidget extends StatefulWidget {
|
||||
|
@ -153,7 +153,7 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
void _navigateToSignUpPage() {
|
||||
Future<void> _navigateToSignUpPage() async {
|
||||
UpdateService.instance.hideChangeLog().ignore();
|
||||
UserRemoteFlagService.instance.stopPasswordReminder().ignore();
|
||||
Widget page;
|
||||
|
@ -212,17 +212,23 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {
|
|||
Future<void> _showAutoLogoutDialogIfRequired() async {
|
||||
final bool autoLogout = Configuration.instance.showAutoLogoutDialog();
|
||||
if (autoLogout) {
|
||||
final result = await showChoiceDialog(
|
||||
context,
|
||||
"Please login again",
|
||||
'''Unfortunately, the ente app had to log you out because of some technical issues. Sorry!\n\nPlease login again.''',
|
||||
firstAction: "Cancel",
|
||||
secondAction: "Login",
|
||||
final ButtonAction? result = await showDialogWidget(
|
||||
context: context,
|
||||
title: "Please login again",
|
||||
body: "The developer account we use to publish ente on App Store has "
|
||||
"changed. Because of this, you will need to login again.\n\nOur "
|
||||
"apologies for the inconvenience, but this was unavoidable.",
|
||||
buttons: const [
|
||||
ButtonWidget(
|
||||
buttonType: ButtonType.neutral,
|
||||
buttonAction: ButtonAction.first,
|
||||
labelText: "Ok",
|
||||
isInAlert: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
if (result != null) {
|
||||
await Configuration.instance.clearAutoLogoutFlag();
|
||||
}
|
||||
if (result == DialogUserChoice.secondChoice) {
|
||||
Configuration.instance.clearAutoLogoutFlag().ignore();
|
||||
if (result != null && result == ButtonAction.first) {
|
||||
_navigateToSignInPage();
|
||||
}
|
||||
}
|
||||
|
|
76
lib/ui/settings/inherited_settings_state.dart
Normal file
76
lib/ui/settings/inherited_settings_state.dart
Normal file
|
@ -0,0 +1,76 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// StatefulWidget that wraps InheritedSettingsState
|
||||
class SettingsStateContainer extends StatefulWidget {
|
||||
const SettingsStateContainer({
|
||||
Key? key,
|
||||
required this.child,
|
||||
}) : super(key: key);
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<SettingsStateContainer> createState() => _SettingsState();
|
||||
}
|
||||
|
||||
class _SettingsState extends State<SettingsStateContainer> {
|
||||
int _expandedSectionCount = 0;
|
||||
|
||||
void increment() {
|
||||
setState(() {
|
||||
_expandedSectionCount += 1;
|
||||
});
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
setState(() {
|
||||
_expandedSectionCount -= 1;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InheritedSettingsState(
|
||||
expandedSectionCount: _expandedSectionCount,
|
||||
increment: increment,
|
||||
decrement: decrement,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep track of the number of expanded sections in an entire menu tree.
|
||||
///
|
||||
/// Since this is an InheritedWidget, subsections can obtain it from the context
|
||||
/// and use the current expansion state to style themselves differently if
|
||||
/// needed.
|
||||
///
|
||||
/// Example usage:
|
||||
///
|
||||
/// InheritedSettingsState.of(context).increment()
|
||||
///
|
||||
class InheritedSettingsState extends InheritedWidget {
|
||||
final int expandedSectionCount;
|
||||
final void Function() increment;
|
||||
final void Function() decrement;
|
||||
|
||||
const InheritedSettingsState({
|
||||
Key? key,
|
||||
required this.expandedSectionCount,
|
||||
required this.increment,
|
||||
required this.decrement,
|
||||
required Widget child,
|
||||
}) : super(key: key, child: child);
|
||||
|
||||
bool get isAnySectionExpanded => expandedSectionCount > 0;
|
||||
|
||||
static InheritedSettingsState of(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<InheritedSettingsState>()!;
|
||||
|
||||
static InheritedSettingsState? maybeOf(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<InheritedSettingsState>();
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(covariant InheritedSettingsState oldWidget) {
|
||||
return isAnySectionExpanded != oldWidget.isAnySectionExpanded;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import 'package:photos/ui/settings/app_version_widget.dart';
|
|||
import 'package:photos/ui/settings/backup_section_widget.dart';
|
||||
import 'package:photos/ui/settings/debug_section_widget.dart';
|
||||
import 'package:photos/ui/settings/general_section_widget.dart';
|
||||
import 'package:photos/ui/settings/inherited_settings_state.dart';
|
||||
import 'package:photos/ui/settings/security_section_widget.dart';
|
||||
import 'package:photos/ui/settings/settings_title_bar_widget.dart';
|
||||
import 'package:photos/ui/settings/social_section_widget.dart';
|
||||
|
@ -33,7 +34,9 @@ class SettingsPage extends StatelessWidget {
|
|||
return Scaffold(
|
||||
body: Container(
|
||||
color: enteColorScheme.backdropMuted,
|
||||
child: _getBody(context, enteColorScheme),
|
||||
child: SettingsStateContainer(
|
||||
child: _getBody(context, enteColorScheme),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue