feat: klasor tabanli galeri, brightness efekti (Ctrl+Shift+sag tik), .deb guncellendi
This commit is contained in:
1 parent
56ab4b5495
commit
d4c243b445
9 files changed
+249
-37
No files matched your search
@@ -6,6 +6,10 @@ class ImageManager extends ChangeNotifier {
|
||||
static ImageManager get instance => _instance;
|
||||
ImageManager._();
|
||||
|
||||
static const _supportedExtensions = [
|
||||
'png', 'jpg', 'jpeg', 'jfif', 'jpe', 'webp', 'bmp', 'gif', 'wbmp',
|
||||
];
|
||||
|
||||
final List<String> _images = [];
|
||||
int _currentIndex = 0;
|
||||
|
||||
@@ -18,22 +22,47 @@ class ImageManager extends ChangeNotifier {
|
||||
return _images[_currentIndex];
|
||||
}
|
||||
|
||||
void addImages(List<String> paths) {
|
||||
final validPaths = paths.where((p) {
|
||||
/// Açılan resmin bulunduğu klasörü galeri olarak kurar (en yeni önce).
|
||||
void setGalleryFromPaths(List<String> paths) {
|
||||
String? anchor;
|
||||
for (final p in paths) {
|
||||
final ext = p.toLowerCase().split('.').last;
|
||||
const supported = ['png', 'jpg', 'jpeg', 'jfif', 'jpe', 'webp', 'bmp', 'gif', 'wbmp'];
|
||||
return supported.contains(ext) && File(p).existsSync();
|
||||
}).toList();
|
||||
|
||||
if (validPaths.isEmpty) return;
|
||||
|
||||
_images.addAll(validPaths);
|
||||
|
||||
// Precache images
|
||||
for (final path in validPaths) {
|
||||
precacheImage(FileImage(File(path)), context!);
|
||||
if (_supportedExtensions.contains(ext) && File(p).existsSync()) {
|
||||
anchor = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (anchor == null) return;
|
||||
|
||||
final dir = File(anchor).parent;
|
||||
if (!dir.existsSync()) return;
|
||||
|
||||
final List<(String, DateTime)> entries = [];
|
||||
for (final entity in dir.listSync()) {
|
||||
if (entity is! File) continue;
|
||||
final p = entity.path;
|
||||
final ext = p.toLowerCase().split('.').last;
|
||||
if (!_supportedExtensions.contains(ext)) continue;
|
||||
try {
|
||||
entries.add((p, entity.lastModifiedSync()));
|
||||
} catch (_) {}
|
||||
}
|
||||
entries.sort((a, b) {
|
||||
final byDate = b.$2.compareTo(a.$2);
|
||||
return byDate != 0 ? byDate : a.$1.compareTo(b.$1);
|
||||
});
|
||||
|
||||
_images
|
||||
..clear()
|
||||
..addAll(entries.map((e) => e.$1));
|
||||
|
||||
_currentIndex = _images.indexOf(anchor);
|
||||
if (_currentIndex < 0) {
|
||||
final base = anchor.split(Platform.pathSeparator).last;
|
||||
_currentIndex = _images
|
||||
.indexWhere((p) => p.split(Platform.pathSeparator).last == base);
|
||||
}
|
||||
if (_currentIndex < 0) _currentIndex = 0;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -55,19 +84,12 @@ class ImageManager extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Precache needs a BuildContext
|
||||
BuildContext? context;
|
||||
|
||||
/// Configure image cache for high-res images
|
||||
static void configureCache() {
|
||||
PaintingBinding.instance.imageCache.maximumSize = 1000;
|
||||
PaintingBinding.instance.imageCache.maximumSizeBytes = 1024 * 1024 * 1024; // 1 GB
|
||||
}
|
||||
|
||||
set buildContext(BuildContext ctx) {
|
||||
context = ctx;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_images.clear();
|
||||
_currentIndex = 0;
|
||||
|
||||
Reference in new issue
Block a user