1.0.15 + random

This commit is contained in:
2025-06-02 16:14:38 +02:00
parent 69de940e33
commit e24a2122a5
5 changed files with 183 additions and 83 deletions

View File

@ -13,12 +13,16 @@ class MediaGrid extends StatefulWidget {
class _MediaGridState extends State<MediaGrid> {
final ScrollController _scrollController = ScrollController();
final String _version = '1.0.15';
List<MediaItem> mediaItems = [];
bool isLoading = false;
Timer? _debounceTimer;
Completer<void>? _navigationCompleter;
int _crossAxisCount = 3;
String _selectedMode = "alles";
int _crossAxisCount = 0;
String _selectedType = 'alles';
int _selectedMode = 0;
bool _random = false;
final List<String> _modes = ["sfw", "nsfw", "untagged", "all"];
@override
void initState() {
@ -37,6 +41,17 @@ class _MediaGridState extends State<MediaGrid> {
_debounceTimer = Timer(const Duration(milliseconds: 500), _loadMedia);
}
int _calculateCrossAxisCount(BuildContext context) {
if (_crossAxisCount != 0) {
return _crossAxisCount;
}
double screenWidth = MediaQuery.of(context).size.width;
int columnCount = (screenWidth / 110).clamp(3, 5).toInt();
return columnCount;
}
Future<void> _loadMedia() async {
if (isLoading) return;
setState(() => isLoading = true);
@ -44,7 +59,9 @@ class _MediaGridState extends State<MediaGrid> {
try {
final newMedia = await fetchMedia(
older: mediaItems.isNotEmpty ? mediaItems.last.id.toString() : null,
type: _selectedType,
mode: _selectedMode,
random: _random,
);
if (mounted) {
setState(() => mediaItems.addAll(newMedia));
@ -63,7 +80,12 @@ class _MediaGridState extends State<MediaGrid> {
Future<void> _refreshMedia() async {
setState(() => isLoading = true);
try {
final freshMedia = await fetchMedia(older: null, mode: _selectedMode);
final freshMedia = await fetchMedia(
older: null,
type: _selectedType,
mode: _selectedMode,
random: _random,
);
if (mounted) {
setState(() {
mediaItems.clear();
@ -93,7 +115,9 @@ class _MediaGridState extends State<MediaGrid> {
builder: (context) => DetailView(
initialItemId: item.id,
mediaItems: mediaItems,
type: _selectedType,
mode: _selectedMode,
random: _random,
),
),
);
@ -113,12 +137,24 @@ class _MediaGridState extends State<MediaGrid> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: const Color.fromARGB(255, 43, 43, 43),
foregroundColor: const Color.fromARGB(255, 255, 255, 255),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [const Text('f0cks')],
),
children: [
Text('f0ck v$_version'),
Checkbox(
value: _random,
onChanged: (bool? value) {
setState(() {
_random = !_random;
_refreshMedia();
});
},
)
]
)
),
bottomNavigationBar: BottomAppBar(
color: const Color.fromARGB(255, 43, 43, 43),
@ -126,9 +162,10 @@ class _MediaGridState extends State<MediaGrid> {
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
DropdownButton<String>(
value: _selectedMode,
value: _selectedType,
dropdownColor: const Color.fromARGB(255, 43, 43, 43),
iconEnabledColor: Colors.white,
items: ["alles", "image", "video", "audio"].map((String value) {
@ -140,7 +177,26 @@ class _MediaGridState extends State<MediaGrid> {
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
_selectedMode = newValue;
_selectedType = newValue;
_refreshMedia();
});
}
},
),
DropdownButton<String>(
value: _modes[_selectedMode],
dropdownColor: const Color.fromARGB(255, 43, 43, 43),
iconEnabledColor: Colors.white,
items: _modes.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value, style: TextStyle(color: Colors.white)),
);
}).toList(),
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
_selectedMode = _modes.indexOf(newValue);
_refreshMedia();
});
}
@ -150,11 +206,11 @@ class _MediaGridState extends State<MediaGrid> {
value: _crossAxisCount,
dropdownColor: const Color.fromARGB(255, 43, 43, 43),
iconEnabledColor: Colors.white,
items: [3, 4].map((int value) {
items: [0, 3, 4].map((int value) {
return DropdownMenuItem<int>(
value: value,
child: Text(
'$value Spalten',
value == 0 ? 'auto' : '$value Spalten',
style: TextStyle(color: Colors.white),
),
);
@ -176,7 +232,7 @@ class _MediaGridState extends State<MediaGrid> {
child: GridView.builder(
controller: _scrollController,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: _crossAxisCount,
crossAxisCount: _calculateCrossAxisCount(context),
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),