новости
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:moonwell_launcher/features/downloader/domain/entities/download_e
|
||||
import 'package:moonwell_launcher/features/downloader/domain/entities/download_progress.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/application/client_sync_use_case.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/data/game_installation_service.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/data/launcher_api_client.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/client_manifest.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/client_sync_status.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/launcher_exception.dart';
|
||||
@@ -21,11 +22,13 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
HomeScreenBloc({
|
||||
required ClientSyncUseCase clientSyncUseCase,
|
||||
required GameInstallationService gameInstallationService,
|
||||
required LauncherApiClient launcherApiClient,
|
||||
required PreferencesRepository preferencesRepository,
|
||||
required LauncherSession session,
|
||||
required ClientManifest manifest,
|
||||
}) : _clientSyncUseCase = clientSyncUseCase,
|
||||
_gameInstallationService = gameInstallationService,
|
||||
_launcherApiClient = launcherApiClient,
|
||||
_preferencesRepository = preferencesRepository,
|
||||
_session = session,
|
||||
_manifest = manifest,
|
||||
@@ -51,6 +54,7 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
|
||||
final ClientSyncUseCase _clientSyncUseCase;
|
||||
final GameInstallationService _gameInstallationService;
|
||||
final LauncherApiClient _launcherApiClient;
|
||||
final PreferencesRepository _preferencesRepository;
|
||||
|
||||
StreamSubscription<ClientSyncStatus>? _syncSubscription;
|
||||
@@ -79,6 +83,30 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final newsItems = await _launcherApiClient.fetchNews(
|
||||
_session.accessToken,
|
||||
);
|
||||
emit(
|
||||
HomeScreenState(
|
||||
model: state.model.copyWith(
|
||||
newsItems: newsItems,
|
||||
isLoadingNews: false,
|
||||
newsErrorMessage: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
emit(
|
||||
HomeScreenState(
|
||||
model: state.model.copyWith(
|
||||
isLoadingNews: false,
|
||||
newsErrorMessage: _formatError(error),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onHomeScreenSyncRequested(
|
||||
@@ -238,14 +266,16 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
phase: HomeScreenPhase.idle,
|
||||
isAuthenticated: false,
|
||||
progress: const DownloadProgress.initial(),
|
||||
statusText:
|
||||
'Сессия завершена. Войдите снова.',
|
||||
statusText: 'Сессия завершена. Войдите снова.',
|
||||
currentPath: null,
|
||||
errorMessage: null,
|
||||
localBuildHash: null,
|
||||
remoteBuildHash: null,
|
||||
processedFiles: 0,
|
||||
totalFiles: 0,
|
||||
newsItems: const [],
|
||||
isLoadingNews: false,
|
||||
newsErrorMessage: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:moonwell_launcher/features/downloader/domain/entities/download_progress.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/launcher_news_item.dart';
|
||||
|
||||
enum HomeScreenPhase {
|
||||
idle,
|
||||
@@ -27,6 +28,9 @@ final class HomeScreenModel {
|
||||
final String? remoteBuildHash;
|
||||
final int processedFiles;
|
||||
final int totalFiles;
|
||||
final List<LauncherNewsItem> newsItems;
|
||||
final bool isLoadingNews;
|
||||
final String? newsErrorMessage;
|
||||
|
||||
const HomeScreenModel({
|
||||
required this.progress,
|
||||
@@ -41,6 +45,9 @@ final class HomeScreenModel {
|
||||
required this.remoteBuildHash,
|
||||
required this.processedFiles,
|
||||
required this.totalFiles,
|
||||
required this.newsItems,
|
||||
required this.isLoadingNews,
|
||||
required this.newsErrorMessage,
|
||||
});
|
||||
|
||||
const HomeScreenModel.initial()
|
||||
@@ -55,7 +62,10 @@ final class HomeScreenModel {
|
||||
localBuildHash = null,
|
||||
remoteBuildHash = null,
|
||||
processedFiles = 0,
|
||||
totalFiles = 0;
|
||||
totalFiles = 0,
|
||||
newsItems = const <LauncherNewsItem>[],
|
||||
isLoadingNews = true,
|
||||
newsErrorMessage = null;
|
||||
|
||||
bool get isBusy =>
|
||||
phase == HomeScreenPhase.authenticating ||
|
||||
@@ -78,6 +88,9 @@ final class HomeScreenModel {
|
||||
Object? remoteBuildHash = _sentinel,
|
||||
int? processedFiles,
|
||||
int? totalFiles,
|
||||
List<LauncherNewsItem>? newsItems,
|
||||
bool? isLoadingNews,
|
||||
Object? newsErrorMessage = _sentinel,
|
||||
}) {
|
||||
return HomeScreenModel(
|
||||
progress: progress ?? this.progress,
|
||||
@@ -102,6 +115,11 @@ final class HomeScreenModel {
|
||||
: remoteBuildHash as String?,
|
||||
processedFiles: processedFiles ?? this.processedFiles,
|
||||
totalFiles: totalFiles ?? this.totalFiles,
|
||||
newsItems: newsItems ?? this.newsItems,
|
||||
isLoadingNews: isLoadingNews ?? this.isLoadingNews,
|
||||
newsErrorMessage: newsErrorMessage == _sentinel
|
||||
? this.newsErrorMessage
|
||||
: newsErrorMessage as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user