From c7e91011a660dd5b0551694e46a3d3f300d1af68 Mon Sep 17 00:00:00 2001 From: Aidaiym Date: Mon, 11 Mar 2024 23:00:27 -0700 Subject: [PATCH] finish changing read module architecture --- app/lib/modules/home/data/data.dart | 2 +- ...ository.dart => home_repository_impl.dart} | 6 +-- app/lib/modules/home/domain/domain.dart | 2 +- .../{home_model.dart => home_entity.dart} | 4 +- .../domain/repository/home_repository.dart | 2 +- .../home/domain/usecase/get_data_usecase.dart | 2 +- .../home/presentation/cubit/home_state.dart | 2 +- app/lib/modules/read/data/data.dart | 9 +++- .../read/data/model/filters_response.dart | 16 ++++++ .../model/filters_response.g.dart} | 6 +-- .../read/data/model/meta_response.dart | 16 ++++++ .../model/meta_response.g.dart} | 8 +-- .../read/data/model/quran_page_response.dart | 20 ++++++++ ...page.g.dart => quran_page_response.g.dart} | 10 ++-- .../read/data/model/verse_response.dart | 23 +++++++++ .../model/verse_response.g.dart} | 6 +-- .../data/repository/read_repository_impl.dart | 50 ++++++++++++------- .../read_theme_repository_impl.dart | 15 +++--- .../data/source/local_theme_data_source.dart | 10 ++-- .../data/source/read_local_data_source.dart | 11 ++-- .../data/source/read_remote_data_source.dart | 10 ++-- app/lib/modules/read/data/source/source.dart | 3 -- app/lib/modules/read/domain/domain.dart | 9 +++- .../modules/read/domain/entity/entity.dart | 3 -- .../modules/read/domain/entity/filters.dart | 16 ------ .../read/domain/entity/filters_entity.dart | 8 +++ app/lib/modules/read/domain/entity/meta.dart | 16 ------ .../read/domain/entity/meta_entity.dart | 9 ++++ .../entity/quran_page_entity.dart} | 20 +++----- app/lib/modules/read/domain/entity/verse.dart | 25 ---------- .../read/domain/entity/verse_entity.dart | 20 ++++++++ .../domain/repository/read_repository.dart | 2 +- .../repository/read_theme_repository.dart | 3 +- .../usecase/get_initial_theme_usecase.dart | 9 ++-- .../read/domain/usecase/get_read_page.dart | 6 ++- .../usecase/save_theme_changes_usecase.dart | 5 +- .../modules/read/domain/usecase/usecase.dart | 3 -- .../{logic => cubit}/read_cubit.dart | 3 +- .../{logic => cubit}/read_state.dart | 3 +- .../{logic => cubit}/read_theme_cubit.dart | 12 +++-- .../{logic => cubit}/read_theme_state.dart | 3 +- .../read/presentation/presentation.dart | 4 +- .../presentation/view/pagination_view.dart | 9 ++-- .../read/presentation/view/read_view.dart | 14 +++--- app/test/widget_test.dart | 4 +- 45 files changed, 263 insertions(+), 176 deletions(-) rename app/lib/modules/home/data/repository/{home_repository.dart => home_repository_impl.dart} (85%) rename app/lib/modules/home/domain/entity/{home_model.dart => home_entity.dart} (81%) create mode 100644 app/lib/modules/read/data/model/filters_response.dart rename app/lib/modules/read/{domain/entity/filters.g.dart => data/model/filters_response.g.dart} (60%) create mode 100644 app/lib/modules/read/data/model/meta_response.dart rename app/lib/modules/read/{domain/entity/meta.g.dart => data/model/meta_response.g.dart} (50%) create mode 100644 app/lib/modules/read/data/model/quran_page_response.dart rename app/lib/modules/read/data/model/{quran_page.g.dart => quran_page_response.g.dart} (50%) create mode 100644 app/lib/modules/read/data/model/verse_response.dart rename app/lib/modules/read/{domain/entity/verse.g.dart => data/model/verse_response.g.dart} (70%) delete mode 100644 app/lib/modules/read/data/source/source.dart delete mode 100644 app/lib/modules/read/domain/entity/entity.dart delete mode 100644 app/lib/modules/read/domain/entity/filters.dart create mode 100644 app/lib/modules/read/domain/entity/filters_entity.dart delete mode 100644 app/lib/modules/read/domain/entity/meta.dart create mode 100644 app/lib/modules/read/domain/entity/meta_entity.dart rename app/lib/modules/read/{data/model/quran_page.dart => domain/entity/quran_page_entity.dart} (69%) delete mode 100644 app/lib/modules/read/domain/entity/verse.dart create mode 100644 app/lib/modules/read/domain/entity/verse_entity.dart delete mode 100644 app/lib/modules/read/domain/usecase/usecase.dart rename app/lib/modules/read/presentation/{logic => cubit}/read_cubit.dart (80%) rename app/lib/modules/read/presentation/{logic => cubit}/read_state.dart (84%) rename app/lib/modules/read/presentation/{logic => cubit}/read_theme_cubit.dart (75%) rename app/lib/modules/read/presentation/{logic => cubit}/read_theme_state.dart (96%) diff --git a/app/lib/modules/home/data/data.dart b/app/lib/modules/home/data/data.dart index a71521b2..5252bc35 100644 --- a/app/lib/modules/home/data/data.dart +++ b/app/lib/modules/home/data/data.dart @@ -1,4 +1,4 @@ export 'model/home_model_response.dart'; -export 'repository/home_repository.dart'; +export 'repository/home_repository_impl.dart'; export 'source/home_local_data_source.dart'; export 'source/home_remote_data_source.dart'; diff --git a/app/lib/modules/home/data/repository/home_repository.dart b/app/lib/modules/home/data/repository/home_repository_impl.dart similarity index 85% rename from app/lib/modules/home/data/repository/home_repository.dart rename to app/lib/modules/home/data/repository/home_repository_impl.dart index 582acbae..462e85ed 100644 --- a/app/lib/modules/home/data/repository/home_repository.dart +++ b/app/lib/modules/home/data/repository/home_repository_impl.dart @@ -12,7 +12,7 @@ class HomeRepositoryImpl implements HomeRepository { final HomeRemoteDataSource remoteDataSource; @override - Future getData(String token) async { + Future getData(String token) async { try { final remoteData = await remoteDataSource.getRemoteData(token); await localDataSource.saveLocalData(remoteData); @@ -23,8 +23,8 @@ class HomeRepositoryImpl implements HomeRepository { } } - HomeModel _convertData(HomeModelResponse response) { - return HomeModel( + HomeEntity _convertData(HomeModelResponse response) { + return HomeEntity( allDoneHatims: response.allDoneHatims, allDonePages: response.allDonePages, donePages: response.donePages, diff --git a/app/lib/modules/home/domain/domain.dart b/app/lib/modules/home/domain/domain.dart index 41284c56..9ea3a746 100644 --- a/app/lib/modules/home/domain/domain.dart +++ b/app/lib/modules/home/domain/domain.dart @@ -1,3 +1,3 @@ -export 'entity/home_model.dart'; +export 'entity/home_entity.dart'; export 'repository/home_repository.dart'; export 'usecase/get_data_usecase.dart'; diff --git a/app/lib/modules/home/domain/entity/home_model.dart b/app/lib/modules/home/domain/entity/home_entity.dart similarity index 81% rename from app/lib/modules/home/domain/entity/home_model.dart rename to app/lib/modules/home/domain/entity/home_entity.dart index 1fbac626..1082155f 100644 --- a/app/lib/modules/home/domain/entity/home_model.dart +++ b/app/lib/modules/home/domain/entity/home_entity.dart @@ -1,5 +1,5 @@ -class HomeModel { - const HomeModel({ +class HomeEntity { + const HomeEntity({ required this.allDoneHatims, required this.allDonePages, required this.donePages, diff --git a/app/lib/modules/home/domain/repository/home_repository.dart b/app/lib/modules/home/domain/repository/home_repository.dart index c9792f31..05ba36f0 100644 --- a/app/lib/modules/home/domain/repository/home_repository.dart +++ b/app/lib/modules/home/domain/repository/home_repository.dart @@ -1,5 +1,5 @@ import 'package:my_quran/modules/modules.dart'; abstract class HomeRepository { - Future getData(String token); + Future getData(String token); } diff --git a/app/lib/modules/home/domain/usecase/get_data_usecase.dart b/app/lib/modules/home/domain/usecase/get_data_usecase.dart index d0ce703f..b12bb4d8 100644 --- a/app/lib/modules/home/domain/usecase/get_data_usecase.dart +++ b/app/lib/modules/home/domain/usecase/get_data_usecase.dart @@ -5,7 +5,7 @@ class GetHomeDataUseCase { final HomeRepository repository; - Future execute(String token) { + Future execute(String token) { return repository.getData(token); } } diff --git a/app/lib/modules/home/presentation/cubit/home_state.dart b/app/lib/modules/home/presentation/cubit/home_state.dart index 4a26b219..5da04e45 100644 --- a/app/lib/modules/home/presentation/cubit/home_state.dart +++ b/app/lib/modules/home/presentation/cubit/home_state.dart @@ -6,7 +6,7 @@ class HomeState extends Equatable { this.homeModel, }); - final HomeModel? homeModel; + final HomeEntity? homeModel; final FetchStatus status; @override diff --git a/app/lib/modules/read/data/data.dart b/app/lib/modules/read/data/data.dart index 2bf8e1eb..edec7ecf 100644 --- a/app/lib/modules/read/data/data.dart +++ b/app/lib/modules/read/data/data.dart @@ -1,4 +1,9 @@ export 'repository/read_repository_impl.dart'; export 'repository/read_theme_repository_impl.dart'; -export 'source/source.dart'; -export 'model/quran_page.dart'; +export 'source/local_theme_data_source.dart'; +export 'source/read_local_data_source.dart'; +export 'source/read_remote_data_source.dart'; +export 'model/filters_response.dart'; +export 'model/meta_response.dart'; +export 'model/quran_page_response.dart'; +export 'model/verse_response.dart'; diff --git a/app/lib/modules/read/data/model/filters_response.dart b/app/lib/modules/read/data/model/filters_response.dart new file mode 100644 index 00000000..b05b8d1b --- /dev/null +++ b/app/lib/modules/read/data/model/filters_response.dart @@ -0,0 +1,16 @@ +import 'package:meta/meta.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'filters_response.g.dart'; + +@immutable +@JsonSerializable() +final class FiltersResponse { + const FiltersResponse({required this.pageNumber}); + + factory FiltersResponse.fromJson(Map json) => _$FiltersResponseFromJson(json); + Map toJson() => _$FiltersResponseToJson(this); + + @JsonKey(name: 'page_number') + final String pageNumber; +} diff --git a/app/lib/modules/read/domain/entity/filters.g.dart b/app/lib/modules/read/data/model/filters_response.g.dart similarity index 60% rename from app/lib/modules/read/domain/entity/filters.g.dart rename to app/lib/modules/read/data/model/filters_response.g.dart index cc64753c..b72780ff 100644 --- a/app/lib/modules/read/domain/entity/filters.g.dart +++ b/app/lib/modules/read/data/model/filters_response.g.dart @@ -1,15 +1,15 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'filters.dart'; +part of 'filters_response.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -Filters _$FiltersFromJson(Map json) => Filters( +FiltersResponse _$FiltersResponseFromJson(Map json) => FiltersResponse( pageNumber: json['page_number'] as String, ); -Map _$FiltersToJson(Filters instance) => { +Map _$FiltersResponseToJson(FiltersResponse instance) => { 'page_number': instance.pageNumber, }; diff --git a/app/lib/modules/read/data/model/meta_response.dart b/app/lib/modules/read/data/model/meta_response.dart new file mode 100644 index 00000000..74c1eba4 --- /dev/null +++ b/app/lib/modules/read/data/model/meta_response.dart @@ -0,0 +1,16 @@ +import 'package:meta/meta.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:my_quran/modules/modules.dart'; + +part 'meta_response.g.dart'; + +@immutable +@JsonSerializable() +final class MetaResponse { + const MetaResponse({required this.filters}); + + factory MetaResponse.fromJson(Map json) => _$MetaResponseFromJson(json); + Map toJson() => _$MetaResponseToJson(this); + + final FiltersResponse filters; +} diff --git a/app/lib/modules/read/domain/entity/meta.g.dart b/app/lib/modules/read/data/model/meta_response.g.dart similarity index 50% rename from app/lib/modules/read/domain/entity/meta.g.dart rename to app/lib/modules/read/data/model/meta_response.g.dart index 89d2fd5a..a0e90b45 100644 --- a/app/lib/modules/read/domain/entity/meta.g.dart +++ b/app/lib/modules/read/data/model/meta_response.g.dart @@ -1,15 +1,15 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'meta.dart'; +part of 'meta_response.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -Meta _$MetaFromJson(Map json) => Meta( - filters: Filters.fromJson(json['filters'] as Map), +MetaResponse _$MetaResponseFromJson(Map json) => MetaResponse( + filters: FiltersResponse.fromJson(json['filters'] as Map), ); -Map _$MetaToJson(Meta instance) => { +Map _$MetaResponseToJson(MetaResponse instance) => { 'filters': instance.filters, }; diff --git a/app/lib/modules/read/data/model/quran_page_response.dart b/app/lib/modules/read/data/model/quran_page_response.dart new file mode 100644 index 00000000..190a0a93 --- /dev/null +++ b/app/lib/modules/read/data/model/quran_page_response.dart @@ -0,0 +1,20 @@ +import 'package:meta/meta.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:my_quran/modules/modules.dart'; + +part 'quran_page_response.g.dart'; + +@immutable +@JsonSerializable() +final class QuranPageResponse { + const QuranPageResponse({ + required this.verses, + required this.meta, + }); + + factory QuranPageResponse.fromJson(Map json) => _$QuranPageResponseFromJson(json); + Map toJson() => _$QuranPageResponseToJson(this); + + final List verses; + final MetaResponse meta; +} diff --git a/app/lib/modules/read/data/model/quran_page.g.dart b/app/lib/modules/read/data/model/quran_page_response.g.dart similarity index 50% rename from app/lib/modules/read/data/model/quran_page.g.dart rename to app/lib/modules/read/data/model/quran_page_response.g.dart index 90d566e4..76391f60 100644 --- a/app/lib/modules/read/data/model/quran_page.g.dart +++ b/app/lib/modules/read/data/model/quran_page_response.g.dart @@ -1,17 +1,17 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'quran_page.dart'; +part of 'quran_page_response.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -QuranPage _$QuranPageFromJson(Map json) => QuranPage( - verses: (json['verses'] as List).map((e) => Verse.fromJson(e as Map)).toList(), - meta: Meta.fromJson(json['meta'] as Map), +QuranPageResponse _$QuranPageResponseFromJson(Map json) => QuranPageResponse( + verses: (json['verses'] as List).map((e) => VerseResponse.fromJson(e as Map)).toList(), + meta: MetaResponse.fromJson(json['meta'] as Map), ); -Map _$QuranPageToJson(QuranPage instance) => { +Map _$QuranPageResponseToJson(QuranPageResponse instance) => { 'verses': instance.verses, 'meta': instance.meta, }; diff --git a/app/lib/modules/read/data/model/verse_response.dart b/app/lib/modules/read/data/model/verse_response.dart new file mode 100644 index 00000000..dd43707c --- /dev/null +++ b/app/lib/modules/read/data/model/verse_response.dart @@ -0,0 +1,23 @@ +import 'package:meta/meta.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'verse_response.g.dart'; + +@immutable +@JsonSerializable() +final class VerseResponse { + const VerseResponse({ + required this.id, + required this.verseKey, + required this.textUthmani, + }); + + factory VerseResponse.fromJson(Map json) => _$VerseResponseFromJson(json); + Map toJson() => _$VerseResponseToJson(this); + + final int id; + @JsonKey(name: 'verse_key') + final String verseKey; + @JsonKey(name: 'text_imlaei') + final String textUthmani; +} diff --git a/app/lib/modules/read/domain/entity/verse.g.dart b/app/lib/modules/read/data/model/verse_response.g.dart similarity index 70% rename from app/lib/modules/read/domain/entity/verse.g.dart rename to app/lib/modules/read/data/model/verse_response.g.dart index 2a7c18a9..3687791f 100644 --- a/app/lib/modules/read/domain/entity/verse.g.dart +++ b/app/lib/modules/read/data/model/verse_response.g.dart @@ -1,18 +1,18 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'verse.dart'; +part of 'verse_response.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -Verse _$VerseFromJson(Map json) => Verse( +VerseResponse _$VerseResponseFromJson(Map json) => VerseResponse( id: json['id'] as int, verseKey: json['verse_key'] as String, textUthmani: json['text_imlaei'] as String, ); -Map _$VerseToJson(Verse instance) => { +Map _$VerseResponseToJson(VerseResponse instance) => { 'id': instance.id, 'verse_key': instance.verseKey, 'text_imlaei': instance.textUthmani, diff --git a/app/lib/modules/read/data/repository/read_repository_impl.dart b/app/lib/modules/read/data/repository/read_repository_impl.dart index a253bf45..2319f12f 100644 --- a/app/lib/modules/read/data/repository/read_repository_impl.dart +++ b/app/lib/modules/read/data/repository/read_repository_impl.dart @@ -1,28 +1,42 @@ -import 'dart:developer'; - +import 'package:meta/meta.dart'; import 'package:my_quran/modules/modules.dart'; -class ReadRepositoryImpl implements ReadRepository { - const ReadRepositoryImpl(this.remoteDataSource, this.localDataSource); +@immutable +final class ReadRepositoryImpl implements ReadRepository { + const ReadRepositoryImpl( + this.remoteDataSource, + this.localDataSource, + ); final ReadRemoteDataSource remoteDataSource; final ReadLocalDataSource localDataSource; @override - Future getPage(int page, String quranFmt) async { - try { - final localPage = await localDataSource.getPage(page, quranFmt); - final remotePage = await remoteDataSource.fetchPage(page, quranFmt); - if (remotePage != null) { - await localDataSource.cachePage(page, quranFmt, remotePage); - return remotePage; - } - if (localPage != null) { - return localPage; - } - } catch (e) { - log('Error fetching page locally and remotely: $e'); + Future getPage(int page, String quranFmt) async { + final cachedData = localDataSource.getPage(page, quranFmt); + if (cachedData != null) return _convertData(cachedData); + + final data = await remoteDataSource.fetchPage(page, quranFmt); + if (data != null) { + await localDataSource.cachePage(page, quranFmt, data); + return _convertData(data); + } else { + return null; } - return null; + } + + QuranPageEntity _convertData(QuranPageResponse response) { + return QuranPageEntity( + meta: MetaEntity(FiltersEnity(response.meta.filters.pageNumber)), + verses: response.verses + .map( + (e) => VerseEnity( + id: e.id, + verseKey: e.verseKey, + textUthmani: e.textUthmani, + ), + ) + .toList(), + ); } } diff --git a/app/lib/modules/read/data/repository/read_theme_repository_impl.dart b/app/lib/modules/read/data/repository/read_theme_repository_impl.dart index 137a9169..a7aa813f 100644 --- a/app/lib/modules/read/data/repository/read_theme_repository_impl.dart +++ b/app/lib/modules/read/data/repository/read_theme_repository_impl.dart @@ -1,16 +1,19 @@ +import 'package:meta/meta.dart'; import 'package:my_quran/modules/modules.dart'; -class ReadThemeRepositoryImpl implements ReadThemeRepository { - const ReadThemeRepositoryImpl({required this.localDataSource}); - final LocalThemeDataSource localDataSource; +@immutable +final class ReadThemeRepositoryImpl implements ReadThemeRepository { + const ReadThemeRepositoryImpl(this.localThemeDataSource); + + final LocalThemeDataSource localThemeDataSource; @override - Future getInitialThemeState() async { - return localDataSource.getInitialThemeState(); + ReadThemeState get getInitialThemeState { + return localThemeDataSource.initialTheme; } @override Future saveThemeState(ReadThemeState themeState) async { - return localDataSource.saveThemeState(themeState); + return localThemeDataSource.saveThemeState(themeState); } } diff --git a/app/lib/modules/read/data/source/local_theme_data_source.dart b/app/lib/modules/read/data/source/local_theme_data_source.dart index a376e6ae..ea1c80b7 100644 --- a/app/lib/modules/read/data/source/local_theme_data_source.dart +++ b/app/lib/modules/read/data/source/local_theme_data_source.dart @@ -1,14 +1,16 @@ -import 'package:my_quran/constants/contants.dart'; -import 'package:my_quran/modules/modules.dart'; import 'dart:convert'; +import 'package:meta/meta.dart'; import 'package:mq_storage/mq_storage.dart'; +import 'package:my_quran/constants/contants.dart'; +import 'package:my_quran/modules/modules.dart'; -class LocalThemeDataSource { +@immutable +final class LocalThemeDataSource { const LocalThemeDataSource(this.storage); final PreferencesStorage storage; - ReadThemeState getInitialThemeState() { + ReadThemeState get initialTheme { final value = storage.readString(key: AppConst.readThemeKey); return value != null ? ReadThemeState.fromJson(json.decode(value) as Map) : const ReadThemeState(); } diff --git a/app/lib/modules/read/data/source/read_local_data_source.dart b/app/lib/modules/read/data/source/read_local_data_source.dart index 10e8ea06..19026474 100644 --- a/app/lib/modules/read/data/source/read_local_data_source.dart +++ b/app/lib/modules/read/data/source/read_local_data_source.dart @@ -1,25 +1,26 @@ import 'dart:convert'; - +import 'package:meta/meta.dart'; import 'package:mq_storage/mq_storage.dart'; import 'package:my_quran/modules/modules.dart'; -class ReadLocalDataSource { +@immutable +final class ReadLocalDataSource { const ReadLocalDataSource(this.storage); final PreferencesStorage storage; - Future getPage(int page, String quranFmt) async { + QuranPageResponse? getPage(int page, String quranFmt) { final key = 'quran-$quranFmt-$page'; final localValue = storage.readString(key: key); if (localValue != null) { final data = jsonDecode(localValue); - return QuranPage.fromJson(data as Map); + return QuranPageResponse.fromJson(data as Map); } return null; } - Future cachePage(int page, String quranFmt, QuranPage pageData) async { + Future cachePage(int page, String quranFmt, QuranPageResponse pageData) async { final key = 'quran-$quranFmt-$page'; await storage.writeString(key: key, value: jsonEncode(pageData.toJson())); } diff --git a/app/lib/modules/read/data/source/read_remote_data_source.dart b/app/lib/modules/read/data/source/read_remote_data_source.dart index 36e0912a..b0243d7d 100644 --- a/app/lib/modules/read/data/source/read_remote_data_source.dart +++ b/app/lib/modules/read/data/source/read_remote_data_source.dart @@ -1,16 +1,18 @@ +import 'package:meta/meta.dart'; import 'package:my_quran/config/config.dart'; import 'package:my_quran/core/core.dart'; import 'package:my_quran/modules/modules.dart'; -class ReadRemoteDataSource { +@immutable +final class ReadRemoteDataSource { const ReadRemoteDataSource(this.remoteClient); final RemoteClient remoteClient; - Future fetchPage(int page, String quranFmt) async { - final remoteValue = await remoteClient.get( + Future fetchPage(int page, String quranFmt) async { + final remoteValue = await remoteClient.get( apiConst.verse(page, quranFmt), - fromJson: QuranPage.fromJson, + fromJson: QuranPageResponse.fromJson, ); return remoteValue.fold( diff --git a/app/lib/modules/read/data/source/source.dart b/app/lib/modules/read/data/source/source.dart deleted file mode 100644 index 9a7cb583..00000000 --- a/app/lib/modules/read/data/source/source.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'read_local_data_source.dart'; -export 'read_remote_data_source.dart'; -export 'local_theme_data_source.dart'; diff --git a/app/lib/modules/read/domain/domain.dart b/app/lib/modules/read/domain/domain.dart index d252b8bf..65c76802 100644 --- a/app/lib/modules/read/domain/domain.dart +++ b/app/lib/modules/read/domain/domain.dart @@ -1,4 +1,9 @@ export 'repository/read_repository.dart'; export 'repository/read_theme_repository.dart'; -export 'usecase/usecase.dart'; -export 'entity/entity.dart'; +export 'usecase/get_initial_theme_usecase.dart'; +export 'usecase/get_read_page.dart'; +export 'usecase/save_theme_changes_usecase.dart'; +export 'entity/filters_entity.dart'; +export 'entity/meta_entity.dart'; +export 'entity/quran_page_entity.dart'; +export 'entity/verse_entity.dart'; diff --git a/app/lib/modules/read/domain/entity/entity.dart b/app/lib/modules/read/domain/entity/entity.dart deleted file mode 100644 index 0a44bd49..00000000 --- a/app/lib/modules/read/domain/entity/entity.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'filters.dart'; -export 'meta.dart'; -export 'verse.dart'; diff --git a/app/lib/modules/read/domain/entity/filters.dart b/app/lib/modules/read/domain/entity/filters.dart deleted file mode 100644 index 78da5968..00000000 --- a/app/lib/modules/read/domain/entity/filters.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'filters.g.dart'; - -@immutable -@JsonSerializable() -final class Filters { - const Filters({required this.pageNumber}); - - factory Filters.fromJson(Map json) => _$FiltersFromJson(json); - Map toJson() => _$FiltersToJson(this); - - @JsonKey(name: 'page_number') - final String pageNumber; -} diff --git a/app/lib/modules/read/domain/entity/filters_entity.dart b/app/lib/modules/read/domain/entity/filters_entity.dart new file mode 100644 index 00000000..ff1893d1 --- /dev/null +++ b/app/lib/modules/read/domain/entity/filters_entity.dart @@ -0,0 +1,8 @@ +import 'package:meta/meta.dart'; + +@immutable +final class FiltersEnity { + const FiltersEnity(this.pageNumber); + + final String pageNumber; +} diff --git a/app/lib/modules/read/domain/entity/meta.dart b/app/lib/modules/read/domain/entity/meta.dart deleted file mode 100644 index 0172e44f..00000000 --- a/app/lib/modules/read/domain/entity/meta.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:json_annotation/json_annotation.dart'; -import 'package:my_quran/modules/modules.dart'; - -part 'meta.g.dart'; - -@immutable -@JsonSerializable() -final class Meta { - const Meta({required this.filters}); - - factory Meta.fromJson(Map json) => _$MetaFromJson(json); - Map toJson() => _$MetaToJson(this); - - final Filters filters; -} diff --git a/app/lib/modules/read/domain/entity/meta_entity.dart b/app/lib/modules/read/domain/entity/meta_entity.dart new file mode 100644 index 00000000..9729aa3c --- /dev/null +++ b/app/lib/modules/read/domain/entity/meta_entity.dart @@ -0,0 +1,9 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/modules/modules.dart'; + +@immutable +final class MetaEntity { + const MetaEntity(this.filters); + + final FiltersEnity filters; +} diff --git a/app/lib/modules/read/data/model/quran_page.dart b/app/lib/modules/read/domain/entity/quran_page_entity.dart similarity index 69% rename from app/lib/modules/read/data/model/quran_page.dart rename to app/lib/modules/read/domain/entity/quran_page_entity.dart index f3ddd528..4719fdd7 100644 --- a/app/lib/modules/read/data/model/quran_page.dart +++ b/app/lib/modules/read/domain/entity/quran_page_entity.dart @@ -1,20 +1,16 @@ -import 'package:flutter/foundation.dart'; -import 'package:json_annotation/json_annotation.dart'; - +import 'package:meta/meta.dart'; import 'package:my_quran/constants/contants.dart'; import 'package:my_quran/modules/modules.dart'; -part 'quran_page.g.dart'; @immutable -@JsonSerializable() -final class QuranPage { - const QuranPage({required this.verses, required this.meta}); - - factory QuranPage.fromJson(Map json) => _$QuranPageFromJson(json); - Map toJson() => _$QuranPageToJson(this); +final class QuranPageEntity { + const QuranPageEntity({ + required this.verses, + required this.meta, + }); - final List verses; - final Meta meta; + final List verses; + final MetaEntity meta; StringBuffer get samePage { return StringBuffer() diff --git a/app/lib/modules/read/domain/entity/verse.dart b/app/lib/modules/read/domain/entity/verse.dart deleted file mode 100644 index 4ad43637..00000000 --- a/app/lib/modules/read/domain/entity/verse.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:json_annotation/json_annotation.dart'; -import 'package:my_quran/constants/app/app_const.dart'; - -part 'verse.g.dart'; - -@immutable -@JsonSerializable() -final class Verse { - const Verse({required this.id, required this.verseKey, required this.textUthmani}); - - factory Verse.fromJson(Map json) => _$VerseFromJson(json); - Map toJson() => _$VerseToJson(this); - - final int id; - @JsonKey(name: 'verse_key') - final String verseKey; - @JsonKey(name: 'text_imlaei') - final String textUthmani; - - int get juzNumber => int.parse(verseKey.split(':').first); - int get ayatNumber => int.parse(verseKey.split(':').last); - bool get isFirst => ayatNumber == 1; - bool get hasSajda => AppConst.sajdaAyats.contains(id); -} diff --git a/app/lib/modules/read/domain/entity/verse_entity.dart b/app/lib/modules/read/domain/entity/verse_entity.dart new file mode 100644 index 00000000..47e5641d --- /dev/null +++ b/app/lib/modules/read/domain/entity/verse_entity.dart @@ -0,0 +1,20 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/constants/contants.dart'; + +@immutable +final class VerseEnity { + const VerseEnity({ + required this.id, + required this.verseKey, + required this.textUthmani, + }); + + final int id; + final String verseKey; + final String textUthmani; + + int get juzNumber => int.parse(verseKey.split(':').first); + int get ayatNumber => int.parse(verseKey.split(':').last); + bool get isFirst => ayatNumber == 1; + bool get hasSajda => AppConst.sajdaAyats.contains(id); +} diff --git a/app/lib/modules/read/domain/repository/read_repository.dart b/app/lib/modules/read/domain/repository/read_repository.dart index 16f315c7..129ebd88 100644 --- a/app/lib/modules/read/domain/repository/read_repository.dart +++ b/app/lib/modules/read/domain/repository/read_repository.dart @@ -1,5 +1,5 @@ import 'package:my_quran/modules/modules.dart'; abstract class ReadRepository { - Future getPage(int page, String quranFmt); + Future getPage(int page, String quranFmt); } diff --git a/app/lib/modules/read/domain/repository/read_theme_repository.dart b/app/lib/modules/read/domain/repository/read_theme_repository.dart index 6653f133..4a025307 100644 --- a/app/lib/modules/read/domain/repository/read_theme_repository.dart +++ b/app/lib/modules/read/domain/repository/read_theme_repository.dart @@ -1,6 +1,7 @@ import 'package:my_quran/modules/modules.dart'; abstract class ReadThemeRepository { - Future getInitialThemeState(); + ReadThemeState get getInitialThemeState; + Future saveThemeState(ReadThemeState themeState); } diff --git a/app/lib/modules/read/domain/usecase/get_initial_theme_usecase.dart b/app/lib/modules/read/domain/usecase/get_initial_theme_usecase.dart index c49cd6f8..7f72c7ec 100644 --- a/app/lib/modules/read/domain/usecase/get_initial_theme_usecase.dart +++ b/app/lib/modules/read/domain/usecase/get_initial_theme_usecase.dart @@ -1,10 +1,13 @@ +import 'package:meta/meta.dart'; import 'package:my_quran/modules/modules.dart'; -class GetInitialThemeUseCase { +@immutable +final class GetInitialThemeUseCase { const GetInitialThemeUseCase(this.repository); + final ReadThemeRepository repository; - Future execute() { - return repository.getInitialThemeState(); + ReadThemeState get execute { + return repository.getInitialThemeState; } } diff --git a/app/lib/modules/read/domain/usecase/get_read_page.dart b/app/lib/modules/read/domain/usecase/get_read_page.dart index 2af1881f..00cc52ab 100644 --- a/app/lib/modules/read/domain/usecase/get_read_page.dart +++ b/app/lib/modules/read/domain/usecase/get_read_page.dart @@ -1,11 +1,13 @@ +import 'package:meta/meta.dart'; import 'package:my_quran/modules/modules.dart'; -class GetReadPageUseCase { +@immutable +final class GetReadPageUseCase { const GetReadPageUseCase(this.repository); final ReadRepository repository; - Future getPage(int page, String quranFmt) { + Future getPage(int page, String quranFmt) { return repository.getPage(page, quranFmt); } } diff --git a/app/lib/modules/read/domain/usecase/save_theme_changes_usecase.dart b/app/lib/modules/read/domain/usecase/save_theme_changes_usecase.dart index a07d7ece..2cc629fe 100644 --- a/app/lib/modules/read/domain/usecase/save_theme_changes_usecase.dart +++ b/app/lib/modules/read/domain/usecase/save_theme_changes_usecase.dart @@ -1,7 +1,10 @@ +import 'package:meta/meta.dart'; import 'package:my_quran/modules/modules.dart'; -class SaveThemeChangesUseCase { +@immutable +final class SaveThemeChangesUseCase { const SaveThemeChangesUseCase(this.repository); + final ReadThemeRepository repository; Future execute(ReadThemeState themeState) { diff --git a/app/lib/modules/read/domain/usecase/usecase.dart b/app/lib/modules/read/domain/usecase/usecase.dart deleted file mode 100644 index 10455866..00000000 --- a/app/lib/modules/read/domain/usecase/usecase.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'get_read_page.dart'; -export 'get_initial_theme_usecase.dart'; -export 'save_theme_changes_usecase.dart'; diff --git a/app/lib/modules/read/presentation/logic/read_cubit.dart b/app/lib/modules/read/presentation/cubit/read_cubit.dart similarity index 80% rename from app/lib/modules/read/presentation/logic/read_cubit.dart rename to app/lib/modules/read/presentation/cubit/read_cubit.dart index 7e5bc372..2e7de179 100644 --- a/app/lib/modules/read/presentation/logic/read_cubit.dart +++ b/app/lib/modules/read/presentation/cubit/read_cubit.dart @@ -1,5 +1,6 @@ import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:meta/meta.dart'; import 'package:my_quran/modules/modules.dart'; part 'read_state.dart'; @@ -9,7 +10,7 @@ class ReadCubit extends Cubit { final GetReadPageUseCase getQuranPageUseCase; - Future fetchQuranPage(int page) async { + Future fetchQuranPage(int page) async { return getQuranPageUseCase.getPage(page, state.fmt.name); } } diff --git a/app/lib/modules/read/presentation/logic/read_state.dart b/app/lib/modules/read/presentation/cubit/read_state.dart similarity index 84% rename from app/lib/modules/read/presentation/logic/read_state.dart rename to app/lib/modules/read/presentation/cubit/read_state.dart index 91364983..2d46dbdf 100644 --- a/app/lib/modules/read/presentation/logic/read_state.dart +++ b/app/lib/modules/read/presentation/cubit/read_state.dart @@ -1,6 +1,7 @@ part of 'read_cubit.dart'; -class ReadState extends Equatable { +@immutable +final class ReadState extends Equatable { const ReadState({this.fmt = QuranTextFmt.imlaei}); final QuranTextFmt fmt; diff --git a/app/lib/modules/read/presentation/logic/read_theme_cubit.dart b/app/lib/modules/read/presentation/cubit/read_theme_cubit.dart similarity index 75% rename from app/lib/modules/read/presentation/logic/read_theme_cubit.dart rename to app/lib/modules/read/presentation/cubit/read_theme_cubit.dart index bdae4643..f35cd2ea 100644 --- a/app/lib/modules/read/presentation/logic/read_theme_cubit.dart +++ b/app/lib/modules/read/presentation/cubit/read_theme_cubit.dart @@ -1,19 +1,21 @@ import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:meta/meta.dart'; import 'package:my_quran/modules/modules.dart'; part 'read_theme_state.dart'; class ReadThemeCubit extends Cubit { - ReadThemeCubit({required this.getInitialThemeUseCase, required this.saveThemeChangesUseCase}) - : super(const ReadThemeState()); + ReadThemeCubit({ + required this.getInitialThemeUseCase, + required this.saveThemeChangesUseCase, + }) : super(const ReadThemeState()); final GetInitialThemeUseCase getInitialThemeUseCase; final SaveThemeChangesUseCase saveThemeChangesUseCase; - Future initializeTheme() async { - final themeState = await getInitialThemeUseCase.execute(); - emit(themeState); + void initializeTheme() { + emit(getInitialThemeUseCase.execute); } void changeMode(int index) { diff --git a/app/lib/modules/read/presentation/logic/read_theme_state.dart b/app/lib/modules/read/presentation/cubit/read_theme_state.dart similarity index 96% rename from app/lib/modules/read/presentation/logic/read_theme_state.dart rename to app/lib/modules/read/presentation/cubit/read_theme_state.dart index 75babc99..c9f95bea 100644 --- a/app/lib/modules/read/presentation/logic/read_theme_state.dart +++ b/app/lib/modules/read/presentation/cubit/read_theme_state.dart @@ -1,6 +1,7 @@ part of 'read_theme_cubit.dart'; -class ReadThemeState extends Equatable { +@immutable +final class ReadThemeState extends Equatable { const ReadThemeState({ this.verticalSpaceSize = 0, this.horizontalSpaceSize = 14, diff --git a/app/lib/modules/read/presentation/presentation.dart b/app/lib/modules/read/presentation/presentation.dart index 56a31db8..3cb13ce7 100644 --- a/app/lib/modules/read/presentation/presentation.dart +++ b/app/lib/modules/read/presentation/presentation.dart @@ -1,4 +1,4 @@ -export 'logic/read_cubit.dart'; -export 'logic/read_theme_cubit.dart'; +export 'cubit/read_cubit.dart'; +export 'cubit/read_theme_cubit.dart'; export 'view/read_view.dart'; export 'view/pagination_view.dart'; diff --git a/app/lib/modules/read/presentation/view/pagination_view.dart b/app/lib/modules/read/presentation/view/pagination_view.dart index 0ff793d5..2d54bd49 100644 --- a/app/lib/modules/read/presentation/view/pagination_view.dart +++ b/app/lib/modules/read/presentation/view/pagination_view.dart @@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:mq_ci_keys/mq_ci_keys.dart'; - import 'package:my_quran/constants/contants.dart'; import 'package:my_quran/utils/urils.dart'; import 'package:my_quran/app/app.dart'; @@ -21,12 +20,12 @@ class PaginationView extends StatefulWidget { } class _PaginationViewState extends State { - late final PagingController _pagingController; + late final PagingController _pagingController; var _index = 0; @override void initState() { - _pagingController = PagingController( + _pagingController = PagingController( firstPageKey: widget.pages.first, ); _pagingController.addPageRequestListener(_fetchPage); @@ -52,7 +51,7 @@ class _PaginationViewState extends State { @override Widget build(BuildContext context) { final readThemeCubit = context.watch(); - return PagedSliverList.separated( + return PagedSliverList.separated( key: const Key(MqKeys.quranReadView), pagingController: _pagingController, separatorBuilder: (context, index) => Center( @@ -64,7 +63,7 @@ class _PaginationViewState extends State { ), ), ), - builderDelegate: PagedChildBuilderDelegate( + builderDelegate: PagedChildBuilderDelegate( itemBuilder: (context, item, index) { final strb = item.samePage.toString(); final text = strb.startsWith('\n\n') ? strb.replaceFirst('\n\n', '') : strb; diff --git a/app/lib/modules/read/presentation/view/read_view.dart b/app/lib/modules/read/presentation/view/read_view.dart index f8ab9e03..0753b8da 100644 --- a/app/lib/modules/read/presentation/view/read_view.dart +++ b/app/lib/modules/read/presentation/view/read_view.dart @@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:mq_ci_keys/mq_ci_keys.dart'; import 'package:mq_storage/mq_storage.dart'; - import 'package:my_quran/constants/contants.dart'; import 'package:my_quran/core/core.dart'; import 'package:my_quran/l10n/l10.dart'; @@ -37,17 +36,18 @@ class ReadView extends StatelessWidget { ), ), ), + RepositoryProvider( + create: (context) => ReadThemeRepositoryImpl( + LocalThemeDataSource(context.read()), + ), + ), BlocProvider( create: (context) => ReadThemeCubit( getInitialThemeUseCase: GetInitialThemeUseCase( - ReadThemeRepositoryImpl( - localDataSource: LocalThemeDataSource(context.read()), - ), + context.read(), ), saveThemeChangesUseCase: SaveThemeChangesUseCase( - ReadThemeRepositoryImpl( - localDataSource: LocalThemeDataSource(context.read()), - ), + context.read(), ), ), ), diff --git a/app/test/widget_test.dart b/app/test/widget_test.dart index 49a7b73e..a1226d32 100644 --- a/app/test/widget_test.dart +++ b/app/test/widget_test.dart @@ -16,8 +16,8 @@ final class MockRemoteClient extends Mock implements RemoteClient {} final class MockHomeRepositoryImpl implements HomeRepository { @override - Future getData(String token) async { - return const HomeModel(allDoneHatims: 8, allDonePages: 5325, donePages: 634); + Future getData(String token) async { + return const HomeEntity(allDoneHatims: 8, allDonePages: 5325, donePages: 634); } }