mute schmute
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import 'package:f0ckapp/services/Api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import 'package:f0ckapp/models/MediaItem.dart';
|
||||
import 'package:f0ckapp/services/Api.dart';
|
||||
|
||||
class MediaProvider extends ChangeNotifier {
|
||||
int _typeid = 0;
|
||||
@ -10,6 +12,10 @@ class MediaProvider extends ChangeNotifier {
|
||||
int _crossAxisCount = 0;
|
||||
List<MediaItem> _mediaItems = [];
|
||||
bool _isLoading = false;
|
||||
bool _muted = false;
|
||||
final storage = FlutterSecureStorage(
|
||||
aOptions: const AndroidOptions(encryptedSharedPreferences: true),
|
||||
);
|
||||
|
||||
List<String> types = ["alles", "image", "video", "audio"];
|
||||
List<String> modes = ["sfw", "nsfw", "untagged", "all"];
|
||||
@ -22,8 +28,14 @@ class MediaProvider extends ChangeNotifier {
|
||||
int get crossAxisCount => _crossAxisCount;
|
||||
List<MediaItem> get mediaItems => _mediaItems;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get muted => _muted;
|
||||
|
||||
Function get resetMedia => _resetMedia;
|
||||
|
||||
MediaProvider() {
|
||||
_loadMutedState();
|
||||
}
|
||||
|
||||
void setType(String type) {
|
||||
_typeid = types.indexOf(type);
|
||||
_resetMedia();
|
||||
@ -68,6 +80,22 @@ class MediaProvider extends ChangeNotifier {
|
||||
loadMedia();
|
||||
}
|
||||
|
||||
void toggleMute() {
|
||||
_muted = !_muted;
|
||||
_saveMutedState();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadMutedState() async {
|
||||
_muted = (await storage.read(key: 'muted') == 'true');
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _saveMutedState() async {
|
||||
await storage.write(key: 'muted', value: _muted ? 'false' : 'true');
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadMedia({bool notify = true}) async {
|
||||
if (_isLoading) return;
|
||||
_isLoading = true;
|
||||
@ -82,7 +110,7 @@ class MediaProvider extends ChangeNotifier {
|
||||
tag: tag,
|
||||
);
|
||||
|
||||
if(_mediaItems != newMedia) {
|
||||
if (_mediaItems != newMedia) {
|
||||
addMediaItems(newMedia);
|
||||
if (notify) notifyListeners();
|
||||
}
|
||||
|
@ -105,6 +105,15 @@ class _DetailViewState extends State<DetailView> {
|
||||
'f0ck #${provider.mediaItems.elementAt(_currentIndex).id.toString()}',
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
provider.muted ? Icons.volume_up : Icons.volume_off,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: () {
|
||||
provider.toggleMute();
|
||||
},
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
onSelected: (value) async {
|
||||
final item = provider.mediaItems.elementAt(_currentIndex);
|
||||
@ -121,10 +130,14 @@ class _DetailViewState extends State<DetailView> {
|
||||
await SharePlus.instance.share(params);
|
||||
break;
|
||||
case 'direct_link':
|
||||
await SharePlus.instance.share(ShareParams(text: item.mediaUrl));
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(text: item.mediaUrl),
|
||||
);
|
||||
break;
|
||||
case 'post_link':
|
||||
await SharePlus.instance.share(ShareParams(text: item.postUrl));
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(text: item.postUrl),
|
||||
);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'package:f0ckapp/services/Api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -48,8 +48,10 @@ Future<MediaItem> fetchMediaDetail(int itemId) async {
|
||||
}
|
||||
|
||||
Future<bool> login(String username, String password) async {
|
||||
final Uri url = Uri.parse('https://api.f0ck.me/login');
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('https://api.f0ck.me/login'),
|
||||
url,
|
||||
body: {'username': username, 'password': password},
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user