Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alextran1502 committed Dec 2, 2024
1 parent 15e5572 commit f780548
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 87 deletions.
2 changes: 2 additions & 0 deletions mobile/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linter:
use_build_context_synchronously: false
require_trailing_commas: true
unrelated_type_equality_checks: true
prefer_const_constructors: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Expand All @@ -42,6 +43,7 @@ analyzer:
custom_lint:
debug: true
rules:
- prefer_const_constructors: true
- avoid_build_context_in_providers: false
- avoid_public_notifier_properties: false
- avoid_manual_providers_as_generated_provider_dependency: false
Expand Down
4 changes: 0 additions & 4 deletions mobile/lib/interfaces/network.interface.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
abstract interface class INetworkRepository {
Future<String?> getWifiName();
Future<String?> getWifiIp();

Future<bool> isWifiConnected();
Future<bool> isVpnConnected();
Future<bool> isMobileDataConnected();
}
10 changes: 5 additions & 5 deletions mobile/lib/pages/albums/albums.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AlbumsPage extends HookConsumerWidget {
showUploadButton: false,
actions: [
IconButton(
icon: Icon(
icon: const Icon(
Icons.add_rounded,
size: 28,
),
Expand Down Expand Up @@ -112,13 +112,13 @@ class AlbumsPage extends HookConsumerWidget {
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
transform: GradientRotation(0.5 * pi),
transform: const GradientRotation(0.5 * pi),
),
),
child: TextField(
autofocus: false,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(16),
contentPadding: const EdgeInsets.all(16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: BorderSide(
Expand Down Expand Up @@ -362,13 +362,13 @@ class SortButton extends ConsumerWidget {

return MenuAnchor(
style: MenuStyle(
elevation: WidgetStatePropertyAll(1),
elevation: const WidgetStatePropertyAll(1),
shape: WidgetStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
),
padding: WidgetStatePropertyAll(
padding: const WidgetStatePropertyAll(
EdgeInsets.all(4),
),
),
Expand Down
23 changes: 13 additions & 10 deletions mobile/lib/providers/app_life_cycle.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {
return state;
}

void handleAppResume() {
void handleAppResume() async {
state = AppLifeCycleEnum.resumed;

// no need to resume because app was never really paused
Expand All @@ -47,36 +47,39 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {
// Needs to be logged in
if (isAuthenticated) {
// switch endpoint if needed
_ref.read(authProvider.notifier).setOpenApiServiceEndpoint();
await _ref.read(authProvider.notifier).setOpenApiServiceEndpoint();

final permission = _ref.watch(galleryPermissionNotifier);
if (permission.isGranted || permission.isLimited) {
_ref.read(backupProvider.notifier).resumeBackup();
_ref.read(backgroundServiceProvider).resumeServiceIfEnabled();
await _ref.read(backupProvider.notifier).resumeBackup();
await _ref.read(backgroundServiceProvider).resumeServiceIfEnabled();
}

_ref.read(serverInfoProvider.notifier).getServerVersion();
await _ref.read(serverInfoProvider.notifier).getServerVersion();

switch (_ref.read(tabProvider)) {
case TabEnum.home:
_ref.read(assetProvider.notifier).getAllAsset();
await _ref.read(assetProvider.notifier).getAllAsset();
case TabEnum.search:
// nothing to do
case TabEnum.albums:
_ref.read(albumProvider.notifier).refreshRemoteAlbums();
await _ref.read(albumProvider.notifier).refreshRemoteAlbums();
case TabEnum.library:
// nothing to do
}
}

_ref.read(websocketProvider.notifier).connect();

_ref
await _ref
.read(notificationPermissionProvider.notifier)
.getNotificationPermission();
_ref.read(galleryPermissionNotifier.notifier).getGalleryPermissionStatus();

_ref.read(iOSBackgroundSettingsProvider.notifier).refresh();
await _ref
.read(galleryPermissionNotifier.notifier)
.getGalleryPermissionStatus();

await _ref.read(iOSBackgroundSettingsProvider.notifier).refresh();

_ref.invalidate(memoryFutureProvider);
}
Expand Down
2 changes: 1 addition & 1 deletion mobile/lib/providers/network.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NetworkNotifier extends StateNotifier<String> {

NetworkNotifier(this._networkService) : super('');

Future<String?> getWifiName() async {
Future<String?> getWifiName() {
return _networkService.getWifiName();
}

Expand Down
2 changes: 1 addition & 1 deletion mobile/lib/providers/server_info.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
await getServerConfig();
}

getServerVersion() async {
Future<void> getServerVersion() async {
try {
final serverVersion = await _serverInfoService.getServerVersion();

Expand Down
25 changes: 2 additions & 23 deletions mobile/lib/repositories/network.repository.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import 'dart:io';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/interfaces/network.interface.dart';
import 'package:network_info_plus/network_info_plus.dart';

final networkRepositoryProvider = Provider((_) {
final networkInfo = NetworkInfo();
final connectivity = Connectivity();

return NetworkRepository(networkInfo, connectivity);
return NetworkRepository(networkInfo);
});

class NetworkRepository implements INetworkRepository {
final NetworkInfo _networkInfo;
final Connectivity _connectivity;

NetworkRepository(this._networkInfo, this._connectivity);
NetworkRepository(this._networkInfo);

@override
Future<String?> getWifiName() {
Expand All @@ -37,22 +34,4 @@ class NetworkRepository implements INetworkRepository {
Future<String?> getWifiIp() {
return _networkInfo.getWifiIP();
}

@override
Future<bool> isMobileDataConnected() async {
final result = await _connectivity.checkConnectivity();
return result.contains(ConnectivityResult.mobile);
}

@override
Future<bool> isWifiConnected() async {
final result = await _connectivity.checkConnectivity();
return result.contains(ConnectivityResult.wifi);
}

@override
Future<bool> isVpnConnected() async {
final result = await _connectivity.checkConnectivity();
return result.contains(ConnectivityResult.vpn);
}
}
6 changes: 0 additions & 6 deletions mobile/lib/services/network.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ class NetworkService {
return null;
}

final isWifiConnected = await _repository.isWifiConnected();

if (!isWifiConnected) {
return null;
}

return await _repository.getWifiName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class EndpointInputState extends ConsumerState<EndpointInput> {
),
),
child: ListTile(
contentPadding: EdgeInsets.only(left: 24, right: 24),
contentPadding: const EdgeInsets.only(left: 24, right: 24),
trailing: ReorderableDragStartListener(
index: widget.index,
child: Icon(Icons.drag_handle_rounded),
child: const Icon(Icons.drag_handle_rounded),
),
leading: NetworkStatusIcon(
key: ValueKey('status_$auxCheckStatus'),
Expand Down Expand Up @@ -131,14 +131,14 @@ class EndpointInputState extends ConsumerState<EndpointInput> {
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red[300]!),
borderRadius: BorderRadius.all(Radius.circular(16)),
borderRadius: const BorderRadius.all(Radius.circular(16)),
),
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color:
context.isDarkTheme ? Colors.grey[900]! : Colors.grey[300]!,
),
borderRadius: BorderRadius.all(Radius.circular(16)),
borderRadius: const BorderRadius.all(Radius.circular(16)),
),
),
controller: controller,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ExternalNetworkPreference extends HookConsumerWidget {
jsonList.map((e) => AuxilaryEndpoint.fromJson(e)).toList();
return null;
},
[],
const [],
);

return Padding(
Expand All @@ -112,8 +112,8 @@ class ExternalNetworkPreference extends HookConsumerWidget {
child: Stack(
children: [
ListView(
padding: EdgeInsets.symmetric(vertical: 16.0),
physics: ClampingScrollPhysics(),
padding: const EdgeInsets.symmetric(vertical: 16.0),
physics: const ClampingScrollPhysics(),
shrinkWrap: true,
children: [
Padding(
Expand All @@ -126,15 +126,15 @@ class ExternalNetworkPreference extends HookConsumerWidget {
style: context.textTheme.bodyMedium,
),
),
SizedBox(height: 4),
const SizedBox(height: 4),
Divider(color: context.colorScheme.surfaceContainerHighest),
Form(
key: GlobalKey<FormState>(),
child: ReorderableListView.builder(
buildDefaultDragHandles: false,
proxyDecorator: proxyDecorator,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
physics: const NeverScrollableScrollPhysics(),
itemCount: entries.value.length,
onReorder: handleReorder,
itemBuilder: (context, index) {
Expand All @@ -154,8 +154,8 @@ class ExternalNetworkPreference extends HookConsumerWidget {
child: SizedBox(
height: 48,
child: OutlinedButton.icon(
icon: Icon(Icons.add),
label: Text('ADD ENDPOINT'),
icon: const Icon(Icons.add),
label: const Text('ADD ENDPOINT'),
onPressed: () {
entries.value = [
...entries.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LocalNetworkPreference extends HookConsumerWidget {
controller: controller,
autofocus: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
border: const OutlineInputBorder(),
hintText: hintText,
),
),
Expand Down Expand Up @@ -154,8 +154,8 @@ class LocalNetworkPreference extends HookConsumerWidget {
child: Stack(
children: [
ListView(
padding: EdgeInsets.symmetric(vertical: 16.0),
physics: ClampingScrollPhysics(),
padding: const EdgeInsets.symmetric(vertical: 16.0),
physics: const ClampingScrollPhysics(),
shrinkWrap: true,
children: [
Padding(
Expand All @@ -168,16 +168,16 @@ class LocalNetworkPreference extends HookConsumerWidget {
style: context.textTheme.bodyMedium,
),
),
SizedBox(height: 4),
const SizedBox(height: 4),
Divider(
color: context.colorScheme.surfaceContainerHighest,
),
ListTile(
contentPadding: EdgeInsets.only(left: 24, right: 8),
leading: Icon(Icons.wifi_rounded),
title: Text("WiFi Name"),
contentPadding: const EdgeInsets.only(left: 24, right: 8),
leading: const Icon(Icons.wifi_rounded),
title: const Text("WiFi Name"),
subtitle: wifiNameText.value.isEmpty
? Text("enter-WiFi-name")
? const Text("enter-WiFi-name")
: Text(
wifiNameText.value,
style: context.textTheme.labelLarge?.copyWith(
Expand All @@ -188,15 +188,15 @@ class LocalNetworkPreference extends HookConsumerWidget {
),
trailing: IconButton(
onPressed: enabled ? handleEditWifiName : null,
icon: Icon(Icons.edit_rounded),
icon: const Icon(Icons.edit_rounded),
),
),
ListTile(
contentPadding: EdgeInsets.only(left: 24, right: 8),
leading: Icon(Icons.lan_rounded),
title: Text("Server Endpoint"),
contentPadding: const EdgeInsets.only(left: 24, right: 8),
leading: const Icon(Icons.lan_rounded),
title: const Text("Server Endpoint"),
subtitle: localEndpointText.value.isEmpty
? Text("http://local-ip:2283/api")
? const Text("http://local-ip:2283/api")
: Text(
localEndpointText.value,
style: context.textTheme.labelLarge?.copyWith(
Expand All @@ -207,19 +207,19 @@ class LocalNetworkPreference extends HookConsumerWidget {
),
trailing: IconButton(
onPressed: enabled ? handleEditServerEndpoint : null,
icon: Icon(Icons.edit_rounded),
icon: const Icon(Icons.edit_rounded),
),
),
SizedBox(height: 16),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 24.0,
),
child: SizedBox(
height: 48,
child: OutlinedButton.icon(
icon: Icon(Icons.wifi_find_rounded),
label: Text('USE CURRENT CONNECTION'),
icon: const Icon(Icons.wifi_find_rounded),
label: const Text('USE CURRENT CONNECTION'),
onPressed: enabled ? autofillCurrentNetwork : null,
),
),
Expand Down
Loading

0 comments on commit f780548

Please sign in to comment.