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

fix(mobile): fixes on language change #14089

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 26 additions & 14 deletions mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/providers/locale_provider.dart';
import 'package:immich_mobile/utils/download.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:timezone/data/latest.dart';
Expand Down Expand Up @@ -191,6 +192,12 @@ class ImmichAppState extends ConsumerState<ImmichApp>
await ref.read(localNotificationService).setup();
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
Intl.defaultLocale = context.locale.toLanguageTag();
}

@override
initState() {
super.initState();
Expand All @@ -212,20 +219,25 @@ class ImmichAppState extends ConsumerState<ImmichApp>
final router = ref.watch(appRouterProvider);
final immichTheme = ref.watch(immichThemeProvider);

return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: true,
home: MaterialApp.router(
title: 'Immich',
debugShowCheckedModeBanner: false,
themeMode: ref.watch(immichThemeModeProvider),
darkTheme: getThemeData(colorScheme: immichTheme.dark),
theme: getThemeData(colorScheme: immichTheme.light),
routeInformationParser: router.defaultRouteParser(),
routerDelegate: router.delegate(
navigatorObservers: () => [TabNavigationObserver(ref: ref)],
return ProviderScope(
overrides: [
localeProvider.overrideWithValue(context.locale),
],
child: MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: true,
home: MaterialApp.router(
title: 'Immich',
debugShowCheckedModeBanner: false,
themeMode: ref.watch(immichThemeModeProvider),
darkTheme: getThemeData(colorScheme: immichTheme.dark),
theme: getThemeData(colorScheme: immichTheme.light),
routeInformationParser: router.defaultRouteParser(),
routerDelegate: router.delegate(
navigatorObservers: () => [TabNavigationObserver(ref: ref)],
),
),
),
);
Expand Down
2 changes: 2 additions & 0 deletions mobile/lib/pages/common/settings.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SettingsPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
context.locale;
return Scaffold(
appBar: AppBar(
centerTitle: false,
Expand Down Expand Up @@ -129,6 +130,7 @@ class SettingsSubPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
context.locale;
return Scaffold(
appBar: AppBar(
centerTitle: false,
Expand Down
1 change: 1 addition & 0 deletions mobile/lib/pages/library/library.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LibraryPage extends ConsumerWidget {
const LibraryPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
context.locale;
final trashEnabled =
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));

Expand Down
44 changes: 26 additions & 18 deletions mobile/lib/providers/asset.provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/providers/locale_provider.dart';
import 'package:immich_mobile/providers/memory.provider.dart';
import 'package:immich_mobile/repositories/asset_media.repository.dart';
import 'package:immich_mobile/services/album.service.dart';
Expand Down Expand Up @@ -328,24 +329,31 @@ final assetWatcher =
return db.assets.watchObject(asset.id, fireImmediately: true);
});

final assetsProvider = StreamProvider.family<RenderList, int?>((ref, userId) {
if (userId == null) return const Stream.empty();
final query = _commonFilterAndSort(
_assets(ref).where().ownerIdEqualToAnyChecksum(userId),
);
return renderListGenerator(query, ref);
});

final multiUserAssetsProvider =
StreamProvider.family<RenderList, List<int>>((ref, userIds) {
if (userIds.isEmpty) return const Stream.empty();
final query = _commonFilterAndSort(
_assets(ref)
.where()
.anyOf(userIds, (q, u) => q.ownerIdEqualToAnyChecksum(u)),
);
return renderListGenerator(query, ref);
});
final assetsProvider = StreamProvider.family<RenderList, int?>(
(ref, userId) {
if (userId == null) return const Stream.empty();
ref.watch(localeProvider);
final query = _commonFilterAndSort(
_assets(ref).where().ownerIdEqualToAnyChecksum(userId),
);
return renderListGenerator(query, ref);
},
dependencies: [localeProvider],
);

final multiUserAssetsProvider = StreamProvider.family<RenderList, List<int>>(
(ref, userIds) {
if (userIds.isEmpty) return const Stream.empty();
ref.watch(localeProvider);
final query = _commonFilterAndSort(
_assets(ref)
.where()
.anyOf(userIds, (q, u) => q.ownerIdEqualToAnyChecksum(u)),
);
return renderListGenerator(query, ref);
},
dependencies: [localeProvider],
);

QueryBuilder<Asset, Asset, QAfterSortBy>? getRemoteAssetQuery(WidgetRef ref) {
final userId = ref.watch(currentUserProvider)?.isarId;
Expand Down
4 changes: 4 additions & 0 deletions mobile/lib/providers/locale_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:flutter/widgets.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final localeProvider = Provider<Locale>((_) => throw UnimplementedError());
Loading