Skip to content

Commit

Permalink
library and addtoplaylist cubit fix -> 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Mar 24, 2024
1 parent 2b743bb commit 0f34e70
Show file tree
Hide file tree
Showing 23 changed files with 441 additions and 378 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ jobs:
run: jarsigner --verify --verbose build/app/outputs/flutter-apk/app-release.apk

- name: Rename APK file
run: mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/bloomee_tunes_v2.2.1+${{github.run_number}}.apk
run: mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/bloomee_tunes_v2.3.0+${{github.run_number}}.apk

- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: Release
path: |
build/app/outputs/flutter-apk/bloomee_tunes_v2.2.1+${{github.run_number}}.apk
build/app/outputs/flutter-apk/bloomee_tunes_v2.3.0+${{github.run_number}}.apk
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/flutter-apk/bloomee_tunes_v2.2.1+${{github.run_number}}.apk"
tag: v2.2.1+${{github.run_number}}
artifacts: "build/app/outputs/flutter-apk/bloomee_tunes_v2.3.0+${{github.run_number}}.apk"
tag: v2.3.0+${{github.run_number}}
token: ${{secrets.SECRET_KEY}}
62 changes: 3 additions & 59 deletions lib/blocs/add_to_playlist/cubit/add_to_playlist_cubit.dart
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 lib/blocs/add_to_playlist/cubit/add_to_playlist_state.dart
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 lib/blocs/internet_connectivity/cubit/connectivity_cubit.dart
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 lib/blocs/internet_connectivity/cubit/connectivity_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
part of 'connectivity_cubit.dart';

enum ConnectivityState { connected, disconnected }
125 changes: 66 additions & 59 deletions lib/blocs/library/cubit/library_items_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,93 @@
import 'dart:developer';

import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:Bloomee/model/MediaPlaylistModel.dart';
import 'package:Bloomee/services/db/GlobalDB.dart';
import 'package:equatable/equatable.dart';

import 'package:Bloomee/model/songModel.dart';
import 'package:Bloomee/screens/widgets/snackbar.dart';
import 'package:Bloomee/services/db/GlobalDB.dart';
import 'package:Bloomee/services/db/bloomee_db_service.dart';
import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart';
import 'package:Bloomee/utils/load_Image.dart';

part 'library_items_state.dart';

class LibraryItemsCubit extends Cubit<LibraryItemsState> {
Stream<void>? playlistWatcherDB;
List<PlaylistItemProperties> playlistItems = List.empty();
BloomeeDBCubit bloomeeDBCubit;
List<MediaPlaylist> mediaPlaylist = [];
LibraryItemsState libraryItemsState =
LibraryItemsState(playlists: List.empty(growable: true));
List<MediaPlaylistDB> mediaPlaylistsDB = [];

LibraryItemsCubit({required this.bloomeeDBCubit})
: super(LibraryItemsInitial()) {
bloomeeDBCubit.refreshLibrary.listen(
(value) {
log(value.toString(), name: "libItemsCubit");
if (value) {
getAndEmitPlaylists();
log("got refresh command", name: "libItemsCubit");
}
},
);
LibraryItemsCubit({
required this.bloomeeDBCubit,
}) : super(LibraryItemsInitial()) {
getAndEmitPlaylists();
getDBWatcher();
}

Future<void> getAndEmitPlaylists() async {
List<PlaylistItemProperties> _playlists = List.empty(growable: true);
libraryItemsState =
LibraryItemsState(playlists: List.empty(growable: true));

mediaPlaylist = await bloomeeDBCubit.getListOfPlaylists2();

// List<String> _playlists = List.empty(growable: true);

// if (libraryItemsState.playlists.isNotEmpty) {
// for (var element in libraryItemsState.playlists) {
// _playlists.add(element.playlistName ?? "Unknown");
// }
// libraryItemsState.playlists = [];
// }
libraryItemsState.playlists.clear();
log("emitted from library0 ${_playlists.length} - MediaPlaylists ${mediaPlaylist.length}",
name: "libItemsCubit");
Future<void> getDBWatcher() async {
playlistWatcherDB = await BloomeeDBService.getPlaylistsWatcher();
playlistWatcherDB?.listen((event) {
getAndEmitPlaylists();
});
}

if (mediaPlaylist.length > 0) {
for (var element in mediaPlaylist) {
ImageProvider _tempProvider;
Future<void> getAndEmitPlaylists() async {
mediaPlaylistsDB = await BloomeeDBService.getPlaylists4Library();
if (mediaPlaylistsDB.isNotEmpty) {
playlistItems = mediaPlaylistsDB2ItemProperties(mediaPlaylistsDB);

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: "${element.mediaItems.length} Items");
// libraryItemsState.playlists.add(_playlistItem);
_playlists.add(_playlistItem);
emit(LibraryItemsState(playlists: playlistItems));
} else {
emit(LibraryItemsInitial());
}
}

// libraryItemsState.playlistNames?.add(element.albumName);
// libraryItemsState.subTitles?.add("Saavan");
}
if (_playlists.length == mediaPlaylist.length) {
emit(state.copyWith(playlists: _playlists));
List<PlaylistItemProperties> mediaPlaylistsDB2ItemProperties(
List<MediaPlaylistDB> _mediaPlaylistsDB) {
List<PlaylistItemProperties> _playlists = List.empty(growable: true);
if (_mediaPlaylistsDB.isNotEmpty) {
for (var element in _mediaPlaylistsDB) {
log("${element.playlistName}", name: "libItemCubit");
_playlists.add(
PlaylistItemProperties(
playlistName: element.playlistName,
subTitle: "${element.mediaItems.length} Items",
coverImgUrl: element.mediaItems.isNotEmpty
? element.mediaItems.first.artURL
: null,
),
);
}
log("emitted from library ${_playlists.length} - MediaPlaylists ${mediaPlaylist.length}",
name: "libItemsCubit");
}
return _playlists;
}

void removePlaylist(MediaPlaylistDB mediaPlaylistDB) {
if (mediaPlaylistDB.playlistName != "Null") {
bloomeeDBCubit.removePlaylist(mediaPlaylistDB);
BloomeeDBService.removePlaylist(mediaPlaylistDB);
// getAndEmitPlaylists();
SnackbarService.showMessage(
"Playlist ${mediaPlaylistDB.playlistName} removed");
}
}

void addToPlaylist(
MediaItemModel mediaItem, MediaPlaylistDB mediaPlaylistDB) {
if (mediaPlaylistDB.playlistName != "Null") {
bloomeeDBCubit.addMediaItemToPlaylist(mediaItem, mediaPlaylistDB);
getAndEmitPlaylists();
SnackbarService.showMessage(
"Added ${mediaItem.title} to ${mediaPlaylistDB.playlistName}");
}
}

void removeFromPlaylist(
MediaItemModel mediaItem, MediaPlaylistDB mediaPlaylistDB) {
if (mediaPlaylistDB.playlistName != "Null") {
bloomeeDBCubit.removeMediaFromPlaylist(mediaItem, mediaPlaylistDB);
getAndEmitPlaylists();
SnackbarService.showMessage(
"Removed ${mediaItem.title} from ${mediaPlaylistDB.playlistName}");
}
}
}
Loading

0 comments on commit 0f34e70

Please sign in to comment.