Compare commits
11 Commits
v1.1.8+38
...
v1.1.15+45
Author | SHA1 | Date | |
---|---|---|---|
493422e724 | |||
3b95d128e1 | |||
57636c5de6 | |||
f75299f0d4 | |||
03c6431eca | |||
5876c809a5 | |||
c35308fbc1 | |||
e945844151 | |||
74eb6e3d26 | |||
9755066d1e | |||
671b3cfbe0 |
@ -51,3 +51,9 @@ jobs:
|
|||||||
files: |-
|
files: |-
|
||||||
build/app/outputs/flutter-apk/app-release.apk
|
build/app/outputs/flutter-apk/app-release.apk
|
||||||
token: '${{secrets.RELEASE_TOKEN}}'
|
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)
|
1. Add the F-Droid repository to your F-Droid app:
|
||||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
- 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
|
2. Search for "f0ckapp" in the F-Droid app and install the app.
|
||||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
|
||||||
samples, guidance on mobile development, and a full API reference.
|
## 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">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<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
|
<application
|
||||||
android:label="f0ckapp"
|
android:label="f0ckapp"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
@ -15,8 +15,7 @@
|
|||||||
android:theme="@style/LaunchTheme"
|
android:theme="@style/LaunchTheme"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize">
|
||||||
android:requestLegacyExternalStorage="true">
|
|
||||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||||
the Android process has started. This theme is visible to the user
|
the Android process has started. This theme is visible to the user
|
||||||
while the Flutter UI initializes. After that, this theme continues
|
while the Flutter UI initializes. After that, this theme continues
|
||||||
|
@ -1,5 +1,69 @@
|
|||||||
package com.f0ck.f0ckapp
|
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.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,36 +1,87 @@
|
|||||||
import 'package:app_links/app_links.dart';
|
import 'package:f0ckapp/providers/media_provider.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import 'package:f0ckapp/screens/MediaGrid.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:f0ckapp/utils/AppVersion.dart';
|
|
||||||
import 'package:f0ckapp/providers/ThemeProvider.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.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 {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
await AppVersion.init();
|
await AppVersion.init();
|
||||||
final Uri? initialUri = await AppLinks().getInitialLink();
|
|
||||||
|
|
||||||
runApp(ProviderScope(child: F0ckApp(initialUri: initialUri)));
|
runApp(ProviderScope(child: F0ckApp()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class F0ckApp extends ConsumerWidget {
|
class F0ckApp extends ConsumerWidget {
|
||||||
final Uri? initialUri;
|
F0ckApp({super.key});
|
||||||
const F0ckApp({super.key, this.initialUri});
|
|
||||||
|
final GoRouter _router = GoRouter(
|
||||||
|
initialLocation: '/',
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: '/',
|
||||||
|
builder: (BuildContext context, GoRouterState state) {
|
||||||
|
return const MediaGrid();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/:rest(.*)',
|
||||||
|
builder: (context, state) {
|
||||||
|
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 RegExpMatch? match = regExp.firstMatch(fullPath);
|
||||||
|
|
||||||
|
if (match == null) {
|
||||||
|
return const Scaffold(body: Center(child: Text('Ungültiger Link')));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String? tag = match.namedGroup('tag');
|
||||||
|
final String? mime = match.namedGroup('mime');
|
||||||
|
final String? idStr = match.namedGroup('itemid');
|
||||||
|
final int? itemId = idStr != null ? int.tryParse(idStr) : null;
|
||||||
|
const int preloadOffset = 50;
|
||||||
|
|
||||||
|
return Consumer(
|
||||||
|
builder: (BuildContext context, WidgetRef ref, Widget? child) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
|
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||||
|
if (!isInternalLink) {
|
||||||
|
mediaNotifier.setType(mime ?? "alles");
|
||||||
|
mediaNotifier.setTag(tag);
|
||||||
|
}
|
||||||
|
if (itemId != null) {
|
||||||
|
await mediaNotifier.loadMedia(id: itemId + preloadOffset);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (itemId != null) {
|
||||||
|
return DetailView(initialItemId: itemId);
|
||||||
|
} else {
|
||||||
|
return MediaGrid();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return Consumer(
|
final ThemeData theme = ref.watch(themeNotifierProvider);
|
||||||
builder: (context, ref, _) {
|
return MaterialApp.router(
|
||||||
return MaterialApp(
|
debugShowCheckedModeBanner: false,
|
||||||
debugShowCheckedModeBanner: false,
|
routerConfig: _router,
|
||||||
theme: ref.watch(themeNotifierProvider),
|
theme: theme,
|
||||||
home: MediaGrid(initialUri: initialUri),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
|
||||||
import 'package:f0ckapp/models/MediaItem.dart';
|
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||||
import 'package:f0ckapp/services/Api.dart';
|
import 'package:f0ckapp/services/api_service.dart';
|
||||||
|
|
||||||
const List<String> mediaTypes = ["alles", "image", "video", "audio"];
|
const List<String> mediaTypes = ["alles", "image", "video", "audio"];
|
||||||
const List<String> mediaModes = ["sfw", "nsfw", "untagged", "all"];
|
const List<String> mediaModes = ["sfw", "nsfw", "untagged", "all"];
|
||||||
@ -102,16 +102,21 @@ class MediaNotifier extends StateNotifier<MediaState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addMediaItems(List<MediaItem> newItems) {
|
void addMediaItems(List<MediaItem> newItems) {
|
||||||
final updated = List<MediaItem>.from(state.mediaItems)..addAll(newItems);
|
final Set<int> existingIds = state.mediaItems
|
||||||
state = state.replace(mediaItems: updated);
|
.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 {
|
Future<void> loadMedia({int? id}) async {
|
||||||
//if (state.isLoading) return;
|
if (state.isLoading) return;
|
||||||
if (id != null) {
|
|
||||||
print('requested id: ${id.toString()}');
|
|
||||||
}
|
|
||||||
|
|
||||||
state = state.replace(isLoading: true);
|
state = state.replace(isLoading: true);
|
||||||
try {
|
try {
|
||||||
final older =
|
final older =
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
@ -2,17 +2,19 @@ import 'dart:io';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_cache_manager/flutter_cache_manager.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:share_plus/share_plus.dart';
|
||||||
|
|
||||||
import 'package:f0ckapp/models/MediaItem.dart';
|
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||||
import 'package:f0ckapp/widgets/VideoWidget.dart';
|
import 'package:f0ckapp/widgets/video_widget.dart';
|
||||||
import 'package:f0ckapp/utils/SmartRefreshIndicator.dart';
|
import 'package:f0ckapp/utils/smartrefreshindicator_util.dart';
|
||||||
import 'package:f0ckapp/utils/PageTransformer.dart';
|
import 'package:f0ckapp/utils/pagetransformer_util.dart';
|
||||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
import 'package:f0ckapp/providers/media_provider.dart';
|
||||||
|
|
||||||
class DetailView extends ConsumerStatefulWidget {
|
class DetailView extends ConsumerStatefulWidget {
|
||||||
final int initialItemId;
|
final int initialItemId;
|
||||||
@ -24,26 +26,13 @@ class DetailView extends ConsumerStatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _DetailViewState extends ConsumerState<DetailView> {
|
class _DetailViewState extends ConsumerState<DetailView> {
|
||||||
late PageController _pageController;
|
PageController? _pageController;
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
int _currentIndex = 0;
|
int _currentIndex = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
final mediaState = ref.read(mediaProvider);
|
|
||||||
final initialIndex = mediaState.mediaItems.indexWhere(
|
|
||||||
(item) => item.id == widget.initialItemId,
|
|
||||||
);
|
|
||||||
_pageController = PageController(initialPage: initialIndex);
|
|
||||||
_currentIndex = initialIndex;
|
|
||||||
|
|
||||||
_pageController.addListener(() {
|
|
||||||
setState(() => _currentIndex = _pageController.page?.round() ?? 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
_preloadAdjacentMedia(initialIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _preloadAdjacentMedia(int index) async {
|
void _preloadAdjacentMedia(int index) async {
|
||||||
@ -66,53 +55,90 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
|||||||
try {
|
try {
|
||||||
await ref.read(mediaProvider.notifier).loadMedia();
|
await ref.read(mediaProvider.notifier).loadMedia();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_showError("Fehler beim Laden der Medien: $e");
|
_showMsg("Fehler beim Laden der Medien: $e");
|
||||||
} finally {
|
} finally {
|
||||||
setState(() => isLoading = false);
|
setState(() => isLoading = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showError(String message) {
|
void _showMsg(String message) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(context)
|
ScaffoldMessenger.of(context)
|
||||||
..removeCurrentSnackBar()
|
..removeCurrentSnackBar()
|
||||||
..showSnackBar(SnackBar(content: Text(message)));
|
..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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_pageController.dispose();
|
_pageController?.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final mediaState = ref.watch(mediaProvider);
|
final MediaState mediaState = ref.watch(mediaProvider);
|
||||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
final int itemIndex = mediaState.mediaItems.indexWhere(
|
||||||
|
(item) => item.id == widget.initialItemId,
|
||||||
|
);
|
||||||
|
|
||||||
if (mediaState.mediaItems.isEmpty) {
|
if (itemIndex == -1) {
|
||||||
|
Future.microtask(() {
|
||||||
|
ref
|
||||||
|
.read(mediaProvider.notifier)
|
||||||
|
.loadMedia(id: widget.initialItemId + 50);
|
||||||
|
});
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(),
|
appBar: AppBar(),
|
||||||
body: const Center(child: CircularProgressIndicator()),
|
body: const Center(child: CircularProgressIndicator()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_pageController == null) {
|
||||||
|
_pageController = PageController(initialPage: itemIndex);
|
||||||
|
_currentIndex = itemIndex;
|
||||||
|
_pageController!.addListener(() {
|
||||||
|
setState(() => _currentIndex = _pageController!.page?.round() ?? 0);
|
||||||
|
});
|
||||||
|
_preloadAdjacentMedia(itemIndex);
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
title: Text('f0ck #${mediaState.mediaItems[_currentIndex].id}'),
|
title: Text('f0ck #${mediaState.mediaItems[_currentIndex].id}'),
|
||||||
|
automaticallyImplyLeading: false,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back),
|
||||||
|
onPressed: () {
|
||||||
|
context.canPop() ? context.pop() : context.go('/', extra: true);
|
||||||
|
},
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.fullscreen),
|
icon: const Icon(Icons.fullscreen),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// wip
|
_showMsg('fullscreen ist wip');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.download),
|
icon: const Icon(Icons.download),
|
||||||
onPressed: () {
|
onPressed: _downloadMedia,
|
||||||
// wip
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
PopupMenuButton<String>(
|
PopupMenuButton<String>(
|
||||||
onSelected: (value) async {
|
onSelected: (value) async {
|
||||||
@ -170,7 +196,7 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
|||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
PageTransformer(
|
PageTransformer(
|
||||||
controller: _pageController,
|
controller: _pageController!,
|
||||||
pages: mediaState.mediaItems.map((item) {
|
pages: mediaState.mediaItems.map((item) {
|
||||||
int itemIndex = mediaState.mediaItems.indexOf(item);
|
int itemIndex = mediaState.mediaItems.indexOf(item);
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
@ -189,8 +215,8 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
|||||||
child: InputChip(
|
child: InputChip(
|
||||||
label: Text(mediaState.tag!),
|
label: Text(mediaState.tag!),
|
||||||
onDeleted: () {
|
onDeleted: () {
|
||||||
mediaNotifier.setTag(null);
|
ref.read(mediaProvider.notifier).setTag(null);
|
||||||
Navigator.pop(context);
|
context.go('/', extra: true);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -200,7 +226,7 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMediaItem(MediaItem item, bool isActive) {
|
Widget _buildMediaItem(MediaItem item, bool isActive) {
|
||||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -224,7 +250,7 @@ class _DetailViewState extends ConsumerState<DetailView> {
|
|||||||
if (tag.tag == 'sfw' || tag.tag == 'nsfw') return;
|
if (tag.tag == 'sfw' || tag.tag == 'nsfw') return;
|
||||||
setState(() {
|
setState(() {
|
||||||
mediaNotifier.setTag(tag.tag);
|
mediaNotifier.setTag(tag.tag);
|
||||||
Navigator.pop(context, true);
|
context.go('/', extra: true);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
label: Text(tag.tag),
|
label: Text(tag.tag),
|
@ -1,21 +1,17 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:app_links/app_links.dart';
|
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import 'package:f0ckapp/screens/DetailView.dart';
|
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
import 'package:f0ckapp/providers/media_provider.dart';
|
||||||
import 'package:f0ckapp/utils/AppVersion.dart';
|
import 'package:f0ckapp/utils/appversion_util.dart';
|
||||||
import 'package:f0ckapp/utils/ParseDeepLink.dart';
|
import 'package:f0ckapp/providers/theme_provider.dart';
|
||||||
import 'package:f0ckapp/providers/ThemeProvider.dart';
|
import 'package:f0ckapp/utils/customsearchdelegate_util.dart';
|
||||||
|
|
||||||
const List<String> mediaTypes = ["alles", "image", "video", "audio"];
|
|
||||||
const List<String> mediaModes = ["sfw", "nsfw", "untagged", "all"];
|
|
||||||
|
|
||||||
class MediaGrid extends ConsumerStatefulWidget {
|
class MediaGrid extends ConsumerStatefulWidget {
|
||||||
final Uri? initialUri = null;
|
const MediaGrid({super.key});
|
||||||
const MediaGrid({super.key, required initialUri});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<MediaGrid> createState() => _MediaGridState();
|
ConsumerState<MediaGrid> createState() => _MediaGridState();
|
||||||
@ -28,8 +24,6 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
final TextEditingController _usernameController = TextEditingController();
|
final TextEditingController _usernameController = TextEditingController();
|
||||||
final TextEditingController _passwordController = TextEditingController();
|
final TextEditingController _passwordController = TextEditingController();
|
||||||
|
|
||||||
final appLinks = AppLinks();
|
|
||||||
|
|
||||||
int _calculateCrossAxisCount(BuildContext context, int defaultCount) {
|
int _calculateCrossAxisCount(BuildContext context, int defaultCount) {
|
||||||
return defaultCount == 0
|
return defaultCount == 0
|
||||||
? (MediaQuery.of(context).size.width / 110).clamp(3, 5).toInt()
|
? (MediaQuery.of(context).size.width / 110).clamp(3, 5).toInt()
|
||||||
@ -48,23 +42,6 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
ref.read(mediaProvider.notifier).loadMedia();
|
ref.read(mediaProvider.notifier).loadMedia();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
appLinks.uriLinkStream.listen((Uri uri) async {
|
|
||||||
final parsedResult = parseDeepLink(uri);
|
|
||||||
if (parsedResult == null) return;
|
|
||||||
if (parsedResult['route'] != 'complex') return;
|
|
||||||
final params = parsedResult['params'] as Map<String, String>;
|
|
||||||
await handleComplexDeepLink(params, context, ref, _scrollController);
|
|
||||||
});
|
|
||||||
|
|
||||||
//print('initial: ${parseDeepLink(widget.initialUri)}');
|
|
||||||
Future.microtask(() async {
|
|
||||||
final initparsedResult = parseDeepLink(widget.initialUri);
|
|
||||||
if (initparsedResult == null) return;
|
|
||||||
if (initparsedResult['route'] != 'complex') return;
|
|
||||||
final initparams = initparsedResult['params'] as Map<String, String>;
|
|
||||||
await handleComplexDeepLink(initparams, context, ref, _scrollController);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -77,8 +54,8 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final mediaState = ref.watch(mediaProvider);
|
final MediaState mediaState = ref.watch(mediaProvider);
|
||||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
@ -100,6 +77,15 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.search),
|
||||||
|
onPressed: () async {
|
||||||
|
await showSearch(
|
||||||
|
context: context,
|
||||||
|
delegate: CustomSearchDelegate(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
mediaState.random ? Icons.shuffle_on_outlined : Icons.shuffle,
|
mediaState.random ? Icons.shuffle_on_outlined : Icons.shuffle,
|
||||||
@ -173,7 +159,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
),
|
),
|
||||||
child: null,
|
child: null,
|
||||||
),
|
),
|
||||||
ExpansionTile(
|
/*ExpansionTile(
|
||||||
title: const Text('Login'),
|
title: const Text('Login'),
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
@ -203,7 +189,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text("noch nicht implementiert lol"),
|
content: Text("noch nicht implementiert lol"),
|
||||||
),
|
),
|
||||||
/*final success = await login(
|
final success = await login(
|
||||||
_usernameController.text,
|
_usernameController.text,
|
||||||
_passwordController.text,
|
_passwordController.text,
|
||||||
);
|
);
|
||||||
@ -214,7 +200,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Login fehlgeschlagen!")),
|
SnackBar(content: Text("Login fehlgeschlagen!")),
|
||||||
);
|
);
|
||||||
}*/
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('Login'),
|
child: const Text('Login'),
|
||||||
@ -223,7 +209,7 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),*/
|
||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
title: const Text('Theme'),
|
title: const Text('Theme'),
|
||||||
children: [
|
children: [
|
||||||
@ -231,10 +217,10 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: themeMap.entries.map((entry) {
|
children: themeMap.entries.map((entry) {
|
||||||
final themeName = entry.key;
|
final String themeName = entry.key;
|
||||||
final themeData = entry.value;
|
final ThemeData themeData = entry.value;
|
||||||
final currentTheme = ref.watch(themeNotifierProvider);
|
final ThemeData currentTheme = ref.watch(themeNotifierProvider);
|
||||||
final isSelected = currentTheme == themeData;
|
final bool isSelected = currentTheme == themeData;
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(themeName),
|
title: Text(themeName),
|
||||||
selected: isSelected,
|
selected: isSelected,
|
||||||
@ -294,23 +280,15 @@ class _MediaGridState extends ConsumerState<MediaGrid> {
|
|||||||
),
|
),
|
||||||
itemCount:
|
itemCount:
|
||||||
mediaState.mediaItems.length + (mediaState.isLoading ? 1 : 0),
|
mediaState.mediaItems.length + (mediaState.isLoading ? 1 : 0),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
if (index >= mediaState.mediaItems.length) {
|
if (index >= mediaState.mediaItems.length) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
final item = mediaState.mediaItems[index];
|
final MediaItem item = mediaState.mediaItems[index];
|
||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
bool? ret = await Navigator.push(
|
context.push('/${item.id}', extra: true);
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => DetailView(initialItemId: item.id),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (ret != null && ret) {
|
|
||||||
_scrollController.jumpTo(0);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.expand,
|
@ -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:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
import 'package:f0ckapp/models/MediaItem.dart';
|
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||||
import 'package:f0ckapp/widgets/VideoOverlay.dart';
|
import 'package:f0ckapp/widgets/videooverlay_widget.dart';
|
||||||
import 'package:f0ckapp/providers/MediaProvider.dart';
|
import 'package:f0ckapp/providers/media_provider.dart';
|
||||||
|
|
||||||
class VideoWidget extends ConsumerStatefulWidget {
|
class VideoWidget extends ConsumerStatefulWidget {
|
||||||
final MediaItem details;
|
final MediaItem details;
|
||||||
@ -45,7 +45,7 @@ class _VideoWidgetState extends ConsumerState<VideoWidget> {
|
|||||||
}
|
}
|
||||||
_controller.setLooping(true);
|
_controller.setLooping(true);
|
||||||
|
|
||||||
final muted = ref.read(mediaProvider).muted;
|
final bool muted = ref.read(mediaProvider).muted;
|
||||||
_controller.setVolume(muted ? 0.0 : 1.0);
|
_controller.setVolume(muted ? 0.0 : 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class _VideoWidgetState extends ConsumerState<VideoWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final muted = ref.watch(mediaProvider).muted;
|
final bool muted = ref.watch(mediaProvider).muted;
|
||||||
if (_controller.value.isInitialized &&
|
if (_controller.value.isInitialized &&
|
||||||
_controller.value.volume != (muted ? 0.0 : 1.0)) {
|
_controller.value.volume != (muted ? 0.0 : 1.0)) {
|
||||||
_controller.setVolume(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:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:cached_video_player_plus/cached_video_player_plus.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 {
|
class VideoControlsOverlay extends ConsumerWidget {
|
||||||
final CachedVideoPlayerPlusController controller;
|
final CachedVideoPlayerPlusController controller;
|
||||||
@ -17,8 +17,8 @@ class VideoControlsOverlay extends ConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
final mediaState = ref.watch(mediaProvider);
|
final MediaState mediaState = ref.watch(mediaProvider);
|
||||||
final mediaNotifier = ref.read(mediaProvider.notifier);
|
final MediaNotifier mediaNotifier = ref.read(mediaProvider.notifier);
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
50
pubspec.lock
50
pubspec.lock
@ -1,38 +1,6 @@
|
|||||||
# Generated by pub
|
# Generated by pub
|
||||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
packages:
|
packages:
|
||||||
app_links:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: app_links
|
|
||||||
sha256: "85ed8fc1d25a76475914fff28cc994653bd900bc2c26e4b57a49e097febb54ba"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.4.0"
|
|
||||||
app_links_linux:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: app_links_linux
|
|
||||||
sha256: f5f7173a78609f3dfd4c2ff2c95bd559ab43c80a87dc6a095921d96c05688c81
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.3"
|
|
||||||
app_links_platform_interface:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: app_links_platform_interface
|
|
||||||
sha256: "05f5379577c513b534a29ddea68176a4d4802c46180ee8e2e966257158772a3f"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.2"
|
|
||||||
app_links_web:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: app_links_web
|
|
||||||
sha256: af060ed76183f9e2b87510a9480e56a5352b6c249778d07bd2c95fc35632a555
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.4"
|
|
||||||
async:
|
async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -272,14 +240,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.1"
|
version: "2.1.1"
|
||||||
gtk:
|
go_router:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: gtk
|
name: go_router
|
||||||
sha256: e8ce9ca4b1df106e4d72dad201d345ea1a036cc12c360f1a7d5a758f78ffa42c
|
sha256: b453934c36e289cef06525734d1e676c1f91da9e22e2017d9dcab6ce0f999175
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "15.1.3"
|
||||||
html:
|
html:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -344,6 +312,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.0.0"
|
version: "6.0.0"
|
||||||
|
logging:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: logging
|
||||||
|
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.0"
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -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.1.8+38
|
version: 1.1.15+45
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.9.0-100.2.beta
|
sdk: ^3.9.0-100.2.beta
|
||||||
@ -41,7 +41,7 @@ dependencies:
|
|||||||
share_plus: ^11.0.0
|
share_plus: ^11.0.0
|
||||||
flutter_secure_storage: ^9.2.4
|
flutter_secure_storage: ^9.2.4
|
||||||
flutter_riverpod: ^2.6.1
|
flutter_riverpod: ^2.6.1
|
||||||
app_links: ^6.4.0
|
go_router: ^15.1.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
@ -13,7 +13,7 @@ import 'package:f0ckapp/main.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
// Build our app and trigger a frame.
|
||||||
await tester.pumpWidget(const F0ckApp());
|
await tester.pumpWidget(F0ckApp());
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
// Verify that our counter starts at 0.
|
||||||
expect(find.text('0'), findsOneWidget);
|
expect(find.text('0'), findsOneWidget);
|
||||||
|
Reference in New Issue
Block a user