Skip to content

Commit

Permalink
share upload request entry presentation layer (linagora#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE committed Sep 9, 2021
1 parent 24f4dcc commit c62c233
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// LinShare is an open source filesharing software, part of the LinPKI software
// suite, developed by Linagora.
//
// Copyright (C) 2020 LINAGORA
//
// This program is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later version,
// provided you comply with the Additional Terms applicable for LinShare software by
// Linagora pursuant to Section 7 of the GNU Affero General Public License,
// subsections (b), (c), and (e), pursuant to which you must notably (i) retain the
// display in the interface of the “LinShare™” trademark/logo, the "Libre & Free" mention,
// the words “You are using the Free and Open Source version of LinShare™, powered by
// Linagora © 2009–2020. Contribute to Linshare R&D by subscribing to an Enterprise
// offer!”. You must also retain the latter notice in all asynchronous messages such as
// e-mails sent with the Program, (ii) retain all hypertext links between LinShare and
// http://www.linshare.org, between linagora.com and Linagora, and (iii) refrain from
// infringing Linagora intellectual property rights over its trademarks and commercial
// brands. Other Additional Terms apply, see
// <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf>
// for more details.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
// more details.
// You should have received a copy of the GNU Affero General Public License and its
// applicable Additional Terms for LinShare along with this program. If not, see
// <http://www.gnu.org/licenses/> for the GNU Affero General Public License version
// 3 and <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf> for
// the Additional Terms applicable to LinShare software.

import 'package:domain/domain.dart';
import 'package:linshare_flutter_app/presentation/util/data_structure/router_arguments.dart';

class ShareUploadRequestEntryArguments extends RouterArguments {
List<UploadRequestEntry> entries;

ShareUploadRequestEntryArguments(this.entries);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ class UploadFileArguments extends RouterArguments {
final List<FileInfo> uploadFiles;
late ShareType shareType;
List<Document>? documents;
List<UploadRequestEntry>? entries;
late WorkGroupDocumentUploadInfo? workGroupDocumentUploadInfo;

UploadFileArguments(this.uploadFiles, {
ShareType shareType = ShareType.uploadAndShare,
List<Document>? documents,
List<UploadRequestEntry>? entries,
WorkGroupDocumentUploadInfo? workGroupDocumentUploadInfo
}) {
this.shareType = shareType;
this.documents = documents;
this.entries = entries;
this.workGroupDocumentUploadInfo = workGroupDocumentUploadInfo;
}
}

enum ShareType { quickShare, uploadAndShare, none, uploadFromOutside }
enum ShareType { quickShare, uploadAndShare, none, uploadFromOutside, quickShareUploadRequestEntry }

enum ShareButtonType { justUpload, uploadAndShare, workGroup }

Expand Down
30 changes: 25 additions & 5 deletions lib/presentation/widget/upload_file/upload_file_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class UploadFileViewModel extends BaseViewModel {
ShareType get shareTypeArgument => _shareTypeArgument;

List<Document>? _documentsArgument;
List<UploadRequestEntry>? _entriesArgument;
WorkGroupDocumentUploadInfo? _workGroupDocumentUploadInfoArgument;
WorkGroupDocumentUploadInfo? get workGroupDocumentUploadInfoArgument => _workGroupDocumentUploadInfoArgument;

Expand Down Expand Up @@ -156,9 +157,14 @@ class UploadFileViewModel extends BaseViewModel {
}

List<SelectedPresentationFile>? get filesInfos {
return (_shareTypeArgument == ShareType.quickShare)
? _convertDocumentsToPresentationFile(_documentsArgument!)
: _convertFilesToPresentationFile(_uploadFilesArgument!);
switch (_shareTypeArgument) {
case ShareType.quickShare:
return _convertDocumentsToPresentationFile(_documentsArgument!);
case ShareType.quickShareUploadRequestEntry:
return _convertUploadRequestEntriesToPresentationFile(_entriesArgument!);
default:
return _convertFilesToPresentationFile(_uploadFilesArgument!);
}
}

void onPickUploadDestinationPressed(BuildContext context) {
Expand Down Expand Up @@ -300,7 +306,7 @@ class UploadFileViewModel extends BaseViewModel {
}

List<SelectedPresentationFile>? _convertDocumentsToPresentationFile(List<Document>? documents) {
if(documents == null) {
if (documents == null) {
return null;
}
return documents.map((document) {
Expand All @@ -309,14 +315,23 @@ class UploadFileViewModel extends BaseViewModel {
}

List<SelectedPresentationFile>? _convertFilesToPresentationFile(List<FileInfo>? filesInfo) {
if(filesInfo == null) {
if (filesInfo == null) {
return null;
}
return filesInfo.map((uploadFiles) {
return SelectedPresentationFile(uploadFiles.fileName, uploadFiles.fileSize, mediaType: uploadFiles.fileName.getMediaType());
}).toList();
}

List<SelectedPresentationFile>? _convertUploadRequestEntriesToPresentationFile(List<UploadRequestEntry>? entries) {
if (entries == null) {
return null;
}
return entries.map((entry) {
return SelectedPresentationFile(entry.name, entry.size, mediaType: entry.mediaType);
}).toList();
}

void cancelSelection() {
store.dispatch(MySpaceClearSelectedDocumentsAction());
}
Expand All @@ -333,6 +348,11 @@ class UploadFileViewModel extends BaseViewModel {
}
}

// Upload Request Entry
void setEntriesArgument(List<UploadRequestEntry>? entries) {
_entriesArgument = entries;
}

@override
void onDisposed() {
_autoCompleteResultListSubscription.cancel();
Expand Down
221 changes: 110 additions & 111 deletions lib/presentation/widget/upload_file/upload_file_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import 'package:flutter_tags/flutter_tags.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:linshare_flutter_app/presentation/di/get_it_service.dart';
import 'package:linshare_flutter_app/presentation/localizations/app_localizations.dart';
import 'package:linshare_flutter_app/presentation/model/file/selected_presentation_file.dart';
import 'package:linshare_flutter_app/presentation/redux/states/app_state.dart';
import 'package:linshare_flutter_app/presentation/redux/states/functionality_state.dart';
import 'package:linshare_flutter_app/presentation/util/app_image_paths.dart';
Expand Down Expand Up @@ -85,10 +86,13 @@ class _UploadFileWidgetState extends State<UploadFileWidget> {
if (arguments.documents != null) {
uploadFileViewModel.setDocumentsArgument(arguments.documents);
}
if (arguments.entries != null) {
uploadFileViewModel.setEntriesArgument(arguments.entries);
}
if (arguments.workGroupDocumentUploadInfo != null) {
uploadFileViewModel.setWorkGroupDocumentUploadInfoArgument(arguments.workGroupDocumentUploadInfo);
}

print(uploadFileViewModel.filesInfos);
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
Expand All @@ -99,7 +103,7 @@ class _UploadFileWidgetState extends State<UploadFileWidget> {
),
centerTitle: true,
title: Text(
uploadFileViewModel.shareTypeArgument == ShareType.quickShare
uploadFileViewModel.shareTypeArgument == ShareType.quickShare || uploadFileViewModel.shareTypeArgument == ShareType.quickShareUploadRequestEntry
? AppLocalizations.of(context).title_quick_share
: AppLocalizations.of(context).upload_file_title,
key: Key('upload_file_title'),
Expand All @@ -110,115 +114,7 @@ class _UploadFileWidgetState extends State<UploadFileWidget> {
child: Container(
child: Column(
children: [
(uploadFileViewModel.filesInfos != null)
? (uploadFileViewModel.filesInfos!.length > 1)
? ExpansionPanelList(
elevation: 1,
expandedHeaderPadding: EdgeInsets.all(0),
expansionCallback: (int index, bool isExpanded) {
setState(() {
isHeaderExpanded = !isHeaderExpanded;
});
},
children: [
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(
AppLocalizations.of(context)
.items_selected(uploadFileViewModel.filesInfos!.length),
style: TextStyle(
fontSize: 14,
color: AppColor.multipleSelectionBarTextColor)),
);
},
body: Padding(
padding: const EdgeInsets.only(bottom: 11.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: 209),
child: ListView.builder(
padding: EdgeInsets.only(left: 16),
shrinkWrap: true,
itemExtent: 38,
itemCount: uploadFileViewModel.filesInfos!.length,
itemBuilder: (BuildContext context, int index) {
final fileInfo = uploadFileViewModel.filesInfos![index];
return ListTile(
dense: true,
visualDensity: VisualDensity(horizontal: 0, vertical: -4),
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
fileInfo.mediaType
.getFileTypeImagePath(
imagePath),
width: 20,
height: 24,
fit: BoxFit.fill,
),
],
),
title: Transform(
transform: Matrix4.translationValues(-20, 0.0, 0.0),
child: Text(fileInfo.fileName,
style: TextStyle(
fontSize: 14,
color: AppColor.multipleSelectionBarTextColor)),
),
trailing: Text(
'${filesize(fileInfo.fileSize)}',
key: Key('upload_file_size'),
style: TextStyle(
fontSize: 14,
color: AppColor.uploadFileFileSizeTextColor),
));
})),
),
isExpanded: isHeaderExpanded),
])
: SizedBox(
width: double.maxFinite,
child: Align(
alignment: Alignment.center,
child: ListTile(
dense: true,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
uploadFileViewModel.filesInfos![0].mediaType.getFileTypeImagePath(imagePath),
width: 20,
height: 24,
fit: BoxFit.fill,
),
],
),
title: Transform(
transform: Matrix4.translationValues(-20.0, 0.0, 0.0),
child: CustomPaint(
size: Size(double.infinity, 14),
painter: EllipsisTextPainter(
text: TextSpan(text: uploadFileViewModel.filesInfos![0].fileName, style: TextStyle(
fontSize: 14,
color: AppColor.multipleSelectionBarTextColor),
),
ellipsis: uploadFileViewModel.filesInfos![0].fileName.toMiddleEllipsis(),
maxLines: 1,
),
)
),
trailing: Text(
'${filesize(uploadFileViewModel.filesInfos![0].fileSize)}',
key: Key('upload_file_size'),
style: TextStyle(
fontSize: 14,
color: AppColor.uploadFileFileSizeTextColor),
),
),
)
)
: SizedBox.shrink(),
if (uploadFileViewModel.filesInfos != null) _buildFilesInfos(uploadFileViewModel.filesInfos!) else SizedBox.shrink(),
StreamBuilder<DestinationType>(
stream: uploadFileViewModel.uploadDestinationTypeObservable,
builder: (_, snapshot) {
Expand Down Expand Up @@ -274,6 +170,109 @@ class _UploadFileWidgetState extends State<UploadFileWidget> {
);
}

Widget _buildFilesInfos(List<SelectedPresentationFile> files) {
if (files.length > 1) {
return ExpansionPanelList(
elevation: 1,
expandedHeaderPadding: EdgeInsets.all(0),
expansionCallback: (int index, bool isExpanded) {
setState(() {
isHeaderExpanded = !isHeaderExpanded;
});
},
children: [
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(AppLocalizations.of(context).items_selected(files.length),
style:
TextStyle(fontSize: 14, color: AppColor.multipleSelectionBarTextColor)),
);
},
body: Padding(
padding: const EdgeInsets.only(bottom: 11.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: 209),
child: ListView.builder(
padding: EdgeInsets.only(left: 16),
shrinkWrap: true,
itemExtent: 38,
itemCount: files.length,
itemBuilder: (BuildContext context, int index) {
final fileInfo = files[index];
return ListTile(
dense: true,
visualDensity: VisualDensity(horizontal: 0, vertical: -4),
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
fileInfo.mediaType.getFileTypeImagePath(imagePath),
width: 20,
height: 24,
fit: BoxFit.fill,
),
],
),
title: Transform(
transform: Matrix4.translationValues(-20, 0.0, 0.0),
child: Text(fileInfo.fileName,
style: TextStyle(
fontSize: 14,
color: AppColor.multipleSelectionBarTextColor)),
),
trailing: Text(
'${filesize(fileInfo.fileSize)}',
key: Key('upload_file_size'),
style: TextStyle(
fontSize: 14, color: AppColor.uploadFileFileSizeTextColor),
));
})),
),
isExpanded: isHeaderExpanded),
]);
} else {
return SizedBox(
width: double.maxFinite,
child: Align(
alignment: Alignment.center,
child: ListTile(
dense: true,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
files[0].mediaType.getFileTypeImagePath(imagePath),
width: 20,
height: 24,
fit: BoxFit.fill,
),
],
),
title: Transform(
transform: Matrix4.translationValues(-20.0, 0.0, 0.0),
child: CustomPaint(
size: Size(double.infinity, 14),
painter: EllipsisTextPainter(
text: TextSpan(
text: files[0].fileName,
style:
TextStyle(fontSize: 14, color: AppColor.multipleSelectionBarTextColor),
),
ellipsis: files[0].fileName.toMiddleEllipsis(),
maxLines: 1,
),
)),
trailing: Text(
'${filesize(files[0].fileSize)}',
key: Key('upload_file_size'),
style: TextStyle(fontSize: 14, color: AppColor.uploadFileFileSizeTextColor),
),
),
));
}
}

Widget _buildUploadDestinationPicker() {
return StoreConnector<AppState, FunctionalityState>(
converter: (Store<AppState> store) => store.state.functionalityState,
Expand Down
Loading

0 comments on commit c62c233

Please sign in to comment.