Compare commits
10 Commits
v1.1.9+39
...
v1.1.15+45
Author | SHA1 | Date | |
---|---|---|---|
493422e724 | |||
3b95d128e1 | |||
57636c5de6 | |||
f75299f0d4 | |||
03c6431eca | |||
5876c809a5 | |||
c35308fbc1 | |||
e945844151 | |||
74eb6e3d26 | |||
9755066d1e |
@ -51,3 +51,9 @@ jobs:
|
||||
files: |-
|
||||
build/app/outputs/flutter-apk/app-release.apk
|
||||
token: '${{secrets.RELEASE_TOKEN}}'
|
||||
|
||||
- name: wait for gitea to catch up xD
|
||||
run: sleep 5
|
||||
|
||||
- name: trigger fdroid puller
|
||||
run: curl https://flumm.io/pullfdroid.php?token=${{secrets.PULLER_TOKEN}}
|
||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 f0ck
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
52
README.md
52
README.md
@ -1,16 +1,48 @@
|
||||
# f0ckapp
|
||||
# fApp
|
||||

|
||||
## Overview
|
||||
|
||||
A new Flutter project.
|
||||
fApp is the mobile application for the website [f0ck.me](https://f0ck.me). This app provides a user-friendly interface to access the content of the website and utilize its features conveniently from your mobile device.
|
||||
|
||||
## Getting Started
|
||||
## Installation
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
fApp is available in its own F-Droid repository.
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
### Installation Steps
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
1. Add the F-Droid repository to your F-Droid app:
|
||||
- Go to the settings in the F-Droid app.
|
||||
- Select "Repositories" and add the URL `https://fdroid.flumm.io/fdroid/repo/`.
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
2. Search for "f0ckapp" in the F-Droid app and install the app.
|
||||
|
||||
## Development
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Flutter SDK
|
||||
- Dart SDK
|
||||
- Android Studio or Visual Studio Code
|
||||
|
||||
### Setting Up the Project
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://git.lat/f0ck/fApp.git
|
||||
cd fApp
|
||||
2. Install dependencies:
|
||||
```flutter pub get```
|
||||
3. Run the app:
|
||||
```flutter run```
|
||||
|
||||
### Contributing
|
||||
|
||||
don't.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License. See the LICENSE file for more information.
|
||||
|
||||
### Contact
|
||||
|
||||
For questions or feedback, you can reach us at [contact@f0ck.me](mailto:contact@f0ck.me).
|
||||
|
@ -1,7 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<application
|
||||
android:label="f0ckapp"
|
||||
android:name="${applicationName}"
|
||||
@ -15,8 +15,7 @@
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:requestLegacyExternalStorage="true">
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
@ -29,7 +28,7 @@
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<meta-data android:name="flutter_deeplinking_enabled" android:value="true"/>
|
||||
<meta-data android:name="flutter_deeplinking_enabled" android:value="false"/>
|
||||
<intent-filter android:autoVerify="true">
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
@ -1,5 +1,69 @@
|
||||
package com.f0ck.f0ckapp
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import androidx.annotation.NonNull
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
class MainActivity : FlutterActivity()
|
||||
class MainActivity : FlutterActivity() {
|
||||
private val CHANNEL = "MediaShit"
|
||||
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine): Unit {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
|
||||
call,
|
||||
result ->
|
||||
if (call.method == "saveFile") {
|
||||
val filePath = call.argument<String>("filePath")
|
||||
val fileName = call.argument<String>("fileName")
|
||||
val subDir = call.argument<String?>("subDir")
|
||||
|
||||
if (filePath == null || fileName == null)
|
||||
result.error("SAVE_FAILED", "file not found", null)
|
||||
|
||||
if (!saveFileUsingMediaStore(applicationContext, filePath!!, fileName!!, subDir))
|
||||
result.error("COPY_FAILED", "Datei konnte nicht gespeichert werden", null)
|
||||
result.success(true)
|
||||
} else result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveFileUsingMediaStore(
|
||||
context: Context,
|
||||
filePath: String,
|
||||
fileName: String,
|
||||
subDir: String?
|
||||
|
||||
): Boolean {
|
||||
val srcFile = File(filePath)
|
||||
if (!srcFile.exists()) return false
|
||||
|
||||
val values =
|
||||
ContentValues().apply {
|
||||
put(MediaStore.MediaColumns.DISPLAY_NAME, fileName)
|
||||
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + "/" + (subDir ?: "f0ck"))
|
||||
put(MediaStore.MediaColumns.IS_PENDING, 1)
|
||||
}
|
||||
|
||||
val resolver = context.contentResolver
|
||||
val collection = MediaStore.Downloads.EXTERNAL_CONTENT_URI
|
||||
val uri = resolver.insert(collection, values) ?: return false
|
||||
|
||||
resolver.openOutputStream(uri).use { out ->
|
||||
FileInputStream(srcFile).use { input -> input.copyTo(out!!, 4096) }
|
||||
}
|
||||
|
||||
values.clear()
|
||||
values.put(MediaStore.MediaColumns.IS_PENDING, 0)
|
||||
resolver.update(uri, values, null, null)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
||||
import 'package:f0ckapp/providers/media_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:f0ckapp/screens/MediaGrid.dart';
|
||||
import 'package:f0ckapp/screens/DetailView.dart';
|
||||
import 'package:f0ckapp/utils/AppVersion.dart';
|
||||
import 'package:f0ckapp/providers/ThemeProvider.dart';
|
||||
import 'package:f0ckapp/screens/mediagrid_screen.dart';
|
||||
import 'package:f0ckapp/screens/detailview_screen.dart';
|
||||
import 'package:f0ckapp/utils/appversion_util.dart';
|
||||
import 'package:f0ckapp/providers/theme_provider.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@ -26,20 +26,20 @@ class F0ckApp extends ConsumerWidget {
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) {
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const MediaGrid();
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/:rest(.*)',
|
||||
builder: (context, state) {
|
||||
final isInternalLink = (state.extra is bool && state.extra == true);
|
||||
final fullPath = state.matchedLocation;
|
||||
final bool isInternalLink = (state.extra is bool && state.extra == true);
|
||||
final String fullPath = state.matchedLocation;
|
||||
|
||||
final regExp = RegExp(
|
||||
r'^(?:/tag/(?<tag>.+?))?(?:/(?<mime>image|audio|video))?(?:/(?<itemid>\d+))?$',
|
||||
);
|
||||
final match = regExp.firstMatch(fullPath);
|
||||
final RegExpMatch? match = regExp.firstMatch(fullPath);
|
||||
|
||||
if (match == null) {
|
||||
return const Scaffold(body: Center(child: Text('Ungültiger Link')));
|
||||
@ -49,12 +49,12 @@ class F0ckApp extends ConsumerWidget {
|
||||
final String? mime = match.namedGroup('mime');
|
||||
final String? idStr = match.namedGroup('itemid');
|
||||
final int? itemId = idStr != null ? int.tryParse(idStr) : null;
|
||||
const preloadOffset = 50;
|
||||
const int preloadOffset = 50;
|
||||
|
||||
return Consumer(
|
||||
builder: (context, ref, child) {
|
||||
builder: (BuildContext context, WidgetRef ref, Widget? child) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
if (!isInternalLink) {
|
||||
mediaNotifier.setType(mime ?? "alles");
|
||||
mediaNotifier.setTag(tag);
|
||||
@ -77,7 +77,7 @@ class F0ckApp extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = ref.watch(themeNotifierProvider);
|
||||
final ThemeData theme = ref.watch(themeNotifierProvider);
|
||||
return MaterialApp.router(
|
||||
debugShowCheckedModeBanner: false,
|
||||
routerConfig: _router,
|
||||
|
19
lib/models/suggestion_model.dart
Normal file
19
lib/models/suggestion_model.dart
Normal file
@ -0,0 +1,19 @@
|
||||
class Suggestion {
|
||||
final String tag;
|
||||
final int tagged;
|
||||
final double score;
|
||||
|
||||
Suggestion({
|
||||
required this.tag,
|
||||
required this.tagged,
|
||||
required this.score,
|
||||
});
|
||||
|
||||
factory Suggestion.fromJson(Map<String, dynamic> json) {
|
||||
return Suggestion(
|
||||
tag: json['tag'].toString(),
|
||||
tagged: json['tagged'],
|
||||
score: (json['score'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import 'package:f0ckapp/models/MediaItem.dart';
|
||||
import 'package:f0ckapp/services/Api.dart';
|
||||
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||
import 'package:f0ckapp/services/api_service.dart';
|
||||
|
||||
const List<String> mediaTypes = ["alles", "image", "video", "audio"];
|
||||
const List<String> mediaModes = ["sfw", "nsfw", "untagged", "all"];
|
||||
@ -102,8 +102,17 @@ class MediaNotifier extends StateNotifier<MediaState> {
|
||||
}
|
||||
|
||||
void addMediaItems(List<MediaItem> newItems) {
|
||||
final updated = List<MediaItem>.from(state.mediaItems)..addAll(newItems);
|
||||
state = state.replace(mediaItems: updated);
|
||||
final Set<int> existingIds = state.mediaItems
|
||||
.map((item) => item.id)
|
||||
.toSet();
|
||||
final List<MediaItem> filteredItems = newItems
|
||||
.where((item) => !existingIds.contains(item.id))
|
||||
.toList();
|
||||
if (filteredItems.isNotEmpty) {
|
||||
final List<MediaItem> updated = List<MediaItem>.from(state.mediaItems)
|
||||
..addAll(filteredItems);
|
||||
state = state.replace(mediaItems: updated);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadMedia({int? id}) async {
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
@ -2,17 +2,19 @@ import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import 'package:f0ckapp/models/MediaItem.dart';
|
||||
import 'package:f0ckapp/widgets/VideoWidget.dart';
|
||||
import 'package:f0ckapp/utils/SmartRefreshIndicator.dart';
|
||||
import 'package:f0ckapp/utils/PageTransformer.dart';
|
||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
||||
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||
import 'package:f0ckapp/widgets/video_widget.dart';
|
||||
import 'package:f0ckapp/utils/smartrefreshindicator_util.dart';
|
||||
import 'package:f0ckapp/utils/pagetransformer_util.dart';
|
||||
import 'package:f0ckapp/providers/media_provider.dart';
|
||||
|
||||
class DetailView extends ConsumerStatefulWidget {
|
||||
final int initialItemId;
|
||||
@ -53,19 +55,35 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
||||
try {
|
||||
await ref.read(mediaProvider.notifier).loadMedia();
|
||||
} catch (e) {
|
||||
_showError("Fehler beim Laden der Medien: $e");
|
||||
_showMsg("Fehler beim Laden der Medien: $e");
|
||||
} finally {
|
||||
setState(() => isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _showError(String message) {
|
||||
void _showMsg(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
..removeCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
Future<void> _downloadMedia() async {
|
||||
final MediaState mediaState = ref.read(mediaProvider);
|
||||
final MediaItem currentItem = mediaState.mediaItems[_currentIndex];
|
||||
final File file = await DefaultCacheManager().getSingleFile(currentItem.mediaUrl);
|
||||
final MethodChannel methodChannel = const MethodChannel('MediaShit');
|
||||
|
||||
bool? success = await methodChannel.invokeMethod<bool>('saveFile', {
|
||||
'filePath': file.path,
|
||||
'fileName': currentItem.dest,
|
||||
});
|
||||
|
||||
success == true
|
||||
? _showMsg('${currentItem.dest} wurde in Downloads/fApp neigespeichert.')
|
||||
: _showMsg('${currentItem.dest} konnte nicht heruntergeladen werden.');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController?.dispose();
|
||||
@ -74,7 +92,7 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mediaState = ref.watch(mediaProvider);
|
||||
final MediaState mediaState = ref.watch(mediaProvider);
|
||||
final int itemIndex = mediaState.mediaItems.indexWhere(
|
||||
(item) => item.id == widget.initialItemId,
|
||||
);
|
||||
@ -115,14 +133,12 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.fullscreen),
|
||||
onPressed: () {
|
||||
_showError('fullscreen ist wip');
|
||||
_showMsg('fullscreen ist wip');
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.download),
|
||||
onPressed: () {
|
||||
_showError('download ist wip');
|
||||
},
|
||||
onPressed: _downloadMedia,
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
onSelected: (value) async {
|
||||
@ -210,7 +226,7 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
||||
}
|
||||
|
||||
Widget _buildMediaItem(MediaItem item, bool isActive) {
|
||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
@ -2,15 +2,13 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:f0ckapp/screens/DetailView.dart';
|
||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
||||
import 'package:f0ckapp/utils/AppVersion.dart';
|
||||
import 'package:f0ckapp/providers/ThemeProvider.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
const List<String> mediaTypes = ["alles", "image", "video", "audio"];
|
||||
const List<String> mediaModes = ["sfw", "nsfw", "untagged", "all"];
|
||||
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||
import 'package:f0ckapp/providers/media_provider.dart';
|
||||
import 'package:f0ckapp/utils/appversion_util.dart';
|
||||
import 'package:f0ckapp/providers/theme_provider.dart';
|
||||
import 'package:f0ckapp/utils/customsearchdelegate_util.dart';
|
||||
|
||||
class MediaGrid extends ConsumerStatefulWidget {
|
||||
const MediaGrid({super.key});
|
||||
@ -56,8 +54,8 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mediaState = ref.watch(mediaProvider);
|
||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
final MediaState mediaState = ref.watch(mediaProvider);
|
||||
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
@ -79,6 +77,15 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () async {
|
||||
await showSearch(
|
||||
context: context,
|
||||
delegate: CustomSearchDelegate(),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
mediaState.random ? Icons.shuffle_on_outlined : Icons.shuffle,
|
||||
@ -152,7 +159,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
),
|
||||
child: null,
|
||||
),
|
||||
ExpansionTile(
|
||||
/*ExpansionTile(
|
||||
title: const Text('Login'),
|
||||
children: [
|
||||
Padding(
|
||||
@ -182,7 +189,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
const SnackBar(
|
||||
content: Text("noch nicht implementiert lol"),
|
||||
),
|
||||
/*final success = await login(
|
||||
final success = await login(
|
||||
_usernameController.text,
|
||||
_passwordController.text,
|
||||
);
|
||||
@ -193,7 +200,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Login fehlgeschlagen!")),
|
||||
);
|
||||
}*/
|
||||
}
|
||||
);
|
||||
},
|
||||
child: const Text('Login'),
|
||||
@ -202,7 +209,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),*/
|
||||
ExpansionTile(
|
||||
title: const Text('Theme'),
|
||||
children: [
|
||||
@ -210,10 +217,10 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
children: themeMap.entries.map((entry) {
|
||||
final themeName = entry.key;
|
||||
final themeData = entry.value;
|
||||
final currentTheme = ref.watch(themeNotifierProvider);
|
||||
final isSelected = currentTheme == themeData;
|
||||
final String themeName = entry.key;
|
||||
final ThemeData themeData = entry.value;
|
||||
final ThemeData currentTheme = ref.watch(themeNotifierProvider);
|
||||
final bool isSelected = currentTheme == themeData;
|
||||
return ListTile(
|
||||
title: Text(themeName),
|
||||
selected: isSelected,
|
||||
@ -273,11 +280,11 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
||||
),
|
||||
itemCount:
|
||||
mediaState.mediaItems.length + (mediaState.isLoading ? 1 : 0),
|
||||
itemBuilder: (context, index) {
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index >= mediaState.mediaItems.length) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final item = mediaState.mediaItems[index];
|
||||
final MediaItem item = mediaState.mediaItems[index];
|
||||
|
||||
return InkWell(
|
||||
onTap: () async {
|
@ -1,69 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import 'package:f0ckapp/models/MediaItem.dart';
|
||||
|
||||
final storage = FlutterSecureStorage();
|
||||
|
||||
Future<List<MediaItem>> fetchMedia({
|
||||
int? older,
|
||||
String? type,
|
||||
int? mode,
|
||||
bool? random,
|
||||
String? tag,
|
||||
}) 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 (tag != null) 'tag': tag,
|
||||
if (older != null) 'older': older.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
final response = await http.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> jsonList = jsonDecode(response.body);
|
||||
return jsonList.map((item) => MediaItem.fromJson(item)).toList();
|
||||
} else {
|
||||
throw Exception('Fehler beim Abrufen der Medien: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
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 MediaItem.fromJson(jsonResponse);
|
||||
} else {
|
||||
throw Exception(
|
||||
'Fehler beim Abrufen der Media-Details: ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> login(String username, String password) async {
|
||||
final Uri url = Uri.parse('https://api.f0ck.me/login');
|
||||
|
||||
final response = await http.post(
|
||||
url,
|
||||
body: {'username': username, 'password': password},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
final token = data['token'];
|
||||
|
||||
await storage.write(key: "token", value: token);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
109
lib/services/api_service.dart
Normal file
109
lib/services/api_service.dart
Normal file
@ -0,0 +1,109 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||
import 'package:f0ckapp/models/suggestion_model.dart';
|
||||
|
||||
final FlutterSecureStorage storage = const FlutterSecureStorage(
|
||||
aOptions: AndroidOptions(encryptedSharedPreferences: true),
|
||||
);
|
||||
|
||||
Future<List<MediaItem>> fetchMedia({
|
||||
int? older,
|
||||
String? type,
|
||||
int? mode,
|
||||
bool? random,
|
||||
String? tag,
|
||||
}) 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 (tag != null) 'tag': tag,
|
||||
if (older != null) 'older': older.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
final http.Response response = await http.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> jsonList = jsonDecode(response.body);
|
||||
return jsonList.map((item) => MediaItem.fromJson(item)).toList();
|
||||
} else {
|
||||
throw Exception('Fehler beim Abrufen der Medien: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<MediaItem> fetchMediaDetail(int itemId) async {
|
||||
final Uri url = Uri.parse('https://api.f0ck.me/item/${itemId.toString()}');
|
||||
|
||||
final http.Response response = await http.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
final Map<String, dynamic> jsonResponse = jsonDecode(response.body);
|
||||
|
||||
return MediaItem.fromJson(jsonResponse);
|
||||
} else {
|
||||
throw Exception(
|
||||
'Fehler beim Abrufen der Media-Details: ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Suggestion>> fetchSuggestions(String query) async {
|
||||
final Uri uri = Uri.parse('https://api.f0ck.me/search/?q=$query');
|
||||
try {
|
||||
final http.Response response = await http
|
||||
.get(uri)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final dynamic decoded = jsonDecode(response.body);
|
||||
|
||||
if (decoded is List) {
|
||||
return decoded
|
||||
.map((item) => Suggestion.fromJson(item as Map<String, dynamic>))
|
||||
.toList()
|
||||
..sort((a, b) => b.score.compareTo(a.score));
|
||||
} else {
|
||||
throw Exception('Unerwartetes Format: Erwartet wurde eine Liste.');
|
||||
}
|
||||
} else if (response.statusCode == 400) {
|
||||
final dynamic error = jsonDecode(response.body);
|
||||
final String message = error is Map<String, dynamic>
|
||||
? error['detail']?.toString() ?? 'Unbekannter Fehler.'
|
||||
: 'Unbekannter Fehler.';
|
||||
throw Exception('Client-Fehler 400: $message');
|
||||
} else {
|
||||
throw Exception(
|
||||
'Fehler beim Abrufen der Vorschläge: ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
} on TimeoutException {
|
||||
throw Exception('Anfrage an die API hat zu lange gedauert.');
|
||||
} catch (e) {
|
||||
throw Exception('Fehler beim Verarbeiten der Anfrage: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> login(String username, String password) async {
|
||||
final Uri url = Uri.parse('https://api.f0ck.me/login');
|
||||
|
||||
final http.Response response = await http.post(
|
||||
url,
|
||||
body: {'username': username, 'password': password},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final dynamic data = jsonDecode(response.body);
|
||||
final dynamic token = data['token'];
|
||||
|
||||
await storage.write(key: "token", value: token);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
||||
import 'package:f0ckapp/screens/DetailView.dart';
|
||||
|
||||
Map<String, RegExp> routes = {
|
||||
//'login': RegExp(r'^/login/?$'),
|
||||
//'user': RegExp(r'^/user/(?<user>.*)$'),
|
||||
'complex': RegExp(
|
||||
r'^/?'
|
||||
r'(?:tag/(?<tag>.+?))?'
|
||||
r'(?:/user/(?<username>.+?)/(?<set>f0cks|favs))?'
|
||||
r'(?:/(?<media>image|audio|video))?'
|
||||
r'(?:/(?<id>\d+))?'
|
||||
r'$',
|
||||
),
|
||||
//'random': RegExp(r'^/random$'),
|
||||
//'search': RegExp(r'^/search/?$'),
|
||||
};
|
||||
|
||||
Map<String, dynamic> parseDeepLink(Uri? uri) {
|
||||
if (uri == null) {
|
||||
return {};
|
||||
}
|
||||
String url = uri.toString().replaceAll("https://f0ck.me", "");
|
||||
|
||||
for (final MapEntry<String, RegExp> entry in routes.entries) {
|
||||
final String routeName = entry.key;
|
||||
final RegExp pattern = entry.value;
|
||||
final RegExpMatch? match = pattern.firstMatch(url.toString());
|
||||
if (match != null) {
|
||||
Map<String, String> params = <String, String>{};
|
||||
for (String name in match.groupNames) {
|
||||
params[name] = match.namedGroup(name) ?? '';
|
||||
}
|
||||
return {'route': routeName, 'params': params};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Future<void> handleComplexDeepLink(
|
||||
Map<String, String> params,
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ScrollController scrollController,
|
||||
) async {
|
||||
final media = params['media'];
|
||||
const validMediaTypes = {'audio', 'video', 'image'};
|
||||
if (media != null && validMediaTypes.contains(media)) {
|
||||
ref.read(mediaProvider.notifier).setType(media);
|
||||
} else {
|
||||
ref.read(mediaProvider.notifier).setType('alles');
|
||||
}
|
||||
ref.read(mediaProvider.notifier).setMode(0); // wip
|
||||
ref.read(mediaProvider.notifier).setTag(null);
|
||||
|
||||
final idParam = params['id'];
|
||||
if (idParam == null || idParam.isEmpty) return;
|
||||
|
||||
final int? id = int.tryParse(idParam);
|
||||
if (id == null) return;
|
||||
|
||||
final mediaState = ref.read(mediaProvider);
|
||||
final index = mediaState.mediaItems.indexWhere((item) => item.id == id);
|
||||
if (index == -1) {
|
||||
await ref.read(mediaProvider.notifier).loadMedia(id: id + 50);
|
||||
|
||||
final updatedState = ref.read(mediaProvider);
|
||||
final updatedIndex = updatedState.mediaItems.indexWhere(
|
||||
(item) => item.id == id,
|
||||
);
|
||||
print(updatedIndex.toString());
|
||||
if (updatedIndex == -1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool? navigationResult = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => DetailView(initialItemId: id)),
|
||||
);
|
||||
|
||||
if (navigationResult == true) {
|
||||
scrollController.jumpTo(0);
|
||||
}
|
||||
}
|
||||
/*
|
||||
type: mediaTypes[state.typeIndex],
|
||||
mode: state.modeIndex,
|
||||
random: state.random,
|
||||
tag: state.tag,*/
|
145
lib/utils/customsearchdelegate_util.dart
Normal file
145
lib/utils/customsearchdelegate_util.dart
Normal file
@ -0,0 +1,145 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:f0ckapp/services/api_service.dart';
|
||||
import 'package:f0ckapp/models/suggestion_model.dart';
|
||||
import 'package:f0ckapp/providers/media_provider.dart';
|
||||
|
||||
class CustomSearchDelegate extends SearchDelegate<String> {
|
||||
Timer? _debounceTimer;
|
||||
List<Suggestion>? _suggestions;
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
String _lastFetchedQuery = "";
|
||||
|
||||
@override
|
||||
List<Widget> buildActions(BuildContext context) {
|
||||
return [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
query = '';
|
||||
_clearResults();
|
||||
showSuggestions(context);
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildLeading(BuildContext context) {
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
_debounceTimer?.cancel();
|
||||
close(context, 'null');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildResults(BuildContext context) {
|
||||
return Center(child: Text('Suchergebnisse für: "$query"'));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildSuggestions(BuildContext context) {
|
||||
return StatefulBuilder(
|
||||
builder: (BuildContext context, void Function(void Function()) setState) {
|
||||
if (query.isEmpty) {
|
||||
_debounceTimer?.cancel();
|
||||
return Container(padding: const EdgeInsets.all(16.0), child: const Text(''));
|
||||
}
|
||||
|
||||
if (query != _lastFetchedQuery) {
|
||||
_debounceTimer?.cancel();
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
_suggestions = null;
|
||||
|
||||
_debounceTimer = Timer(Duration(milliseconds: 500), () async {
|
||||
try {
|
||||
final List<Suggestion> results = await fetchSuggestions(query);
|
||||
_lastFetchedQuery = query;
|
||||
setState(() {
|
||||
_suggestions = results;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
_lastFetchedQuery = query;
|
||||
setState(() {
|
||||
_error = e.toString();
|
||||
_suggestions = [];
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return Center(child: _buildLoadingIndicator());
|
||||
}
|
||||
|
||||
if (_isLoading) {
|
||||
return Center(child: _buildLoadingIndicator());
|
||||
}
|
||||
|
||||
if (_error != null) {
|
||||
return Center(child: Text("Fehler: $_error"));
|
||||
}
|
||||
|
||||
if (_suggestions == null || _suggestions!.isEmpty) {
|
||||
return Center(child: const Text("Keine Ergebnisse gefunden."));
|
||||
}
|
||||
|
||||
return Consumer(
|
||||
builder: (BuildContext context, WidgetRef ref, Widget? child) {
|
||||
return ListView.builder(
|
||||
itemCount: _suggestions!.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final Suggestion suggestion = _suggestions![index];
|
||||
return ListTile(
|
||||
title: Text(suggestion.tag),
|
||||
subtitle: Text(
|
||||
'Getaggt: ${suggestion.tagged}x • Score: ${suggestion.score.toStringAsFixed(2)}',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
onTap: () {
|
||||
ref.read(mediaProvider.notifier).setTag(suggestion.tag);
|
||||
close(context, suggestion.tag);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingIndicator() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const CircularProgressIndicator(strokeWidth: 3.0),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Vorschläge werden geladen...',
|
||||
style: TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _clearResults() {
|
||||
_debounceTimer?.cancel();
|
||||
_suggestions = null;
|
||||
_isLoading = false;
|
||||
_error = null;
|
||||
_lastFetchedQuery = "";
|
||||
}
|
||||
|
||||
@override
|
||||
void close(BuildContext context, String result) {
|
||||
_debounceTimer?.cancel();
|
||||
super.close(context, result);
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ import 'package:cached_video_player_plus/cached_video_player_plus.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:f0ckapp/models/MediaItem.dart';
|
||||
import 'package:f0ckapp/widgets/VideoOverlay.dart';
|
||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
||||
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||
import 'package:f0ckapp/widgets/videooverlay_widget.dart';
|
||||
import 'package:f0ckapp/providers/media_provider.dart';
|
||||
|
||||
class VideoWidget extends ConsumerStatefulWidget {
|
||||
final MediaItem details;
|
||||
@ -45,7 +45,7 @@ class _VideoWidgetState extends ConsumerState<VideoWidget> {
|
||||
}
|
||||
_controller.setLooping(true);
|
||||
|
||||
final muted = ref.read(mediaProvider).muted;
|
||||
final bool muted = ref.read(mediaProvider).muted;
|
||||
_controller.setVolume(muted ? 0.0 : 1.0);
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ class _VideoWidgetState extends ConsumerState<VideoWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final muted = ref.watch(mediaProvider).muted;
|
||||
final bool muted = ref.watch(mediaProvider).muted;
|
||||
if (_controller.value.isInitialized &&
|
||||
_controller.value.volume != (muted ? 0.0 : 1.0)) {
|
||||
_controller.setVolume(muted ? 0.0 : 1.0);
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:cached_video_player_plus/cached_video_player_plus.dart';
|
||||
|
||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
||||
import 'package:f0ckapp/providers/media_provider.dart';
|
||||
|
||||
class VideoControlsOverlay extends ConsumerWidget {
|
||||
final CachedVideoPlayerPlusController controller;
|
||||
@ -17,8 +17,8 @@ class VideoControlsOverlay extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, ref) {
|
||||
final mediaState = ref.watch(mediaProvider);
|
||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
final MediaState mediaState = ref.watch(mediaProvider);
|
||||
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
@ -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
|
||||
# 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.
|
||||
version: 1.1.9+39
|
||||
version: 1.1.15+45
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.0-100.2.beta
|
||||
|
@ -13,7 +13,7 @@ import 'package:f0ckapp/main.dart';
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const F0ckApp());
|
||||
await tester.pumpWidget(F0ckApp());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
|
Reference in New Issue
Block a user