Skip to content

Commit

Permalink
ファイルの複数選択を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Jan 28, 2024
1 parent 8ec3ed6 commit 89577f6
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 23 deletions.
27 changes: 27 additions & 0 deletions lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,34 @@
"move": "移動",
"changeFolderName": "フォルダ名を変更",
"confirmDeleteFolder": "このフォルダを削除しますか?",
"selectedFiles": "選択中 ({n})",
"@selectedFiles": {
"placeholders": {
"n": {
"type": "int",
"format": "decimalPattern"
}
}
},
"noFiles": "ファイルがありません",
"confirmDeleteFiles": "{n, plural, other {{n}個のファイルを削除しますか?}}",
"@confirmDeleteFiles": {
"placeholders": {
"n": {
"type": "int",
"format": "decimalPattern"
}
}
},
"nFiles": "{n, plural, other {{n}個のファイル}}",
"@nFiles": {
"placeholders": {
"n": {
"type": "int",
"format": "decimalPattern"
}
}
},
"changeFileName": "ファイル名を変更",
"changeCaption": "キャプションを変更",
"none": "なし",
Expand Down
1 change: 1 addition & 0 deletions lib/model/drive_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ part 'drive_page_state.freezed.dart';
class DrivePageState with _$DrivePageState {
const factory DrivePageState({
@Default([]) List<DriveFolder> breadcrumbs,
@Default([]) List<DriveFile> selectedFiles,
}) = _DrivePageState;
}
48 changes: 39 additions & 9 deletions lib/model/drive_page_state.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final _privateConstructorUsedError = UnsupportedError(
/// @nodoc
mixin _$DrivePageState {
List<DriveFolder> get breadcrumbs => throw _privateConstructorUsedError;
List<DriveFile> get selectedFiles => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$DrivePageStateCopyWith<DrivePageState> get copyWith =>
Expand All @@ -29,7 +30,7 @@ abstract class $DrivePageStateCopyWith<$Res> {
DrivePageState value, $Res Function(DrivePageState) then) =
_$DrivePageStateCopyWithImpl<$Res, DrivePageState>;
@useResult
$Res call({List<DriveFolder> breadcrumbs});
$Res call({List<DriveFolder> breadcrumbs, List<DriveFile> selectedFiles});
}

/// @nodoc
Expand All @@ -46,12 +47,17 @@ class _$DrivePageStateCopyWithImpl<$Res, $Val extends DrivePageState>
@override
$Res call({
Object? breadcrumbs = null,
Object? selectedFiles = null,
}) {
return _then(_value.copyWith(
breadcrumbs: null == breadcrumbs
? _value.breadcrumbs
: breadcrumbs // ignore: cast_nullable_to_non_nullable
as List<DriveFolder>,
selectedFiles: null == selectedFiles
? _value.selectedFiles
: selectedFiles // ignore: cast_nullable_to_non_nullable
as List<DriveFile>,
) as $Val);
}
}
Expand All @@ -64,7 +70,7 @@ abstract class _$$DrivePageStateImplCopyWith<$Res>
__$$DrivePageStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({List<DriveFolder> breadcrumbs});
$Res call({List<DriveFolder> breadcrumbs, List<DriveFile> selectedFiles});
}

/// @nodoc
Expand All @@ -79,21 +85,29 @@ class __$$DrivePageStateImplCopyWithImpl<$Res>
@override
$Res call({
Object? breadcrumbs = null,
Object? selectedFiles = null,
}) {
return _then(_$DrivePageStateImpl(
breadcrumbs: null == breadcrumbs
? _value._breadcrumbs
: breadcrumbs // ignore: cast_nullable_to_non_nullable
as List<DriveFolder>,
selectedFiles: null == selectedFiles
? _value._selectedFiles
: selectedFiles // ignore: cast_nullable_to_non_nullable
as List<DriveFile>,
));
}
}

/// @nodoc
class _$DrivePageStateImpl implements _DrivePageState {
const _$DrivePageStateImpl({final List<DriveFolder> breadcrumbs = const []})
: _breadcrumbs = breadcrumbs;
const _$DrivePageStateImpl(
{final List<DriveFolder> breadcrumbs = const [],
final List<DriveFile> selectedFiles = const []})
: _breadcrumbs = breadcrumbs,
_selectedFiles = selectedFiles;

final List<DriveFolder> _breadcrumbs;
@override
Expand All @@ -104,9 +118,18 @@ class _$DrivePageStateImpl implements _DrivePageState {
return EqualUnmodifiableListView(_breadcrumbs);
}

final List<DriveFile> _selectedFiles;
@override
@JsonKey()
List<DriveFile> get selectedFiles {
if (_selectedFiles is EqualUnmodifiableListView) return _selectedFiles;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_selectedFiles);
}

