feat: appbar

This commit is contained in:
shenlong-tanwen
2024-10-27 23:43:58 +05:30
parent 5385d43c8c
commit 8450c8cc4f
40 changed files with 1150 additions and 211 deletions
@@ -0,0 +1,112 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:immich_mobile/domain/models/server-info/server_version.model.dart';
import 'package:immich_mobile/utils/extensions/string.extension.dart';
import 'package:package_info_plus/package_info_plus.dart';
class AppInfoProvider extends ValueNotifier<AppInfo> {
AppInfoProvider() : super(const AppInfo.initial()) {
unawaited(_getAppVersion());
}
Future<void> _getAppVersion() async {
final version = (await PackageInfo.fromPlatform()).version;
final segments = version.split(".");
final major = segments.firstOrNull ?? '1';
final minor = segments.elementAtOrNull(1) ?? '0';
final patch = segments.elementAtOrNull(2)?.replaceAll("-DEBUG", "") ?? '0';
value = value.copyWith(
versionString: version,
version: ServerVersion(
major: major.parseInt(),
minor: minor.parseInt(),
patch: patch.parseInt(),
),
);
}
void checkVersionMismatch(ServerVersion? serverVersion) {
if (serverVersion == null) {
value = value.copyWith(
isVersionMismatch: true,
versionMismatchError:
"common.components.appbar.server_version_common_error",
);
return;
}
String? errorMessage;
if (value.version.major != serverVersion.major) {
errorMessage = value.version.major > serverVersion.major
? "common.components.appbar.server_version_major_error"
: "common.components.appbar.app_version_major_error";
} else if (value.version.minor != serverVersion.minor) {
errorMessage = value.version.minor > serverVersion.minor
? "common.components.appbar.server_version_minor_error"
: "common.components.appbar.app_version_minor_error";
}
value = value.copyWith(
isVersionMismatch: errorMessage != null,
versionMismatchError: errorMessage ??
"common.components.appbar.server_version_common_error",
);
}
}
class AppInfo {
final String versionString;
final ServerVersion version;
final bool isVersionMismatch;
final String versionMismatchError;
const AppInfo({
required this.versionString,
required this.version,
required this.isVersionMismatch,
required this.versionMismatchError,
});
const AppInfo.initial()
: versionString = '1.0.0',
version = const ServerVersion.initial(),
isVersionMismatch = false,
versionMismatchError = '';
AppInfo copyWith({
String? versionString,
ServerVersion? version,
bool? isVersionMismatch,
String? versionMismatchError,
}) {
return AppInfo(
versionString: versionString ?? this.versionString,
version: version ?? this.version,
isVersionMismatch: isVersionMismatch ?? this.isVersionMismatch,
versionMismatchError: versionMismatchError ?? this.versionMismatchError,
);
}
@override
String toString() =>
'AppInfo(versionString: $versionString, isVersionMismatch: $isVersionMismatch, versionMismatchError: $versionMismatchError)';
@override
bool operator ==(covariant AppInfo other) {
if (identical(this, other)) return true;
return other.versionString == versionString &&
other.isVersionMismatch == isVersionMismatch &&
other.versionMismatchError == versionMismatchError;
}
@override
int get hashCode =>
versionString.hashCode ^
isVersionMismatch.hashCode ^
versionMismatchError.hashCode;
}
@@ -1,28 +0,0 @@
import 'package:flutter/foundation.dart';
import 'package:immich_mobile/domain/interfaces/api/server_api.interface.dart';
import 'package:immich_mobile/domain/models/server-info/server_feature_config.model.dart';
class ServerFeatureConfigProvider extends ValueNotifier<ServerFeatureConfig> {
final IServerApiRepository _serverApiRepository;
ServerFeatureConfigProvider({required IServerApiRepository serverApiRepo})
: _serverApiRepository = serverApiRepo,
super(const ServerFeatureConfig.initial());
Future<void> getFeatures() async =>
await Future.wait([_getFeatures(), _getConfig()]);
Future<void> _getFeatures() async {
final features = await _serverApiRepository.getServerFeatures();
if (features != null) {
value = value.copyWith(features: features);
}
}
Future<void> _getConfig() async {
final config = await _serverApiRepository.getServerConfig();
if (config != null) {
value = value.copyWith(config: config);
}
}
}
@@ -0,0 +1,45 @@
import 'package:flutter/foundation.dart';
import 'package:immich_mobile/domain/interfaces/api/server_api.interface.dart';
import 'package:immich_mobile/domain/models/server-info/server_info.model.dart';
import 'package:immich_mobile/presentation/states/app_info.state.dart';
import 'package:immich_mobile/service_locator.dart';
class ServerInfoProvider extends ValueNotifier<ServerInfo> {
final IServerApiRepository _serverApiRepository;
ServerInfoProvider({required IServerApiRepository serverApiRepo})
: _serverApiRepository = serverApiRepo,
super(const ServerInfo.initial());
Future<void> fetchFeatures() async =>
await Future.wait([_getFeatures(), _getConfig(), _getVersion()]);
Future<void> _getFeatures() async {
final features = await _serverApiRepository.getServerFeatures();
if (features != null) {
value = value.copyWith(features: features);
}
}
Future<void> _getConfig() async {
final config = await _serverApiRepository.getServerConfig();
if (config != null) {
value = value.copyWith(config: config);
}
}
Future<void> _getVersion() async {
final version = await _serverApiRepository.getServerVersion();
di<AppInfoProvider>().checkVersionMismatch(version);
if (version != null) {
value = value.copyWith(version: version);
}
}
Future<void> fetchServerDisk() async {
final disk = await _serverApiRepository.getServerDiskInfo();
if (disk != null) {
value = value.copyWith(disk: disk);
}
}
}