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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user