Skip to content

Commit

Permalink
💄 View mode has added file notification
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgnefz committed Sep 23, 2024
1 parent 231dbce commit 66fafd8
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 33 deletions.
10 changes: 10 additions & 0 deletions lib/core/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,29 @@ void formatFolder(WidgetRef ref, List<String?> folders) async {
}

void addFileInfo(WidgetRef ref, List<String> list) async {
bool isViewMode = ref.watch(viewModeProvider);
bool append = ref.watch(appendModeProvider);
if (!append) ref.read(fileListProvider.notifier).clear();
int count = 0;
ref.read(totalProvider.notifier).update(list.length);
int startTime = DateTime.now().microsecondsSinceEpoch;
for (var filePath in list) {
if (isViewMode && !image.contains(getFileExtension(filePath))) continue;
ref.read(countProvider.notifier).update(++count);
bool exist = ref.watch(fileListProvider).any((e) => e.filePath == filePath);
if (exist) continue;
FileInfo fileInfo = await generateFileInfo(ref, filePath);
ref.read(fileListProvider.notifier).add(fileInfo);
await Future.delayed(const Duration(microseconds: 1));
}
if (isViewMode) {
int removeCount = list.length - count;
if (removeCount > 0) {
NotificationType type = SuccessNotification(
S.current.viewMode, S.current.removeNonImage(removeCount));
NotificationMessage.show(type, 3);
}
}
int endTime = DateTime.now().microsecondsSinceEpoch;
double cost = (endTime - startTime) / 1000000;
ref.read(costProvider.notifier).update(cost);
Expand Down
15 changes: 9 additions & 6 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ class MessageLookup extends MessageLookupByLibrary {

static String m6(name) => "No longer exists in ${name}";

static String m7(total) =>
static String m7(count) => "Removed ${count} non-image files";

static String m8(total) =>
"All ${total} selected items have been successfully renamed";

static String m8(count, total) =>
static String m9(count, total) =>
"${count} out of ${total} selected undo renames failed";

static String m9(total) =>
static String m10(total) =>
"All ${total} selected items have been successfully undone";

final messages = _notInlinedMessages(_notInlinedMessages);
Expand Down Expand Up @@ -164,6 +166,7 @@ class MessageLookup extends MessageLookupByLibrary {
"prefix": MessageLookupByLibrary.simpleMessage("Prefix"),
"prefixContent":
MessageLookupByLibrary.simpleMessage("Add prefix content"),
"removeNonImage": m7,
"renameLogs": MessageLookupByLibrary.simpleMessage("rename logs"),
"renameName": MessageLookupByLibrary.simpleMessage("Rename name"),
"replace": MessageLookupByLibrary.simpleMessage("Replace"),
Expand All @@ -186,7 +189,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Successfully deleted all empty folders"),
"successful":
MessageLookupByLibrary.simpleMessage("Renaming successful"),
"successfulNum": m7,
"successfulNum": m8,
"suffix": MessageLookupByLibrary.simpleMessage("Suffix"),
"suffixContent":
MessageLookupByLibrary.simpleMessage("Add suffix content"),
Expand All @@ -211,10 +214,10 @@ class MessageLookup extends MessageLookupByLibrary {
"undo": MessageLookupByLibrary.simpleMessage("Undo"),
"undoFailed":
MessageLookupByLibrary.simpleMessage("Undo rename failed"),
"undoFailedNum": m8,
"undoFailedNum": m9,
"undoSuccessful":
MessageLookupByLibrary.simpleMessage("Undo Successful"),
"undoSuccessfulNum": m9,
"undoSuccessfulNum": m10,
"unselect": MessageLookupByLibrary.simpleMessage("Unselect"),
"uploadCSV": MessageLookupByLibrary.simpleMessage(
"Upload CSV and TXT files with \",\" separating old and new names, or OPLOG file generated by OncePower"),
Expand Down
15 changes: 9 additions & 6 deletions lib/generated/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class MessageLookup extends MessageLookupByLibrary {

static String m6(name) => "在 ${name} 中已不存在";

static String m7(total) => "选中的 ${total} 个已全部重命名成功";
static String m7(count) => "已移除${count}个非图片文件";

static String m8(count, total) => "选中 ${total} 个中 ${count} 个取消重命名失败";
static String m8(total) => "选中的 ${total} 个已全部重命名成功";

static String m9(total) => "选中的 ${total} 个已全部撤销重命名";
static String m9(count, total) => "选中 ${total} 个中 ${count} 个取消重命名失败";

static String m10(total) => "选中的 ${total} 个已全部撤销重命名";

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
Expand Down Expand Up @@ -141,6 +143,7 @@ class MessageLookup extends MessageLookupByLibrary {
"other": MessageLookupByLibrary.simpleMessage("其他"),
"prefix": MessageLookupByLibrary.simpleMessage("前缀"),
"prefixContent": MessageLookupByLibrary.simpleMessage("添加前缀内容"),
"removeNonImage": m7,
"renameLogs": MessageLookupByLibrary.simpleMessage("重命名日志"),
"renameName": MessageLookupByLibrary.simpleMessage("重命名名称"),
"replace": MessageLookupByLibrary.simpleMessage("替换"),
Expand All @@ -156,7 +159,7 @@ class MessageLookup extends MessageLookupByLibrary {
"start": MessageLookupByLibrary.simpleMessage("开始"),
"successInfo": MessageLookupByLibrary.simpleMessage("已成功删除所有空文件夹"),
"successful": MessageLookupByLibrary.simpleMessage("重命名成功"),
"successfulNum": m7,
"successfulNum": m8,
"suffix": MessageLookupByLibrary.simpleMessage("后缀"),
"suffixContent": MessageLookupByLibrary.simpleMessage("添加后缀内容"),
"swapPrefixDesc": MessageLookupByLibrary.simpleMessage("交换前缀和递增数字位置"),
Expand All @@ -173,9 +176,9 @@ class MessageLookup extends MessageLookupByLibrary {
"tvSeriesInfo": MessageLookupByLibrary.simpleMessage("获取剧集信息"),
"undo": MessageLookupByLibrary.simpleMessage("撤销"),
"undoFailed": MessageLookupByLibrary.simpleMessage("撤销重命名失败"),
"undoFailedNum": m8,
"undoFailedNum": m9,
"undoSuccessful": MessageLookupByLibrary.simpleMessage("已成功撤销"),
"undoSuccessfulNum": m9,
"undoSuccessfulNum": m10,
"unselect": MessageLookupByLibrary.simpleMessage("取消选择"),
"uploadCSV": MessageLookupByLibrary.simpleMessage(
"上传以\",\"分隔新旧名称的csv、txt文件或本软件生成的oplog文件"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

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

3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@
"allExtension": "All Extension",
"detailTitle": "All File Extensions",
"selectAllSwitch": "Select All Switch",
"exitOperation": "Exit Operation"
"exitOperation": "Exit Operation",
"removeNonImage": "Removed {count} non-image files"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@
"allExtension": "全部扩展",
"detailTitle": "所有文件扩展",
"selectAllSwitch": "全选切换",
"exitOperation": "退出操作"
"exitOperation": "退出操作",
"removeNonImage": "已移除{count}个非图片文件"
}
2 changes: 1 addition & 1 deletion lib/provider/file.g.dart

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

17 changes: 11 additions & 6 deletions lib/views/action_bar/rename/operation_menu/modify_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ModifyInput extends ConsumerWidget {
bool reserveTypeEmpty = ref.watch(currentReserveTypeProvider).isNotEmpty;
bool disable = dateRename ||
(reverseMode && (inputNotEmpty || reserveTypeEmpty || inputLength));
final TextEditingController controller =
ref.watch(modifyControllerProvider);
final controller = ref.watch(modifyControllerProvider);

void toggleCase() {
ref.read(matchCaseProvider.notifier).update();
Expand All @@ -53,11 +52,17 @@ class ModifyInput extends ConsumerWidget {
int? num = int.tryParse(controller.text);
if (num != null && event is KeyUpEvent) {
if (event.logicalKey == LogicalKeyboardKey.arrowUp) {
num += 1;
} else if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
num -= 1;
ref
.read(modifyControllerProvider.notifier)
.updateText((num += 1).toString());
updateName(ref);
}
if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
ref
.read(modifyControllerProvider.notifier)
.updateText((num -= 1).toString());
updateName(ref);
}
ref.read(modifyControllerProvider.notifier).updateText(num.toString());
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/views/bottom_bar/view_mode.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:once_power/constants/icons.dart';
import 'package:once_power/core/core.dart';
import 'package:once_power/generated/l10n.dart';
import 'package:once_power/model/enum.dart';
import 'package:once_power/model/notification_info.dart';
import 'package:once_power/provider/file.dart';
import 'package:once_power/provider/select.dart';
import 'package:once_power/widgets/common/notification.dart';
import 'package:once_power/widgets/common/tooltip_icon.dart';

class ViewModeBtn extends ConsumerWidget {
Expand All @@ -19,9 +22,18 @@ class ViewModeBtn extends ConsumerWidget {
void toggleView() {
if (!selected) {
final provider = ref.read(fileListProvider.notifier);
final before = ref.watch(fileListProvider).length;
provider.removeOtherClassify(FileClassify.image);
final after = ref.watch(fileListProvider).length;
if (before > after) {
int removeCount = before - after;
NotificationType type = SuccessNotification(S.of(context).viewMode,
S.of(context).removeNonImage(removeCount));
NotificationMessage.show(type, 3);
}
}
ref.read(viewModeProvider.notifier).update();
updateName(ref);
}

return TooltipIcon(
Expand Down
36 changes: 34 additions & 2 deletions lib/views/content_bar/rename/view_model/err_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import 'package:once_power/constants/constants.dart';
import 'package:once_power/generated/l10n.dart';

class ErrorImage extends StatelessWidget {
const ErrorImage({super.key, this.isPreview = false});
const ErrorImage({super.key, this.isPreview = false, required this.file});

final bool isPreview;
final String file;

@override
Widget build(BuildContext context) {
Expand All @@ -15,8 +16,39 @@ class ErrorImage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(AppImages.error, fit: BoxFit.contain),
isPreview
? Image.asset(AppImages.error, fit: BoxFit.none)
: Expanded(
child: Image.asset(AppImages.error, fit: BoxFit.contain)),
SizedBox(height: isPreview ? 12 : 4),
if (isPreview) ...[
Stack(
children: <Widget>[
// Stroked text as border.
Text(
file,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 6
..color = Colors.white,
).useSystemChineseFont(),
),
// Solid text as fill.
Text(
file,
style: const TextStyle(
fontSize: 14,
color: Colors.red,
fontWeight: FontWeight.bold,
).useSystemChineseFont(),
),
],
),
const SizedBox(height: 12),
],
Text(
'$errorLabel(((;꒪ꈊ꒪;)))',
style: isPreview
Expand Down
3 changes: 2 additions & 1 deletion lib/views/content_bar/rename/view_model/image_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class ImageView extends ConsumerWidget {
color: file.checked ? null : Colors.grey,
colorBlendMode: BlendMode.saturation,
cacheWidth: AppNum.imageW.toInt() + (isRefresh ? 1 : 0),
errorBuilder: (context, exception, stackTrace) => const ErrorImage(),
errorBuilder: (context, exception, stackTrace) =>
ErrorImage(file: file.filePath),
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
if (wasSynchronouslyLoaded) {
return child;
Expand Down
2 changes: 1 addition & 1 deletion lib/views/content_bar/rename/view_model/loading_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LoadingImage extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(AppImages.loading, fit: BoxFit.contain),
Expanded(child: Image.asset(AppImages.loading, fit: BoxFit.contain)),
Text(
loadingLabel,
style: const TextStyle(fontSize: 12).useSystemChineseFont(),
Expand Down
4 changes: 2 additions & 2 deletions lib/views/content_bar/rename/view_model/preview_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class _PreviewImageViewState extends ConsumerState<PreviewImageView> {
File(widget.files[index].filePath),
fit: BoxFit.scaleDown,
cacheHeight: MediaQuery.of(context).size.height.toInt(),
errorBuilder: (context, exception, stackTrace) =>
const ErrorImage(isPreview: true),
errorBuilder: (context, exception, stackTrace) => ErrorImage(
isPreview: true, file: widget.files[index].filePath),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/action_bar/action_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class ActionInput extends StatelessWidget {
label: label,
slot: BaseInput(
disable: disable,
focusNode: focusNode,
onKeyEvent: onKeyEvent,
controller: controller,
hintText: hintText,
show: show,
action: action,
focusNode: focusNode,
onChanged: onChanged,
),
message: message,
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/common/base_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class BaseInput extends StatelessWidget {
this.padding,
this.textStyle,
this.leading,
this.focusNode,
this.onKeyEvent,
this.controller,
this.hintText,
this.textAlign = TextAlign.start,
this.inputFormatters,
this.focusNode,
this.onChanged,
this.onEditingComplete,
this.onSubmitted,
Expand All @@ -35,12 +35,12 @@ class BaseInput extends StatelessWidget {
final EdgeInsets? padding;
final TextStyle? textStyle;
final Widget? leading;
final FocusNode? focusNode;
final void Function(KeyEvent)? onKeyEvent;
final TextEditingController? controller;
final String? hintText;
final TextAlign textAlign;
final List<TextInputFormatter>? inputFormatters;
final FocusNode? focusNode;
final void Function(String)? onChanged;
final void Function()? onEditingComplete;
final void Function(String)? onSubmitted;
Expand Down Expand Up @@ -74,6 +74,7 @@ class BaseInput extends StatelessWidget {
controller: controller,
readOnly: readOnly,
style: textStyle,
focusNode: focusNode,
decoration: InputDecoration(
hintText: hintText,
isDense: true,
Expand All @@ -82,7 +83,6 @@ class BaseInput extends StatelessWidget {
),
textAlign: textAlign,
inputFormatters: inputFormatters,
focusNode: focusNode,
onChanged: onChanged,
onEditingComplete: onEditingComplete,
onSubmitted: onSubmitted,
Expand Down
1 change: 0 additions & 1 deletion lib/widgets/common/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class NotificationMessage {
static show(NotificationType type, [int time = 5]) {
final (color, icon) = showMark(type);
if (type is SuccessNotification && type.infoList.isNotEmpty) time = 30;

BotToast.showCustomNotification(
toastBuilder: (context) {
return Container(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 2.9.1+0
version: 2.9.2+0

environment:
sdk: '>=3.0.6 <4.0.0'
Expand Down
Loading

0 comments on commit 66fafd8

Please sign in to comment.