-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
library and addtoplaylist cubit fix -> 2.3.0
- Loading branch information
1 parent
2b743bb
commit 0f34e70
Showing
23 changed files
with
441 additions
and
378 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
62 changes: 3 additions & 59 deletions
62
lib/blocs/add_to_playlist/cubit/add_to_playlist_cubit.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,70 +1,14 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
import 'dart:developer'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:rxdart/rxdart.dart'; | ||
import 'package:Bloomee/model/songModel.dart'; | ||
import 'package:Bloomee/routes_and_consts/global_conts.dart'; | ||
|
||
import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart'; | ||
import 'package:Bloomee/utils/load_Image.dart'; | ||
|
||
import '../../../model/MediaPlaylistModel.dart'; | ||
|
||
part 'add_to_playlist_state.dart'; | ||
|
||
class AddToPlaylistCubit extends Cubit<AddToPlaylistState> { | ||
BloomeeDBCubit bloomeeDBCubit; | ||
BehaviorSubject<MediaItemModel> mediaItemModelBS = | ||
BehaviorSubject.seeded(mediaItemModelNull); | ||
AddToPlaylistCubit({ | ||
required this.bloomeeDBCubit, | ||
}) : super(AddToPlaylistInitial()) { | ||
getAndEmitPlaylists(); | ||
} | ||
|
||
List<MediaPlaylist> mediaPlaylist = []; | ||
|
||
AddToPlaylistState addToPlaylistState = | ||
AddToPlaylistState(playlists: List.empty(growable: true)); | ||
|
||
Future<void> getAndEmitPlaylists() async { | ||
addToPlaylistState = | ||
AddToPlaylistState(playlists: List.empty(growable: true)); | ||
mediaPlaylist = await bloomeeDBCubit.getListOfPlaylists2(); | ||
List<String> _playlists = List.empty(growable: true); | ||
if (addToPlaylistState.playlists.isNotEmpty) { | ||
for (var element in addToPlaylistState.playlists) { | ||
_playlists.add(element.playlistName ?? "Unknown"); | ||
} | ||
} | ||
if (mediaPlaylist.length > 0) { | ||
for (var element in mediaPlaylist) { | ||
// if (_playlists.contains(element.albumName)) { | ||
// int? _idx = _playlists.indexOf(element.albumName); | ||
|
||
// addToPlaylistState.playlists.removeAt(_idx); | ||
// } | ||
ImageProvider _tempProvider; | ||
|
||
if (element.mediaItems.length > 0) { | ||
_tempProvider = | ||
await getImageProvider(element.mediaItems[0].artUri.toString()); | ||
} else { | ||
_tempProvider = await getImageProvider(""); | ||
} | ||
PlaylistItemProperties _playlistItem = PlaylistItemProperties( | ||
playlistName: element.albumName, | ||
imageProvider: _tempProvider, | ||
subTitle: "Saavan"); | ||
addToPlaylistState.playlists.add(_playlistItem); | ||
AddToPlaylistCubit() : super(AddToPlaylistInitial()); | ||
|
||
// addToPlaylistState.playlistNames?.add(element.albumName); | ||
// addToPlaylistState.subTitles?.add("Saavan"); | ||
} | ||
emit(state.copyWith(playlists: addToPlaylistState.playlists)); | ||
log("emitted from addtoplaylist ${_playlists.toString()} - ${addToPlaylistState.playlists.length} - MediaPlaylists ${mediaPlaylist}"); | ||
} | ||
void setMediaItemModel(MediaItemModel mediaItemModel) { | ||
emit(state.copyWith(mediaItemModel: mediaItemModel)); | ||
} | ||
} |
59 changes: 35 additions & 24 deletions
59
lib/blocs/add_to_playlist/cubit/add_to_playlist_state.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,44 +1,55 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
part of 'add_to_playlist_cubit.dart'; | ||
|
||
class PlaylistItemProperties { | ||
String? playlistName; | ||
ImageProvider? imageProvider; | ||
String? subTitle; | ||
PlaylistItemProperties({ | ||
required this.playlistName, | ||
required this.imageProvider, | ||
required this.subTitle, | ||
// class PlaylistItemProperties { | ||
// String? playlistName; | ||
// ImageProvider? imageProvider; | ||
// String? subTitle; | ||
// PlaylistItemProperties({ | ||
// required this.playlistName, | ||
// required this.imageProvider, | ||
// required this.subTitle, | ||
// }); | ||
|
||
// @override | ||
// bool operator ==(covariant PlaylistItemProperties other) { | ||
// if (identical(this, other)) return true; | ||
|
||
// return other.playlistName == playlistName && | ||
// other.imageProvider == imageProvider && | ||
// other.subTitle == subTitle; | ||
// } | ||
|
||
// @override | ||
// int get hashCode => | ||
// playlistName.hashCode ^ imageProvider.hashCode ^ subTitle.hashCode; | ||
// } | ||
|
||
class AddToPlaylistState { | ||
MediaItemModel mediaItemModel; | ||
AddToPlaylistState({ | ||
required this.mediaItemModel, | ||
}); | ||
|
||
@override | ||
bool operator ==(covariant PlaylistItemProperties other) { | ||
bool operator ==(covariant AddToPlaylistState other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other.playlistName == playlistName && | ||
other.imageProvider == imageProvider && | ||
other.subTitle == subTitle; | ||
return other.mediaItemModel == mediaItemModel; | ||
} | ||
|
||
@override | ||
int get hashCode => | ||
playlistName.hashCode ^ imageProvider.hashCode ^ subTitle.hashCode; | ||
} | ||
|
||
class AddToPlaylistState { | ||
List<PlaylistItemProperties> playlists; | ||
AddToPlaylistState({ | ||
required this.playlists, | ||
}); | ||
int get hashCode => mediaItemModel.hashCode; | ||
|
||
AddToPlaylistState copyWith({ | ||
List<PlaylistItemProperties>? playlists, | ||
MediaItemModel? mediaItemModel, | ||
}) { | ||
return AddToPlaylistState( | ||
playlists: playlists ?? this.playlists, | ||
mediaItemModel: mediaItemModel ?? this.mediaItemModel, | ||
); | ||
} | ||
} | ||
|
||
final class AddToPlaylistInitial extends AddToPlaylistState { | ||
AddToPlaylistInitial() : super(playlists: List.empty()); | ||
AddToPlaylistInitial() : super(mediaItemModel: mediaItemModelNull); | ||
} |
23 changes: 23 additions & 0 deletions
23
lib/blocs/internet_connectivity/cubit/connectivity_cubit.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,23 @@ | ||
import 'dart:async'; | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
part 'connectivity_state.dart'; | ||
|
||
class ConnectivityCubit extends Cubit<ConnectivityState> { | ||
StreamSubscription<ConnectivityResult>? _subscription; | ||
ConnectivityCubit() : super(ConnectivityState.disconnected) { | ||
_subscription = Connectivity().onConnectivityChanged.listen((event) { | ||
if (event == ConnectivityResult.none || | ||
event == ConnectivityResult.bluetooth) { | ||
emit(ConnectivityState.disconnected); | ||
} else { | ||
emit(ConnectivityState.connected); | ||
} | ||
}); | ||
} | ||
@override | ||
Future<void> close() { | ||
_subscription?.cancel(); | ||
return super.close(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
lib/blocs/internet_connectivity/cubit/connectivity_state.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 @@ | ||
part of 'connectivity_cubit.dart'; | ||
|
||
enum ConnectivityState { connected, disconnected } |
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.