-
-
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.
- Loading branch information
Showing
34 changed files
with
212 additions
and
83 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
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,4 @@ | ||
export 'repository/read_repository_impl.dart'; | ||
export 'repository/read_theme_repository_impl.dart'; | ||
export 'source/source.dart'; | ||
export 'model/quran_page.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
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
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'); | ||
} | ||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
class ReadThemeRepositoryImpl implements ReadThemeRepository { | ||
const ReadThemeRepositoryImpl({required this.localDataSource}); | ||
final LocalThemeDataSource localDataSource; | ||
|
||
@override | ||
Future<ReadThemeState> getInitialThemeState() async { | ||
return localDataSource.getInitialThemeState(); | ||
} | ||
|
||
@override | ||
Future<void> saveThemeState(ReadThemeState themeState) async { | ||
return localDataSource.saveThemeState(themeState); | ||
} | ||
} |
15 changes: 7 additions & 8 deletions
15
...les/read/services/read_theme_service.dart → .../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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import 'package:my_quran/constants/contants.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
import 'dart:convert'; | ||
|
||
import 'package:mq_storage/mq_storage.dart'; | ||
import 'package:my_quran/constants/contants.dart'; | ||
import 'package:my_quran/modules/read/logic/read_theme_cubit.dart'; | ||
|
||
class ReadThemeService { | ||
const ReadThemeService(this.storage); | ||
class LocalThemeDataSource { | ||
const LocalThemeDataSource(this.storage); | ||
|
||
final PreferencesStorage storage; | ||
|
||
ReadThemeState get init { | ||
ReadThemeState getInitialThemeState() { | ||
final value = storage.readString(key: AppConst.readThemeKey); | ||
return value != null ? ReadThemeState.fromJson(json.decode(value) as Map<String, dynamic>) : const ReadThemeState(); | ||
} | ||
|
||
Future<void> saveChanges(ReadThemeState theme) async { | ||
final value = json.encode(theme.toJson()); | ||
Future<void> saveThemeState(ReadThemeState themeState) async { | ||
final value = json.encode(themeState.toJson()); | ||
await storage.writeString(key: AppConst.readThemeKey, value: value); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:mq_storage/mq_storage.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
class ReadLocalDataSource { | ||
const ReadLocalDataSource(this.storage); | ||
|
||
final PreferencesStorage storage; | ||
|
||
Future<QuranPage?> getPage(int page, String quranFmt) async { | ||
final key = 'quran-$quranFmt-$page'; | ||
final localValue = storage.readString(key: key); | ||
|
||
if (localValue != null) { | ||
final data = jsonDecode(localValue); | ||
return QuranPage.fromJson(data as Map<String, dynamic>); | ||
} | ||
return null; | ||
} | ||
|
||
Future<void> cachePage(int page, String quranFmt, QuranPage pageData) async { | ||
final key = 'quran-$quranFmt-$page'; | ||
await storage.writeString(key: key, value: jsonEncode(pageData.toJson())); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/lib/modules/read/data/source/read_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:my_quran/config/config.dart'; | ||
import 'package:my_quran/core/core.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
class ReadRemoteDataSource { | ||
const ReadRemoteDataSource(this.remoteClient); | ||
|
||
final RemoteClient remoteClient; | ||
|
||
Future<QuranPage?> fetchPage(int page, String quranFmt) async { | ||
final remoteValue = await remoteClient.get<QuranPage>( | ||
apiConst.verse(page, quranFmt), | ||
fromJson: QuranPage.fromJson, | ||
); | ||
|
||
return remoteValue.fold( | ||
(l) => throw Exception('Failed to fetch remote data $l'), | ||
(r) => r, | ||
); | ||
} | ||
} |
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 'read_local_data_source.dart'; | ||
export 'read_remote_data_source.dart'; | ||
export '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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'repository/read_repository.dart'; | ||
export 'repository/read_theme_repository.dart'; | ||
export 'usecase/usecase.dart'; | ||
export 'entity/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'filters.dart'; | ||
export 'meta.dart'; | ||
export 'verse.dart'; |
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
app/lib/models/quran_page/meta.dart → app/lib/modules/read/domain/entity/meta.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,5 @@ | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
abstract class ReadRepository { | ||
Future<QuranPage?> getPage(int page, String quranFmt); | ||
} |
6 changes: 6 additions & 0 deletions
6
app/lib/modules/read/domain/repository/read_theme_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 ReadThemeRepository { | ||
Future<ReadThemeState> getInitialThemeState(); | ||
Future<void> saveThemeState(ReadThemeState themeState); | ||
} |
10 changes: 10 additions & 0 deletions
10
app/lib/modules/read/domain/usecase/get_initial_theme_usecase.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:my_quran/modules/modules.dart'; | ||
|
||
class GetInitialThemeUseCase { | ||
const GetInitialThemeUseCase(this.repository); | ||
final ReadThemeRepository repository; | ||
|
||
Future<ReadThemeState> execute() { | ||
return repository.getInitialThemeState(); | ||
} | ||
} |
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,11 @@ | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
class GetReadPageUseCase { | ||
const GetReadPageUseCase(this.repository); | ||
|
||
final ReadRepository repository; | ||
|
||
Future<QuranPage?> getPage(int page, String quranFmt) { | ||
return repository.getPage(page, quranFmt); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/lib/modules/read/domain/usecase/save_theme_changes_usecase.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:my_quran/modules/modules.dart'; | ||
|
||
class SaveThemeChangesUseCase { | ||
const SaveThemeChangesUseCase(this.repository); | ||
final ReadThemeRepository repository; | ||
|
||
Future<void> execute(ReadThemeState themeState) { | ||
return repository.saveThemeState(themeState); | ||
} | ||
} |
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 'get_read_page.dart'; | ||
export 'get_initial_theme_usecase.dart'; | ||
export 'save_theme_changes_usecase.dart'; |
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,15 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:my_quran/modules/modules.dart'; | ||
|
||
part 'read_state.dart'; | ||
|
||
class ReadCubit extends Cubit<ReadState> { | ||
ReadCubit(this.getQuranPageUseCase) : super(const ReadState()); | ||
|
||
final GetReadPageUseCase getQuranPageUseCase; | ||
|
||
Future<QuranPage?> fetchQuranPage(int page) async { | ||
return getQuranPageUseCase.getPage(page, state.fmt.name); | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
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,4 @@ | ||
export 'logic/read_cubit.dart'; | ||
export 'logic/read_theme_cubit.dart'; | ||
export 'view/read_view.dart'; | ||
export 'view/pagination_view.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
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,6 +1,3 @@ | ||
export 'logic/read_cubit.dart'; | ||
export 'logic/read_theme_cubit.dart'; | ||
export 'services/read_service.dart'; | ||
export 'services/read_theme_service.dart'; | ||
export 'view/pagination_view.dart'; | ||
export 'view/read_view.dart'; | ||
export 'data/data.dart'; | ||
export 'domain/domain.dart'; | ||
export 'presentation/presentation.dart'; |
This file was deleted.
Oops, something went wrong.