mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 12:57:24 +00:00
search settings
This commit is contained in:
@@ -7,6 +7,8 @@ import 'network/models.dart';
|
|||||||
class _Appdata {
|
class _Appdata {
|
||||||
Account? account;
|
Account? account;
|
||||||
|
|
||||||
|
var searchOptions = SearchOptions();
|
||||||
|
|
||||||
void writeData() async {
|
void writeData() async {
|
||||||
await File("${App.dataPath}/account.json")
|
await File("${App.dataPath}/account.json")
|
||||||
.writeAsString(jsonEncode(account));
|
.writeAsString(jsonEncode(account));
|
||||||
|
@@ -3,7 +3,7 @@ import 'package:pixes/foundation/app.dart';
|
|||||||
import 'package:pixes/network/res.dart';
|
import 'package:pixes/network/res.dart';
|
||||||
|
|
||||||
abstract class LoadingState<T extends StatefulWidget, S extends Object> extends State<T>{
|
abstract class LoadingState<T extends StatefulWidget, S extends Object> extends State<T>{
|
||||||
bool isLoading = true;
|
bool isLoading = false;
|
||||||
|
|
||||||
S? data;
|
S? data;
|
||||||
|
|
||||||
@@ -14,8 +14,9 @@ abstract class LoadingState<T extends StatefulWidget, S extends Object> extends
|
|||||||
Widget buildContent(BuildContext context, S data);
|
Widget buildContent(BuildContext context, S data);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
@mustCallSuper
|
||||||
if(isLoading){
|
void initState() {
|
||||||
|
isLoading = true;
|
||||||
loadData().then((value) {
|
loadData().then((value) {
|
||||||
if(value.success) {
|
if(value.success) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -29,6 +30,12 @@ abstract class LoadingState<T extends StatefulWidget, S extends Object> extends
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if(isLoading){
|
||||||
return const Center(
|
return const Center(
|
||||||
child: ProgressRing(),
|
child: ProgressRing(),
|
||||||
);
|
);
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import 'package:pixes/appdata.dart';
|
||||||
|
|
||||||
class Account {
|
class Account {
|
||||||
String accessToken;
|
String accessToken;
|
||||||
String refreshToken;
|
String refreshToken;
|
||||||
@@ -213,3 +215,74 @@ class TrendingTag {
|
|||||||
|
|
||||||
TrendingTag(this.tag, this.illust);
|
TrendingTag(this.tag, this.illust);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum KeywordMatchType {
|
||||||
|
tagsPartialMatches("Tags partial matches"),
|
||||||
|
tagsExactMatch("Tags exact match"),
|
||||||
|
titleOrDescriptionSearch("Title or description search");
|
||||||
|
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
const KeywordMatchType(this.text);
|
||||||
|
|
||||||
|
@override
|
||||||
|
toString() => text;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum FavoriteNumber {
|
||||||
|
unlimited(-1),
|
||||||
|
f500(500),
|
||||||
|
f1000(1000),
|
||||||
|
f2000(2000),
|
||||||
|
f5000(5000),
|
||||||
|
f7500(7500),
|
||||||
|
f10000(10000),
|
||||||
|
f20000(20000),
|
||||||
|
f50000(50000),
|
||||||
|
f100000(100000);
|
||||||
|
|
||||||
|
final int number;
|
||||||
|
const FavoriteNumber(this.number);
|
||||||
|
|
||||||
|
@override
|
||||||
|
toString() => this == FavoriteNumber.unlimited ? "Unlimited" : "$number Bookmarks";
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SearchSort {
|
||||||
|
newToOld,
|
||||||
|
oldToNew,
|
||||||
|
popular;
|
||||||
|
|
||||||
|
@override
|
||||||
|
toString() {
|
||||||
|
if(this == SearchSort.popular) {
|
||||||
|
return appdata.account?.user.isPremium == true ? "Popular" : "Popular(limited)";
|
||||||
|
} else if(this == SearchSort.newToOld) {
|
||||||
|
return "New to old";
|
||||||
|
} else {
|
||||||
|
return "Old to new";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum AgeLimit {
|
||||||
|
unlimited("Unlimited"),
|
||||||
|
allAges("All ages"),
|
||||||
|
r18("R18");
|
||||||
|
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
const AgeLimit(this.text);
|
||||||
|
|
||||||
|
@override
|
||||||
|
toString() => text;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchOptions {
|
||||||
|
KeywordMatchType matchType = KeywordMatchType.tagsPartialMatches;
|
||||||
|
FavoriteNumber favoriteNumber = FavoriteNumber.unlimited;
|
||||||
|
SearchSort sort = SearchSort.newToOld;
|
||||||
|
DateTime? startTime;
|
||||||
|
DateTime? endTime;
|
||||||
|
AgeLimit ageLimit = AgeLimit.unlimited;
|
||||||
|
}
|
||||||
|
@@ -31,7 +31,7 @@ class MainPage extends StatefulWidget {
|
|||||||
class _MainPageState extends State<MainPage> with WindowListener {
|
class _MainPageState extends State<MainPage> with WindowListener {
|
||||||
final navigatorKey = GlobalKey<NavigatorState>();
|
final navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
int index = 1;
|
int index = 2;
|
||||||
|
|
||||||
int windowButtonKey = 0;
|
int windowButtonKey = 0;
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||||
|
import 'package:pixes/appdata.dart';
|
||||||
import 'package:pixes/components/loading.dart';
|
import 'package:pixes/components/loading.dart';
|
||||||
import 'package:pixes/components/page_route.dart';
|
import 'package:pixes/components/page_route.dart';
|
||||||
import 'package:pixes/foundation/app.dart';
|
import 'package:pixes/foundation/app.dart';
|
||||||
@@ -246,9 +247,83 @@ class _SearchSettingsState extends State<SearchSettings> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
||||||
child: Text("Search Settings".tl, style: const TextStyle(fontSize: 18),),
|
child: Text("Search Settings".tl, style: const TextStyle(fontSize: 18),),
|
||||||
).toAlign(Alignment.centerLeft),
|
).toAlign(Alignment.centerLeft),
|
||||||
|
buildItem(title: "Match".tl, child: DropDownButton(
|
||||||
|
title: Text(appdata.searchOptions.matchType.toString()),
|
||||||
|
items: KeywordMatchType.values.map((e) =>
|
||||||
|
MenuFlyoutItem(
|
||||||
|
text: Text(e.toString()),
|
||||||
|
onPressed: () => setState(() => appdata.searchOptions.matchType = e)
|
||||||
|
)
|
||||||
|
).toList(),
|
||||||
|
)),
|
||||||
|
buildItem(title: "Favorite number".tl, child: DropDownButton(
|
||||||
|
title: Text(appdata.searchOptions.favoriteNumber.toString()),
|
||||||
|
items: FavoriteNumber.values.map((e) =>
|
||||||
|
MenuFlyoutItem(
|
||||||
|
text: Text(e.toString()),
|
||||||
|
onPressed: () => setState(() => appdata.searchOptions.favoriteNumber = e)
|
||||||
|
)
|
||||||
|
).toList(),
|
||||||
|
)),
|
||||||
|
buildItem(title: "Sort".tl, child: DropDownButton(
|
||||||
|
title: Text(appdata.searchOptions.sort.toString()),
|
||||||
|
items: SearchSort.values.map((e) =>
|
||||||
|
MenuFlyoutItem(
|
||||||
|
text: Text(e.toString()),
|
||||||
|
onPressed: () => setState(() => appdata.searchOptions.sort = e)
|
||||||
|
)
|
||||||
|
).toList(),
|
||||||
|
)),
|
||||||
|
Card(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||||
|
child: SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const Text("Start Time", style: TextStyle(fontSize: 16),)
|
||||||
|
.paddingVertical(8)
|
||||||
|
.toAlign(Alignment.centerLeft)
|
||||||
|
.paddingLeft(16),
|
||||||
|
DatePicker(
|
||||||
|
selected: appdata.searchOptions.startTime,
|
||||||
|
onChanged: (t) => setState(() => appdata.searchOptions.startTime = t),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8,)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
Card(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||||
|
child: SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const Text("End Time", style: TextStyle(fontSize: 16),)
|
||||||
|
.paddingVertical(8)
|
||||||
|
.toAlign(Alignment.centerLeft)
|
||||||
|
.paddingLeft(16),
|
||||||
|
DatePicker(
|
||||||
|
selected: appdata.searchOptions.endTime,
|
||||||
|
onChanged: (t) => setState(() => appdata.searchOptions.endTime = t),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8,)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
buildItem(title: "Age limit".tl, child: DropDownButton(
|
||||||
|
title: Text(appdata.searchOptions.ageLimit.toString()),
|
||||||
|
items: AgeLimit.values.map((e) =>
|
||||||
|
MenuFlyoutItem(
|
||||||
|
text: Text(e.toString()),
|
||||||
|
onPressed: () => setState(() => appdata.searchOptions.ageLimit = e)
|
||||||
|
)
|
||||||
|
).toList(),
|
||||||
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user