Skip to content

Commit

Permalink
Merge pull request #42 from ZhuJHua/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
ZhuJHua authored Nov 18, 2024
2 parents ef38f4d + 5239fc5 commit 4e188a3
Show file tree
Hide file tree
Showing 79 changed files with 7,619 additions and 91 deletions.
3 changes: 3 additions & 0 deletions flutter_rust_bridge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rust_input: crate::api
rust_root: rust/
dart_output: lib/src/rust
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1610;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1610"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:intl/find_locale.dart';
import 'package:media_kit/media_kit.dart';
import 'package:mood_diary/router/app_pages.dart';
import 'package:mood_diary/router/app_routes.dart';
import 'package:mood_diary/src/rust/frb_generated.dart';
import 'package:mood_diary/utils/utils.dart';

import 'components/window_buttons/window_buttons.dart';
Expand All @@ -29,6 +30,7 @@ Future<void> initSystem() async {
//地图缓存
await FMTCObjectBoxBackend().initialise();
await const FMTCStore('mapStore').manage.create();
await RustLib.init();
platFormOption();
}

Expand Down
10 changes: 10 additions & 0 deletions lib/pages/diary_details/diary_details_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:get/get.dart';
import 'package:mood_diary/common/models/isar/diary.dart';
Expand All @@ -20,14 +21,19 @@ class DiaryDetailsLogic extends GetxController {
selection: const TextSelection.collapsed(offset: 0),
);

// 图片预览
late final PageController pageController = PageController();

@override
void onClose() {
quillController.dispose();
pageController.dispose();
super.onClose();
}

//点击图片跳转到图片预览页面
void toPhotoView(List<String> imagePathList, int index) {
HapticFeedback.selectionClick();
Get.toNamed(AppRoutes.photoPage, arguments: [imagePathList, index]);
}

Expand Down Expand Up @@ -61,4 +67,8 @@ class DiaryDetailsLogic extends GetxController {
await Utils().isarUtil.updateADiary(diary..show = false);
Get.backLegacy(result: 'delete');
}

Future<void> jumpToPage(int index) async {
await pageController.animateToPage(index, duration: const Duration(milliseconds: 200), curve: Curves.easeInOut);
}
}
98 changes: 78 additions & 20 deletions lib/pages/diary_details/diary_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:mood_diary/components/ask_question/ask_question_view.dart';
import 'package:mood_diary/components/audio_player/audio_player_view.dart';
import 'package:mood_diary/components/mood_icon/mood_icon_view.dart';
import 'package:mood_diary/utils/utils.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';

import 'diary_details_logic.dart';

Expand Down Expand Up @@ -182,6 +183,80 @@ class DiaryDetailsPage extends StatelessWidget {
);
}

Widget buildCoverImage() {
return InkWell(
onTap: () {
logic.toPhotoView(
List.generate(state.diary.imageName.length, (index) {
return Utils().fileUtil.getRealPath('image', state.diary.imageName[index]);
}),
0);
},
child: Image.file(
File(Utils().fileUtil.getRealPath('image', state.diary.imageName.first)),
fit: BoxFit.cover,
),
);
}

Widget buildImageView(ColorScheme colorScheme) {
return Stack(
alignment: Alignment.center,
children: [
PageView.builder(
controller: logic.pageController,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
logic.toPhotoView(
List.generate(state.diary.imageName.length, (i) {
return Utils().fileUtil.getRealPath('image', state.diary.imageName[i]);
}),
index,
);
},
child: Image.file(
File(Utils().fileUtil.getRealPath('image', state.diary.imageName[index])),
fit: BoxFit.cover,
),
);
},
itemCount: state.diary.imageName.length,
),
Positioned(
bottom: 0,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: ShapeDecoration(
shape: const StadiumBorder(side: BorderSide.none),
color: colorScheme.surfaceContainer.withAlpha(100)),
padding: const EdgeInsets.all(2.0),
child: SmoothPageIndicator(
controller: logic.pageController,
count: state.diary.imageName.length,
effect: state.diary.imageName.length > 9
? ScrollingDotsEffect(
activeDotColor: colorScheme.tertiary,
dotColor: colorScheme.surfaceContainerLow.withAlpha(200),
dotWidth: 8,
dotHeight: 8,
maxVisibleDots: 9)
: WormEffect(
activeDotColor: colorScheme.tertiary,
dotColor: colorScheme.surfaceContainerLow.withAlpha(200),
dotWidth: 8,
dotHeight: 8,
),
onDotClicked: logic.jumpToPage,
),
),
),
)
],
);
}

