mirror of
https://github.com/immich-app/immich.git
synced 2024-12-28 22:51:59 +00:00
Clean code of shared folder (#249)
* optimize android side gradle settings * android minsdk back to 21 * remove unused package, update linter and fix lint error * clean code of 'shared module' with offical dart style guide * restore uploadProfileImage method in UserService
This commit is contained in:
parent
caaa474c23
commit
ef097d15dd
12 changed files with 100 additions and 103 deletions
|
@ -3,7 +3,7 @@ version: "3.8"
|
|||
services:
|
||||
immich-server:
|
||||
image: altran1502/immich-server:latest
|
||||
entrypoint: ["/bin/sh", "./start-server.sh"]
|
||||
entrypoint: [ "/bin/sh", "./start-server.sh" ]
|
||||
expose:
|
||||
- "3000"
|
||||
volumes:
|
||||
|
@ -21,7 +21,7 @@ services:
|
|||
|
||||
immich-microservices:
|
||||
image: altran1502/immich-server:latest
|
||||
entrypoint: ["/bin/sh", "./start-microservices.sh"]
|
||||
entrypoint: [ "/bin/sh", "./start-microservices.sh" ]
|
||||
volumes:
|
||||
- ${UPLOAD_LOCATION}:/usr/src/app/upload
|
||||
env_file:
|
||||
|
@ -37,7 +37,7 @@ services:
|
|||
|
||||
immich-machine-learning:
|
||||
image: altran1502/immich-machine-learning:latest
|
||||
entrypoint: ["/bin/sh", "./entrypoint.sh"]
|
||||
entrypoint: [ "/bin/sh", "./entrypoint.sh" ]
|
||||
expose:
|
||||
- "3001"
|
||||
volumes:
|
||||
|
@ -54,7 +54,7 @@ services:
|
|||
|
||||
immich-web:
|
||||
image: altran1502/immich-web:latest
|
||||
entrypoint: ["/bin/sh", "./entrypoint.sh"]
|
||||
entrypoint: [ "/bin/sh", "./entrypoint.sh" ]
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
|
|
|
@ -4,18 +4,19 @@ import 'package:hive_flutter/hive_flutter.dart';
|
|||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/constants/immich_colors.dart';
|
||||
import 'package:immich_mobile/modules/backup/models/hive_backup_albums.model.dart';
|
||||
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
||||
import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart';
|
||||
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
||||
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
||||
import 'package:immich_mobile/routing/router.dart';
|
||||
import 'package:immich_mobile/routing/tab_navigation_observer.dart';
|
||||
import 'package:immich_mobile/shared/providers/app_state.provider.dart';
|
||||
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
||||
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
||||
import 'package:immich_mobile/shared/providers/release_info.provider.dart';
|
||||
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
||||
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
||||
import 'package:immich_mobile/shared/views/immich_loading_overlay.dart';
|
||||
import 'package:immich_mobile/shared/views/version_announcement_overlay.dart';
|
||||
|
||||
import 'constants/hive_box.dart';
|
||||
|
||||
void main() async {
|
||||
|
@ -39,7 +40,7 @@ void main() async {
|
|||
}
|
||||
|
||||
class ImmichApp extends ConsumerStatefulWidget {
|
||||
const ImmichApp({Key? key}) : super(key: key);
|
||||
const ImmichApp({super.key});
|
||||
|
||||
@override
|
||||
ImmichAppState createState() => ImmichAppState();
|
||||
|
|
|
@ -33,12 +33,12 @@ class AssetNotifier extends StateNotifier<List<ImmichAsset>> {
|
|||
deleteAssets(Set<ImmichAsset> deleteAssets) async {
|
||||
var deviceInfo = await _deviceInfoService.getDeviceInfo();
|
||||
var deviceId = deviceInfo["deviceId"];
|
||||
List<String> deleteIdList = [];
|
||||
var deleteIdList = <String>[];
|
||||
// Delete asset from device
|
||||
for (var asset in deleteAssets) {
|
||||
// Delete asset on device if present
|
||||
if (asset.deviceId == deviceId) {
|
||||
AssetEntity? localAsset = await AssetEntity.fromId(asset.deviceAssetId);
|
||||
var localAsset = await AssetEntity.fromId(asset.deviceAssetId);
|
||||
|
||||
if (localAsset != null) {
|
||||
deleteIdList.add(localAsset.id);
|
||||
|
|
|
@ -15,7 +15,7 @@ class ReleaseInfoNotifier extends StateNotifier<String> {
|
|||
try {
|
||||
String? localReleaseVersion = box.get(githubReleaseInfoKey);
|
||||
|
||||
Response res = await dio.get(
|
||||
var res = await dio.get(
|
||||
"https://api.github.com/repos/alextran1502/immich/releases/latest",
|
||||
options: Options(
|
||||
headers: {"Accept": "application/vnd.github.v3+json"},
|
||||
|
|
|
@ -11,7 +11,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
|
|||
: super(
|
||||
ServerInfoState(
|
||||
mapboxInfo: MapboxInfo(isEnable: false, mapboxSecret: ""),
|
||||
serverVersion: ServerVersion(major: 0, patch: 0, minor: 0, build: 0),
|
||||
serverVersion:
|
||||
ServerVersion(major: 0, patch: 0, minor: 0, build: 0),
|
||||
isVersionMismatch: false,
|
||||
versionMismatchErrorMessage: "",
|
||||
),
|
||||
|
@ -33,7 +34,7 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
|
|||
|
||||
state = state.copyWith(serverVersion: serverVersion);
|
||||
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
var packageInfo = await PackageInfo.fromPlatform();
|
||||
|
||||
Map<String, int> appVersion = _getDetailVersion(packageInfo.version);
|
||||
|
||||
|
@ -57,7 +58,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
|
|||
return;
|
||||
}
|
||||
|
||||
state = state.copyWith(isVersionMismatch: false, versionMismatchErrorMessage: "");
|
||||
state = state.copyWith(
|
||||
isVersionMismatch: false, versionMismatchErrorMessage: "");
|
||||
}
|
||||
|
||||
Map<String, int> _getDetailVersion(String version) {
|
||||
|
@ -75,6 +77,7 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
|
|||
}
|
||||
}
|
||||
|
||||
final serverInfoProvider = StateNotifierProvider<ServerInfoNotifier, ServerInfoState>((ref) {
|
||||
final serverInfoProvider =
|
||||
StateNotifierProvider<ServerInfoNotifier, ServerInfoState>((ref) {
|
||||
return ServerInfoNotifier();
|
||||
});
|
||||
|
|
|
@ -4,8 +4,8 @@ import 'dart:io' show Platform;
|
|||
class DeviceInfoService {
|
||||
Future<Map<String, dynamic>> getDeviceInfo() async {
|
||||
// Get device info
|
||||
String deviceId = await FlutterUdid.consistentUdid;
|
||||
String deviceType = "";
|
||||
var deviceId = await FlutterUdid.consistentUdid;
|
||||
var deviceType = "";
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
deviceType = "ANDROID";
|
||||
|
|
|
@ -4,15 +4,22 @@ import 'dart:convert';
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:immich_mobile/constants/hive_box.dart';
|
||||
import 'package:immich_mobile/utils/dio_http_interceptor.dart';
|
||||
import 'package:immich_mobile/utils/files_helper.dart';
|
||||
|
||||
class NetworkService {
|
||||
late final Dio dio;
|
||||
|
||||
NetworkService() {
|
||||
dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
}
|
||||
|
||||
Future<dynamic> deleteRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
Response res = await dio.delete('$savedEndpoint/$url', data: data);
|
||||
|
||||
|
@ -26,11 +33,11 @@ class NetworkService {
|
|||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getRequest({required String url, bool isByteResponse = false, bool isStreamReponse = false}) async {
|
||||
Future<dynamic> getRequest(
|
||||
{required String url,
|
||||
bool isByteResponse = false,
|
||||
bool isStreamReponse = false}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
|
||||
if (isByteResponse) {
|
||||
|
@ -66,12 +73,9 @@ class NetworkService {
|
|||
|
||||
Future<dynamic> postRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
String validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
Response res = await dio.post(validUrl, data: data);
|
||||
var validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
var res = await dio.post(validUrl, data: data);
|
||||
|
||||
return res;
|
||||
} on DioError catch (e) {
|
||||
|
@ -85,12 +89,9 @@ class NetworkService {
|
|||
|
||||
Future<dynamic> putRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
String validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
Response res = await dio.put(validUrl, data: data);
|
||||
var validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
var res = await dio.put(validUrl, data: data);
|
||||
|
||||
return res;
|
||||
} on DioError catch (e) {
|
||||
|
@ -104,13 +105,9 @@ class NetworkService {
|
|||
|
||||
Future<dynamic> patchRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
|
||||
String validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
Response res = await dio.patch(validUrl, data: data);
|
||||
var validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
var res = await dio.patch(validUrl, data: data);
|
||||
|
||||
return res;
|
||||
} on DioError catch (e) {
|
||||
|
@ -122,21 +119,15 @@ class NetworkService {
|
|||
|
||||
Future<bool> pingServer() async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
|
||||
String validUrl = Uri.parse('$savedEndpoint/server-info/ping').toString();
|
||||
var validUrl = Uri.parse('$savedEndpoint/server-info/ping').toString();
|
||||
|
||||
debugPrint("ping server at url $validUrl");
|
||||
Response res = await dio.get(validUrl);
|
||||
|
||||
var res = await dio.get(validUrl);
|
||||
var jsonRespsonse = jsonDecode(res.toString());
|
||||
|
||||
if (jsonRespsonse["res"] == "pong") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return jsonRespsonse["res"] == "pong";
|
||||
} on DioError catch (e) {
|
||||
debugPrint("[PING SERVER] DioError: ${e.response} - $e");
|
||||
return false;
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:convert';
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:immich_mobile/constants/hive_box.dart';
|
||||
import 'package:immich_mobile/shared/models/upload_profile_image_repsonse.model.dart';
|
||||
|
@ -10,14 +11,13 @@ import 'package:immich_mobile/shared/models/user.model.dart';
|
|||
import 'package:immich_mobile/shared/services/network.service.dart';
|
||||
import 'package:immich_mobile/utils/dio_http_interceptor.dart';
|
||||
import 'package:immich_mobile/utils/files_helper.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
class UserService {
|
||||
final NetworkService _networkService = NetworkService();
|
||||
|
||||
Future<List<User>> getAllUsersInfo() async {
|
||||
try {
|
||||
Response res = await _networkService.getRequest(url: 'user');
|
||||
var res = await _networkService.getRequest(url: 'user');
|
||||
List<dynamic> decodedData = jsonDecode(res.toString());
|
||||
List<User> result = List.from(decodedData.map((e) => User.fromMap(e)));
|
||||
|
||||
|
|
|
@ -10,12 +10,10 @@ class ImmichToast {
|
|||
ToastType toastType = ToastType.info,
|
||||
ToastGravity gravity = ToastGravity.TOP,
|
||||
}) {
|
||||
FToast fToast;
|
||||
|
||||
fToast = FToast();
|
||||
final fToast = FToast();
|
||||
fToast.init(context);
|
||||
|
||||
_getColor(ToastType type, BuildContext context) {
|
||||
Color _getColor(ToastType type, BuildContext context) {
|
||||
switch (type) {
|
||||
case ToastType.info:
|
||||
return Theme.of(context).primaryColor;
|
||||
|
@ -26,6 +24,26 @@ class ImmichToast {
|
|||
}
|
||||
}
|
||||
|
||||
Icon _getIcon(ToastType type) {
|
||||
switch (type) {
|
||||
case ToastType.info:
|
||||
return Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: Theme.of(context).primaryColor,
|
||||
);
|
||||
case ToastType.success:
|
||||
return const Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: Color.fromARGB(255, 78, 140, 124),
|
||||
);
|
||||
case ToastType.error:
|
||||
return const Icon(
|
||||
Icons.error_outline_rounded,
|
||||
color: Color.fromARGB(255, 240, 162, 156),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fToast.showToast(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
|
||||
|
@ -40,24 +58,7 @@ class ImmichToast {
|
|||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
(toastType == ToastType.info)
|
||||
? Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: Theme.of(context).primaryColor,
|
||||
)
|
||||
: Container(),
|
||||
(toastType == ToastType.success)
|
||||
? const Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: Color.fromARGB(255, 78, 140, 124),
|
||||
)
|
||||
: Container(),
|
||||
(toastType == ToastType.error)
|
||||
? const Icon(
|
||||
Icons.error_outline_rounded,
|
||||
color: Color.fromARGB(255, 240, 162, 156),
|
||||
)
|
||||
: Container(),
|
||||
_getIcon(toastType),
|
||||
const SizedBox(
|
||||
width: 12.0,
|
||||
),
|
||||
|
|
|
@ -9,25 +9,25 @@ class ImmichLoadingOverlay extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: ImmichLoadingOverlayController.appLoader.loaderShowingNotifier,
|
||||
valueListenable:
|
||||
ImmichLoadingOverlayController.appLoader.loaderShowingNotifier,
|
||||
builder: (context, shouldShow, child) {
|
||||
if (shouldShow) {
|
||||
return const Scaffold(
|
||||
backgroundColor: Colors.black54,
|
||||
body: Center(
|
||||
child: ImmichLoadingIndicator(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
return shouldShow
|
||||
? const Scaffold(
|
||||
backgroundColor: Colors.black54,
|
||||
body: Center(
|
||||
child: ImmichLoadingIndicator(),
|
||||
),
|
||||
)
|
||||
: const SizedBox();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ImmichLoadingOverlayController {
|
||||
static final ImmichLoadingOverlayController appLoader = ImmichLoadingOverlayController();
|
||||
static final ImmichLoadingOverlayController appLoader =
|
||||
ImmichLoadingOverlayController();
|
||||
ValueNotifier<bool> loaderShowingNotifier = ValueNotifier(false);
|
||||
ValueNotifier<String> loaderTextNotifier = ValueNotifier('error message');
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class VersionAnnouncementOverlay extends HookConsumerWidget {
|
|||
const TextSpan(
|
||||
text:
|
||||
" and ensure your docker-compose and .env setup is up-to-date to prevent any misconfigurations, especially if you use WatchTower or any mechanism that handles updating your server application automatically.",
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -93,23 +93,24 @@ class VersionAnnouncementOverlay extends HookConsumerWidget {
|
|||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16.0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: const StadiumBorder(),
|
||||
visualDensity: VisualDensity.standard,
|
||||
primary: Colors.indigo,
|
||||
onPrimary: Colors.grey[50],
|
||||
elevation: 2,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10, horizontal: 25),
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: const StadiumBorder(),
|
||||
visualDensity: VisualDensity.standard,
|
||||
primary: Colors.indigo,
|
||||
onPrimary: Colors.grey[50],
|
||||
elevation: 2,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10, horizontal: 25),
|
||||
),
|
||||
onPressed: onAcknowledgeTapped,
|
||||
child: const Text(
|
||||
"Acknowledge",
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
onPressed: onAcknowledgeTapped,
|
||||
child: const Text(
|
||||
"Acknowledge",
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
)),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -5,7 +5,7 @@ publish_to: "none"
|
|||
version: 1.12.1+19
|
||||
|
||||
environment:
|
||||
sdk: ">=2.15.1 <3.0.0"
|
||||
sdk: ">=2.17.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
|
Loading…
Reference in a new issue