Skip to content

Commit

Permalink
Updated Version
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLixo committed Dec 8, 2024
1 parent 16c676f commit da02447
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 77 deletions.
3 changes: 2 additions & 1 deletion lib/app/app_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class _AppWidgetState extends State<AppWidget> with WidgetsBindingObserver {

if (state == AppLifecycleState.resumed) {
_onEnterApp();
} else if (state == AppLifecycleState.paused) {
}
if (state == AppLifecycleState.paused) {
_onExitApp();
}
}
Expand Down
20 changes: 5 additions & 15 deletions lib/app/core/controllers/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class PlayerController extends BaseAudioHandler
futures.add(pauseSong());

// Executa todas as operações em paralelo
final results = await Future.wait(futures);
final List<dynamic> results = await Future.wait(futures);

// Extraindo os resultados
songs.addAll(results[0] as List<SongModel>);
Expand All @@ -283,16 +283,8 @@ class PlayerController extends BaseAudioHandler

await songAllLoad(
songs,
typeLoad: [
UpdatedTypeLoad.folder,
UpdatedTypeLoad.image,
UpdatedTypeLoad.album,
UpdatedTypeLoad.artist,
],
typeInore: [
IgnoresLoad.duration,
IgnoresLoad.folders,
],
typeLoad: UpdatedTypeLoad.values,
typeInore: IgnoresLoad.values,
);
}

Expand Down Expand Up @@ -387,9 +379,8 @@ class PlayerController extends BaseAudioHandler
songList = songList.where((song) {
if (song.duration != null && song.duration! < (ignoreTime * 1000)) {
return false;
} else {
return true;
}
return true;
}).toList();
break;
case IgnoresLoad.folders:
Expand All @@ -399,9 +390,8 @@ class PlayerController extends BaseAudioHandler
if (ignoreFolder
.contains(song.data.split('/').reversed.skip(1).first)) {
return false;
} else {
return true;
}
return true;
}).toList();
break;
}
Expand Down
28 changes: 14 additions & 14 deletions lib/app/core/static/app_manifest.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:io';
import 'dart:math';
import 'dart:convert';
import 'dart:convert' as convert;

import 'package:flutter/services.dart';
import 'package:on_audio_query/on_audio_query.dart';
Expand All @@ -10,7 +10,7 @@ import 'package:get/instance_manager.dart';

abstract class AppManifest {
// ==================================================
static final AppShared sharedController = Get.find<AppShared>();
static final AppShared _sharedController = Get.find<AppShared>();

// ==================================================
static const String title = 'Player Hub';
Expand All @@ -33,15 +33,15 @@ abstract class AppManifest {
switch (type) {
case ImageQuality.low:
file = File(
'${sharedController.documentDir.path}/${id}_${ImageQuality.low.name}.jpg');
'${_sharedController.documentDir.path}/${id}_${ImageQuality.low.name}.jpg');
break;
case ImageQuality.high:
file = File(
'${sharedController.documentDir.path}/${id}_${ImageQuality.high.name}.jpg');
'${_sharedController.documentDir.path}/${id}_${ImageQuality.high.name}.jpg');
break;
}

return file.readAsBytes();
return await file.readAsBytes();
}

// ==================================================
Expand All @@ -50,7 +50,7 @@ abstract class AppManifest {
required ImageQuality type,
}) async {
final File targetFile =
File('${sharedController.documentDir.path}/${id}_${type.name}.jpg');
File('${_sharedController.documentDir.path}/${id}_${type.name}.jpg');

if (!await targetFile.exists()) {
await _generateImageFile(id: id);
Expand All @@ -65,9 +65,9 @@ abstract class AppManifest {
required Uint8List bytes,
}) async {
final File fileLow = File(
'${sharedController.documentDir.path}/${id}_${ImageQuality.low.name}.jpg');
'${_sharedController.documentDir.path}/${id}_${ImageQuality.low.name}.jpg');
final File fileHigh = File(
'${sharedController.documentDir.path}/${id}_${ImageQuality.high.name}.jpg');
'${_sharedController.documentDir.path}/${id}_${ImageQuality.high.name}.jpg');

