1.0.15 + random
This commit is contained in:
		@@ -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,
 | 
			
		||||
          ),
 | 
			
		||||
 
 | 
			
		||||
@@ -6,13 +6,17 @@ import 'package:f0ckapp/widgets/video_widget.dart';
 | 
			
		||||
class DetailView extends StatefulWidget {
 | 
			
		||||
  final int initialItemId;
 | 
			
		||||
  final List<MediaItem> mediaItems;
 | 
			
		||||
  final String mode;
 | 
			
		||||
  final String type;
 | 
			
		||||
  final int mode;
 | 
			
		||||
  final bool random;
 | 
			
		||||
 | 
			
		||||
  const DetailView({
 | 
			
		||||
    super.key,
 | 
			
		||||
    required this.initialItemId,
 | 
			
		||||
    required this.mediaItems,
 | 
			
		||||
    required this.type,
 | 
			
		||||
    required this.mode,
 | 
			
		||||
    required this.random,
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@@ -22,12 +26,14 @@ class DetailView extends StatefulWidget {
 | 
			
		||||
class _DetailViewState extends State<DetailView> {
 | 
			
		||||
  late PageController _pageController;
 | 
			
		||||
  late List<MediaItem> mediaItems;
 | 
			
		||||
  final List<String> _modes = ["sfw", "nsfw", "untagged", "all"];
 | 
			
		||||
  int currentItemId = 0;
 | 
			
		||||
  bool isLoading = false;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
 | 
			
		||||
    mediaItems = widget.mediaItems;
 | 
			
		||||
    final initialIndex = mediaItems.indexWhere(
 | 
			
		||||
      (item) => item.id == widget.initialItemId,
 | 
			
		||||
@@ -56,7 +62,9 @@ class _DetailViewState extends State<DetailView> {
 | 
			
		||||
    try {
 | 
			
		||||
      final newMedia = await fetchMedia(
 | 
			
		||||
        older: mediaItems.last.id.toString(),
 | 
			
		||||
        type: widget.type,
 | 
			
		||||
        mode: widget.mode,
 | 
			
		||||
        random: widget.random,
 | 
			
		||||
      );
 | 
			
		||||
      if (mounted) {
 | 
			
		||||
        setState(() => mediaItems.addAll(newMedia));
 | 
			
		||||
@@ -72,72 +80,99 @@ class _DetailViewState extends State<DetailView> {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> _refreshMediaItem() async {
 | 
			
		||||
    try {
 | 
			
		||||
      final updatedItem = await fetchMediaDetail(currentItemId);
 | 
			
		||||
      if (mounted) {
 | 
			
		||||
        setState(() {
 | 
			
		||||
          final index = mediaItems.indexWhere(
 | 
			
		||||
            (item) => item.id == currentItemId,
 | 
			
		||||
          );
 | 
			
		||||
          if (index != -1) {
 | 
			
		||||
            mediaItems[index] = updatedItem;
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      if (mounted) {
 | 
			
		||||
        ScaffoldMessenger.of(context).showSnackBar(
 | 
			
		||||
          SnackBar(content: Text('Fehler beim Aktualisieren des Items: $e')),
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      backgroundColor: Color(0xFF171717),
 | 
			
		||||
      backgroundColor: const Color(0xFF171717),
 | 
			
		||||
      appBar: AppBar(
 | 
			
		||||
        backgroundColor: const Color(0xFF2B2B2B),
 | 
			
		||||
        foregroundColor: Colors.white,
 | 
			
		||||
        title: Text('f0ck #$currentItemId (${widget.mode})'),
 | 
			
		||||
        title: Text(
 | 
			
		||||
          'f0ck #$currentItemId (${widget.type}, ${_modes[widget.mode]})',
 | 
			
		||||
        ),
 | 
			
		||||
        centerTitle: true,
 | 
			
		||||
      ),
 | 
			
		||||
      body: PageView.builder(
 | 
			
		||||
        controller: _pageController,
 | 
			
		||||
        itemCount: mediaItems.length + (isLoading ? 1 : 0),
 | 
			
		||||
        itemBuilder: (context, index) {
 | 
			
		||||
          if (index >= mediaItems.length) {
 | 
			
		||||
            return const Center(child: CircularProgressIndicator());
 | 
			
		||||
          }
 | 
			
		||||
      body: RefreshIndicator(
 | 
			
		||||
        onRefresh: _refreshMediaItem,
 | 
			
		||||
        child: SingleChildScrollView(
 | 
			
		||||
          child: Column(
 | 
			
		||||
            children: [
 | 
			
		||||
              SizedBox(
 | 
			
		||||
                height: MediaQuery.of(context).size.height,
 | 
			
		||||
                child: PageView.builder(
 | 
			
		||||
                  controller: _pageController,
 | 
			
		||||
                  itemCount: mediaItems.length,
 | 
			
		||||
                  itemBuilder: (context, index) {
 | 
			
		||||
                    final item = mediaItems[index];
 | 
			
		||||
                    return Column(
 | 
			
		||||
                      children: [
 | 
			
		||||
                        if (item.mime.startsWith('image'))
 | 
			
		||||
                          Image.network(item.mediaUrl, fit: BoxFit.contain)
 | 
			
		||||
                        else
 | 
			
		||||
                          VideoWidget(details: item),
 | 
			
		||||
                        const SizedBox(height: 20),
 | 
			
		||||
                        Text(
 | 
			
		||||
                          item.mime,
 | 
			
		||||
                          style: const TextStyle(
 | 
			
		||||
                            color: Colors.white,
 | 
			
		||||
                            fontSize: 18,
 | 
			
		||||
                          ),
 | 
			
		||||
                        ),
 | 
			
		||||
                        const SizedBox(height: 10),
 | 
			
		||||
                        Wrap(
 | 
			
		||||
                          alignment: WrapAlignment.center,
 | 
			
		||||
                          spacing: 5.0,
 | 
			
		||||
                          children: item.tags.map((tag) {
 | 
			
		||||
                            Color tagColor;
 | 
			
		||||
                            switch (tag.id) {
 | 
			
		||||
                              case 1:
 | 
			
		||||
                                tagColor = Colors.green;
 | 
			
		||||
                                break;
 | 
			
		||||
                              case 2:
 | 
			
		||||
                                tagColor = Colors.red;
 | 
			
		||||
                                break;
 | 
			
		||||
                              default:
 | 
			
		||||
                                tagColor = const Color(0xFF090909);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
          final item = mediaItems[index];
 | 
			
		||||
          return SingleChildScrollView(
 | 
			
		||||
            child: Column(
 | 
			
		||||
              mainAxisAlignment: MainAxisAlignment.start,
 | 
			
		||||
              crossAxisAlignment: CrossAxisAlignment.center,
 | 
			
		||||
              children: [
 | 
			
		||||
                if (item.mime.startsWith('image')) ...[
 | 
			
		||||
                  Image.network(
 | 
			
		||||
                    item.mediaUrl,
 | 
			
		||||
                    fit: BoxFit.contain,
 | 
			
		||||
                  ),
 | 
			
		||||
                ] else ...[
 | 
			
		||||
                  VideoWidget(details: item),
 | 
			
		||||
                ],
 | 
			
		||||
                const SizedBox(height: 20),
 | 
			
		||||
                Text(
 | 
			
		||||
                  item.mime,
 | 
			
		||||
                  style: const TextStyle(color: Colors.white, fontSize: 18),
 | 
			
		||||
                ),
 | 
			
		||||
                const SizedBox(height: 10),
 | 
			
		||||
                Wrap(
 | 
			
		||||
                  alignment: WrapAlignment.center,
 | 
			
		||||
                  spacing: 5.0,
 | 
			
		||||
                  children: item.tags.map((tag) {
 | 
			
		||||
                    Color tagColor;
 | 
			
		||||
                    switch (tag.id) {
 | 
			
		||||
                      case 1:
 | 
			
		||||
                        tagColor = Colors.green;
 | 
			
		||||
                        break;
 | 
			
		||||
                      case 2:
 | 
			
		||||
                        tagColor = Colors.red;
 | 
			
		||||
                        break;
 | 
			
		||||
                      default:
 | 
			
		||||
                        tagColor = Color(0xFF090909);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    return Chip(
 | 
			
		||||
                      label: Text(tag.tag),
 | 
			
		||||
                      backgroundColor: tagColor,
 | 
			
		||||
                      labelStyle: const TextStyle(color: Colors.white),
 | 
			
		||||
                            return Chip(
 | 
			
		||||
                              label: Text(tag.tag),
 | 
			
		||||
                              backgroundColor: tagColor,
 | 
			
		||||
                              labelStyle: const TextStyle(color: Colors.white),
 | 
			
		||||
                            );
 | 
			
		||||
                          }).toList(),
 | 
			
		||||
                        ),
 | 
			
		||||
                        const SizedBox(height: 40),
 | 
			
		||||
                      ],
 | 
			
		||||
                    );
 | 
			
		||||
                  }).toList(),
 | 
			
		||||
                  },
 | 
			
		||||
                ),
 | 
			
		||||
                const SizedBox(height: 40),
 | 
			
		||||
              ],
 | 
			
		||||
            ),
 | 
			
		||||
          );
 | 
			
		||||
        },
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,14 +2,21 @@ import 'dart:convert';
 | 
			
		||||
import 'package:http/http.dart' as http;
 | 
			
		||||
 | 
			
		||||
import 'package:f0ckapp/models/mediaitem.dart';
 | 
			
		||||
//import 'package:f0ckapp/models/mediaitem_detail.dart';
 | 
			
		||||
 | 
			
		||||
Future<List<MediaItem>> fetchMedia({String? older, String? mode}) async {
 | 
			
		||||
  final Uri url = Uri.parse('https://api.f0ck.me/items/get')
 | 
			
		||||
    .replace(queryParameters: {
 | 
			
		||||
      'mode': mode ?? 'image',
 | 
			
		||||
Future<List<MediaItem>> fetchMedia({
 | 
			
		||||
  String? older,
 | 
			
		||||
  String? type,
 | 
			
		||||
  int? mode,
 | 
			
		||||
  bool? random,
 | 
			
		||||
}) async {
 | 
			
		||||
  final Uri url = Uri.parse('https://api.f0ck.me/items/get').replace(
 | 
			
		||||
    queryParameters: {
 | 
			
		||||
      'type': type ?? 'image',
 | 
			
		||||
      'mode': (mode ?? 0).toString(),
 | 
			
		||||
      'random': (random! ? 1 : 0).toString(),
 | 
			
		||||
      if (older != null) 'older': older,
 | 
			
		||||
    });
 | 
			
		||||
    },
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  final response = await http.get(url);
 | 
			
		||||
  if (response.statusCode == 200) {
 | 
			
		||||
@@ -20,14 +27,17 @@ Future<List<MediaItem>> fetchMedia({String? older, String? mode}) async {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*Future<MediaItemDetail> fetchMediaDetail(int itemId) async {
 | 
			
		||||
  final Uri url = Uri.parse('https://f0ck.me/api/v2/item/${itemId.toString()}');
 | 
			
		||||
Future<MediaItem> fetchMediaDetail(int itemId) async {
 | 
			
		||||
  final Uri url = Uri.parse('https://api.f0ck.me/item/${itemId.toString()}');
 | 
			
		||||
 | 
			
		||||
  final response = await http.get(url);
 | 
			
		||||
  if (response.statusCode == 200) {
 | 
			
		||||
    final Map<String, dynamic> jsonResponse = jsonDecode(response.body);
 | 
			
		||||
    return MediaItemDetail.fromJson(jsonResponse['rows']);
 | 
			
		||||
 | 
			
		||||
    return MediaItem.fromJson(jsonResponse);
 | 
			
		||||
  } else {
 | 
			
		||||
    throw Exception('Fehler beim Abrufen der Media-Details: ${response.statusCode}');
 | 
			
		||||
    throw Exception(
 | 
			
		||||
      'Fehler beim Abrufen der Media-Details: ${response.statusCode}',
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}*/
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,9 @@ class _VideoWidgetState extends State<VideoWidget> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> _initController() async {
 | 
			
		||||
    _controller = VideoPlayerController.networkUrl(Uri.parse(widget.details.mediaUrl));
 | 
			
		||||
    _controller = VideoPlayerController.networkUrl(
 | 
			
		||||
      Uri.parse(widget.details.mediaUrl),
 | 
			
		||||
    );
 | 
			
		||||
    await _controller.initialize();
 | 
			
		||||
    setState(() {});
 | 
			
		||||
 | 
			
		||||
@@ -63,10 +65,7 @@ class _VideoWidgetState extends State<VideoWidget> {
 | 
			
		||||
                  });
 | 
			
		||||
                },
 | 
			
		||||
                child: isAudio
 | 
			
		||||
                    ? Image.network(
 | 
			
		||||
                        widget.details.coverUrl,
 | 
			
		||||
                        fit: BoxFit.cover,
 | 
			
		||||
                      )
 | 
			
		||||
                    ? Image.network(widget.details.coverUrl, fit: BoxFit.cover)
 | 
			
		||||
                    : VideoPlayer(_controller),
 | 
			
		||||
              ),
 | 
			
		||||
              Align(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user