mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 12:57:24 +00:00
page view
This commit is contained in:
@@ -10,10 +10,12 @@ import '../pages/illust_page.dart';
|
|||||||
import 'md.dart';
|
import 'md.dart';
|
||||||
|
|
||||||
class IllustWidget extends StatefulWidget {
|
class IllustWidget extends StatefulWidget {
|
||||||
const IllustWidget(this.illust, {super.key});
|
const IllustWidget(this.illust, {this.onTap, super.key});
|
||||||
|
|
||||||
final Illust illust;
|
final Illust illust;
|
||||||
|
|
||||||
|
final void Function()? onTap;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<IllustWidget> createState() => _IllustWidgetState();
|
State<IllustWidget> createState() => _IllustWidgetState();
|
||||||
}
|
}
|
||||||
@@ -45,7 +47,7 @@ class _IllustWidgetState extends State<IllustWidget> {
|
|||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
margin: EdgeInsets.zero,
|
margin: EdgeInsets.zero,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: (){
|
onTap: widget.onTap ?? (){
|
||||||
context.to(() => IllustPage(widget.illust, favoriteCallback: (v) {
|
context.to(() => IllustPage(widget.illust, favoriteCallback: (v) {
|
||||||
setState(() {
|
setState(() {
|
||||||
widget.illust.isBookmarked = v;
|
widget.illust.isBookmarked = v;
|
||||||
|
@@ -208,13 +208,14 @@ class Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const recommendationUrl = "/v1/illust/recommended?include_privacy_policy=true&filter=for_android&include_ranking_illusts=true";
|
||||||
|
|
||||||
Future<Res<List<Illust>>> getRecommendedIllusts() async {
|
Future<Res<List<Illust>>> getRecommendedIllusts() async {
|
||||||
var res = await apiGet(
|
var res = await apiGet(recommendationUrl);
|
||||||
"/v1/illust/recommended?include_privacy_policy=true&filter=for_android&include_ranking_illusts=true");
|
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
return Res((res.data["illusts"] as List)
|
return Res((res.data["illusts"] as List)
|
||||||
.map((e) => Illust.fromJson(e))
|
.map((e) => Illust.fromJson(e))
|
||||||
.toList());
|
.toList(), subData: recommendationUrl);
|
||||||
} else {
|
} else {
|
||||||
return Res.error(res.errorMessage);
|
return Res.error(res.errorMessage);
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import 'package:pixes/components/segmented_button.dart';
|
|||||||
import 'package:pixes/components/title_bar.dart';
|
import 'package:pixes/components/title_bar.dart';
|
||||||
import 'package:pixes/foundation/app.dart';
|
import 'package:pixes/foundation/app.dart';
|
||||||
import 'package:pixes/network/network.dart';
|
import 'package:pixes/network/network.dart';
|
||||||
|
import 'package:pixes/pages/illust_page.dart';
|
||||||
import 'package:pixes/utils/translation.dart';
|
import 'package:pixes/utils/translation.dart';
|
||||||
|
|
||||||
import '../components/illust_widget.dart';
|
import '../components/illust_widget.dart';
|
||||||
@@ -83,7 +84,13 @@ class _OneBookmarkedPageState extends MultiPageLoadingState<_OneBookmarkedPage,
|
|||||||
if(index == data.length - 1){
|
if(index == data.length - 1){
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
return IllustWidget(data[index]);
|
return IllustWidget(data[index], onTap: () {
|
||||||
|
context.to(() => IllustGalleryPage(
|
||||||
|
illusts: data,
|
||||||
|
initialPage: index,
|
||||||
|
nextUrl: nextUrl
|
||||||
|
));
|
||||||
|
},);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -9,6 +9,7 @@ import '../components/illust_widget.dart';
|
|||||||
import '../components/loading.dart';
|
import '../components/loading.dart';
|
||||||
import '../components/segmented_button.dart';
|
import '../components/segmented_button.dart';
|
||||||
import '../network/network.dart';
|
import '../network/network.dart';
|
||||||
|
import 'illust_page.dart';
|
||||||
|
|
||||||
class FollowingArtworksPage extends StatefulWidget {
|
class FollowingArtworksPage extends StatefulWidget {
|
||||||
const FollowingArtworksPage({super.key});
|
const FollowingArtworksPage({super.key});
|
||||||
@@ -84,7 +85,13 @@ class _OneFollowingPageState extends MultiPageLoadingState<_OneFollowingPage, Il
|
|||||||
if(index == data.length - 1){
|
if(index == data.length - 1){
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
return IllustWidget(data[index]);
|
return IllustWidget(data[index], onTap: () {
|
||||||
|
context.to(() => IllustGalleryPage(
|
||||||
|
illusts: data,
|
||||||
|
initialPage: index,
|
||||||
|
nextUrl: nextUrl
|
||||||
|
));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -4,11 +4,11 @@ import 'package:pixes/appdata.dart';
|
|||||||
import 'package:pixes/components/loading.dart';
|
import 'package:pixes/components/loading.dart';
|
||||||
import 'package:pixes/components/title_bar.dart';
|
import 'package:pixes/components/title_bar.dart';
|
||||||
import 'package:pixes/foundation/app.dart';
|
import 'package:pixes/foundation/app.dart';
|
||||||
import 'package:pixes/network/models.dart';
|
|
||||||
import 'package:pixes/network/network.dart';
|
import 'package:pixes/network/network.dart';
|
||||||
import 'package:pixes/utils/translation.dart';
|
import 'package:pixes/utils/translation.dart';
|
||||||
|
|
||||||
import '../components/illust_widget.dart';
|
import '../components/illust_widget.dart';
|
||||||
|
import 'illust_page.dart';
|
||||||
|
|
||||||
class HistoryPage extends StatefulWidget {
|
class HistoryPage extends StatefulWidget {
|
||||||
const HistoryPage({super.key});
|
const HistoryPage({super.key});
|
||||||
@@ -36,7 +36,12 @@ class _HistoryPageState extends MultiPageLoadingState<HistoryPage, Illust> {
|
|||||||
if(index == data.length - 1){
|
if(index == data.length - 1){
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
return IllustWidget(data[index]);
|
return IllustWidget(data[index], onTap: () {
|
||||||
|
context.to(() => IllustGalleryPage(
|
||||||
|
illusts: data,
|
||||||
|
initialPage: index,
|
||||||
|
));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
@@ -28,17 +28,100 @@ import '../components/ugoira.dart';
|
|||||||
const _kBottomBarHeight = 64.0;
|
const _kBottomBarHeight = 64.0;
|
||||||
|
|
||||||
class IllustGalleryPage extends StatefulWidget {
|
class IllustGalleryPage extends StatefulWidget {
|
||||||
const IllustGalleryPage({super.key});
|
const IllustGalleryPage({required this.illusts, required this.initialPage,
|
||||||
|
this.nextUrl, super.key});
|
||||||
|
|
||||||
|
final List<Illust> illusts;
|
||||||
|
|
||||||
|
final int initialPage;
|
||||||
|
|
||||||
|
final String? nextUrl;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<IllustGalleryPage> createState() => _IllustGalleryPageState();
|
State<IllustGalleryPage> createState() => _IllustGalleryPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _IllustGalleryPageState extends State<IllustGalleryPage> {
|
class _IllustGalleryPageState extends State<IllustGalleryPage> {
|
||||||
|
late List<Illust> illusts;
|
||||||
|
|
||||||
|
late final PageController controller;
|
||||||
|
|
||||||
|
String? nextUrl;
|
||||||
|
|
||||||
|
bool loading = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
illusts = List.from(widget.illusts);
|
||||||
|
controller = PageController(initialPage: widget.initialPage);
|
||||||
|
nextUrl = widget.nextUrl;
|
||||||
|
if(nextUrl == "end") {
|
||||||
|
nextUrl = null;
|
||||||
|
}
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// TODO
|
var length = illusts.length;
|
||||||
return const Placeholder();
|
if(nextUrl != null) {
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CallbackShortcuts(
|
||||||
|
bindings: {
|
||||||
|
LogicalKeySet(LogicalKeyboardKey.arrowLeft): () {
|
||||||
|
if(controller.page == 0) return;
|
||||||
|
controller.previousPage(
|
||||||
|
duration: const Duration(milliseconds: 200), curve: Curves.ease);
|
||||||
|
},
|
||||||
|
LogicalKeySet(LogicalKeyboardKey.arrowRight): () {
|
||||||
|
if(controller.page == length-1) return;
|
||||||
|
controller.nextPage(
|
||||||
|
duration: const Duration(milliseconds: 200), curve: Curves.ease);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Focus(
|
||||||
|
autofocus: true,
|
||||||
|
child: PageView.builder(
|
||||||
|
controller: controller,
|
||||||
|
itemCount: length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if(index == illusts.length) {
|
||||||
|
return buildLast();
|
||||||
|
}
|
||||||
|
return IllustPage(illusts[index]);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildLast(){
|
||||||
|
if(nextUrl == null) {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
load();
|
||||||
|
return const Center(
|
||||||
|
child: ProgressRing(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void load() async {
|
||||||
|
if(loading) return;
|
||||||
|
loading = true;
|
||||||
|
|
||||||
|
var res = await Network().getIllustsWithNextUrl(nextUrl!);
|
||||||
|
loading = false;
|
||||||
|
if(res.error) {
|
||||||
|
if(mounted) {
|
||||||
|
context.showToast(message: "Network Error");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextUrl = res.subData;
|
||||||
|
illusts.addAll(res.data);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -964,7 +1047,7 @@ class _IllustPageWithIdState extends LoadingState<IllustPageWithId, Illust> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _RelatedIllustsPage extends StatefulWidget {
|
class _RelatedIllustsPage extends StatefulWidget {
|
||||||
const _RelatedIllustsPage(this.id, {super.key});
|
const _RelatedIllustsPage(this.id);
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ import '../components/illust_widget.dart';
|
|||||||
import '../components/loading.dart';
|
import '../components/loading.dart';
|
||||||
import '../components/title_bar.dart';
|
import '../components/title_bar.dart';
|
||||||
import '../network/network.dart';
|
import '../network/network.dart';
|
||||||
|
import 'illust_page.dart';
|
||||||
|
|
||||||
class RankingPage extends StatefulWidget {
|
class RankingPage extends StatefulWidget {
|
||||||
const RankingPage({super.key});
|
const RankingPage({super.key});
|
||||||
@@ -97,7 +98,13 @@ class _OneRankingPageState extends MultiPageLoadingState<_OneRankingPage, Illust
|
|||||||
if(index == data.length - 1){
|
if(index == data.length - 1){
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
return IllustWidget(data[index]);
|
return IllustWidget(data[index], onTap: () {
|
||||||
|
context.to(() => IllustGalleryPage(
|
||||||
|
illusts: data,
|
||||||
|
initialPage: index,
|
||||||
|
nextUrl: nextUrl
|
||||||
|
));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -5,6 +5,7 @@ import 'package:pixes/components/loading.dart';
|
|||||||
import 'package:pixes/components/title_bar.dart';
|
import 'package:pixes/components/title_bar.dart';
|
||||||
import 'package:pixes/foundation/app.dart';
|
import 'package:pixes/foundation/app.dart';
|
||||||
import 'package:pixes/network/network.dart';
|
import 'package:pixes/network/network.dart';
|
||||||
|
import 'package:pixes/pages/illust_page.dart';
|
||||||
import 'package:pixes/utils/translation.dart';
|
import 'package:pixes/utils/translation.dart';
|
||||||
|
|
||||||
import '../components/grid.dart';
|
import '../components/grid.dart';
|
||||||
@@ -82,7 +83,10 @@ class _RecommendationArtworksPageState extends MultiPageLoadingState<_Recommenda
|
|||||||
if(index == data.length - 1){
|
if(index == data.length - 1){
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
return IllustWidget(data[index]);
|
return IllustWidget(data[index], onTap: () {
|
||||||
|
context.to(() => IllustGalleryPage(illusts: data,
|
||||||
|
initialPage: index, nextUrl: Network.recommendationUrl,));
|
||||||
|
},);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -426,7 +426,13 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
|
|||||||
if(index == data.length - 1){
|
if(index == data.length - 1){
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
return IllustWidget(data[index]);
|
return IllustWidget(data[index], onTap: () {
|
||||||
|
context.to(() => IllustGalleryPage(
|
||||||
|
illusts: data,
|
||||||
|
initialPage: index,
|
||||||
|
nextUrl: nextUrl
|
||||||
|
));
|
||||||
|
},);
|
||||||
},
|
},
|
||||||
childCount: data.length,
|
childCount: data.length,
|
||||||
),
|
),
|
||||||
|
@@ -15,6 +15,7 @@ import 'package:pixes/utils/translation.dart';
|
|||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
import '../components/illust_widget.dart';
|
import '../components/illust_widget.dart';
|
||||||
|
import 'illust_page.dart';
|
||||||
|
|
||||||
class UserInfoPage extends StatefulWidget {
|
class UserInfoPage extends StatefulWidget {
|
||||||
const UserInfoPage(this.id, {this.followCallback, super.key});
|
const UserInfoPage(this.id, {this.followCallback, super.key});
|
||||||
@@ -311,7 +312,13 @@ class _UserArtworksState extends MultiPageLoadingState<_UserArtworks, Illust> {
|
|||||||
if(index == data.length - 1){
|
if(index == data.length - 1){
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
return IllustWidget(data[index]);
|
return IllustWidget(data[index], onTap: () {
|
||||||
|
context.to(() => IllustGalleryPage(
|
||||||
|
illusts: data,
|
||||||
|
initialPage: index,
|
||||||
|
nextUrl: nextUrl
|
||||||
|
));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
childCount: data.length,
|
childCount: data.length,
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user