await fileLow.writeAsBytes(bytes);
await fileHigh.writeAsBytes(bytes);
Expand All @@ -80,8 +80,8 @@ abstract class AppManifest {
final OnAudioQuery audioQuery = OnAudioQuery();

final List<String> filePaths = [
'${sharedController.documentDir.path}/${id}_${ImageQuality.low.name}.jpg',
'${sharedController.documentDir.path}/${id}_${ImageQuality.high.name}.jpg',
'${_sharedController.documentDir.path}/${id}_${ImageQuality.low.name}.jpg',
'${_sharedController.documentDir.path}/${id}_${ImageQuality.high.name}.jpg',
];

final List<Uint8List?> dataResults = await Future.wait([
Expand Down Expand Up @@ -130,15 +130,15 @@ abstract class AppManifest {

// ==================================================
static String encodeToBase64(String input) {
List<int> bytes = utf8.encode(input);
String encoded = base64.encode(bytes);
List<int> bytes = convert.utf8.encode(input);
String encoded = convert.base64.encode(bytes);
return encoded;
}

// ==================================================
static String decodeFromBase64(String encoded) {
List<int> decodedBytes = base64.decode(encoded);
String decoded = utf8.decode(decodedBytes);
List<int> decodedBytes = convert.base64.decode(encoded);
String decoded = convert.utf8.decode(decodedBytes);
return decoded;
}
}
12 changes: 2 additions & 10 deletions lib/app/core/types/app_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ mixin AppFunctions {
Future<void> showToast(String message) async {
final AppShared sharedController = Get.find<AppShared>();

final MethodChannel toast =
const MethodChannel("${AppManifest.package}/toast");
const MethodChannel toast = MethodChannel("${AppManifest.package}/toast");

try {
await toast.invokeMethod('showToast', {
Expand All @@ -41,16 +40,9 @@ mixin AppFunctions {
}
}

// ==================================================
void printDebug(dynamic debug) {
print('================================\n');
print(debug);
print('\n================================');
}

// ==================================================
String getGenerateHash([int length = 32]) {
const chars =
const String chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

return List.generate(
Expand Down
8 changes: 3 additions & 5 deletions lib/app/pages/edit/edit_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:on_audio_query/on_audio_query.dart';
import 'package:player_hub/app/core/enums/theme_types.dart';
// import 'package:player_hub/app/pages/edit/edit_controller.dart';
import 'package:player_hub/app/services/app_chrome.dart';
import 'package:player_hub/app/services/app_shared.dart';
import 'package:player_hub/app/core/static/app_colors.dart';
Expand All @@ -17,7 +16,6 @@ import 'package:helper_hub/src/theme_widget.dart';
import 'package:share_plus/share_plus.dart';

class EditPage extends StatelessWidget with AppFunctions {
// final EditController editController = Get.find<EditController>();
final PlayerController playerController = Get.find<PlayerController>();
final AppShared sharedController = Get.find<AppShared>();
final AppChrome chromeController = Get.find<AppChrome>();
Expand Down Expand Up @@ -57,13 +55,13 @@ class EditPage extends StatelessWidget with AppFunctions {
"${'edit_save'.tr}: ${sharedController.getTitle(song.id, song.title)}",
);
} catch (e) {
printDebug('Failed to save information.');
// print('Failed to save information.');
}
}

Future<void> _pickerFile() async {
try {
FilePickerResult? result = await FilePicker.platform.pickFiles(
final FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['jpg', 'jpeg', 'png'],
);
Expand All @@ -72,7 +70,7 @@ class EditPage extends StatelessWidget with AppFunctions {
imagePicker.value = File(result.files.single.path!);
}
} catch (e) {
printDebug('Failed to pick file.');
// print('Failed to pick file.');
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/app/pages/equalizer/equalize_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import 'package:player_hub/app/core/types/app_functions.dart';

class EqualizerController extends GetxController with AppFunctions {
// ==================================================
Rx<List<int>?> bandLevelRange = Rxn<List<int>>();
Rx<List<int>?> bandCenterFrequencies = Rxn<List<int>>();
final Rx<List<int>?> bandLevelRange = Rxn<List<int>>();
final Rx<List<int>?> bandCenterFrequencies = Rxn<List<int>>();

// ==================================================
final PlayerController playerController = Get.find<PlayerController>();
Expand Down
15 changes: 10 additions & 5 deletions lib/app/pages/equalizer/equalizer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import 'package:helper_hub/src/theme_widget.dart';
import 'package:player_hub/app/pages/equalizer/equalize_controller.dart';

class EqualizerPage extends StatelessWidget with AppFunctions {
final EqualizerController equalizerController =
Get.find<EqualizerController>();
final AppShared sharedController = Get.find<AppShared>();

EqualizerPage({
const EqualizerPage({
super.key,
});

@override
Widget build(BuildContext context) {
final EqualizerController equalizerController =
Get.find<EqualizerController>();
final AppShared sharedController = Get.find<AppShared>();

return Scaffold(
backgroundColor: AppColors.current().background,
appBar: AppBar(
Expand Down Expand Up @@ -118,6 +118,9 @@ class EqualizerPage extends StatelessWidget with AppFunctions {
required bool enabled,
required List<int> bandLevelRange,
}) {
final EqualizerController equalizerController =
Get.find<EqualizerController>();

int bandId = 0;

return Column(
Expand Down Expand Up @@ -149,6 +152,8 @@ class EqualizerPage extends StatelessWidget with AppFunctions {
required double minLevel,
required double maxLevel,
}) {
final AppShared sharedController = Get.find<AppShared>();

return Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand Down
2 changes: 1 addition & 1 deletion lib/app/pages/playlist/playlist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _PlaylistPageState extends State<PlaylistPage> {
final bool? result = await dialogBool(
title: 'crud_sheet7'.tr,
);
if (result != null && result) {
if (result == true) {
await playerController
.removePlaylist(widget.playlistTitle);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/app/routes/app_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class AppPages {
),
GetPage(
name: AppRoutes.equalizer,
page: () => EqualizerPage(),
page: () => const EqualizerPage(),
transitionDuration: const Duration(milliseconds: 300),
transition: Transition.rightToLeft,
),
Expand Down
6 changes: 6 additions & 0 deletions lib/app/services/app_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ class AppShared extends GetxController {
documentDir = await getApplicationDocumentsDirectory();

final List<SharedAttributes> listSettings = SharedAttributes.values;
final List<SharedAttributes> removeSettings = [
SharedAttributes.equalizeMode,
];

for (var setting in listSettings) {
if (removeSettings.contains(setting)) {
continue;
}
final dynamic value = SharedAttributes.getValueShared(_boxApp, setting);
SharedAttributes.getAttributesMap[setting.name] = value;
sharedMap[setting.name] = value;
Expand Down
4 changes: 2 additions & 2 deletions lib/app/shared/dialog/dialog_bool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Future<bool?> dialogBool({
children: [
GestureDetector(
onTap: () {
Navigator.of(context).pop(false);
Get.back(result: false);
},
child: SizedBox(
width: Get.width * 0.3,
Expand All @@ -47,7 +47,7 @@ Future<bool?> dialogBool({
Obx(() {
return GestureDetector(
onTap: () {
Navigator.of(context).pop(true);
Get.back(result: true);
},
child: Container(
width: Get.width * 0.3,
Expand Down
4 changes: 2 additions & 2 deletions lib/app/shared/dialog/dialog_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Future<void> dialogText({
children: [
GestureDetector(
onTap: () {
Navigator.of(context).pop();
Get.back();
},
child: SizedBox(
width: Get.width * 0.3,
Expand All @@ -53,7 +53,7 @@ Future<void> dialogText({
Obx(() {
return GestureDetector(
onTap: () {
Navigator.of(context).pop();
Get.back();
},
child: Container(
width: Get.width * 0.3,
Expand Down
6 changes: 3 additions & 3 deletions lib/app/shared/dialog/dialog_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Future<String?> dialogTextField({
onSubmitted: (String? value) {
String currentTitle = text.value.trim();
if (currentTitle.isNotEmpty && value != null) {
Navigator.of(context).pop(currentTitle);
Get.back(result: currentTitle);
}
},
),
Expand All @@ -84,7 +84,7 @@ Future<String?> dialogTextField({
children: [
GestureDetector(
onTap: () {
Navigator.of(context).pop(null);
Get.back(result: null);
},
child: SizedBox(
width: Get.width * 0.3,
Expand All @@ -100,7 +100,7 @@ Future<String?> dialogTextField({
onTap: () {
String currentTitle = text.value.trim();
if (currentTitle.isNotEmpty) {
Navigator.of(context).pop(currentTitle);
Get.back(result: currentTitle);
}
},
child: Container(
Expand Down
6 changes: 3 additions & 3 deletions lib/app/shared/more_vert/crud_music.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Future<void> crudMusic({
size: 28,
),
onTap: () async {
Navigator.of(context).pop();
Get.back();
await Get.toNamed(AppRoutes.edit, arguments: {
'song': song,
});
Expand All @@ -85,7 +85,7 @@ Future<void> crudMusic({
size: 28,
),
onTap: () async {
Navigator.of(context).pop();
Get.back();
await sharedFiles();
},
),
Expand All @@ -103,7 +103,7 @@ Future<void> crudMusic({
size: 28,
),
onTap: () async {
Navigator.of(context).pop();
Get.back();
await addPlaylist(songs: [song]);
},
),
Expand Down
Loading

0 comments on commit da02447

Please sign in to comment.