Skip to content

Commit

Permalink
Merge pull request #998 from nextcloud/refactor/neon/dialogs
Browse files Browse the repository at this point in the history
Refactor/neon/dialogs
  • Loading branch information
Leptopoda authored Dec 30, 2023
2 parents 0919cbd + f46202f commit 67b11e5
Show file tree
Hide file tree
Showing 60 changed files with 2,257 additions and 1,330 deletions.
4 changes: 2 additions & 2 deletions packages/neon/neon_files/lib/l10n/en.arb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"@@locale": "en",
"actionYes": "Yes",
"actionNo": "No",
"actionDelete": "Delete",
"actionRename": "Rename",
"actionMove": "Move",
Expand Down Expand Up @@ -43,6 +41,8 @@
}
}
},
"actionDeleteTitle": "Permanently delete?",
"filesChooseCreate": "Add to Nextcloud",
"folderCreate": "Create folder",
"folderName": "Folder name",
"folderRename": "Rename folder",
Expand Down
24 changes: 12 additions & 12 deletions packages/neon/neon_files/lib/l10n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ abstract class FilesLocalizations {
/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[Locale('en')];

/// No description provided for @actionYes.
///
/// In en, this message translates to:
/// **'Yes'**
String get actionYes;

/// No description provided for @actionNo.
///
/// In en, this message translates to:
/// **'No'**
String get actionNo;

/// No description provided for @actionDelete.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -185,6 +173,18 @@ abstract class FilesLocalizations {
/// **'Are you sure you want to download a file that is bigger than {warningSize} ({actualSize})?'**
String downloadConfirmSizeWarning(String warningSize, String actualSize);

/// No description provided for @actionDeleteTitle.
///
/// In en, this message translates to:
/// **'Permanently delete?'**
String get actionDeleteTitle;

/// No description provided for @filesChooseCreate.
///
/// In en, this message translates to:
/// **'Add to Nextcloud'**
String get filesChooseCreate;

/// No description provided for @folderCreate.
///
/// In en, this message translates to:
Expand Down
12 changes: 6 additions & 6 deletions packages/neon/neon_files/lib/l10n/localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import 'localizations.dart';
class FilesLocalizationsEn extends FilesLocalizations {
FilesLocalizationsEn([String locale = 'en']) : super(locale);

@override
String get actionYes => 'Yes';

@override
String get actionNo => 'No';

@override
String get actionDelete => 'Delete';

Expand Down Expand Up @@ -58,6 +52,12 @@ class FilesLocalizationsEn extends FilesLocalizations {
return 'Are you sure you want to download a file that is bigger than $warningSize ($actualSize)?';
}

@override
String get actionDeleteTitle => 'Permanently delete?';

@override
String get filesChooseCreate => 'Add to Nextcloud';

@override
String get folderCreate => 'Create folder';

Expand Down
61 changes: 56 additions & 5 deletions packages/neon/neon_files/lib/src/blocs/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,33 @@ import 'package:neon_framework/utils.dart';
import 'package:nextcloud/webdav.dart';
import 'package:rxdart/rxdart.dart';

/// Mode to operate the `FilesBrowserView` in.
enum FilesBrowserMode {
/// Default file browser mode.
///
/// When a file is selected it will be opened or downloaded.
browser,

/// Select directory.
selectDirectory,

/// Do not show file actions.
noActions,
}

sealed class FilesBrowserBloc implements InteractiveBloc {
@internal
factory FilesBrowserBloc(
final FilesOptions options,
final Account account, {
final PathUri? initialPath,
final FilesBrowserMode? mode,
}) =>
_FilesBrowserBloc(
options,
account,
initialPath: initialPath,
mode: mode,
);

void setPath(final PathUri uri);
Expand All @@ -30,27 +46,41 @@ sealed class FilesBrowserBloc implements InteractiveBloc {
BehaviorSubject<PathUri> get uri;

FilesOptions get options;

/// Mode to operate the `FilesBrowserView` in.
FilesBrowserMode get mode;
}

class _FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBloc {
_FilesBrowserBloc(
this.options,
this.account, {
final PathUri? initialPath,
}) {
if (initialPath != null) {
uri.add(initialPath);
this.initialPath,
final FilesBrowserMode? mode,
}) : mode = mode ?? FilesBrowserMode.browser {
final parent = initialPath?.parent;
if (parent != null) {
uri.add(parent);
}

options.showHiddenFilesOption.addListener(refresh);

unawaited(refresh());
}

@override
final FilesOptions options;
final Account account;

@override
final FilesBrowserMode mode;

final PathUri? initialPath;

@override
void dispose() {
options.showHiddenFilesOption.removeListener(refresh);

unawaited(files.close());
unawaited(uri.close());
super.dispose();
Expand Down Expand Up @@ -80,7 +110,28 @@ class _FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBloc {
),
depth: WebDavDepth.one,
),
(final response) => response.toWebDavFiles().sublist(1),
(final response) {
final unwrapped = response.toWebDavFiles().sublist(1);

return unwrapped.where((final file) {
// Do not show files when selecting a directory
if (mode == FilesBrowserMode.selectDirectory && !file.isDirectory) {
return false;
}

// Do not show itself when selecting a directory
if (mode == FilesBrowserMode.selectDirectory && initialPath == file.path) {
return false;
}

// Do not show hidden files unless the option is enabled
if (!options.showHiddenFilesOption.value && file.isHidden) {
return false;
}

return true;
}).toList();
},
emitEmptyCache: true,
);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/neon/neon_files/lib/src/blocs/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sealed class FilesBloc implements InteractiveBloc {

FilesBrowserBloc get browser;

FilesBrowserBloc getNewFilesBrowserBloc({final PathUri? initialUri});
FilesBrowserBloc getNewFilesBrowserBloc({final PathUri? initialUri, final FilesBrowserMode? mode});
}

class _FilesBloc extends InteractiveBloc implements FilesBloc {
Expand Down Expand Up @@ -235,13 +235,12 @@ class _FilesBloc extends InteractiveBloc implements FilesBloc {
}

@override
FilesBrowserBloc getNewFilesBrowserBloc({
final PathUri? initialUri,
}) =>
FilesBrowserBloc getNewFilesBrowserBloc({final PathUri? initialUri, final FilesBrowserMode? mode}) =>
FilesBrowserBloc(
options,
account,
initialPath: initialUri,
mode: mode,
);

void downloadParallelismListener() {
Expand Down
134 changes: 0 additions & 134 deletions packages/neon/neon_files/lib/src/dialogs/choose_create.dart

This file was deleted.

Loading

0 comments on commit 67b11e5

Please sign in to comment.