Skip to content

Commit

Permalink
fixed some repo issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-dor committed Dec 15, 2024
1 parent 035960a commit 7a212a3
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ final class SearchScreenBlocFactory implements Factory<MainSearchScreenBloc> {

return MainSearchScreenBloc(
screenRepo: searchScreenRepo,
youtubeDataApi: _youtubeDataApi,
hiveDatabaseHelper: _hiveDatabaseHelper,
);
}
Expand Down
18 changes: 5 additions & 13 deletions lib/features/search_screen/bloc/main_search_screen_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:speech_to_text/speech_recognition_result.dart';
import 'package:youtube/core/api/api_get_data/rest_api_get_video_data.dart';
import 'package:youtube/core/utils/enums.dart';
import 'package:youtube/core/utils/hive_database_helper/hive_database_helper.dart';
import 'package:youtube/core/utils/regex_helper/regex_helper.dart';
import 'package:youtube/core/youtube_data_api/youtube_data_api.dart';
import 'package:youtube/core/youtube_data_api/models/thumbnail.dart';
import 'package:youtube/core/youtube_data_api/models/video.dart' as ytv;
import 'package:youtube/core/youtube_data_api/models/video_data.dart' as ytvdata;
Expand All @@ -18,19 +16,14 @@ import 'search_screen_states.dart';
import 'state_model/search_screen_state_model.dart';

class MainSearchScreenBloc extends Bloc<SearchScreenEvents, SearchScreenStates> with RegexHelper {
final YoutubeDataApi _youtubeDataApi;
final HiveDatabaseHelper _hiveDatabaseHelper;
final SearchScreenRepo _screenRepo;

late final SearchScreenStateModel _currentState;

final SearchScreenRepo _screenRepo;

MainSearchScreenBloc(
{required SearchScreenRepo screenRepo,
required YoutubeDataApi youtubeDataApi,
required HiveDatabaseHelper hiveDatabaseHelper})
{required SearchScreenRepo screenRepo, required HiveDatabaseHelper hiveDatabaseHelper})
: _screenRepo = screenRepo,
_youtubeDataApi = youtubeDataApi,
_hiveDatabaseHelper = hiveDatabaseHelper,
super(InitialSearchScreenState(SearchScreenStateModel())) {
_currentState = state.searchScreenStateModel;
Expand Down Expand Up @@ -211,8 +204,7 @@ class MainSearchScreenBloc extends Bloc<SearchScreenEvents, SearchScreenStates>
if (_currentState.searchController.text.trim().contains("https")) {
final extractIdFromUrl = videoId(_currentState.searchController.text.trim());
if (extractIdFromUrl.isNotEmpty) {
final searchById =
await RestApiGetVideoData(youtubeDataApi: _youtubeDataApi).getVideoInfo(
final searchById = await _screenRepo.getVideoInfo(
videoContent: TypeContent.snippet,
videoId: extractIdFromUrl,
);
Expand Down Expand Up @@ -249,7 +241,7 @@ class MainSearchScreenBloc extends Bloc<SearchScreenEvents, SearchScreenStates>
}
//
} else {
var data = await RestApiGetVideoData(youtubeDataApi: _youtubeDataApi).getSearchVideo(
var data = await _screenRepo.getSearchVideo(
q: _currentState.searchController.text,
refresh: true,
orderBy: _currentState.orderBy?.id,
Expand Down Expand Up @@ -297,7 +289,7 @@ class MainSearchScreenBloc extends Bloc<SearchScreenEvents, SearchScreenStates>
// var searchBodyCubit = BlocProvider.of<SearchBodyCubit>(event.context);
if (event.isLoadedSearchBodyState) return;
try {
var data = await RestApiGetVideoData(youtubeDataApi: _youtubeDataApi).getSearchVideo(
var data = await _screenRepo.getSearchVideo(
q: _currentState.searchController.text,
);

Expand Down
20 changes: 20 additions & 0 deletions lib/features/search_screen/data/repo/search_screen_repo_impl.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:youtube/core/utils/enums.dart';
import 'package:youtube/core/youtube_data_api/youtube_data_api.dart';
import 'package:youtube/features/search_screen/data/source/suggestion_datasoruce.dart';
import 'package:youtube/features/search_screen/data/source/suggestion_datasource_impl.dart';
Expand All @@ -11,4 +12,23 @@ class SearchScreenRepoImpl implements SearchScreenRepo {
@override
Future<Map<String, dynamic>> getSuggestionSearch(String query) =>
_suggestionDatasource.getSuggestionSearch(query);

@override
Future<Map<String, dynamic>> getSearchVideo({
required String q,
bool refresh = false,
String? orderBy,
}) {
// TODO: implement getSearchVideo
throw UnimplementedError();
}

@override
Future<Map<String, dynamic>> getVideoInfo({
required TypeContent videoContent,
required String? videoId,
}) {
// TODO: implement getVideoInfo
throw UnimplementedError();
}
}
13 changes: 13 additions & 0 deletions lib/features/search_screen/data/source/suggestion_datasoruce.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import 'package:youtube/core/utils/enums.dart';

abstract interface class SuggestionDatasource {
Future<Map<String, dynamic>> getSuggestionSearch(String query);

Future<Map<String, dynamic>> getVideoInfo({
required TypeContent videoContent,
required String? videoId,
});

Future<Map<String, dynamic>> getSearchVideo({
required String q,
bool refresh = false,
String? orderBy,
});
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:youtube/core/api/api_get_data/rest_api_get_video_data.dart';
import 'package:youtube/core/utils/enums.dart';
import 'package:youtube/core/youtube_data_api/youtube_data_api.dart';
import 'package:youtube/features/search_screen/data/source/suggestion_datasoruce.dart';

Expand All @@ -7,15 +9,12 @@ class SuggestionDatasourceImpl implements SuggestionDatasource {

SuggestionDatasourceImpl(this._youtubeDataApi);


@override
Future<Map<String, dynamic>> getSuggestionSearch(String query) async {
Map<String, dynamic> result = {};
try {
var response = await _youtubeDataApi.fetchSuggestions(
query
.trim()
.isEmpty ? '""' : query.trim(),
query.trim().isEmpty ? '""' : query.trim(),
);

List<String> data = response.map((e) => e).toList();
Expand All @@ -29,4 +28,28 @@ class SuggestionDatasourceImpl implements SuggestionDatasource {
}
return result;
}

@override
Future<Map<String, dynamic>> getSearchVideo({
required String q,
bool refresh = false,
String? orderBy,
}) {
return RestApiGetVideoData(youtubeDataApi: _youtubeDataApi).getSearchVideo(
q: q,
refresh: true,
orderBy: orderBy,
);
}

@override
Future<Map<String, dynamic>> getVideoInfo({
required TypeContent videoContent,
required String? videoId,
}) {
return RestApiGetVideoData(youtubeDataApi: _youtubeDataApi).getVideoInfo(
videoContent: TypeContent.snippet,
videoId: videoId,
);
}
}
13 changes: 13 additions & 0 deletions lib/features/search_screen/domain/repo/search_screen_repo.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import 'package:youtube/core/utils/enums.dart';

abstract interface class SearchScreenRepo {
Future<Map<String, dynamic>> getSuggestionSearch(String query);

Future<Map<String, dynamic>> getVideoInfo({
required TypeContent videoContent,
required String? videoId,
});

Future<Map<String, dynamic>> getSearchVideo({
required String q,
bool refresh = false,
String? orderBy,
});
}

0 comments on commit 7a212a3

Please sign in to comment.