-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from Eldar2021/ai/change-quran-architecture
changed quran module architecture
- Loading branch information
Showing
27 changed files
with
264 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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'; | ||
export 'repository/quran_repository_impl.dart'; |
13 changes: 6 additions & 7 deletions
13
app/lib/models/juz/juz_model.dart → ...b/modules/quran/data/model/juz_model.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json) => _$JuzFromJson(json); | ||
Map<String, dynamic> toJson() => _$JuzToJson(this); | ||
factory JuzResponse.fromJson(Map<String, dynamic> json) => _$JuzResponseFromJson(json); | ||
Map<String, dynamic> toJson() => _$JuzResponseToJson(this); | ||
|
||
final int id; | ||
final String name; | ||
final List<int> pages; | ||
final List<JuzSurah> surahs; | ||
final List<JuzSurahResponse> surahs; | ||
} |
7 changes: 4 additions & 3 deletions
7
app/lib/models/juz/juz_model.g.dart → ...modules/quran/data/model/juz_model.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/lib/models/juz/juz_surah_model.g.dart → ...s/quran/data/model/juz_surah_model.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/lib/models/surah/surah_model.g.dart → ...dules/quran/data/model/surah_model.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
app/lib/modules/quran/data/repository/quran_repository_impl.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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<JuzEntity> getJuzs() { | ||
final juzResponses = juzLocalDataSource.getJuzsFromLocal(); | ||
final juzEntities = juzResponses.map(_convertJuzData).toList(); | ||
return juzEntities; | ||
} | ||
|
||
@override | ||
List<SurahEntity> getSurahs() { | ||
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, | ||
); | ||
} | ||
} |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
app/lib/modules/quran/data/source/juz_local_data_source.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:meta/meta.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
@immutable | ||
final class JuzLocalDataSource { | ||
List<JuzResponse> getJuzsFromLocal() { | ||
final juzs = juzData.map(JuzResponse.fromJson).toList(); | ||
return juzs; | ||
} | ||
} |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
app/lib/modules/quran/data/source/surah_local_data_source.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:meta/meta.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
@immutable | ||
final class SurahLocalDataSource { | ||
List<SurahResponse> getSurahsFromLocal() { | ||
final surahs = surahData.map(SurahResponse.fromJson).toList(); | ||
return surahs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export 'entity/juz_entity.dart'; | ||
export 'entity/juz_surah_entity.dart'; | ||
export 'entity/surah_entity.dart'; | ||
export 'repository/quran_repository.dart'; | ||
export 'usecase/get_juzs.dart'; | ||
export 'usecase/get_surahs.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int> pages; | ||
final List<JuzSurahEntity> surahs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int> pages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int> pages; | ||
final String arabic; | ||
|
||
String get surahPath { | ||
if (id < 10) return '00$id'; | ||
if (id < 100) return '0$id'; | ||
return '$id'; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/lib/modules/quran/domain/repository/quran_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
abstract class QuranRepository { | ||
List<JuzEntity> getJuzs(); | ||
List<SurahEntity> getSurahs(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<JuzEntity> call() { | ||
return repository.getJuzs(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SurahEntity> call() { | ||
return repository.getSurahs(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
class QuranCubit extends Cubit<int> { | ||
QuranCubit({ | ||
required this.getJuzUseCase, | ||
required this.getSurahsUseCase, | ||
}) : super(0); | ||
|
||
final GetJuzUseCase getJuzUseCase; | ||
final GetSurahsUseCase getSurahsUseCase; | ||
|
||
void change(int? val) => emit(val ?? 0); | ||
|
||
List<JuzEntity> getJuz() { | ||
return getJuzUseCase(); | ||
} | ||
|
||
List<SurahEntity> getSurah() { | ||
return getSurahsUseCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'cubit/quran_cubit.dart'; | ||
export 'view/page_view_item.dart'; | ||
export 'view/quran_view.dart'; |
Oops, something went wrong.