return GetBuilder<DiaryDetailsLogic>(
tag: state.diary.id,
builder: (_) {
Expand All @@ -207,21 +282,7 @@ class DiaryDetailsPage extends StatelessWidget {
),
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: state.diary.imageName.isNotEmpty
? InkWell(
onTap: () {
logic.toPhotoView(
List.generate(state.diary.imageName.length, (index) {
return Utils().fileUtil.getRealPath('image', state.diary.imageName[index]);
}),
0);
},
child: Image.file(
File(Utils().fileUtil.getRealPath('image', state.diary.imageName.first)),
fit: BoxFit.cover,
),
)
: null,
background: state.diary.imageName.isNotEmpty ? buildImageView(customColorScheme) : null,
),
pinned: true,
actions: [
Expand Down Expand Up @@ -306,13 +367,10 @@ class DiaryDetailsPage extends StatelessWidget {
),
),
),
buildAudioList(),
Wrap(
children: [
if (state.diary.imageName.length > 1) ...buildMultiImages(customColorScheme),
if (state.diary.videoName.isNotEmpty) ...buildMultiVideo(customColorScheme)
],
children: [if (state.diary.videoName.isNotEmpty) ...buildMultiVideo(customColorScheme)],
),
buildAudioList()
],
),
),
Expand Down
11 changes: 5 additions & 6 deletions lib/pages/edit/edit_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ class EditLogic extends GetxController with WidgetsBindingObserver {

//相册选择多张照片
Future<void> pickMultiPhoto() async {
//获取一堆照片,最多10张
List<XFile> photoList = await Utils().mediaUtil.pickMultiPhoto(10);
//获取一堆照片
List<XFile> photoList = await Utils().mediaUtil.pickMultiPhoto(null);
if (photoList.isNotEmpty) {
//关闭dialog
Get.backLegacy();
if (photoList.length > 10 - state.imageFileList.length) {
photoList = photoList.sublist(0, 10 - state.imageFileList.length);
}
// if (photoList.length > 10 - state.imageFileList.length) {
// photoList = photoList.sublist(0, 10 - state.imageFileList.length);
// }
for (var photo in photoList) {
addNewImage(photo);
}
Expand Down Expand Up @@ -317,7 +317,6 @@ class EditLogic extends GetxController with WidgetsBindingObserver {
..imageColor = await getCoverColor()
..aspect = await getCoverAspect();
await Utils().isarUtil.updateADiary(state.currentDiary);
Utils().logUtil.printInfo(state.currentDiary.toJson());
Get.backLegacy();
state.isNew ? Get.backLegacy(result: state.currentDiary.categoryId ?? '') : Get.backLegacy(result: 'changed');
Utils().noticeUtil.showToast(state.isNew ? '保存成功' : '修改成功');
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/edit/edit_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class EditPage extends StatelessWidget {
),
);
}),
if (state.imageFileList.length < 10) ...[
...[
InkWell(
borderRadius: AppBorderRadius.smallBorderRadius,
onTap: () {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/video/video_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VideoLogic extends GetxController {

@override
void onReady() async {
await player.open(state.playable, play: false);
await player.open(state.playable, play: true);
player.stream.playlist.listen((data) {
state.videoIndex.value = data.index;
});
Expand Down
68 changes: 47 additions & 21 deletions lib/pages/video/video_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:media_kit_video/media_kit_video.dart';
Expand All @@ -13,32 +15,56 @@ class VideoPage extends StatelessWidget {
final state = Bind.find<VideoLogic>().state;
final colorScheme = Theme.of(context).colorScheme;

return GetBuilder<VideoLogic>(
builder: (_) {
Widget buildCustomTheme({required Widget child}) {
if (Platform.isAndroid || Platform.isIOS) {
return MaterialVideoControlsTheme(
normal: MaterialVideoControlsThemeData(
normal: kDefaultMaterialVideoControlsThemeData.copyWith(
seekBarPositionColor: colorScheme.primary,
seekBarThumbColor: colorScheme.primary,
),
fullscreen: kDefaultMaterialVideoControlsThemeDataFullscreen.copyWith(
seekBarPositionColor: colorScheme.primary,
seekBarThumbColor: colorScheme.primary,
),
child: child,
);
} else {
return MaterialDesktopVideoControlsTheme(
normal: kDefaultMaterialDesktopVideoControlsThemeData.copyWith(
seekBarPositionColor: colorScheme.primary,
seekBarThumbColor: colorScheme.primary,
padding: const EdgeInsets.only(bottom: 56.0),
),
fullscreen: MaterialVideoControlsThemeData(
seekBarPositionColor: colorScheme.primary,
seekBarThumbColor: colorScheme.primary,
padding: const EdgeInsets.only(bottom: 24.0)),
child: Scaffold(
fullscreen: kDefaultMaterialDesktopVideoControlsThemeData.copyWith(
seekBarPositionColor: colorScheme.primary,
seekBarThumbColor: colorScheme.primary,
),
child: child,
);
}
}

return GetBuilder<VideoLogic>(
builder: (_) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.black,
title: Obx(() {
return Text(
'${state.videoIndex.value + 1}/${state.videoPathList.length}',
style: const TextStyle(color: Colors.white),
);
}),
iconTheme: const IconThemeData(color: Colors.white),
),
body: Video(
controller: logic.videoController,
title: Obx(() {
return Text(
'${state.videoIndex.value + 1}/${state.videoPathList.length}',
style: const TextStyle(color: Colors.white),
);
}),
iconTheme: const IconThemeData(color: Colors.white),
),
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 56.0),
child: buildCustomTheme(
child: Video(
controller: logic.videoController,
controls: AdaptiveVideoControls,
alignment: Alignment.center,
),
),
),
);
Expand Down
35 changes: 35 additions & 0 deletions lib/src/rust/api/compress.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.6.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

import '../frb_generated.dart';
import 'constants.dart';

// These functions are ignored because they are not marked as `pub`: `calculate_target_dimensions`, `load_image`

Future<Uint8List> compress(
{required DynamicImage img,
required int dstHeight,
required int dstWidth,
required CompressFormat compressFormat,
required int quality}) =>
RustLib.instance.api.crateApiCompressCompress(
img: img, dstHeight: dstHeight, dstWidth: dstWidth, compressFormat: compressFormat, quality: quality);

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<DynamicImage>>
abstract class DynamicImage implements RustOpaqueInterface {}

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<ImageCompress>>
abstract class ImageCompress implements RustOpaqueInterface {
static Future<Uint8List> contain(
{required String filePath, CompressFormat? compressFormat, int? maxWidth, int? maxHeight, int? quality}) =>
RustLib.instance.api.crateApiCompressImageCompressContain(
filePath: filePath,
compressFormat: compressFormat,
maxWidth: maxWidth,
maxHeight: maxHeight,
quality: quality);
}
17 changes: 17 additions & 0 deletions lib/src/rust/api/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.6.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

import '../frb_generated.dart';

// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `assert_receiver_is_total_eq`, `eq`

enum CompressFormat {
jpeg,
webP,
png,
;
}
Loading

0 comments on commit 4e188a3

Please sign in to comment.