From 041e30e65819376f6770ba35beffa59aaf081358 Mon Sep 17 00:00:00 2001 From: Aidaiym Date: Wed, 27 Mar 2024 22:05:48 -0700 Subject: [PATCH 1/3] changed quran module architecture --- app/lib/models/models.dart | 5 --- app/lib/modules/quran/data/data.dart | 3 ++ .../quran/data/model}/juz_model.dart | 13 +++--- .../quran/data/model}/juz_model.g.dart | 7 +-- .../quran/data/model}/juz_surah_model.dart | 8 ++-- .../quran/data/model}/juz_surah_model.g.dart | 4 +- .../quran/data/model}/surah_model.dart | 14 ++---- .../quran/data/model}/surah_model.g.dart | 4 +- app/lib/modules/quran/domain/domain.dart | 5 +++ .../quran/domain/entity}/juz_data.dart | 0 .../quran/domain/entity/juz_entity.dart | 17 ++++++++ .../quran/domain/entity/juz_surah_entity.dart | 14 ++++++ .../quran/domain/entity}/surah_data.dart | 0 .../quran/domain/entity/surah_entity.dart | 24 +++++++++++ app/lib/modules/quran/logic/quran_cubit.dart | 13 ------ .../quran/presentation/cubit/quran_cubit.dart | 43 +++++++++++++++++++ .../quran/presentation/presentation.dart | 3 ++ .../view/page_view_item.dart | 6 +-- .../{ => presentation}/view/quran_view.dart | 5 +-- app/lib/modules/quran/quran.dart | 6 +-- .../quran_audio/logic/quran_audio_cubit.dart | 16 +++++-- 21 files changed, 152 insertions(+), 58 deletions(-) create mode 100644 app/lib/modules/quran/data/data.dart rename app/lib/{models/juz => modules/quran/data/model}/juz_model.dart (53%) rename app/lib/{models/juz => modules/quran/data/model}/juz_model.g.dart (64%) rename app/lib/{models/juz => modules/quran/data/model}/juz_surah_model.dart (58%) rename app/lib/{models/juz => modules/quran/data/model}/juz_surah_model.g.dart (73%) rename app/lib/{models/surah => modules/quran/data/model}/surah_model.dart (57%) rename app/lib/{models/surah => modules/quran/data/model}/surah_model.g.dart (78%) create mode 100644 app/lib/modules/quran/domain/domain.dart rename app/lib/{models/juz => modules/quran/domain/entity}/juz_data.dart (100%) create mode 100644 app/lib/modules/quran/domain/entity/juz_entity.dart create mode 100644 app/lib/modules/quran/domain/entity/juz_surah_entity.dart rename app/lib/{models/surah => modules/quran/domain/entity}/surah_data.dart (100%) create mode 100644 app/lib/modules/quran/domain/entity/surah_entity.dart delete mode 100644 app/lib/modules/quran/logic/quran_cubit.dart create mode 100644 app/lib/modules/quran/presentation/cubit/quran_cubit.dart create mode 100644 app/lib/modules/quran/presentation/presentation.dart rename app/lib/modules/quran/{ => presentation}/view/page_view_item.dart (94%) rename app/lib/modules/quran/{ => presentation}/view/quran_view.dart (88%) diff --git a/app/lib/models/models.dart b/app/lib/models/models.dart index 7aafb516..88977d5c 100644 --- a/app/lib/models/models.dart +++ b/app/lib/models/models.dart @@ -1,8 +1,3 @@ export 'hatim/hatim_juz.dart'; export 'hatim/hatim_page.dart'; export 'hatim/hatim_read_model.dart'; -export 'juz/juz_data.dart'; -export 'juz/juz_model.dart'; -export 'juz/juz_surah_model.dart'; -export 'surah/surah_data.dart'; -export 'surah/surah_model.dart'; diff --git a/app/lib/modules/quran/data/data.dart b/app/lib/modules/quran/data/data.dart new file mode 100644 index 00000000..d904f3ca --- /dev/null +++ b/app/lib/modules/quran/data/data.dart @@ -0,0 +1,3 @@ +export 'model/juz_model.dart'; +export 'model/juz_surah_model.dart'; +export 'model/surah_model.dart'; diff --git a/app/lib/models/juz/juz_model.dart b/app/lib/modules/quran/data/model/juz_model.dart similarity index 53% rename from app/lib/models/juz/juz_model.dart rename to app/lib/modules/quran/data/model/juz_model.dart index 8e9ff629..0159ad93 100644 --- a/app/lib/models/juz/juz_model.dart +++ b/app/lib/modules/quran/data/model/juz_model.dart @@ -1,25 +1,24 @@ import 'package:flutter/foundation.dart'; import 'package:json_annotation/json_annotation.dart'; - -import 'package:my_quran/models/models.dart'; +import 'package:my_quran/modules/modules.dart'; part 'juz_model.g.dart'; @immutable @JsonSerializable() -final class Juz { - const Juz({ +final class JuzResponse { + const JuzResponse({ required this.id, required this.name, required this.pages, required this.surahs, }); - factory Juz.fromJson(Map json) => _$JuzFromJson(json); - Map toJson() => _$JuzToJson(this); + factory JuzResponse.fromJson(Map json) => _$JuzResponseFromJson(json); + Map toJson() => _$JuzResponseToJson(this); final int id; final String name; final List pages; - final List surahs; + final List surahs; } diff --git a/app/lib/models/juz/juz_model.g.dart b/app/lib/modules/quran/data/model/juz_model.g.dart similarity index 64% rename from app/lib/models/juz/juz_model.g.dart rename to app/lib/modules/quran/data/model/juz_model.g.dart index e83c5337..e204110f 100644 --- a/app/lib/models/juz/juz_model.g.dart +++ b/app/lib/modules/quran/data/model/juz_model.g.dart @@ -6,14 +6,15 @@ part of 'juz_model.dart'; // JsonSerializableGenerator // ************************************************************************** -Juz _$JuzFromJson(Map json) => Juz( +JuzResponse _$JuzResponseFromJson(Map json) => JuzResponse( id: json['id'] as int, name: json['name'] as String, pages: (json['pages'] as List).map((e) => e as int).toList(), - surahs: (json['surahs'] as List).map((e) => JuzSurah.fromJson(e as Map)).toList(), + surahs: + (json['surahs'] as List).map((e) => JuzSurahResponse.fromJson(e as Map)).toList(), ); -Map _$JuzToJson(Juz instance) => { +Map _$JuzResponseToJson(JuzResponse instance) => { 'id': instance.id, 'name': instance.name, 'pages': instance.pages, diff --git a/app/lib/models/juz/juz_surah_model.dart b/app/lib/modules/quran/data/model/juz_surah_model.dart similarity index 58% rename from app/lib/models/juz/juz_surah_model.dart rename to app/lib/modules/quran/data/model/juz_surah_model.dart index 9f7e9749..ef6e5dfa 100644 --- a/app/lib/models/juz/juz_surah_model.dart +++ b/app/lib/modules/quran/data/model/juz_surah_model.dart @@ -5,15 +5,15 @@ part 'juz_surah_model.g.dart'; @immutable @JsonSerializable() -final class JuzSurah { - const JuzSurah({ +final class JuzSurahResponse { + const JuzSurahResponse({ required this.name, required this.arName, required this.pages, }); - factory JuzSurah.fromJson(Map json) => _$JuzSurahFromJson(json); - Map toJson() => _$JuzSurahToJson(this); + factory JuzSurahResponse.fromJson(Map json) => _$JuzSurahResponseFromJson(json); + Map toJson() => _$JuzSurahResponseToJson(this); final String name; final String arName; diff --git a/app/lib/models/juz/juz_surah_model.g.dart b/app/lib/modules/quran/data/model/juz_surah_model.g.dart similarity index 73% rename from app/lib/models/juz/juz_surah_model.g.dart rename to app/lib/modules/quran/data/model/juz_surah_model.g.dart index 0a445587..d2cde8a4 100644 --- a/app/lib/models/juz/juz_surah_model.g.dart +++ b/app/lib/modules/quran/data/model/juz_surah_model.g.dart @@ -6,13 +6,13 @@ part of 'juz_surah_model.dart'; // JsonSerializableGenerator // ************************************************************************** -JuzSurah _$JuzSurahFromJson(Map json) => JuzSurah( +JuzSurahResponse _$JuzSurahResponseFromJson(Map json) => JuzSurahResponse( name: json['name'] as String, arName: json['arName'] as String, pages: (json['pages'] as List).map((e) => e as int).toList(), ); -Map _$JuzSurahToJson(JuzSurah instance) => { +Map _$JuzSurahResponseToJson(JuzSurahResponse instance) => { 'name': instance.name, 'arName': instance.arName, 'pages': instance.pages, diff --git a/app/lib/models/surah/surah_model.dart b/app/lib/modules/quran/data/model/surah_model.dart similarity index 57% rename from app/lib/models/surah/surah_model.dart rename to app/lib/modules/quran/data/model/surah_model.dart index 2b9b5f1a..a697d6d4 100644 --- a/app/lib/models/surah/surah_model.dart +++ b/app/lib/modules/quran/data/model/surah_model.dart @@ -5,8 +5,8 @@ part 'surah_model.g.dart'; @immutable @JsonSerializable() -final class Surah { - const Surah({ +final class SurahResponse { + const SurahResponse({ required this.id, required this.name, required this.aya, @@ -14,18 +14,12 @@ final class Surah { required this.arabic, }); - factory Surah.fromJson(Map json) => _$SurahFromJson(json); - Map toJson() => _$SurahToJson(this); + factory SurahResponse.fromJson(Map json) => _$SurahResponseFromJson(json); + Map toJson() => _$SurahResponseToJson(this); final int id; final String name; final int aya; final List pages; final String arabic; - - String get surahPath { - if (id < 10) return '00$id'; - if (id < 100) return '0$id'; - return '$id'; - } } diff --git a/app/lib/models/surah/surah_model.g.dart b/app/lib/modules/quran/data/model/surah_model.g.dart similarity index 78% rename from app/lib/models/surah/surah_model.g.dart rename to app/lib/modules/quran/data/model/surah_model.g.dart index 7d070c47..b197af24 100644 --- a/app/lib/models/surah/surah_model.g.dart +++ b/app/lib/modules/quran/data/model/surah_model.g.dart @@ -6,7 +6,7 @@ part of 'surah_model.dart'; // JsonSerializableGenerator // ************************************************************************** -Surah _$SurahFromJson(Map json) => Surah( +SurahResponse _$SurahResponseFromJson(Map json) => SurahResponse( id: json['id'] as int, name: json['name'] as String, aya: json['aya'] as int, @@ -14,7 +14,7 @@ Surah _$SurahFromJson(Map json) => Surah( arabic: json['arabic'] as String, ); -Map _$SurahToJson(Surah instance) => { +Map _$SurahResponseToJson(SurahResponse instance) => { 'id': instance.id, 'name': instance.name, 'aya': instance.aya, diff --git a/app/lib/modules/quran/domain/domain.dart b/app/lib/modules/quran/domain/domain.dart new file mode 100644 index 00000000..3611a0ec --- /dev/null +++ b/app/lib/modules/quran/domain/domain.dart @@ -0,0 +1,5 @@ +export 'entity/juz_data.dart'; +export 'entity/juz_entity.dart'; +export 'entity/juz_surah_entity.dart'; +export 'entity/surah_data.dart'; +export 'entity/surah_entity.dart'; diff --git a/app/lib/models/juz/juz_data.dart b/app/lib/modules/quran/domain/entity/juz_data.dart similarity index 100% rename from app/lib/models/juz/juz_data.dart rename to app/lib/modules/quran/domain/entity/juz_data.dart diff --git a/app/lib/modules/quran/domain/entity/juz_entity.dart b/app/lib/modules/quran/domain/entity/juz_entity.dart new file mode 100644 index 00000000..e7655458 --- /dev/null +++ b/app/lib/modules/quran/domain/entity/juz_entity.dart @@ -0,0 +1,17 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/modules/modules.dart'; + +@immutable +final class JuzEntity { + const JuzEntity({ + required this.id, + required this.name, + required this.pages, + required this.surahs, + }); + + final int id; + final String name; + final List pages; + final List surahs; +} diff --git a/app/lib/modules/quran/domain/entity/juz_surah_entity.dart b/app/lib/modules/quran/domain/entity/juz_surah_entity.dart new file mode 100644 index 00000000..3b464e98 --- /dev/null +++ b/app/lib/modules/quran/domain/entity/juz_surah_entity.dart @@ -0,0 +1,14 @@ +import 'package:meta/meta.dart'; + +@immutable +final class JuzSurahEntity { + const JuzSurahEntity({ + required this.name, + required this.arName, + required this.pages, + }); + + final String name; + final String arName; + final List pages; +} diff --git a/app/lib/models/surah/surah_data.dart b/app/lib/modules/quran/domain/entity/surah_data.dart similarity index 100% rename from app/lib/models/surah/surah_data.dart rename to app/lib/modules/quran/domain/entity/surah_data.dart diff --git a/app/lib/modules/quran/domain/entity/surah_entity.dart b/app/lib/modules/quran/domain/entity/surah_entity.dart new file mode 100644 index 00000000..6c1c84e4 --- /dev/null +++ b/app/lib/modules/quran/domain/entity/surah_entity.dart @@ -0,0 +1,24 @@ +import 'package:meta/meta.dart'; + +@immutable +final class SurahEntity { + const SurahEntity({ + required this.id, + required this.name, + required this.aya, + required this.pages, + required this.arabic, + }); + + final int id; + final String name; + final int aya; + final List pages; + final String arabic; + + String get surahPath { + if (id < 10) return '00$id'; + if (id < 100) return '0$id'; + return '$id'; + } +} diff --git a/app/lib/modules/quran/logic/quran_cubit.dart b/app/lib/modules/quran/logic/quran_cubit.dart deleted file mode 100644 index 42fca8b2..00000000 --- a/app/lib/modules/quran/logic/quran_cubit.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter_bloc/flutter_bloc.dart'; - -import 'package:my_quran/models/models.dart'; - -class QuranCubit extends Cubit { - QuranCubit() : super(0); - - void change(int? val) => emit(val ?? 0); - - final List juzs = juzData.map(Juz.fromJson).toList(); - - final List surahs = surahData.map(Surah.fromJson).toList(); -} diff --git a/app/lib/modules/quran/presentation/cubit/quran_cubit.dart b/app/lib/modules/quran/presentation/cubit/quran_cubit.dart new file mode 100644 index 00000000..fae0d032 --- /dev/null +++ b/app/lib/modules/quran/presentation/cubit/quran_cubit.dart @@ -0,0 +1,43 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:my_quran/modules/modules.dart'; + +class QuranCubit extends Cubit { + QuranCubit() : super(0) { + juzs = juzData.map((data) => _convertJuzData(JuzResponse.fromJson(data))).toList(); + surahs = surahData.map((data) => _convertSurahData(SurahResponse.fromJson(data))).toList(); + } + + void change(int? val) => emit(val ?? 0); + + SurahEntity _convertSurahData(SurahResponse response) { + return SurahEntity( + id: response.id, + name: response.name, + aya: response.aya, + pages: response.pages, + arabic: response.arabic, + ); + } + + JuzEntity _convertJuzData(JuzResponse response) { + final convertedSurahs = response.surahs + .map( + (juzSurahResponse) => JuzSurahEntity( + name: juzSurahResponse.name, + arName: juzSurahResponse.arName, + pages: juzSurahResponse.pages, + ), + ) + .toList(); + + return JuzEntity( + id: response.id, + name: response.name, + pages: response.pages, + surahs: convertedSurahs, + ); + } + + late final List juzs; + late final List surahs; +} diff --git a/app/lib/modules/quran/presentation/presentation.dart b/app/lib/modules/quran/presentation/presentation.dart new file mode 100644 index 00000000..7d9fd606 --- /dev/null +++ b/app/lib/modules/quran/presentation/presentation.dart @@ -0,0 +1,3 @@ +export 'cubit/quran_cubit.dart'; +export 'view/page_view_item.dart'; +export 'view/quran_view.dart'; diff --git a/app/lib/modules/quran/view/page_view_item.dart b/app/lib/modules/quran/presentation/view/page_view_item.dart similarity index 94% rename from app/lib/modules/quran/view/page_view_item.dart rename to app/lib/modules/quran/presentation/view/page_view_item.dart index 519a7afb..edfcf592 100644 --- a/app/lib/modules/quran/view/page_view_item.dart +++ b/app/lib/modules/quran/presentation/view/page_view_item.dart @@ -4,7 +4,7 @@ import 'package:mq_ci_keys/mq_ci_keys.dart'; import 'package:my_quran/config/config.dart'; import 'package:my_quran/l10n/l10.dart'; -import 'package:my_quran/models/models.dart'; +import 'package:my_quran/modules/modules.dart'; class PageViewItem extends StatelessWidget { const PageViewItem(this.items, {super.key}); @@ -18,7 +18,7 @@ class PageViewItem extends StatelessWidget { itemCount: items.length, itemBuilder: (BuildContext context, int index) { final item = items[index]; - if (item is Juz) { + if (item is JuzEntity) { return Card( child: ListTile( key: Key(MqKeys.quranReadJus(index)), @@ -42,7 +42,7 @@ class PageViewItem extends StatelessWidget { }, ), ); - } else if (item is Surah) { + } else if (item is SurahEntity) { return Card( child: ListTile( key: Key(MqKeys.quranReadSurah(index)), diff --git a/app/lib/modules/quran/view/quran_view.dart b/app/lib/modules/quran/presentation/view/quran_view.dart similarity index 88% rename from app/lib/modules/quran/view/quran_view.dart rename to app/lib/modules/quran/presentation/view/quran_view.dart index eff4e933..359be5f1 100644 --- a/app/lib/modules/quran/view/quran_view.dart +++ b/app/lib/modules/quran/presentation/view/quran_view.dart @@ -4,7 +4,6 @@ import 'package:mq_ci_keys/mq_ci_keys.dart'; import 'package:my_quran/components/components.dart'; import 'package:my_quran/l10n/l10.dart'; -import 'package:my_quran/models/models.dart'; import 'package:my_quran/modules/modules.dart'; import 'package:my_quran/theme/theme.dart'; @@ -43,8 +42,8 @@ class QuranBody extends StatelessWidget { ), body: TabBarView( children: [ - PageViewItem(context.read().juzs), - PageViewItem(context.read().surahs), + PageViewItem(context.read().juzs), + PageViewItem(context.read().surahs), ], ), ); diff --git a/app/lib/modules/quran/quran.dart b/app/lib/modules/quran/quran.dart index acd78ce8..0192af9d 100644 --- a/app/lib/modules/quran/quran.dart +++ b/app/lib/modules/quran/quran.dart @@ -1,3 +1,3 @@ -export 'logic/quran_cubit.dart'; -export 'view/page_view_item.dart'; -export 'view/quran_view.dart'; +export 'presentation/presentation.dart'; +export 'domain/domain.dart'; +export 'data/data.dart'; diff --git a/app/lib/modules/quran_audio/logic/quran_audio_cubit.dart b/app/lib/modules/quran_audio/logic/quran_audio_cubit.dart index b82da9a1..3b9e8817 100644 --- a/app/lib/modules/quran_audio/logic/quran_audio_cubit.dart +++ b/app/lib/modules/quran_audio/logic/quran_audio_cubit.dart @@ -4,7 +4,7 @@ import 'package:just_audio_background/just_audio_background.dart'; import 'package:my_quran/config/config.dart'; import 'package:my_quran/core/core.dart'; -import 'package:my_quran/models/models.dart'; +import 'package:my_quran/modules/modules.dart'; part 'quran_audio_state.dart'; @@ -15,11 +15,21 @@ class QuranAudioCubit extends Cubit { final NetworkClient networkClient; late final Stream sequenceStateStream; late final Stream playerStateStream; - late final List surahs; + late final List surahs; + + SurahEntity _convertData(SurahResponse response) { + return SurahEntity( + id: response.id, + name: response.name, + aya: response.aya, + pages: response.pages, + arabic: response.arabic, + ); + } Future init() async { try { - surahs = surahData.map(Surah.fromJson).toList(); + surahs = surahData.map((surahResponse) => _convertData(SurahResponse.fromJson(surahResponse))).toList(); sequenceStateStream = player.sequenceStateStream; playerStateStream = player.playerStateStream; final playList = ConcatenatingAudioSource( From 0e02f3aded5e4c84aa91b8e64c6725f443c8d54b Mon Sep 17 00:00:00 2001 From: Aidaiym Date: Wed, 27 Mar 2024 23:43:13 -0700 Subject: [PATCH 2/3] fix quran module --- app/lib/modules/quran/data/data.dart | 4 ++ .../repository/quran_repository_impl.dart | 23 ++++++++++ .../entity => data/source}/juz_data.dart | 0 .../data/source/juz_local_data_source.dart | 29 +++++++++++++ .../entity => data/source}/surah_data.dart | 0 .../data/source/surah_local_data_source.dart | 20 +++++++++ app/lib/modules/quran/domain/domain.dart | 5 ++- .../domain/repository/quran_repository.dart | 6 +++ .../quran/domain/usecase/get_juzs.dart | 13 ++++++ .../quran/domain/usecase/get_surahs.dart | 13 ++++++ .../quran/presentation/cubit/quran_cubit.dart | 43 +++++-------------- .../quran/presentation/view/quran_view.dart | 20 +++++++-- 12 files changed, 139 insertions(+), 37 deletions(-) create mode 100644 app/lib/modules/quran/data/repository/quran_repository_impl.dart rename app/lib/modules/quran/{domain/entity => data/source}/juz_data.dart (100%) create mode 100644 app/lib/modules/quran/data/source/juz_local_data_source.dart rename app/lib/modules/quran/{domain/entity => data/source}/surah_data.dart (100%) create mode 100644 app/lib/modules/quran/data/source/surah_local_data_source.dart create mode 100644 app/lib/modules/quran/domain/repository/quran_repository.dart create mode 100644 app/lib/modules/quran/domain/usecase/get_juzs.dart create mode 100644 app/lib/modules/quran/domain/usecase/get_surahs.dart diff --git a/app/lib/modules/quran/data/data.dart b/app/lib/modules/quran/data/data.dart index d904f3ca..24fafa4b 100644 --- a/app/lib/modules/quran/data/data.dart +++ b/app/lib/modules/quran/data/data.dart @@ -1,3 +1,7 @@ export 'model/juz_model.dart'; export 'model/juz_surah_model.dart'; export 'model/surah_model.dart'; +export 'source/juz_data.dart'; +export 'source/juz_local_data_source.dart'; +export 'source/surah_data.dart'; +export 'source/surah_local_data_source.dart'; diff --git a/app/lib/modules/quran/data/repository/quran_repository_impl.dart b/app/lib/modules/quran/data/repository/quran_repository_impl.dart new file mode 100644 index 00000000..5ce0750a --- /dev/null +++ b/app/lib/modules/quran/data/repository/quran_repository_impl.dart @@ -0,0 +1,23 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/modules/modules.dart'; + +@immutable +final class QuranRepositoryImpl implements QuranRepository { + const QuranRepositoryImpl( + this.juzLocalDataSource, + this.surahLocalDataSource, + ); + + final JuzLocalDataSource juzLocalDataSource; + final SurahLocalDataSource surahLocalDataSource; + + @override + List getJuzs() { + return juzLocalDataSource.getJuzsFromLocal(); + } + + @override + List getSurahs() { + return surahLocalDataSource.getSurahsFromLocal(); + } +} diff --git a/app/lib/modules/quran/domain/entity/juz_data.dart b/app/lib/modules/quran/data/source/juz_data.dart similarity index 100% rename from app/lib/modules/quran/domain/entity/juz_data.dart rename to app/lib/modules/quran/data/source/juz_data.dart diff --git a/app/lib/modules/quran/data/source/juz_local_data_source.dart b/app/lib/modules/quran/data/source/juz_local_data_source.dart new file mode 100644 index 00000000..53d125e5 --- /dev/null +++ b/app/lib/modules/quran/data/source/juz_local_data_source.dart @@ -0,0 +1,29 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/modules/modules.dart'; + +@immutable +final class JuzLocalDataSource { + List getJuzsFromLocal() { + final juzs = juzData.map((data) => _convertJuzData(JuzResponse.fromJson(data))).toList(); + return juzs; + } + + JuzEntity _convertJuzData(JuzResponse response) { + final convertedSurahs = response.surahs + .map( + (juzSurahResponse) => JuzSurahEntity( + name: juzSurahResponse.name, + arName: juzSurahResponse.arName, + pages: juzSurahResponse.pages, + ), + ) + .toList(); + + return JuzEntity( + id: response.id, + name: response.name, + pages: response.pages, + surahs: convertedSurahs, + ); + } +} diff --git a/app/lib/modules/quran/domain/entity/surah_data.dart b/app/lib/modules/quran/data/source/surah_data.dart similarity index 100% rename from app/lib/modules/quran/domain/entity/surah_data.dart rename to app/lib/modules/quran/data/source/surah_data.dart diff --git a/app/lib/modules/quran/data/source/surah_local_data_source.dart b/app/lib/modules/quran/data/source/surah_local_data_source.dart new file mode 100644 index 00000000..160e5b6a --- /dev/null +++ b/app/lib/modules/quran/data/source/surah_local_data_source.dart @@ -0,0 +1,20 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/modules/modules.dart'; + +@immutable +final class SurahLocalDataSource { + List getSurahsFromLocal() { + final surahs = surahData.map((data) => _convertSurahData(SurahResponse.fromJson(data))).toList(); + return surahs; + } + + SurahEntity _convertSurahData(SurahResponse response) { + return SurahEntity( + id: response.id, + name: response.name, + aya: response.aya, + pages: response.pages, + arabic: response.arabic, + ); + } +} diff --git a/app/lib/modules/quran/domain/domain.dart b/app/lib/modules/quran/domain/domain.dart index 3611a0ec..a8154785 100644 --- a/app/lib/modules/quran/domain/domain.dart +++ b/app/lib/modules/quran/domain/domain.dart @@ -1,5 +1,6 @@ -export 'entity/juz_data.dart'; export 'entity/juz_entity.dart'; export 'entity/juz_surah_entity.dart'; -export 'entity/surah_data.dart'; export 'entity/surah_entity.dart'; +export 'repository/quran_repository.dart'; +export 'usecase/get_juzs.dart'; +export 'usecase/get_surahs.dart'; diff --git a/app/lib/modules/quran/domain/repository/quran_repository.dart b/app/lib/modules/quran/domain/repository/quran_repository.dart new file mode 100644 index 00000000..88d27581 --- /dev/null +++ b/app/lib/modules/quran/domain/repository/quran_repository.dart @@ -0,0 +1,6 @@ +import 'package:my_quran/modules/modules.dart'; + +abstract class QuranRepository { + List getJuzs(); + List getSurahs(); +} diff --git a/app/lib/modules/quran/domain/usecase/get_juzs.dart b/app/lib/modules/quran/domain/usecase/get_juzs.dart new file mode 100644 index 00000000..25da616d --- /dev/null +++ b/app/lib/modules/quran/domain/usecase/get_juzs.dart @@ -0,0 +1,13 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/modules/modules.dart'; + +@immutable +final class GetJuzUseCase { + const GetJuzUseCase(this.repository); + + final QuranRepository repository; + + List call() { + return repository.getJuzs(); + } +} diff --git a/app/lib/modules/quran/domain/usecase/get_surahs.dart b/app/lib/modules/quran/domain/usecase/get_surahs.dart new file mode 100644 index 00000000..a6314d5e --- /dev/null +++ b/app/lib/modules/quran/domain/usecase/get_surahs.dart @@ -0,0 +1,13 @@ +import 'package:meta/meta.dart'; +import 'package:my_quran/modules/modules.dart'; + +@immutable +final class GetSurahsUseCase { + const GetSurahsUseCase(this.repository); + + final QuranRepository repository; + + List call() { + return repository.getSurahs(); + } +} diff --git a/app/lib/modules/quran/presentation/cubit/quran_cubit.dart b/app/lib/modules/quran/presentation/cubit/quran_cubit.dart index fae0d032..c60b5df1 100644 --- a/app/lib/modules/quran/presentation/cubit/quran_cubit.dart +++ b/app/lib/modules/quran/presentation/cubit/quran_cubit.dart @@ -2,42 +2,21 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:my_quran/modules/modules.dart'; class QuranCubit extends Cubit { - QuranCubit() : super(0) { - juzs = juzData.map((data) => _convertJuzData(JuzResponse.fromJson(data))).toList(); - surahs = surahData.map((data) => _convertSurahData(SurahResponse.fromJson(data))).toList(); - } + QuranCubit({ + required this.getJuzUseCase, + required this.getSurahsUseCase, + }) : super(0); + + final GetJuzUseCase getJuzUseCase; + final GetSurahsUseCase getSurahsUseCase; void change(int? val) => emit(val ?? 0); - SurahEntity _convertSurahData(SurahResponse response) { - return SurahEntity( - id: response.id, - name: response.name, - aya: response.aya, - pages: response.pages, - arabic: response.arabic, - ); + List getJuz() { + return getJuzUseCase(); } - JuzEntity _convertJuzData(JuzResponse response) { - final convertedSurahs = response.surahs - .map( - (juzSurahResponse) => JuzSurahEntity( - name: juzSurahResponse.name, - arName: juzSurahResponse.arName, - pages: juzSurahResponse.pages, - ), - ) - .toList(); - - return JuzEntity( - id: response.id, - name: response.name, - pages: response.pages, - surahs: convertedSurahs, - ); + List getSurah() { + return getSurahsUseCase(); } - - late final List juzs; - late final List surahs; } diff --git a/app/lib/modules/quran/presentation/view/quran_view.dart b/app/lib/modules/quran/presentation/view/quran_view.dart index 359be5f1..9bd30434 100644 --- a/app/lib/modules/quran/presentation/view/quran_view.dart +++ b/app/lib/modules/quran/presentation/view/quran_view.dart @@ -5,6 +5,7 @@ import 'package:mq_ci_keys/mq_ci_keys.dart'; import 'package:my_quran/components/components.dart'; import 'package:my_quran/l10n/l10.dart'; import 'package:my_quran/modules/modules.dart'; +import 'package:my_quran/modules/quran/data/repository/quran_repository_impl.dart'; import 'package:my_quran/theme/theme.dart'; class QuranView extends StatelessWidget { @@ -15,7 +16,20 @@ class QuranView extends StatelessWidget { return DefaultTabController( length: 2, child: BlocProvider( - create: (context) => QuranCubit(), + create: (context) => QuranCubit( + getJuzUseCase: GetJuzUseCase( + QuranRepositoryImpl( + JuzLocalDataSource(), + SurahLocalDataSource(), + ), + ), + getSurahsUseCase: GetSurahsUseCase( + QuranRepositoryImpl( + JuzLocalDataSource(), + SurahLocalDataSource(), + ), + ), + ), child: const QuranBody(), ), ); @@ -42,8 +56,8 @@ class QuranBody extends StatelessWidget { ), body: TabBarView( children: [ - PageViewItem(context.read().juzs), - PageViewItem(context.read().surahs), + PageViewItem(context.read().getJuz()), + PageViewItem(context.read().getSurah()), ], ), ); From 171b93d2dc5549f203177a371c6166b7be8425cf Mon Sep 17 00:00:00 2001 From: Aidaiym Date: Sat, 30 Mar 2024 13:39:00 -0700 Subject: [PATCH 3/3] fix comments --- app/lib/modules/quran/data/data.dart | 1 + .../repository/quran_repository_impl.dart | 37 ++++++++++++++++++- .../data/source/juz_local_data_source.dart | 23 +----------- .../data/source/surah_local_data_source.dart | 14 +------ .../quran/presentation/view/quran_view.dart | 23 +++++++----- 5 files changed, 53 insertions(+), 45 deletions(-) diff --git a/app/lib/modules/quran/data/data.dart b/app/lib/modules/quran/data/data.dart index 24fafa4b..575f2270 100644 --- a/app/lib/modules/quran/data/data.dart +++ b/app/lib/modules/quran/data/data.dart @@ -5,3 +5,4 @@ export 'source/juz_data.dart'; export 'source/juz_local_data_source.dart'; export 'source/surah_data.dart'; export 'source/surah_local_data_source.dart'; +export 'repository/quran_repository_impl.dart'; diff --git a/app/lib/modules/quran/data/repository/quran_repository_impl.dart b/app/lib/modules/quran/data/repository/quran_repository_impl.dart index 5ce0750a..5fff6c84 100644 --- a/app/lib/modules/quran/data/repository/quran_repository_impl.dart +++ b/app/lib/modules/quran/data/repository/quran_repository_impl.dart @@ -13,11 +13,44 @@ final class QuranRepositoryImpl implements QuranRepository { @override List getJuzs() { - return juzLocalDataSource.getJuzsFromLocal(); + final juzResponses = juzLocalDataSource.getJuzsFromLocal(); + final juzEntities = juzResponses.map(_convertJuzData).toList(); + return juzEntities; } @override List getSurahs() { - return surahLocalDataSource.getSurahsFromLocal(); + final surahResponses = surahLocalDataSource.getSurahsFromLocal(); + final surahEntities = surahResponses.map(_convertSurahData).toList(); + return surahEntities; + } + + JuzEntity _convertJuzData(JuzResponse response) { + final convertedSurahs = response.surahs + .map( + (juzSurahResponse) => JuzSurahEntity( + name: juzSurahResponse.name, + arName: juzSurahResponse.arName, + pages: juzSurahResponse.pages, + ), + ) + .toList(); + + return JuzEntity( + id: response.id, + name: response.name, + pages: response.pages, + surahs: convertedSurahs, + ); + } + + SurahEntity _convertSurahData(SurahResponse response) { + return SurahEntity( + id: response.id, + name: response.name, + aya: response.aya, + pages: response.pages, + arabic: response.arabic, + ); } } diff --git a/app/lib/modules/quran/data/source/juz_local_data_source.dart b/app/lib/modules/quran/data/source/juz_local_data_source.dart index 53d125e5..cb847db4 100644 --- a/app/lib/modules/quran/data/source/juz_local_data_source.dart +++ b/app/lib/modules/quran/data/source/juz_local_data_source.dart @@ -3,27 +3,8 @@ import 'package:my_quran/modules/modules.dart'; @immutable final class JuzLocalDataSource { - List getJuzsFromLocal() { - final juzs = juzData.map((data) => _convertJuzData(JuzResponse.fromJson(data))).toList(); + List getJuzsFromLocal() { + final juzs = juzData.map(JuzResponse.fromJson).toList(); return juzs; } - - JuzEntity _convertJuzData(JuzResponse response) { - final convertedSurahs = response.surahs - .map( - (juzSurahResponse) => JuzSurahEntity( - name: juzSurahResponse.name, - arName: juzSurahResponse.arName, - pages: juzSurahResponse.pages, - ), - ) - .toList(); - - return JuzEntity( - id: response.id, - name: response.name, - pages: response.pages, - surahs: convertedSurahs, - ); - } } diff --git a/app/lib/modules/quran/data/source/surah_local_data_source.dart b/app/lib/modules/quran/data/source/surah_local_data_source.dart index 160e5b6a..dc48ec7d 100644 --- a/app/lib/modules/quran/data/source/surah_local_data_source.dart +++ b/app/lib/modules/quran/data/source/surah_local_data_source.dart @@ -3,18 +3,8 @@ import 'package:my_quran/modules/modules.dart'; @immutable final class SurahLocalDataSource { - List getSurahsFromLocal() { - final surahs = surahData.map((data) => _convertSurahData(SurahResponse.fromJson(data))).toList(); + List getSurahsFromLocal() { + final surahs = surahData.map(SurahResponse.fromJson).toList(); return surahs; } - - SurahEntity _convertSurahData(SurahResponse response) { - return SurahEntity( - id: response.id, - name: response.name, - aya: response.aya, - pages: response.pages, - arabic: response.arabic, - ); - } } diff --git a/app/lib/modules/quran/presentation/view/quran_view.dart b/app/lib/modules/quran/presentation/view/quran_view.dart index 9bd30434..061263a9 100644 --- a/app/lib/modules/quran/presentation/view/quran_view.dart +++ b/app/lib/modules/quran/presentation/view/quran_view.dart @@ -5,7 +5,6 @@ import 'package:mq_ci_keys/mq_ci_keys.dart'; import 'package:my_quran/components/components.dart'; import 'package:my_quran/l10n/l10.dart'; import 'package:my_quran/modules/modules.dart'; -import 'package:my_quran/modules/quran/data/repository/quran_repository_impl.dart'; import 'package:my_quran/theme/theme.dart'; class QuranView extends StatelessWidget { @@ -15,21 +14,25 @@ class QuranView extends StatelessWidget { Widget build(BuildContext context) { return DefaultTabController( length: 2, - child: BlocProvider( - create: (context) => QuranCubit( - getJuzUseCase: GetJuzUseCase( - QuranRepositoryImpl( + child: MultiBlocProvider( + providers: [ + RepositoryProvider( + create: (context) => QuranRepositoryImpl( JuzLocalDataSource(), SurahLocalDataSource(), ), ), - getSurahsUseCase: GetSurahsUseCase( - QuranRepositoryImpl( - JuzLocalDataSource(), - SurahLocalDataSource(), + BlocProvider( + create: (context) => QuranCubit( + getJuzUseCase: GetJuzUseCase( + context.read(), + ), + getSurahsUseCase: GetSurahsUseCase( + context.read(), + ), ), ), - ), + ], child: const QuranBody(), ), );