Skip to content

Commit

Permalink
settings implt.
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Apr 9, 2024
1 parent 8e094f5 commit 62e4b52
Show file tree
Hide file tree
Showing 23 changed files with 1,158 additions and 125 deletions.
9 changes: 7 additions & 2 deletions lib/blocs/downloader/cubit/downloader_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,15 @@ class DownloaderCubit extends Cubit<DownloaderState> {
downPath = await getDownPath();
final String fileName;
if (song.extras!['source'] != 'youtube') {
fileName = "${song.title} by ${song.artist}.mp4";
fileName = "${song.title} by ${song.artist}.mp4"
.replaceAll('?', '-')
.replaceAll('/', '-');
} else {
fileName = "${song.title} by ${song.artist}.m4a";
fileName = "${song.title} by ${song.artist}.m4a"
.replaceAll('?', '-')
.replaceAll('/', '-');
}
log('downloading $fileName', name: "DownloaderCubit");
final String? taskId = await BloomeeDownloader.downloadSong(song,
fileName: fileName, filePath: downPath);
if (taskId != null) {
Expand Down
121 changes: 119 additions & 2 deletions lib/blocs/settings_cubit/cubit/settings_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,148 @@
import 'dart:developer';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
import 'package:Bloomee/services/db/bloomee_db_service.dart';
import 'package:bloc/bloc.dart';
import 'package:path_provider/path_provider.dart';
part 'settings_state.dart';

class SettingsCubit extends Cubit<SettingsState> {
SettingsCubit() : super(SettingsInitial()) {
initSettings();
autoUpdate();
}

void initSettings() {
BloomeeDBService.getSettingBool(GlobalStrConsts.autoUpdateNotify)
.then((value) {
emit(state.copyWith(autoUpdateNotify: value ?? false));
});

BloomeeDBService.getSettingBool(GlobalStrConsts.autoSlideCharts)
.then((value) {
emit(state.copyWith(autoSlideCharts: value ?? true));
});

// Directory dir = Directory('/storage/emulated/0/Music');
String? path;

BloomeeDBService.getSettingStr(GlobalStrConsts.downPathSetting)
.then((value) async {
await getDownloadsDirectory().then((value) {
if (value != null) {
path = value.path;
}
});
emit(state.copyWith(
downPath: (value ?? path) ??
(await getApplicationDocumentsDirectory()).path));
});

BloomeeDBService.getSettingStr(GlobalStrConsts.downQuality,
defaultValue: '320 kbps')
.then((value) {
emit(state.copyWith(downQuality: value ?? "320 kbps"));
});

BloomeeDBService.getSettingStr(GlobalStrConsts.ytDownQuality).then((value) {
emit(state.copyWith(ytDownQuality: value ?? "High"));
});

BloomeeDBService.getSettingStr(
GlobalStrConsts.strmQuality,
).then((value) {
emit(state.copyWith(strmQuality: value ?? "96 kbps"));
});

BloomeeDBService.getSettingStr(GlobalStrConsts.ytStrmQuality).then((value) {
emit(state.copyWith(ytStrmQuality: value ?? "Low"));
});

BloomeeDBService.getSettingStr(GlobalStrConsts.backupPath)
.then((value) async {
if (value == null || value == "") {
await BloomeeDBService.putSettingStr(GlobalStrConsts.backupPath,
(await getApplicationDocumentsDirectory()).path);
emit(state.copyWith(
backupPath: (await getApplicationDocumentsDirectory()).path));
} else {
emit(state.copyWith(backupPath: value));
}
});

BloomeeDBService.getSettingBool(GlobalStrConsts.autoBackup).then((value) {
emit(state.copyWith(autoBackup: value ?? false));
});
}

void autoUpdate() {
BloomeeDBService.getSettingBool(GlobalStrConsts.autoBackup).then((value) {
if (value != null || value == true) {
BloomeeDBService.createBackUp();
}
});
}

void updateAutoUpdateNotify(bool value) {
void setAutoUpdateNotify(bool value) {
BloomeeDBService.putSettingBool(GlobalStrConsts.autoUpdateNotify, value);
emit(state.copyWith(autoUpdateNotify: value));
}

void updateAutoSlideCharts(bool value) {
void setAutoSlideCharts(bool value) {
BloomeeDBService.putSettingBool(GlobalStrConsts.autoSlideCharts, value);
emit(state.copyWith(autoSlideCharts: value));
}

void setDownPath(String value) {
BloomeeDBService.putSettingStr(GlobalStrConsts.downPathSetting, value);
emit(state.copyWith(downPath: value));
}

void setDownQuality(String value) {
BloomeeDBService.putSettingStr(GlobalStrConsts.downQuality, value);
emit(state.copyWith(downQuality: value));
}

void setYtDownQuality(String value) {
BloomeeDBService.putSettingStr(GlobalStrConsts.ytDownQuality, value);
emit(state.copyWith(ytDownQuality: value));
}

void setStrmQuality(String value) {
BloomeeDBService.putSettingStr(GlobalStrConsts.strmQuality, value);
emit(state.copyWith(strmQuality: value));
}

void setYtStrmQuality(String value) {
BloomeeDBService.putSettingStr(GlobalStrConsts.ytStrmQuality, value);
emit(state.copyWith(ytStrmQuality: value));
}

void setBackupPath(String value) {
BloomeeDBService.putSettingStr(GlobalStrConsts.backupPath, value);
emit(state.copyWith(backupPath: value));
}

void setAutoBackup(bool value) {
BloomeeDBService.putSettingBool(GlobalStrConsts.autoBackup, value);
emit(state.copyWith(autoBackup: value));
}

Future<void> resetDownPath() async {
String? path;

await getDownloadsDirectory().then((value) {
if (value != null) {
path = value.path;
log(path.toString(), name: 'SettingsCubit');
}
});

if (path != null) {
BloomeeDBService.putSettingStr(GlobalStrConsts.downPathSetting, path!);
emit(state.copyWith(downPath: path));
log(path.toString(), name: 'SettingsCubit');
} else {
log("Path is null", name: 'SettingsCubit');
}
}
}
41 changes: 40 additions & 1 deletion lib/blocs/settings_cubit/cubit/settings_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,61 @@ part of 'settings_cubit.dart';
class SettingsState {
bool autoUpdateNotify;
bool autoSlideCharts;
String downPath;
String downQuality;
String ytDownQuality;
String strmQuality;
String ytStrmQuality;
String backupPath;
bool autoBackup;
SettingsState({
required this.autoUpdateNotify,
required this.autoSlideCharts,
required this.downPath,
required this.downQuality,
required this.ytDownQuality,
required this.strmQuality,
required this.ytStrmQuality,
required this.backupPath,
required this.autoBackup,
});

SettingsState copyWith({
bool? autoUpdateNotify,
bool? autoSlideCharts,
String? downPath,
String? downQuality,
String? ytDownQuality,
String? strmQuality,
String? ytStrmQuality,
String? backupPath,
bool? autoBackup,
}) {
return SettingsState(
autoUpdateNotify: autoUpdateNotify ?? this.autoUpdateNotify,
autoSlideCharts: autoSlideCharts ?? this.autoSlideCharts,
downPath: downPath ?? this.downPath,
downQuality: downQuality ?? this.downQuality,
ytDownQuality: ytDownQuality ?? this.ytDownQuality,
strmQuality: strmQuality ?? this.strmQuality,
ytStrmQuality: ytStrmQuality ?? this.ytStrmQuality,
backupPath: backupPath ?? this.backupPath,
autoBackup: autoBackup ?? this.autoBackup,
);
}
}

final class SettingsInitial extends SettingsState {
SettingsInitial() : super(autoUpdateNotify: false, autoSlideCharts: true);
SettingsInitial()
: super(
autoUpdateNotify: false,
autoSlideCharts: true,
downPath: "",
downQuality: "320 kbps",
ytDownQuality: "High",
strmQuality: "96 kbps",
ytStrmQuality: "Low",
backupPath: "",
autoBackup: true,
);
}
21 changes: 21 additions & 0 deletions lib/model/saavnModel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:Bloomee/model/songModel.dart';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
import 'package:Bloomee/services/db/bloomee_db_service.dart';

MediaItemModel fromSaavnSongMap2MediaItem(Map<dynamic, dynamic> songItem) {
return MediaItemModel(
Expand Down Expand Up @@ -31,3 +33,22 @@ List<MediaItemModel> fromSaavnSongMapList2MediaItemList(
.toList();
return mediaList;
}

Future<String?> getJsQualityURL(String url, {bool isStreaming = true}) async {
String ops =
isStreaming ? GlobalStrConsts.strmQuality : GlobalStrConsts.downQuality;
String? kUrl;
await BloomeeDBService.getSettingStr(ops).then((value) {
switch (value) {
case "96 kbps":
kUrl = url;
case "160 kbps":
kUrl = url.replaceAll('_96', '_160').replaceAll('_320', '_160');
case "320 kbps":
kUrl = url.replaceAll('_96', '_320').replaceAll('_160', '_320');
default:
kUrl = url.replaceAll('_160', '_96').replaceAll('_320', '_96');
}
});
return kUrl;
}
13 changes: 3 additions & 10 deletions lib/repository/Youtube/youtube_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,12 @@ class YouTubeServices {
return response;
}

Future<Map?> refreshLink(String id) async {
Future<Map?> refreshLink(String id, {String quality = 'Low'}) async {
final Video? res = await getVideoFromId(id);
if (res == null) {
return null;
}
String quality;
try {
quality = await BloomeeDBService.getSettingStr('quality',
defaultValue: 'Low') ??
'Low';
} catch (e) {
quality = 'Low';
}
// String quality = quality;
final Map? data = await formatVideo(video: res, quality: quality);
return data;
}
Expand Down Expand Up @@ -352,7 +345,7 @@ class YouTubeServices {
urls = await getUri(video);
}

finalUrl = quality == 'High' ? urls.last : urls.first;
finalUrl = ((quality == 'High') ? urls.last : urls.first);
expireAt = RegExp('expire=(.*?)&').firstMatch(finalUrl)!.group(1) ??
(DateTime.now().millisecondsSinceEpoch ~/ 1000 + 3600 * 5.5)
.toString();
Expand Down
6 changes: 6 additions & 0 deletions lib/routes_and_consts/global_str_consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ class GlobalStrConsts {
static const String spotifyAccessToken = "spotify_access_token";
static const String downPathSetting = "downloadPath";
static const String downloadPlaylist = "_DOWNLOADS";
static const String downQuality = "downloadQuality";
static const String ytDownQuality = "ytDownloadQuality";
static const String strmQuality = "streamQuality";
static const String ytStrmQuality = "ytStreamQuality";
static const String backupPath = "backupPath";
static const String autoBackup = "autoBackup";
}
3 changes: 1 addition & 2 deletions lib/screens/screen/chart/chart_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import 'package:Bloomee/screens/widgets/chart_list_tile.dart';
import 'package:Bloomee/theme_data/default.dart';

class ChartScreen extends StatefulWidget {
// ChartCubit? chartCubit;
final String chartName;
ChartScreen({Key? key, required this.chartName}) : super(key: key);
const ChartScreen({Key? key, required this.chartName}) : super(key: key);

@override
State<ChartScreen> createState() => _ChartScreenState();
Expand Down
4 changes: 3 additions & 1 deletion lib/screens/screen/home_views/notification_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class NotificationView extends StatelessWidget {
appBar: AppBar(
backgroundColor: Default_Theme.themeColor,
foregroundColor: Default_Theme.primaryColor1,
surfaceTintColor: Default_Theme.themeColor,
centerTitle: true,
title: Text(
'Notifications',
style: const TextStyle(
color: Default_Theme.primaryColor1,
fontSize: 25,
fontSize: 20,
fontWeight: FontWeight.bold)
.merge(Default_Theme.secondoryTextStyle),
),
Expand Down
Loading

0 comments on commit 62e4b52

Please sign in to comment.