Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.4.8 #39

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/common/models/isar/diary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ class Diary {

Diary();

// 深拷贝方法
Diary clone() {
return Diary()
..id = id
..categoryId = categoryId
..title = title
..content = content
..contentText = contentText
..time = DateTime.fromMillisecondsSinceEpoch(time.millisecondsSinceEpoch)
..show = show
..mood = mood
..weather = List<String>.from(weather)
..imageName = List<String>.from(imageName)
..audioName = List<String>.from(audioName)
..videoName = List<String>.from(videoName)
..tags = List<String>.from(tags)
..position = List<String>.from(position)
..imageColor = imageColor
..aspect = aspect;
}

// 将 Diary 对象转换为 JSON
Map<String, dynamic> toJson() {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/components/audio_player/audio_player_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AudioPlayerComponent extends StatelessWidget {
initState: (_) async {
await logic.initAudioPlayer(path);
},
assignId: true,
builder: (_) {
return ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
Expand Down
2 changes: 2 additions & 0 deletions lib/components/category_add/category_add_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class CategoryAddLogic extends GetxController {
void selectCategory(int index) {
Get.backLegacy();
editLogic.selectCategory(state.categoryList.value[index].id);
editLogic.update(['CategoryName']);
}

void cancelCategory() {
Get.backLegacy();
editLogic.selectCategory(null);
editLogic.update(['CategoryName']);
}
}
1 change: 1 addition & 0 deletions lib/components/category_add/category_add_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CategoryAddComponent extends StatelessWidget {
final i18n = AppLocalizations.of(context)!;

return GetBuilder<CategoryAddLogic>(
assignId: true,
builder: (_) {
return Padding(
padding: const EdgeInsets.all(16.0),
Expand Down
1 change: 1 addition & 0 deletions lib/components/color_dialog/color_dialog_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ColorDialogComponent extends StatelessWidget {
}

return GetBuilder<ColorDialogLogic>(
assignId: true,
builder: (_) {
return SimpleDialog(
title: Text(i18n.settingColor),
Expand Down
68 changes: 34 additions & 34 deletions lib/components/diary_card/basic_diary_card/basic_card_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,48 @@ mixin BasicCardLogic {
Future<void> toDiary(Diary diary) async {
HapticFeedback.mediumImpact();
Bind.lazyPut(() => DiaryDetailsLogic(), tag: diary.id);
var res = await Get.toNamed(AppRoutes.diaryPage, arguments: [diary, true]);
var oldCategoryId = diary.categoryId;
var res = await Get.toNamed(AppRoutes.diaryPage, arguments: [diary.clone(), true]);
if (res == 'delete') {
//如果分类为空,删除主页即可,如果分类不为空,双删除
if (diary.categoryId != null && Bind.isRegistered<DiaryTabViewLogic>(tag: diary.categoryId)) {
Bind.find<DiaryTabViewLogic>(tag: diary.categoryId).state.diaryList.removeWhere((e) => e.id == diary.id);
Bind.find<DiaryTabViewLogic>(tag: diary.categoryId).update(['TabView']);
}
Bind.find<DiaryTabViewLogic>(tag: 'default').state.diaryList.removeWhere((e) => e.id == diary.id);
Bind.find<DiaryTabViewLogic>(tag: 'default').update(['TabView']);
} else {
//重新获取日记
var newDiary = await Utils().isarUtil.getDiaryByID(diary.isarId);
if (newDiary != null) {
var newCategoryId = newDiary.categoryId;
//如果没修改
if (diary == newDiary) {
return;
}
//如果修改了但是没有修改分类,就替换掉原来的
if (oldCategoryId == newCategoryId) {
//替换掉全部分类中的
var oldIndex =
Bind.find<DiaryTabViewLogic>(tag: 'default').state.diaryList.indexWhere((e) => e.id == diary.id);
Bind.find<DiaryTabViewLogic>(tag: 'default').state.diaryList.replaceRange(oldIndex, oldIndex + 1, [newDiary]);

//如果注册了控制器
if (diary.categoryId != null && Bind.isRegistered<DiaryTabViewLogic>(tag: diary.categoryId)) {
var oldIndex =
Bind.find<DiaryTabViewLogic>(tag: diary.categoryId).state.diaryList.indexWhere((e) => e.id == diary.id);
Bind.find<DiaryTabViewLogic>(tag: diary.categoryId)
.state
.diaryList
.replaceRange(oldIndex, oldIndex + 1, [newDiary]);
}

//await Bind.find<DiaryLogic>().updateDiary(oldCategoryId);
} else {
//如果修改了分类
//再去新的分类
await Bind.find<DiaryLogic>().updateDiary(newCategoryId);
//先改旧分类
await Bind.find<DiaryLogic>().updateDiary(oldCategoryId, jump: false);
if (diary == newDiary) {
return;
}
var newCategoryId = newDiary!.categoryId;
var oldCategoryId = diary.categoryId;
//如果修改了但是没有修改分类,就替换掉原来的
if (oldCategoryId == newCategoryId) {
//替换掉全部分类中的
var oldIndex =
Bind.find<DiaryTabViewLogic>(tag: 'default').state.diaryList.indexWhere((e) => e.id == newDiary.id);
Bind.find<DiaryTabViewLogic>(tag: 'default').state.diaryList.replaceRange(oldIndex, oldIndex + 1, [newDiary]);
Bind.find<DiaryTabViewLogic>(tag: 'default').update(['TabView']);
//如果注册了控制器
if (newDiary.categoryId != null && Bind.isRegistered<DiaryTabViewLogic>(tag: newDiary.categoryId)) {
var oldIndex = Bind.find<DiaryTabViewLogic>(tag: newDiary.categoryId)
.state
.diaryList
.indexWhere((e) => e.id == newDiary.id);
Bind.find<DiaryTabViewLogic>(tag: newDiary.categoryId)
.state
.diaryList
.replaceRange(oldIndex, oldIndex + 1, [newDiary]);
Bind.find<DiaryTabViewLogic>(tag: newDiary.categoryId).update(['TabView']);
}
//await Bind.find<DiaryLogic>().updateDiary(oldCategoryId);
} else {
//如果修改了分类
//再去新的分类
await Bind.find<DiaryLogic>().updateDiary(newCategoryId);
//先改旧分类
await Bind.find<DiaryLogic>().updateDiary(oldCategoryId, jump: false);
}
}
}
Expand All @@ -62,7 +62,7 @@ mixin BasicCardLogic {
Bind.lazyPut(() => DiaryDetailsLogic(), tag: diary.id);
await Get.toNamed(
AppRoutes.diaryPage,
arguments: [diary, false],
arguments: [diary.clone(), false],
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class LargeDiaryCardComponent extends StatelessWidget with BasicCardLogic {

return InkWell(
borderRadius: AppBorderRadius.mediumBorderRadius,
onTap: () async {
await toDiary(diary);
onTap: () {
toDiary(diary);
},
child: Card.filled(
color: colorScheme.surfaceContainerLow,
Expand Down
1 change: 1 addition & 0 deletions lib/components/record_sheet/record_sheet_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RecordSheetComponent extends StatelessWidget {

return LayoutBuilder(builder: (context, constrains) {
return GetBuilder<RecordSheetLogic>(
assignId: true,
initState: (_) {
logic.initMaxWidth(constrains.maxWidth);
},
Expand Down
109 changes: 57 additions & 52 deletions lib/components/remove_password/remove_password_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,62 +79,67 @@ class RemovePasswordComponent extends StatelessWidget {
});
}

return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
spacing: 16.0,
children: [
Text(
'请输入密码',
style: textStyle.titleMedium,
),
GetBuilder<RemovePasswordLogic>(builder: (_) {
return AnimatedBuilder(
animation: logic.animation,
builder: (context, child) {
return Transform.translate(
offset: Offset(logic.interpolate(logic.animation.value), 0),
child: Wrap(
spacing: 16.0,
children: buildPasswordIndicator(),
),
);
},
);
}),
Row(
mainAxisAlignment: MainAxisAlignment.center,
return GetBuilder<RemovePasswordLogic>(
assignId: true,
builder: (_) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
spacing: 16.0,
children: [
SizedBox(
width: buttonSize * 3 + 20,
height: buttonSize * 4 + 30,
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: 1.0,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
physics: const NeverScrollableScrollPhysics(),
children: [
buildNumButton('1'),
buildNumButton('2'),
buildNumButton('3'),
buildNumButton('4'),
buildNumButton('5'),
buildNumButton('6'),
buildNumButton('7'),
buildNumButton('8'),
buildNumButton('9'),
buildBiometricsButton(),
buildNumButton('0'),
buildDeleteButton()
],
),
Text(
'请输入密码',
style: textStyle.titleMedium,
),
GetBuilder<RemovePasswordLogic>(builder: (_) {
return AnimatedBuilder(
animation: logic.animation,
builder: (context, child) {
return Transform.translate(
offset: Offset(logic.interpolate(logic.animation.value), 0),
child: Wrap(
spacing: 16.0,
children: buildPasswordIndicator(),
),
);
},
);
}),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: buttonSize * 3 + 20,
height: buttonSize * 4 + 30,
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: 1.0,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
physics: const NeverScrollableScrollPhysics(),
children: [
buildNumButton('1'),
buildNumButton('2'),
buildNumButton('3'),
buildNumButton('4'),
buildNumButton('5'),
buildNumButton('6'),
buildNumButton('7'),
buildNumButton('8'),
buildNumButton('9'),
buildBiometricsButton(),
buildNumButton('0'),
buildDeleteButton()
],
),
),
],
),
],
),
],
),
);
},
);
}
}
4 changes: 3 additions & 1 deletion lib/components/search_card/search_card_logic.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:get/get.dart';
import 'package:mood_diary/common/models/isar/diary.dart';
import 'package:mood_diary/pages/diary_details/diary_details_logic.dart';
import 'package:mood_diary/router/app_routes.dart';

import 'search_card_state.dart';
Expand All @@ -9,6 +10,7 @@ class SearchCardLogic extends GetxController {

//选中卡片后跳转到详情页,直接携带Diary作为参数
Future<void> toDiaryPage(Diary diary) async {
await Get.toNamed(AppRoutes.diaryPage, arguments: [diary, false]);
Bind.lazyPut(() => DiaryDetailsLogic(), tag: diary.id);
await Get.toNamed(AppRoutes.diaryPage, arguments: [diary.clone(), false]);
}
}
Loading
Loading