Skip to content

Commit

Permalink
✨feature: transfer page
Browse files Browse the repository at this point in the history
  • Loading branch information
tom8zds committed Jul 7, 2024
1 parent 24ad684 commit 4bf828e
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// Locales: 2
/// Strings: 26 (13 per locale)
///
/// Built on 2024-07-07 at 04:08 UTC
/// Built on 2024-07-07 at 04:40 UTC
// coverage:ignore-file
// ignore_for_file: type=lint
Expand Down
10 changes: 4 additions & 6 deletions lib/view/pages/frame_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ class _FramePageState extends ConsumerState<FramePage> {

final width = MediaQuery.of(context).size.width;
final frameType = getFrameType(width);
if (frameType == FrameType.compact) {
if (data != null && data.state == MissionState.pending) {
return const MissionPendingPage(
isParalle: false,
);
}
if (frameType == FrameType.compact && data != null) {
return const MissionPendingPage(
isParalle: false,
);
}
return Scaffold(
body: SafeArea(child: getView(frameType)),
Expand Down
115 changes: 95 additions & 20 deletions lib/view/pages/mission_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,108 @@ class TransferPage extends StatelessWidget {
backgroundColor: isParalle ? Colors.transparent : null,
body: Column(
children: [
for (final file in mission.files)
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(12)),
height: 96,
child: Row(
Expanded(
child: ListView.builder(
itemCount: mission.files.length,
itemBuilder: (context, index) {
final file = mission.files.elementAt(index);
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 8),
child: Container(
height: 72,
child: Row(
children: [
SizedBox(
width: 8,
),
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondary,
borderRadius: BorderRadius.circular(12),
),
height: 48,
width: 48,
child: Icon(
Icons.file_present,
size: 36,
),
),
SizedBox(
width: 8,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(file.info.fileName),
Text(file.state.toString()),
LinearProgressIndicator(value: 0.3),
],
),
),
SizedBox(
width: 16,
),
],
),
),
);
})),
Container(
margin: EdgeInsets.symmetric(
horizontal: 16,
),
padding: EdgeInsets.symmetric(
vertical: 8,
horizontal: 16,
),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(12),
),
height: 96,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
mission.state.toString(),
style: Theme.of(context).textTheme.titleMedium,
),
SizedBox(
height: 8,
),
LinearProgressIndicator(
value: 0.3,
minHeight: 8,
borderRadius: BorderRadius.circular(12),
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(Icons.file_present),
SizedBox(
width: 8,
TextButton.icon(
onPressed: () {},
label: Text("高级"),
icon: Icon(Icons.info),
),
Column(
children: [
Text(file.info.fileName),
Text(file.state.toString()),
LinearProgressIndicator(value: 0.3),
],
TextButton.icon(
onPressed: () {
clearMission();
},
label: Text("取消"),
icon: Icon(Icons.info),
)
],
),
),
],
),
),
const SizedBox(
height: 32,
height: 16,
)
],
),
Expand Down
58 changes: 31 additions & 27 deletions rust/src/actor/mission/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,47 +117,51 @@ impl Actor {
};

self.store.mission.replace(transfer_mission.clone());
MISSION_NOTIFY.notify(Some(MissionInfo::from_transfer_mission(transfer_mission)));
MISSION_NOTIFY
.notify(Some(MissionInfo::from_transfer_mission(transfer_mission)))
.await;
let _ = respond_to.send(Ok(()));
}
Message::StartTask {
id,
token,
respond_to,
} => match &self.store.mission {
Some(mission) => {
if mission.id != id {
let _ = respond_to.send(Err("mission not exist".to_string()));
return;
}
if !mission.files.contains_key(&token) {
let _ = respond_to.send(Err("task token not exist".to_string()));
return;
}
} => {
let mission = self.store.mission.as_mut().unwrap();
if mission.id != id {
let _ = respond_to.send(Err("mission not exist".to_string()));
return;
}
if !mission.files.contains_key(&token) {
let _ = respond_to.send(Err("task token not exist".to_string()));
return;
}

let file = mission.files.get(&token).unwrap();
let mut file = mission.files.get(&token).unwrap().clone();
file.state = FileState::Transfer;
mission.files.insert(token.clone(), file.clone());

let (tx, rx) = watch::channel(0);
let (tx, rx) = watch::channel(0);

let task = TransferTask {
token: token,
state: TaskState::Transfering,
progress: rx,
};
let task = TransferTask {
token: token,
state: TaskState::Transfering,
progress: rx,
};

self.store.task.replace(task);
let _ = respond_to.send(Ok((tx, file.info.clone())));
return;
}
None => {
let _ = respond_to.send(Err("mission not exist".to_string()));
}
},
self.store.task.replace(task);

let _ = respond_to.send(Ok((tx, file.info)));
}
Message::Finish { id, respond_to } => {
match &self.store.mission {
Some(mission) => {
if mission.id == id {
let _ = self.store.mission.take();
let mut mission = self.store.mission.take().unwrap();
mission.state = MissionState::Finished;
MISSION_NOTIFY
.notify(Some(MissionInfo::from_transfer_mission(mission)))
.await;
}
}
None => {}
Expand Down

0 comments on commit 4bf828e

Please sign in to comment.