mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 11:39:46 +08:00
feat: change progress indicator
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
type Activity struct {
|
type Activity struct {
|
||||||
*ent.History
|
*ent.History
|
||||||
InBackgroud bool `json:"in_backgroud"`
|
InBackgroud bool `json:"in_backgroud"`
|
||||||
|
Progress int `json:"progress"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
||||||
@@ -22,10 +23,16 @@ func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
|||||||
History: h,
|
History: h,
|
||||||
}
|
}
|
||||||
for id, task := range s.tasks {
|
for id, task := range s.tasks {
|
||||||
|
if h.ID == id {
|
||||||
|
a.Progress = task.Progress()
|
||||||
|
}
|
||||||
if h.ID == id && task.Processing {
|
if h.ID == id && task.Processing {
|
||||||
a.InBackgroud = true
|
a.InBackgroud = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if a.Completed {
|
||||||
|
a.Progress = 100
|
||||||
|
}
|
||||||
activities = append(activities, a)
|
activities = append(activities, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:ui/providers/activity.dart';
|
import 'package:ui/providers/activity.dart';
|
||||||
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
|
||||||
class ActivityPage extends ConsumerWidget {
|
class ActivityPage extends ConsumerWidget {
|
||||||
static const route = "/activities";
|
static const route = "/activities";
|
||||||
@@ -18,8 +19,7 @@ class ActivityPage extends ConsumerWidget {
|
|||||||
DataColumn(label: Text("id"), numeric: true),
|
DataColumn(label: Text("id"), numeric: true),
|
||||||
DataColumn(label: Text("名称")),
|
DataColumn(label: Text("名称")),
|
||||||
DataColumn(label: Text("开始时间")),
|
DataColumn(label: Text("开始时间")),
|
||||||
DataColumn(label: Text("是否完成")),
|
DataColumn(label: Text("状态")),
|
||||||
DataColumn(label: Text("后台操作")),
|
|
||||||
DataColumn(label: Text("操作"))
|
DataColumn(label: Text("操作"))
|
||||||
],
|
],
|
||||||
rows: List<DataRow>.generate(activities.length, (i) {
|
rows: List<DataRow>.generate(activities.length, (i) {
|
||||||
@@ -29,8 +29,24 @@ class ActivityPage extends ConsumerWidget {
|
|||||||
DataCell(Text("${activity.id}")),
|
DataCell(Text("${activity.id}")),
|
||||||
DataCell(Text("${activity.sourceTitle}")),
|
DataCell(Text("${activity.sourceTitle}")),
|
||||||
DataCell(Text("${activity.date!.toLocal()}")),
|
DataCell(Text("${activity.date!.toLocal()}")),
|
||||||
DataCell(Text("${activity.completed}")),
|
DataCell(() {
|
||||||
DataCell(Text("${activity.inBackgroud}")),
|
if (activity.inBackgroud == true) {
|
||||||
|
return MyProgressIndicator(size: 20,);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activity.completed != true && activity.progress == 0) {
|
||||||
|
return MyProgressIndicator(
|
||||||
|
value: 1,
|
||||||
|
color: Colors.red,
|
||||||
|
size: 20,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MyProgressIndicator(
|
||||||
|
value: activity.progress!.toDouble() / 100,
|
||||||
|
size: 20,
|
||||||
|
);
|
||||||
|
}()),
|
||||||
DataCell(IconButton(
|
DataCell(IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ref
|
ref
|
||||||
@@ -44,8 +60,6 @@ class ActivityPage extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const Center(
|
loading: () => MyProgressIndicator());
|
||||||
child: SizedBox(
|
|
||||||
width: 30, height: 30, child: CircularProgressIndicator())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:ui/providers/APIs.dart';
|
import 'package:ui/providers/APIs.dart';
|
||||||
import 'package:ui/providers/server_response.dart';
|
import 'package:ui/providers/server_response.dart';
|
||||||
|
|
||||||
var activitiesDataProvider = AsyncNotifierProvider.autoDispose<ActivityData, List<Activity>>(
|
var activitiesDataProvider =
|
||||||
|
AsyncNotifierProvider.autoDispose<ActivityData, List<Activity>>(
|
||||||
ActivityData.new);
|
ActivityData.new);
|
||||||
|
|
||||||
class ActivityData extends AutoDisposeAsyncNotifier<List<Activity>> {
|
class ActivityData extends AutoDisposeAsyncNotifier<List<Activity>> {
|
||||||
@@ -35,40 +36,42 @@ class ActivityData extends AutoDisposeAsyncNotifier<List<Activity>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Activity {
|
class Activity {
|
||||||
Activity({
|
Activity({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.seriesId,
|
required this.seriesId,
|
||||||
required this.episodeId,
|
required this.episodeId,
|
||||||
required this.sourceTitle,
|
required this.sourceTitle,
|
||||||
required this.date,
|
required this.date,
|
||||||
required this.targetDir,
|
required this.targetDir,
|
||||||
required this.completed,
|
required this.completed,
|
||||||
required this.saved,
|
required this.saved,
|
||||||
required this.inBackgroud,
|
required this.inBackgroud,
|
||||||
});
|
required this.progress
|
||||||
|
});
|
||||||
|
|
||||||
final int? id;
|
final int? id;
|
||||||
final int? seriesId;
|
final int? seriesId;
|
||||||
final int? episodeId;
|
final int? episodeId;
|
||||||
final String? sourceTitle;
|
final String? sourceTitle;
|
||||||
final DateTime? date;
|
final DateTime? date;
|
||||||
final String? targetDir;
|
final String? targetDir;
|
||||||
final bool? completed;
|
final bool? completed;
|
||||||
final String? saved;
|
final String? saved;
|
||||||
final bool? inBackgroud;
|
final bool? inBackgroud;
|
||||||
|
final int? progress;
|
||||||
factory Activity.fromJson(Map<String, dynamic> json){
|
|
||||||
return Activity(
|
|
||||||
id: json["id"],
|
|
||||||
seriesId: json["series_id"],
|
|
||||||
episodeId: json["episode_id"],
|
|
||||||
sourceTitle: json["source_title"],
|
|
||||||
date: DateTime.tryParse(json["date"] ?? ""),
|
|
||||||
targetDir: json["target_dir"],
|
|
||||||
completed: json["completed"],
|
|
||||||
saved: json["saved"],
|
|
||||||
inBackgroud: json["in_backgroud"],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
factory Activity.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Activity(
|
||||||
|
id: json["id"],
|
||||||
|
seriesId: json["series_id"],
|
||||||
|
episodeId: json["episode_id"],
|
||||||
|
sourceTitle: json["source_title"],
|
||||||
|
date: DateTime.tryParse(json["date"] ?? ""),
|
||||||
|
targetDir: json["target_dir"],
|
||||||
|
completed: json["completed"],
|
||||||
|
saved: json["saved"],
|
||||||
|
inBackgroud: json["in_backgroud"],
|
||||||
|
progress: json["progress"]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:ui/providers/APIs.dart';
|
import 'package:ui/providers/APIs.dart';
|
||||||
import 'package:ui/providers/settings.dart';
|
import 'package:ui/providers/settings.dart';
|
||||||
import 'package:ui/providers/welcome_data.dart';
|
import 'package:ui/providers/welcome_data.dart';
|
||||||
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
|
||||||
class SearchPage extends ConsumerStatefulWidget {
|
class SearchPage extends ConsumerStatefulWidget {
|
||||||
const SearchPage({super.key});
|
const SearchPage({super.key});
|
||||||
@@ -69,7 +70,7 @@ class _SearchPageState extends ConsumerState<SearchPage> {
|
|||||||
return cards;
|
return cards;
|
||||||
},
|
},
|
||||||
error: (err, trace) => [Text("$err")],
|
error: (err, trace) => [Text("$err")],
|
||||||
loading: () => [const CircularProgressIndicator()]);
|
loading: () => [MyProgressIndicator()]);
|
||||||
|
|
||||||
var f = FutureBuilder(
|
var f = FutureBuilder(
|
||||||
// We listen to the pending operation, to update the UI accordingly.
|
// We listen to the pending operation, to update the UI accordingly.
|
||||||
@@ -77,9 +78,7 @@ class _SearchPageState extends ConsumerState<SearchPage> {
|
|||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState != ConnectionState.done &&
|
if (snapshot.connectionState != ConnectionState.done &&
|
||||||
snapshot.connectionState != ConnectionState.none) {
|
snapshot.connectionState != ConnectionState.none) {
|
||||||
return const Center(
|
return MyProgressIndicator();
|
||||||
child: SizedBox(
|
|
||||||
width: 30, height: 30, child: CircularProgressIndicator()));
|
|
||||||
}
|
}
|
||||||
return ListView(
|
return ListView(
|
||||||
children: res,
|
children: res,
|
||||||
@@ -149,7 +148,7 @@ class _SearchPageState extends ConsumerState<SearchPage> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const CircularProgressIndicator()),
|
loading: () => MyProgressIndicator()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:quiver/strings.dart';
|
|||||||
import 'package:ui/providers/login.dart';
|
import 'package:ui/providers/login.dart';
|
||||||
import 'package:ui/providers/settings.dart';
|
import 'package:ui/providers/settings.dart';
|
||||||
import 'package:ui/utils.dart';
|
import 'package:ui/utils.dart';
|
||||||
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
|
||||||
import 'providers/APIs.dart';
|
import 'providers/APIs.dart';
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const CircularProgressIndicator()),
|
loading: () => MyProgressIndicator()),
|
||||||
dirKey.when(
|
dirKey.when(
|
||||||
data: (data) {
|
data: (data) {
|
||||||
_downloadDirController.text = data;
|
_downloadDirController.text = data;
|
||||||
@@ -80,7 +81,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const CircularProgressIndicator()),
|
loading: () => MyProgressIndicator()),
|
||||||
Center(
|
Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(top: 28.0),
|
padding: const EdgeInsets.only(top: 28.0),
|
||||||
@@ -154,7 +155,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
)));
|
)));
|
||||||
}),
|
}),
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const CircularProgressIndicator());
|
loading: () => MyProgressIndicator());
|
||||||
});
|
});
|
||||||
|
|
||||||
var downloadClients = ref.watch(dwonloadClientsProvider);
|
var downloadClients = ref.watch(dwonloadClientsProvider);
|
||||||
@@ -197,7 +198,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
)));
|
)));
|
||||||
}),
|
}),
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const CircularProgressIndicator());
|
loading: () => MyProgressIndicator());
|
||||||
});
|
});
|
||||||
|
|
||||||
var storageSettingData = ref.watch(storageSettingProvider);
|
var storageSettingData = ref.watch(storageSettingProvider);
|
||||||
@@ -238,7 +239,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
)));
|
)));
|
||||||
}),
|
}),
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const CircularProgressIndicator());
|
loading: () => MyProgressIndicator());
|
||||||
});
|
});
|
||||||
|
|
||||||
var authData = ref.watch(authSettingProvider);
|
var authData = ref.watch(authSettingProvider);
|
||||||
@@ -293,7 +294,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
error: (err, trace) => Text("$err"),
|
error: (err, trace) => Text("$err"),
|
||||||
loading: () => const CircularProgressIndicator());
|
loading: () => MyProgressIndicator());
|
||||||
|
|
||||||
return ListView(
|
return ListView(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:ui/providers/APIs.dart';
|
|||||||
import 'package:ui/providers/series_details.dart';
|
import 'package:ui/providers/series_details.dart';
|
||||||
import 'package:ui/utils.dart';
|
import 'package:ui/utils.dart';
|
||||||
import 'package:ui/weclome.dart';
|
import 'package:ui/weclome.dart';
|
||||||
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
|
||||||
class TvDetailsPage extends ConsumerStatefulWidget {
|
class TvDetailsPage extends ConsumerStatefulWidget {
|
||||||
static const route = "/series/:id";
|
static const route = "/series/:id";
|
||||||
@@ -160,11 +161,7 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
error: (err, trace) {
|
error: (err, trace) {
|
||||||
return Text("$err");
|
return Text("$err");
|
||||||
},
|
},
|
||||||
loading: () => const Center(
|
loading: () => MyProgressIndicator());
|
||||||
child: SizedBox(
|
|
||||||
width: 30,
|
|
||||||
height: 30,
|
|
||||||
child: CircularProgressIndicator())));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:ui/providers/APIs.dart';
|
import 'package:ui/providers/APIs.dart';
|
||||||
import 'package:ui/providers/welcome_data.dart';
|
import 'package:ui/providers/welcome_data.dart';
|
||||||
import 'package:ui/tv_details.dart';
|
import 'package:ui/tv_details.dart';
|
||||||
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
|
||||||
class WelcomePage extends ConsumerWidget {
|
class WelcomePage extends ConsumerWidget {
|
||||||
static const route = "/series";
|
static const route = "/series";
|
||||||
@@ -48,9 +49,7 @@ class WelcomePage extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
));
|
));
|
||||||
}),
|
}),
|
||||||
_ => const Center(
|
_ => MyProgressIndicator(),
|
||||||
child: SizedBox(
|
|
||||||
width: 30, height: 30, child: CircularProgressIndicator())),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
ui/lib/widgets/progress_indicator.dart
Normal file
20
ui/lib/widgets/progress_indicator.dart
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class MyProgressIndicator extends StatelessWidget {
|
||||||
|
double size;
|
||||||
|
Color? color;
|
||||||
|
double? value;
|
||||||
|
|
||||||
|
MyProgressIndicator({super.key, this.size = 30, this.color, this.value});
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: color,
|
||||||
|
value: value,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user