@override
String toString() {
return 'DrivePageState(breadcrumbs: $breadcrumbs)';
return 'DrivePageState(breadcrumbs: $breadcrumbs, selectedFiles: $selectedFiles)';
}

@override
Expand All @@ -115,12 +138,16 @@ class _$DrivePageStateImpl implements _DrivePageState {
(other.runtimeType == runtimeType &&
other is _$DrivePageStateImpl &&
const DeepCollectionEquality()
.equals(other._breadcrumbs, _breadcrumbs));
.equals(other._breadcrumbs, _breadcrumbs) &&
const DeepCollectionEquality()
.equals(other._selectedFiles, _selectedFiles));
}

@override
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_breadcrumbs));
runtimeType,
const DeepCollectionEquality().hash(_breadcrumbs),
const DeepCollectionEquality().hash(_selectedFiles));

@JsonKey(ignore: true)
@override
Expand All @@ -131,12 +158,15 @@ class _$DrivePageStateImpl implements _DrivePageState {
}

abstract class _DrivePageState implements DrivePageState {
const factory _DrivePageState({final List<DriveFolder> breadcrumbs}) =
_$DrivePageStateImpl;
const factory _DrivePageState(
{final List<DriveFolder> breadcrumbs,
final List<DriveFile> selectedFiles}) = _$DrivePageStateImpl;

@override
List<DriveFolder> get breadcrumbs;
@override
List<DriveFile> get selectedFiles;
@override
@JsonKey(ignore: true)
_$$DrivePageStateImplCopyWith<_$DrivePageStateImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
8 changes: 7 additions & 1 deletion lib/router/app_router.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions lib/state_notifier/drive_page/drive_page_notifier.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:collection';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:miria/model/drive_page_state.dart';
import 'package:misskey_dart/misskey_dart.dart';
Expand Down Expand Up @@ -35,4 +37,43 @@ class DrivePageNotifier extends AutoDisposeNotifier<DrivePageState> {
],
);
}

LinkedHashSet<DriveFile> get _selectedFiles => LinkedHashSet<DriveFile>(
equals: (p0, p1) => p0.id == p1.id,
hashCode: (p0) => p0.id.hashCode,
)..addAll(state.selectedFiles);

void selectFile(DriveFile file) {
final selectedFiles = _selectedFiles..add(file);
state = state.copyWith(
selectedFiles: selectedFiles.toList(),
);
}

void selectFiles(Iterable<DriveFile> files) {
final selectedFiles = _selectedFiles..addAll(files);
state = state.copyWith(
selectedFiles: selectedFiles.toList(),
);
}

void deselectFile(DriveFile file) {
final selectedFiles = _selectedFiles..remove(file);
state = state.copyWith(
selectedFiles: selectedFiles.toList(),
);
}

void deselectFiles(Iterable<DriveFile> files) {
final selectedFiles = _selectedFiles..removeAll(files);
state = state.copyWith(
selectedFiles: selectedFiles.toList(),
);
}

void deselectAll() {
state = state.copyWith(
selectedFiles: [],
);
}
}
6 changes: 6 additions & 0 deletions lib/view/drive_page/drive_file_grid_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:miria/model/account.dart';
import 'package:miria/view/drive_page/drive_file_modal_sheet.dart';
import 'package:miria/view/note_create_page/thumbnail.dart';
import 'package:miria/view/themes/app_theme.dart';
import 'package:misskey_dart/misskey_dart.dart';

class DriveFileGridItem extends ConsumerWidget {
const DriveFileGridItem({
super.key,
required this.account,
required this.file,
this.isSelected = false,
this.onTap,
this.onLongPress,
});

final Account account;
final DriveFile file;
final bool isSelected;
final void Function()? onTap;
final void Function()? onLongPress;

@override
Widget build(BuildContext context, WidgetRef ref) {
return Card(
color: isSelected
? AppTheme.of(context).currentDisplayTabColor.withOpacity(0.7)
: null,
child: InkWell(
onTap: onTap,
onLongPress: onLongPress,
Expand Down
1 change: 1 addition & 0 deletions lib/view/drive_page/drive_file_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class DriveFileModalSheet extends ConsumerWidget {
driveFilesNotifierProvider((misskey, file.folderId)).notifier,
)
.delete(file.id);
ref.read(drivePageNotifierProvider.notifier).deselectFile(file);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(S.of(context).deleted)),
Expand Down
1 change: 1 addition & 0 deletions lib/view/drive_page/drive_folder_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class DriveFolderModalSheet extends ConsumerWidget {
driveFoldersNotifierProvider((misskey, folder.parentId)).notifier,
)
.delete(folder.id);
ref.read(drivePageNotifierProvider.notifier).deselectAll();
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(S.of(context).deleted)),
Expand Down
Loading

0 comments on commit 89577f6

Please sign in to comment.