Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change quran audio architecture #204

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/lib/app/presentation/view/app_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class MyApp extends StatelessWidget {
create: (context) => QuranAudioCubit(
AudioPlayer(),
context.read<NetworkClient>(),
GetAudioSurahsUseCase(
QuranAudioRepositoryImpl(
QuranAudioDataSource(),
),
),
)..init(),
),
],
Expand Down
2 changes: 2 additions & 0 deletions app/lib/modules/quran_audio/data/data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'repository/quran_audio_repository_impl.dart';
export 'source/quran_audio_data_source.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:meta/meta.dart';
import 'package:my_quran/modules/modules.dart';

@immutable
final class QuranAudioRepositoryImpl implements QuranAudioRepository {
const QuranAudioRepositoryImpl(this.localDataSource);

final QuranAudioDataSource localDataSource;

@override
List<SurahEntity> getSurahs() {
final surahResponses = localDataSource.getSurahs();
final surahEntities = surahResponses.map(_convertData).toList();
return surahEntities;
}

SurahEntity _convertData(SurahResponse response) {
return SurahEntity(
id: response.id,
name: response.name,
aya: response.aya,
pages: response.pages,
arabic: response.arabic,
);
}
}
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 QuranAudioDataSource {
List<SurahResponse> getSurahs() {
final surahs = surahData.map(SurahResponse.fromJson).toList();
return surahs;
}
}
2 changes: 2 additions & 0 deletions app/lib/modules/quran_audio/domain/domain.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'repository/quran_audio_repository.dart';
export 'usecase/get_surahs_usecase.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:my_quran/modules/modules.dart';

abstract class QuranAudioRepository {
List<SurahEntity> getSurahs();
}
13 changes: 13 additions & 0 deletions app/lib/modules/quran_audio/domain/usecase/get_surahs_usecase.dart
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 GetAudioSurahsUseCase {
const GetAudioSurahsUseCase(this.repository);

final QuranAudioRepository repository;

List<SurahEntity> call() {
return repository.getSurahs();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,22 @@ import 'package:my_quran/modules/modules.dart';
part 'quran_audio_state.dart';

class QuranAudioCubit extends Cubit<QuranAudioState> {
QuranAudioCubit(this.player, this.networkClient) : super(QuranAudioState());
QuranAudioCubit(
this.player,
this.networkClient,
this.getSurahsUseCase,
) : super(QuranAudioState());

final AudioPlayer player;
final NetworkClient networkClient;
late final Stream<SequenceState?> sequenceStateStream;
late final Stream<PlayerState> playerStateStream;
final GetAudioSurahsUseCase getSurahsUseCase;
late final List<SurahEntity> surahs;

SurahEntity _convertData(SurahResponse response) {
return SurahEntity(
id: response.id,
name: response.name,
aya: response.aya,
pages: response.pages,
arabic: response.arabic,
);
}

Future<void> init() async {
try {
surahs = surahData.map((surahResponse) => _convertData(SurahResponse.fromJson(surahResponse))).toList();
surahs = getSurahsUseCase();
sequenceStateStream = player.sequenceStateStream;
playerStateStream = player.playerStateStream;
final playList = ConcatenatingAudioSource(
Expand Down
3 changes: 3 additions & 0 deletions app/lib/modules/quran_audio/presentation/presentation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'cubit/quran_audio_cubit.dart';
export 'view/quran_audio_view.dart';
export 'widgets/audio_borrom_sheet.dart';
6 changes: 3 additions & 3 deletions app/lib/modules/quran_audio/quran_audio.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'logic/quran_audio_cubit.dart';
export 'view/quran_audio_view.dart';
export 'widgets/audio_borrom_sheet.dart';
export 'presentation/presentation.dart';
export 'domain/domain.dart';
export 'data/data.dart';
Loading