add "downloads" button (UNTRANSLATED), implement that thing (UNTESTED)
This commit is contained in:
parent
ae8fb70a4a
commit
7aca312d29
|
|
@ -42,7 +42,12 @@ class MessageDownloadContent extends StatelessWidget {
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
|
||||||
onTap: () => event.saveFile(context),
|
onTap: () => {
|
||||||
|
if (event.canDownloadInBackground)
|
||||||
|
event.downloadInBackground(context)
|
||||||
|
else
|
||||||
|
event.saveFile(context)
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 400,
|
width: 400,
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:extera_next/pages/download_manager/download_manager_view.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:extera_next/generated/l10n/l10n.dart';
|
import 'package:extera_next/generated/l10n/l10n.dart';
|
||||||
|
|
@ -56,6 +57,16 @@ class ClientChooserButton extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: SettingsAction.downloads,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.download_outlined),
|
||||||
|
const SizedBox(width: 18),
|
||||||
|
Text("Downloads"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: SettingsAction.archive,
|
value: SettingsAction.archive,
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|
@ -220,6 +231,9 @@ class ClientChooserButton extends StatelessWidget {
|
||||||
case SettingsAction.setStatus:
|
case SettingsAction.setStatus:
|
||||||
controller.setStatus();
|
controller.setStatus();
|
||||||
break;
|
break;
|
||||||
|
case SettingsAction.downloads:
|
||||||
|
DownloadManagerView.showDownloads(context);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -229,6 +243,7 @@ enum SettingsAction {
|
||||||
addAccount,
|
addAccount,
|
||||||
newGroup,
|
newGroup,
|
||||||
setStatus,
|
setStatus,
|
||||||
|
downloads,
|
||||||
invite,
|
invite,
|
||||||
settings,
|
settings,
|
||||||
archive,
|
archive,
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,48 @@
|
||||||
import 'package:extera_next/pages/download_manager/download_manager.dart';
|
import 'package:extera_next/pages/download_manager/download_manager.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class DownloadManagerView extends StatelessWidget {
|
class DownloadManagerView extends StatelessWidget {
|
||||||
final DownloadManagerController controller;
|
final DownloadManagerController controller;
|
||||||
const DownloadManagerView(this.controller, {super.key});
|
const DownloadManagerView(this.controller, {super.key});
|
||||||
|
|
||||||
|
static void showDownloads(BuildContext context) {
|
||||||
|
showAdaptiveDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => DownloadManagerView(Provider.of<DownloadManagerController>(context)),
|
||||||
|
barrierDismissible: true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return AlertDialog.adaptive(
|
||||||
body: ListView.builder(
|
content: ConstrainedBox(
|
||||||
itemCount: controller.downloads.length,
|
constraints: const BoxConstraints(maxHeight: 256, maxWidth: 256),
|
||||||
itemBuilder: (context, index) {
|
child: ListView.builder(
|
||||||
final download = controller.downloads[index];
|
itemCount: controller.downloads.length,
|
||||||
return ListTile(
|
itemBuilder: (context, index) {
|
||||||
title: Text(download.name),
|
final download = controller.downloads[index];
|
||||||
subtitle: LinearProgressIndicator(
|
return ListTile(
|
||||||
value: download.progress,
|
title: Text(download.name),
|
||||||
backgroundColor: Colors.grey[200],
|
subtitle: LinearProgressIndicator(
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
|
value: download.progress,
|
||||||
),
|
backgroundColor: Colors.grey[200],
|
||||||
trailing: ElevatedButton(
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
|
||||||
onPressed: () {
|
),
|
||||||
// "Cancel" button action can be added here
|
trailing: ElevatedButton(
|
||||||
},
|
onPressed: () {
|
||||||
child: Text("Cancel"),
|
// "Cancel" button action can be added here
|
||||||
),
|
},
|
||||||
);
|
child: Text("Cancel"),
|
||||||
},
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 256),
|
||||||
|
child: const Center(child: Text("Downloads", textAlign: TextAlign.center)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,12 @@ extension LocalizedBody on Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadInBackground(BuildContext context) async {
|
void downloadInBackground(BuildContext context) async {
|
||||||
if (this.hasAttachment && this.status.isSent && !room.encrypted) {
|
if (!canDownloadInBackground) {
|
||||||
final dmc = Provider.of<DownloadManagerController>(context);
|
final dmc = Provider.of<DownloadManagerController>(context);
|
||||||
final filename = content.tryGet<String>('filename') ?? body;
|
final filename = content.tryGet<String>('filename') ?? body;
|
||||||
dmc.download(context, "$filename.${roomId!.substring(0, 4)}.${eventId.substring(0, 4)}.${extensionFromMime(attachmentMimetype)}", attachmentMxcUrl.toString());
|
dmc.download(context, "$filename.${roomId!.substring(0, 4)}.${eventId.substring(0, 4)}.${extensionFromMime(attachmentMimetype)}", attachmentMxcUrl.toString());
|
||||||
|
} else {
|
||||||
|
throw Exception("Cannot download in background");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,6 +43,11 @@ extension LocalizedBody on Event {
|
||||||
matrixFile.result?.share(context);
|
matrixFile.result?.share(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get canDownloadInBackground =>
|
||||||
|
hasAttachment &&
|
||||||
|
status.isSent &&
|
||||||
|
!room.encrypted;
|
||||||
|
|
||||||
bool get isAttachmentSmallEnough =>
|
bool get isAttachmentSmallEnough =>
|
||||||
infoMap['size'] is int &&
|
infoMap['size'] is int &&
|
||||||
infoMap['size'] < room.client.database!.maxFileSize;
|
infoMap['size'] < room.client.database!.maxFileSize;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue