Compare commits
8 Commits
v1.0.23+23
...
v1.0.25+25
Author | SHA1 | Date | |
---|---|---|---|
ae5f395331 | |||
05484b342a | |||
97d9259fab | |||
b69a9843a7 | |||
acacdef003 | |||
3699e62efc | |||
666a02d293 | |||
28c4a17c43 |
@ -5,6 +5,7 @@ import 'package:f0ckapp/services/Api.dart';
|
|||||||
import 'package:f0ckapp/widgets/VideoWidget.dart';
|
import 'package:f0ckapp/widgets/VideoWidget.dart';
|
||||||
import 'package:f0ckapp/utils/SmartRefreshIndicator.dart';
|
import 'package:f0ckapp/utils/SmartRefreshIndicator.dart';
|
||||||
import 'package:f0ckapp/utils/PageTransformer.dart';
|
import 'package:f0ckapp/utils/PageTransformer.dart';
|
||||||
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||||
|
|
||||||
class DetailView extends StatefulWidget {
|
class DetailView extends StatefulWidget {
|
||||||
final int initialItemId;
|
final int initialItemId;
|
||||||
@ -12,6 +13,7 @@ class DetailView extends StatefulWidget {
|
|||||||
final String type;
|
final String type;
|
||||||
final int mode;
|
final int mode;
|
||||||
final bool random;
|
final bool random;
|
||||||
|
final String? tagname;
|
||||||
|
|
||||||
const DetailView({
|
const DetailView({
|
||||||
super.key,
|
super.key,
|
||||||
@ -20,6 +22,7 @@ class DetailView extends StatefulWidget {
|
|||||||
required this.type,
|
required this.type,
|
||||||
required this.mode,
|
required this.mode,
|
||||||
required this.random,
|
required this.random,
|
||||||
|
required this.tagname,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -29,6 +32,7 @@ class DetailView extends StatefulWidget {
|
|||||||
class _DetailViewState extends State<DetailView> {
|
class _DetailViewState extends State<DetailView> {
|
||||||
late PageController _pageController;
|
late PageController _pageController;
|
||||||
late List<MediaItem> mediaItems;
|
late List<MediaItem> mediaItems;
|
||||||
|
String? _tagname;
|
||||||
int currentItemId = 0;
|
int currentItemId = 0;
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
|
|
||||||
@ -36,25 +40,50 @@ class _DetailViewState extends State<DetailView> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
mediaItems = widget.mediaItems;
|
mediaItems = widget.mediaItems;
|
||||||
|
_tagname = widget.tagname;
|
||||||
final initialIndex = mediaItems.indexWhere(
|
final initialIndex = mediaItems.indexWhere(
|
||||||
(item) => item.id == widget.initialItemId,
|
(item) => item.id == widget.initialItemId,
|
||||||
);
|
);
|
||||||
_pageController = PageController(initialPage: initialIndex);
|
_pageController = PageController(initialPage: initialIndex);
|
||||||
currentItemId = mediaItems[initialIndex].id;
|
currentItemId = mediaItems[initialIndex].id;
|
||||||
|
|
||||||
_pageController.addListener(_onPageScroll);
|
int? lastLoadedIndex;
|
||||||
}
|
_pageController.addListener(() async {
|
||||||
|
|
||||||
void _onPageScroll() {
|
|
||||||
final newIndex = _pageController.page?.round();
|
final newIndex = _pageController.page?.round();
|
||||||
if (newIndex != null && newIndex < mediaItems.length) {
|
if (newIndex != null &&
|
||||||
|
newIndex < mediaItems.length &&
|
||||||
|
newIndex != lastLoadedIndex) {
|
||||||
setState(() => currentItemId = mediaItems[newIndex].id);
|
setState(() => currentItemId = mediaItems[newIndex].id);
|
||||||
|
lastLoadedIndex = newIndex;
|
||||||
|
|
||||||
|
_preloadAdjacentMedia(newIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pageController.position.pixels >=
|
if (_pageController.position.pixels >=
|
||||||
_pageController.position.maxScrollExtent - 100) {
|
_pageController.position.maxScrollExtent - 100) {
|
||||||
_loadMoreMedia();
|
_loadMoreMedia();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
_preloadAdjacentMedia(initialIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _preloadAdjacentMedia(int index) async {
|
||||||
|
if (index + 1 < mediaItems.length) {
|
||||||
|
final nextUrl = mediaItems[index + 1].mediaUrl;
|
||||||
|
if (await DefaultCacheManager().getFileFromCache(nextUrl) == null) {
|
||||||
|
await DefaultCacheManager().downloadFile(nextUrl);
|
||||||
|
print('preload ${mediaItems[index + 1].id}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index - 1 >= 0) {
|
||||||
|
final prevUrl = mediaItems[index - 1].mediaUrl;
|
||||||
|
if (await DefaultCacheManager().getFileFromCache(prevUrl) == null) {
|
||||||
|
await DefaultCacheManager().downloadFile(prevUrl);
|
||||||
|
print('preload ${mediaItems[index - 1].id}');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadMoreMedia() async {
|
Future<void> _loadMoreMedia() async {
|
||||||
@ -67,6 +96,7 @@ class _DetailViewState extends State<DetailView> {
|
|||||||
type: widget.type,
|
type: widget.type,
|
||||||
mode: widget.mode,
|
mode: widget.mode,
|
||||||
random: widget.random,
|
random: widget.random,
|
||||||
|
tag: _tagname,
|
||||||
);
|
);
|
||||||
if (mounted && newMedia.isNotEmpty) {
|
if (mounted && newMedia.isNotEmpty) {
|
||||||
setState(() => mediaItems.addAll(newMedia));
|
setState(() => mediaItems.addAll(newMedia));
|
||||||
@ -110,23 +140,62 @@ class _DetailViewState extends State<DetailView> {
|
|||||||
title: Text('f0ck #$currentItemId (${widget.type})'),
|
title: Text('f0ck #$currentItemId (${widget.type})'),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
),
|
),
|
||||||
body: PageTransformer(
|
body: Stack(
|
||||||
|
children: [
|
||||||
|
PageTransformer(
|
||||||
controller: _pageController,
|
controller: _pageController,
|
||||||
pages: mediaItems.map((item) {
|
pages: mediaItems.map((item) {
|
||||||
|
final isActive = item.id == currentItemId;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: SmartRefreshIndicator(
|
child: SmartRefreshIndicator(
|
||||||
onRefresh: _refreshMediaItem,
|
onRefresh: _refreshMediaItem,
|
||||||
child: _buildMediaItem(item),
|
child: _buildMediaItem(item, isActive),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
|
if (_tagname != null)
|
||||||
|
Positioned(
|
||||||
|
bottom: 60,
|
||||||
|
left: MediaQuery.of(context).size.width * 0.2,
|
||||||
|
right: MediaQuery.of(context).size.width * 0.2,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 10,
|
||||||
|
horizontal: 20,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black.withValues(alpha: 0.8),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Tag: $_tagname',
|
||||||
|
style: const TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close, color: Colors.white),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_tagname = '___empty___';
|
||||||
|
Navigator.pop(context, _tagname);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMediaItem(MediaItem item) {
|
Widget _buildMediaItem(MediaItem item, bool isActive) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
@ -139,7 +208,7 @@ class _DetailViewState extends State<DetailView> {
|
|||||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
VideoWidget(details: item),
|
VideoWidget(details: item, isActive: isActive),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Text(
|
Text(
|
||||||
item.mime,
|
item.mime,
|
||||||
@ -150,7 +219,15 @@ class _DetailViewState extends State<DetailView> {
|
|||||||
alignment: WrapAlignment.center,
|
alignment: WrapAlignment.center,
|
||||||
spacing: 5.0,
|
spacing: 5.0,
|
||||||
children: item.tags.map((tag) {
|
children: item.tags.map((tag) {
|
||||||
return Chip(
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
if (tag.tag == 'sfw' || tag.tag == 'nsfw') return;
|
||||||
|
setState(() {
|
||||||
|
_tagname = tag.tag;
|
||||||
|
Navigator.pop(context, _tagname);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Chip(
|
||||||
label: Text(tag.tag),
|
label: Text(tag.tag),
|
||||||
backgroundColor: switch (tag.id) {
|
backgroundColor: switch (tag.id) {
|
||||||
1 => Colors.green,
|
1 => Colors.green,
|
||||||
@ -158,6 +235,7 @@ class _DetailViewState extends State<DetailView> {
|
|||||||
_ => const Color(0xFF090909),
|
_ => const Color(0xFF090909),
|
||||||
},
|
},
|
||||||
labelStyle: const TextStyle(color: Colors.white),
|
labelStyle: const TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
|
@ -14,7 +14,7 @@ class MediaGrid extends StatefulWidget {
|
|||||||
|
|
||||||
class _MediaGridState extends State<MediaGrid> {
|
class _MediaGridState extends State<MediaGrid> {
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
final String _version = '1.0.23+23';
|
final String _version = '1.0.25+25';
|
||||||
List<MediaItem> mediaItems = [];
|
List<MediaItem> mediaItems = [];
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
Timer? _debounceTimer;
|
Timer? _debounceTimer;
|
||||||
@ -24,6 +24,7 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
int _selectedMode = 0;
|
int _selectedMode = 0;
|
||||||
bool _random = false;
|
bool _random = false;
|
||||||
final List<String> _modes = ["sfw", "nsfw", "untagged", "all"];
|
final List<String> _modes = ["sfw", "nsfw", "untagged", "all"];
|
||||||
|
String? _selectedTag;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -63,6 +64,7 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
type: _selectedType,
|
type: _selectedType,
|
||||||
mode: _selectedMode,
|
mode: _selectedMode,
|
||||||
random: _random,
|
random: _random,
|
||||||
|
tag: _selectedTag,
|
||||||
);
|
);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => mediaItems.addAll(newMedia));
|
setState(() => mediaItems.addAll(newMedia));
|
||||||
@ -86,6 +88,7 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
type: _selectedType,
|
type: _selectedType,
|
||||||
mode: _selectedMode,
|
mode: _selectedMode,
|
||||||
random: _random,
|
random: _random,
|
||||||
|
tag: _selectedTag,
|
||||||
);
|
);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -110,7 +113,7 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
_navigationCompleter = Completer();
|
_navigationCompleter = Completer();
|
||||||
try {
|
try {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
await Navigator.push(
|
final String? newTag = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => DetailView(
|
builder: (context) => DetailView(
|
||||||
@ -119,9 +122,22 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
type: _selectedType,
|
type: _selectedType,
|
||||||
mode: _selectedMode,
|
mode: _selectedMode,
|
||||||
random: _random,
|
random: _random,
|
||||||
|
tagname: _selectedTag,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (newTag != null) {
|
||||||
|
setState(() {
|
||||||
|
if (newTag == '___empty___') {
|
||||||
|
_selectedTag = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_selectedTag = newTag;
|
||||||
|
}
|
||||||
|
_refreshMedia();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@ -153,9 +169,9 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
_refreshMedia();
|
_refreshMedia();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
bottomNavigationBar: BottomAppBar(
|
bottomNavigationBar: BottomAppBar(
|
||||||
color: const Color.fromARGB(255, 43, 43, 43),
|
color: const Color.fromARGB(255, 43, 43, 43),
|
||||||
@ -228,7 +244,9 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: RefreshIndicator(
|
body: Stack(
|
||||||
|
children: [
|
||||||
|
RefreshIndicator(
|
||||||
onRefresh: _refreshMedia,
|
onRefresh: _refreshMedia,
|
||||||
child: GridView.builder(
|
child: GridView.builder(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
@ -262,9 +280,9 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
color: switch (item.mode) {
|
color: switch (item.mode) {
|
||||||
1 => Colors.green,
|
1 => Colors.green,
|
||||||
2 => Colors.red,
|
2 => Colors.red,
|
||||||
_ => Colors.yellow
|
_ => Colors.yellow,
|
||||||
},
|
},
|
||||||
size: 15.0
|
size: 15.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -273,6 +291,58 @@ class _MediaGridState extends State<MediaGrid> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (_selectedTag != null)
|
||||||
|
Positioned(
|
||||||
|
bottom: 20,
|
||||||
|
left: MediaQuery.of(context).size.width * 0.2,
|
||||||
|
right: MediaQuery.of(context).size.width * 0.2,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 10,
|
||||||
|
horizontal: 20,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black.withValues(alpha: 0.8),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Tag: $_selectedTag',
|
||||||
|
style: const TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close, color: Colors.white),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedTag = null;
|
||||||
|
_refreshMedia();
|
||||||
|
});
|
||||||
|
_scrollController.animateTo(
|
||||||
|
0.0,
|
||||||
|
duration: const Duration(milliseconds: 500),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
/*floatingActionButton: FloatingActionButton(
|
||||||
|
backgroundColor: Colors.black.withValues(alpha: 0.8),
|
||||||
|
child: const Icon(Icons.arrow_upward, color: Colors.white),
|
||||||
|
onPressed: () {
|
||||||
|
_scrollController.animateTo(
|
||||||
|
0.0,
|
||||||
|
duration: const Duration(milliseconds: 500),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),*/
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,12 +8,14 @@ Future<List<MediaItem>> fetchMedia({
|
|||||||
String? type,
|
String? type,
|
||||||
int? mode,
|
int? mode,
|
||||||
bool? random,
|
bool? random,
|
||||||
|
String? tag,
|
||||||
}) async {
|
}) async {
|
||||||
final Uri url = Uri.parse('https://api.f0ck.me/items/get').replace(
|
final Uri url = Uri.parse('https://api.f0ck.me/items/get').replace(
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'type': type ?? 'image',
|
'type': type ?? 'image',
|
||||||
'mode': (mode ?? 0).toString(),
|
'mode': (mode ?? 0).toString(),
|
||||||
'random': (random! ? 1 : 0).toString(),
|
'random': (random! ? 1 : 0).toString(),
|
||||||
|
if (tag != null) 'tag': tag,
|
||||||
if (older != null) 'older': older,
|
if (older != null) 'older': older,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -7,7 +7,9 @@ import 'dart:async';
|
|||||||
|
|
||||||
class VideoWidget extends StatefulWidget {
|
class VideoWidget extends StatefulWidget {
|
||||||
final MediaItem details;
|
final MediaItem details;
|
||||||
const VideoWidget({super.key, required this.details});
|
final bool isActive;
|
||||||
|
|
||||||
|
const VideoWidget({super.key, required this.details, required this.isActive});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State createState() => _VideoWidgetState();
|
State createState() => _VideoWidgetState();
|
||||||
@ -32,7 +34,9 @@ class _VideoWidgetState extends State<VideoWidget> {
|
|||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
||||||
_controller.addListener(() => setState(() {}));
|
_controller.addListener(() => setState(() {}));
|
||||||
|
if (widget.isActive) {
|
||||||
_controller.play();
|
_controller.play();
|
||||||
|
}
|
||||||
_controller.setLooping(true);
|
_controller.setLooping(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +47,16 @@ class _VideoWidgetState extends State<VideoWidget> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(VideoWidget oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.isActive) {
|
||||||
|
_controller.play();
|
||||||
|
} else {
|
||||||
|
_controller.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onTap({bool ctrlButton = false}) {
|
void _onTap({bool ctrlButton = false}) {
|
||||||
if (!ctrlButton) {
|
if (!ctrlButton) {
|
||||||
setState(() => _showControls = !_showControls);
|
setState(() => _showControls = !_showControls);
|
||||||
@ -81,7 +95,7 @@ class _VideoWidgetState extends State<VideoWidget> {
|
|||||||
errorWidget: (context, url, error) => Image.asset(
|
errorWidget: (context, url, error) => Image.asset(
|
||||||
'assets/images/music.webp',
|
'assets/images/music.webp',
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
width: double.infinity
|
width: double.infinity,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: _controller.value.isInitialized
|
: _controller.value.isInitialized
|
||||||
|
@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.0.23+23
|
version: 1.0.25+25
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.9.0-100.2.beta
|
sdk: ^3.9.0-100.2.beta
|
||||||
|
Reference in New Issue
Block a user