-
-
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.
finish changing read module architecture
- Loading branch information
Showing
45 changed files
with
263 additions
and
176 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,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'; |
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
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,3 +1,3 @@ | ||
export 'entity/home_model.dart'; | ||
export 'entity/home_entity.dart'; | ||
export 'repository/home_repository.dart'; | ||
export 'usecase/get_data_usecase.dart'; |
4 changes: 2 additions & 2 deletions
4
...odules/home/domain/entity/home_model.dart → ...dules/home/domain/entity/home_entity.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
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,5 +1,5 @@ | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
abstract class HomeRepository { | ||
Future<HomeModel> getData(String token); | ||
Future<HomeEntity> getData(String token); | ||
} |
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
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
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,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'; |
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,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<String, dynamic> json) => _$FiltersResponseFromJson(json); | ||
Map<String, dynamic> toJson() => _$FiltersResponseToJson(this); | ||
|
||
@JsonKey(name: 'page_number') | ||
final String pageNumber; | ||
} |
6 changes: 3 additions & 3 deletions
6
...modules/read/domain/entity/filters.g.dart → ...s/read/data/model/filters_response.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json) => _$MetaResponseFromJson(json); | ||
Map<String, dynamic> toJson() => _$MetaResponseToJson(this); | ||
|
||
final FiltersResponse filters; | ||
} |
8 changes: 4 additions & 4 deletions
8
...ib/modules/read/domain/entity/meta.g.dart → ...ules/read/data/model/meta_response.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json) => _$QuranPageResponseFromJson(json); | ||
Map<String, dynamic> toJson() => _$QuranPageResponseToJson(this); | ||
|
||
final List<VerseResponse> verses; | ||
final MetaResponse meta; | ||
} |
10 changes: 5 additions & 5 deletions
10
...modules/read/data/model/quran_page.g.dart → ...ead/data/model/quran_page_response.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json) => _$VerseResponseFromJson(json); | ||
Map<String, dynamic> toJson() => _$VerseResponseToJson(this); | ||
|
||
final int id; | ||
@JsonKey(name: 'verse_key') | ||
final String verseKey; | ||
@JsonKey(name: 'text_imlaei') | ||
final String textUthmani; | ||
} |
6 changes: 3 additions & 3 deletions
6
...b/modules/read/domain/entity/verse.g.dart → ...les/read/data/model/verse_response.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 32 additions & 18 deletions
50
app/lib/modules/read/data/repository/read_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 |
---|---|---|
@@ -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<QuranPage?> 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<QuranPageEntity?> 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(), | ||
); | ||
} | ||
} |
15 changes: 9 additions & 6 deletions
15
app/lib/modules/read/data/repository/read_theme_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 |
---|---|---|
@@ -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<ReadThemeState> getInitialThemeState() async { | ||
return localDataSource.getInitialThemeState(); | ||
ReadThemeState get getInitialThemeState { | ||
return localThemeDataSource.initialTheme; | ||
} | ||
|
||
@override | ||
Future<void> saveThemeState(ReadThemeState themeState) async { | ||
return localDataSource.saveThemeState(themeState); | ||
return localThemeDataSource.saveThemeState(themeState); | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
app/lib/modules/read/data/source/local_theme_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
11 changes: 6 additions & 5 deletions
11
app/lib/modules/read/data/source/read_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
Oops, something went wrong.