More work on inbox, refactorings (bloc separation of concerns), fixed saved views wrong sort order

This commit is contained in:
Anton Stubenbord
2022-11-29 01:09:36 +01:00
parent 5edbdabf26
commit 50190f035e
43 changed files with 605 additions and 463 deletions

View File

@@ -1,62 +0,0 @@
import 'dart:math';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import 'package:paperless_mobile/core/model/paperless_statistics.dart';
import 'package:paperless_mobile/core/model/paperless_statistics_state.dart';
import 'package:paperless_mobile/core/service/paperless_statistics_service.dart';
@singleton
class PaperlessStatisticsCubit extends Cubit<PaperlessStatisticsState> {
final PaperlessStatisticsService statisticsService;
PaperlessStatisticsCubit(this.statisticsService)
: super(PaperlessStatisticsState(isLoaded: false));
Future<void> updateStatistics() async {
final stats = await statisticsService.getStatistics();
emit(PaperlessStatisticsState(isLoaded: true, statistics: stats));
}
void decrementInboxCount() {
if (state.isLoaded) {
emit(
PaperlessStatisticsState(
isLoaded: true,
statistics: PaperlessStatistics(
documentsInInbox: max(0, state.statistics!.documentsInInbox - 1),
documentsTotal: state.statistics!.documentsTotal,
),
),
);
}
}
void incrementInboxCount() {
if (state.isLoaded) {
emit(
PaperlessStatisticsState(
isLoaded: true,
statistics: PaperlessStatistics(
documentsInInbox: state.statistics!.documentsInInbox + 1,
documentsTotal: state.statistics!.documentsTotal,
),
),
);
}
}
void resetInboxCount() {
if (state.isLoaded) {
emit(
PaperlessStatisticsState(
isLoaded: true,
statistics: PaperlessStatistics(
documentsInInbox: 0,
documentsTotal: state.statistics!.documentsTotal,
),
),
);
}
}
}