mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-22 06:59:21 +01:00
Make album viewer compatible with non file items
This commit is contained in:
parent
fe38f27252
commit
da878c39fe
1 changed files with 65 additions and 56 deletions
|
@ -13,8 +13,8 @@ import 'package:nc_photos/entity/album/sort_provider.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||||
|
import 'package:nc_photos/iterable_extension.dart';
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
import 'package:nc_photos/list_extension.dart';
|
|
||||||
import 'package:nc_photos/session_storage.dart';
|
import 'package:nc_photos/session_storage.dart';
|
||||||
import 'package:nc_photos/snack_bar_manager.dart';
|
import 'package:nc_photos/snack_bar_manager.dart';
|
||||||
import 'package:nc_photos/theme.dart';
|
import 'package:nc_photos/theme.dart';
|
||||||
|
@ -239,24 +239,28 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onItemTap(int index) {
|
void _onItemTap(int index) {
|
||||||
|
// convert item index to file index
|
||||||
|
var fileIndex = index;
|
||||||
|
for (int i = 0; i < index; ++i) {
|
||||||
|
if (_sortedItems[i] is! AlbumFileItem ||
|
||||||
|
!file_util
|
||||||
|
.isSupportedFormat((_sortedItems[i] as AlbumFileItem).file)) {
|
||||||
|
--fileIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
Navigator.pushNamed(context, Viewer.routeName,
|
Navigator.pushNamed(context, Viewer.routeName,
|
||||||
arguments: ViewerArguments(widget.account, _backingFiles, index));
|
arguments: ViewerArguments(widget.account, _backingFiles, fileIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSelectionAppBarRemovePressed() {
|
void _onSelectionAppBarRemovePressed() {
|
||||||
// currently album's are auto sorted by date, so it's ok to remove items w/o
|
|
||||||
// preserving the order. this will be problematic if we want to allow custom
|
|
||||||
// sorting later
|
|
||||||
final selectedIndexes =
|
final selectedIndexes =
|
||||||
selectedListItems.map((e) => itemStreamListItems.indexOf(e)).toList();
|
selectedListItems.map((e) => (e as _ListItem).index).toList();
|
||||||
final selectedFiles = _backingFiles.takeIndex(selectedIndexes).toList();
|
final newItems = _sortedItems
|
||||||
final newItems = _getAlbumItemsOf(_album).where((element) {
|
.withIndex()
|
||||||
if (element is AlbumFileItem) {
|
.where((element) => !selectedIndexes.contains(element.item1))
|
||||||
return !selectedFiles.any((select) => select.path == element.file.path);
|
.map((e) => e.item2)
|
||||||
} else {
|
.toList();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}).toList();
|
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||||
final newAlbum = _album.copyWith(
|
final newAlbum = _album.copyWith(
|
||||||
provider: AlbumStaticProvider(
|
provider: AlbumStaticProvider(
|
||||||
|
@ -439,15 +443,19 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
final items = () sync* {
|
final items = () sync* {
|
||||||
for (int i = 0; i < _backingFiles.length; ++i) {
|
for (int i = 0; i < _sortedItems.length; ++i) {
|
||||||
final f = _backingFiles[i];
|
final item = _sortedItems[i];
|
||||||
|
if (item is AlbumFileItem) {
|
||||||
final previewUrl = api_util.getFilePreviewUrl(widget.account, f,
|
final previewUrl = api_util.getFilePreviewUrl(
|
||||||
width: thumbSize, height: thumbSize);
|
widget.account,
|
||||||
if (file_util.isSupportedImageFormat(f)) {
|
item.file,
|
||||||
|
width: thumbSize,
|
||||||
|
height: thumbSize,
|
||||||
|
);
|
||||||
|
if (file_util.isSupportedImageFormat(item.file)) {
|
||||||
yield _ImageListItem(
|
yield _ImageListItem(
|
||||||
index: i,
|
index: i,
|
||||||
file: f,
|
file: item.file,
|
||||||
account: widget.account,
|
account: widget.account,
|
||||||
previewUrl: previewUrl,
|
previewUrl: previewUrl,
|
||||||
onTap: () => _onItemTap(i),
|
onTap: () => _onItemTap(i),
|
||||||
|
@ -462,7 +470,7 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
_isDragging = false;
|
_isDragging = false;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else if (file_util.isSupportedVideoFormat(f)) {
|
} else if (file_util.isSupportedVideoFormat(item.file)) {
|
||||||
yield _VideoListItem(
|
yield _VideoListItem(
|
||||||
index: i,
|
index: i,
|
||||||
account: widget.account,
|
account: widget.account,
|
||||||
|
@ -481,7 +489,8 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
_log.shout(
|
_log.shout(
|
||||||
"[_transformItems] Unsupported file format: ${f.contentType}");
|
"[_transformItems] Unsupported file format: ${item.file.contentType}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue