Terminada la implementación de los ajustes

parent aa6c8045
...@@ -18,7 +18,7 @@ class ProviderAjustes extends ChangeNotifier { ...@@ -18,7 +18,7 @@ class ProviderAjustes extends ChangeNotifier {
String get carpetaSalida => _carpetaSalida; String get carpetaSalida => _carpetaSalida;
bool get cargando => _cargando; bool get cargando => _cargando;
bool get expand => _cargando || _modoConversion != 0; bool get expandConvert => _cargando || _modoConversion == 0;
ProviderAjustes() { ProviderAjustes() {
_cargarValoresAnteriores(); _cargarValoresAnteriores();
......
...@@ -16,13 +16,7 @@ class PaginaPrincipal extends StatelessWidget { ...@@ -16,13 +16,7 @@ class PaginaPrincipal extends StatelessWidget {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text( content: Text(
'¡Conversión de archivos completada!' '¡Conversión de archivos completada!'
), )
action: SnackBarAction(
label: 'VER',
onPressed: () async {
await OpenFile.open('/storage/emulated/0/Pictures/Screenshots');
},
),
)); ));
}; };
......
...@@ -109,36 +109,45 @@ class ActionButton extends StatelessWidget { ...@@ -109,36 +109,45 @@ class ActionButton extends StatelessWidget {
void copiarAction() async { void copiarAction() async {
if(await _comprobacionesPreviasConversion(context)){ if(await _comprobacionesPreviasConversion(context)){
actualizadorProgreso();
// Averiguamos donde colocar los archivos de salida // Averiguamos donde colocar los archivos de salida
String? directorioSalida; String? directorioSalida;
while (directorioSalida == null) { if(providerAjustes.carpetaSalida.isNotEmpty){
directorioSalida = providerAjustes.carpetaSalida;
}
else{
directorioSalida = await FilePicker.platform.getDirectoryPath(); directorioSalida = await FilePicker.platform.getDirectoryPath();
if(directorioSalida != null){
providerAjustes.setCarpetaSalidaTemporal(directorioSalida);
} }
}
if(directorioSalida != null){
actualizadorProgreso();
// Convertimos los archivos como tal // Convertimos los archivos como tal
List<Archivo> archivos = manager.seleccionables.whereType<Archivo>().toList(); List<Archivo> archivos = manager.seleccionables.whereType<Archivo>().toList();
for (var archivo in archivos) { while(manager.seleccionables.isNotEmpty){
Conversor.convertir(archivo, directorioSalida); ElementoSeleccionable sel = manager.seleccionables.first;
}
// Convertimos las carpetas if(sel is Carpeta){
List<Carpeta> carpetas = manager.seleccionables.whereType<Carpeta>().toList(); for (var archivo in sel.elementosSeleccionados) {
for (var carpeta in carpetas) { Directory d = await Directory("$directorioSalida/${sel.nombre}").create();
for (var archivo in carpeta.elementosSeleccionados) {
Directory d = await Directory("$directorioSalida/${carpeta.nombre}").create();
Conversor.convertir(archivo, d.path); Conversor.convertir(archivo, d.path);
} }
} }
else if (sel is Archivo){
Conversor.convertir(sel, directorioSalida);
}
manager.finalizarConversion(); manager.borraSeleccionable(0);
}
}
} }
} }
void comprimirAction() async { void comprimirAction() async {
if(await _comprobacionesPreviasConversion(context)){ if(await _comprobacionesPreviasConversion(context)){
actualizadorProgreso(); // actualizadorProgreso();
// TODO: Código de compresión // TODO: Código de compresión
} }
...@@ -188,7 +197,7 @@ class ActionButton extends StatelessWidget { ...@@ -188,7 +197,7 @@ class ActionButton extends StatelessWidget {
static Future<bool> comprobacionPermisoArchivos(BuildContext context) async { static Future<bool> comprobacionPermisoArchivos(BuildContext context) async {
final granted = await Permission.manageExternalStorage.isGranted; final granted = await Permission.manageExternalStorage.isGranted;
if(!granted){ if(!granted) {
final permanently = await Permission.manageExternalStorage.isPermanentlyDenied; final permanently = await Permission.manageExternalStorage.isPermanentlyDenied;
if(permanently) { if(permanently) {
_mostrarNotificacion(context, 'El acceso al almacenamiento del dispositivo ha sido denegado permanentemente.\n' _mostrarNotificacion(context, 'El acceso al almacenamiento del dispositivo ha sido denegado permanentemente.\n'
...@@ -258,7 +267,6 @@ enum ActionButtonTypes { ...@@ -258,7 +267,6 @@ enum ActionButtonTypes {
case ActionButtonTypes.comprimir: case ActionButtonTypes.comprimir:
case ActionButtonTypes.reemplazar: case ActionButtonTypes.reemplazar:
return true; return true;
default: default:
return false; return false;
} }
......
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:prueba_multimedia/modelo/modelo.dart'; import 'package:prueba_multimedia/modelo/modelo.dart';
...@@ -39,11 +42,6 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -39,11 +42,6 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
]; ];
@override @override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final manager = Provider.of<ListaSeleccionables>(context, listen: false); final manager = Provider.of<ListaSeleccionables>(context, listen: false);
...@@ -59,7 +57,9 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -59,7 +57,9 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
_convertirOpen = false; _convertirOpen = false;
}); });
_agregarKey.currentState?.close(); _agregarKey.currentState?.close();
if(widget.providerAjustes.expandConvert){
_convertirKey.currentState?.close(); _convertirKey.currentState?.close();
}
}, },
), ),
Align( Align(
...@@ -83,7 +83,7 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -83,7 +83,7 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
tipoBoton: type, tipoBoton: type,
manager: manager, manager: manager,
context: context, context: context,
disabled: !widget.allowConversion && type.isConvertir(), disabled: !(widget.allowConversion) && type.isConvertir(),
onSuccess: widget.onConvertSuccess, onSuccess: widget.onConvertSuccess,
providerAjustes: widget.providerAjustes, providerAjustes: widget.providerAjustes,
); );
...@@ -94,6 +94,7 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -94,6 +94,7 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
final toRet = <Widget>[]; final toRet = <Widget>[];
// FAB con las opciones para convertir // FAB con las opciones para convertir
if(widget.providerAjustes.expandConvert) {
toRet.add(Stack( toRet.add(Stack(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
children: [ children: [
...@@ -115,13 +116,39 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -115,13 +116,39 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
_convertirOpen = !_convertirOpen; _convertirOpen = !_convertirOpen;
}); });
_agregarKey.currentState?.close(); _agregarKey.currentState?.close();
if(widget.providerAjustes.expandConvert){
_convertirKey.currentState?.tap(); _convertirKey.currentState?.tap();
}
}, },
), ),
) )
], ],
)); ));
}
else {
toRet.add(FloatingActionButton.extended(
heroTag: 'btn1',
icon: Icon(Icons.label_important_outline),
label: Text(
'Convertir',
textScaler: TextScaler.linear(1.2)
),
foregroundColor: (!widget.allowConversion)? Colors.grey.shade800 : null,
backgroundColor: (!widget.allowConversion)? Colors.grey.shade200 : null,
disabledElevation: 0,
onPressed: (!widget.allowConversion)? null :
() {
switch(widget.providerAjustes.modoConversion){
case 1:
convertirCopiar(manager);
break;
case 2:
convertirComprimir();
break;
}
},
));
}
// FAB con las opciones para agregar archivos, carpetas, enlaces... // FAB con las opciones para agregar archivos, carpetas, enlaces...
toRet.add(Stack( toRet.add(Stack(
...@@ -142,7 +169,9 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -142,7 +169,9 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
_convertirOpen = false; _convertirOpen = false;
_agregarOpen = !_agregarOpen; _agregarOpen = !_agregarOpen;
}); });
if(widget.providerAjustes.expandConvert){
_convertirKey.currentState?.close(); _convertirKey.currentState?.close();
}
_agregarKey.currentState?.tap(); _agregarKey.currentState?.tap();
}, },
), ),
...@@ -161,7 +190,9 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -161,7 +190,9 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
_convertirOpen = false; _convertirOpen = false;
_agregarOpen = false; _agregarOpen = false;
}); });
if(widget.providerAjustes.expandConvert){
_convertirKey.currentState?.close(); _convertirKey.currentState?.close();
}
_agregarKey.currentState?.close(); _agregarKey.currentState?.close();
}; };
...@@ -176,4 +207,64 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> { ...@@ -176,4 +207,64 @@ class _ConVertexFabBarState extends State<ConVertexFabBar> {
); );
}).toList(); }).toList();
} }
Future<void> convertirCopiar(ListaSeleccionables manager) async {
if(await ActionButton.comprobacionPermisoArchivos(context)){
String? directorioSalida;
if(widget.providerAjustes.carpetaSalida.isNotEmpty){
directorioSalida = widget.providerAjustes.carpetaSalida;
}
else{
directorioSalida = await FilePicker.platform.getDirectoryPath();
}
if(directorioSalida != null){
listenerActualizar(manager);
// Convertimos los archivos como tal
List<Archivo> archivos = manager.seleccionables.whereType<Archivo>().toList();
while(manager.seleccionables.isNotEmpty){
ElementoSeleccionable sel = manager.seleccionables.first;
if(sel is Carpeta){
for (var archivo in sel.elementosSeleccionados) {
Directory d = await Directory("$directorioSalida/${sel.nombre}").create();
Conversor.convertir(archivo, d.path);
}
}
else if (sel is Archivo){
Conversor.convertir(sel, directorioSalida);
}
manager.borraSeleccionable(0);
}
}
}
}
Future<void> convertirComprimir() async {
if(await ActionButton.comprobacionPermisoArchivos(context)){
print('Hola');
}
}
Future<void> listenerActualizar(ListaSeleccionables manager) async {
manager.iniciarConversion();
int initialSize = manager.seleccionables.length;
await Future.delayed(Duration(milliseconds: 200));
while(manager.seleccionables.isNotEmpty){
manager.actualizarProgreso(initialSize);
await Future.delayed(Duration(milliseconds: 200));
}
if(manager.progress < 100){
manager.actualizarProgreso(initialSize);
await Future.delayed(Duration(milliseconds: 200));
}
manager.finalizarConversion();
widget.onConvertSuccess();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment