- FilesControlsRow (and Photos' own controls row) wrapped its Row in a SingleChildScrollView, which gives a child unbounded width - silently breaking the trailing Spacer (a flex child needs bounded width) and leaving the List/Grid toggle sitting right after the filter chip instead of pinned to the row's right edge, "not enough controls to fill the row" or not. Removed the scroll wrapper (two chips and an icon toggle never need it) and the dead scroll-hint plumbing that went with it in files_view.dart. - Photos' All/Photos/Videos chips moved into the filter sheet as a full-width segmented control (matching Settings' Theme control), instead of their own row of chips competing for space with the sort and filter chips. - Settings' Theme row: the System/Light/Dark segmented control now sits on its own row below the label instead of squeezed into a trailing slot beside it, where three icon+label segments were too cramped to read comfortably - same shape as the sort sheet's Ascending/Descending control. - NooBanner (Trash's "Empty trash") and NooSummaryCard (Offline's "Sync now") both move their action onto its own row below the description text instead of squeezed onto the same line, where a longer caption had no room to share with it. - SharesController now caches each scope (with you / by you, which also covers links) after its first fetch instead of re-fetching on every single switch, including switching straight back to a scope already loaded seconds ago. - Shares' per-row overflow menu jumped straight to the unshare confirmation with no menu at all - a link share had no way to copy its own URL short of opening the full Share sheet. It's a real menu now: "Copy link" (link shares only) plus remove/unshare. - Settings gained a trailing jump rail on mobile (one small icon per section) so a specific section can be reached in one tap instead of scrolling the whole list by hand; desktop's 2-column grid doesn't need one. - The media viewer's PageView now disables its own left/right swipe while the current photo is zoomed in, so panning around it doesn't also swipe to the next item. - The PDF preview no longer sets minScale below 1.0: pdfx's PdfViewPinch hard-codes an *infinite* pan boundary whenever minScale < 1 (not an exposed parameter, so there's no way to override it), which let a page be panned arbitrarily far off-screen without ever zooming.
111 lines
3.5 KiB
Dart
111 lines
3.5 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import '../models/nextcloud_share.dart';
|
|
import 'session_controller.dart';
|
|
|
|
/// The Shares tab. Kept separate from Files' own loading/error state,
|
|
/// likewise.
|
|
class SharesController extends ChangeNotifier {
|
|
final SessionController session;
|
|
|
|
/// Each scope's own cache - switching `sharedWithMe` no longer refetches
|
|
/// on every switch, only the first time a scope is visited (or on a
|
|
/// pull-to-refresh/retry), since `By you`/`Links` (see shares_view.dart's
|
|
/// client-side split of this same list) and `With you` used to hit the
|
|
/// network again on every single toggle, even switching straight back to
|
|
/// a scope just fetched seconds ago.
|
|
List<NextcloudShare> _withMeShares = [];
|
|
List<NextcloudShare> _byMeShares = [];
|
|
bool _withMeLoaded = false;
|
|
bool _byMeLoaded = false;
|
|
bool _isLoading = false;
|
|
String? _errorMessage;
|
|
bool _sharedWithMe = false;
|
|
|
|
SharesController(this.session) {
|
|
session.addAccountClearedListener(_onAccountCleared);
|
|
session.addAccountActivatedListener(_onAccountActivated);
|
|
}
|
|
|
|
List<NextcloudShare> get shares =>
|
|
_sharedWithMe ? _withMeShares : _byMeShares;
|
|
bool get isLoading => _isLoading;
|
|
String? get errorMessage => _errorMessage;
|
|
bool get sharedWithMe => _sharedWithMe;
|
|
|
|
void _onAccountCleared() {
|
|
_withMeShares = [];
|
|
_byMeShares = [];
|
|
_withMeLoaded = false;
|
|
_byMeLoaded = false;
|
|
_isLoading = false;
|
|
_errorMessage = null;
|
|
_sharedWithMe = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
void _onAccountActivated() {
|
|
unawaited(fetchAll());
|
|
}
|
|
|
|
/// Fetches the *current* scope fresh, ignoring its cache - the initial
|
|
/// load, pull-to-refresh, and the error-retry button all want a real
|
|
/// round-trip regardless of whether this scope was already loaded.
|
|
Future<void> fetchAll() async {
|
|
final service = session.service;
|
|
if (!session.isLoggedIn || service == null) return;
|
|
final gen = session.sessionGeneration;
|
|
final wantsWithMe = _sharedWithMe;
|
|
|
|
_isLoading = true;
|
|
_errorMessage = null;
|
|
notifyListeners();
|
|
|
|
try {
|
|
final shares = await service.fetchShares(sharedWithMe: wantsWithMe);
|
|
if (gen != session.sessionGeneration) return;
|
|
if (wantsWithMe) {
|
|
_withMeShares = shares;
|
|
_withMeLoaded = true;
|
|
} else {
|
|
_byMeShares = shares;
|
|
_byMeLoaded = true;
|
|
}
|
|
} catch (e) {
|
|
if (gen != session.sessionGeneration) return;
|
|
debugPrint('[SharesController] Error fetching shares: $e');
|
|
_errorMessage = e.toString().replaceAll('Exception: ', '');
|
|
} finally {
|
|
if (gen == session.sessionGeneration) {
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Switches between "shared by me" and "shared with me". Only fetches
|
|
/// when the target scope hasn't been loaded yet - switching back to one
|
|
/// already cached just swaps which list [shares] reads from.
|
|
void setSharedWithMe(bool value) {
|
|
if (_sharedWithMe == value) return;
|
|
_sharedWithMe = value;
|
|
notifyListeners();
|
|
if (!(value ? _withMeLoaded : _byMeLoaded)) fetchAll();
|
|
}
|
|
|
|
Future<bool> deleteShare(NextcloudShare share) async {
|
|
final service = session.service;
|
|
if (service == null) return false;
|
|
final success = await service.deleteShare(share.id);
|
|
if (success) {
|
|
if (_sharedWithMe) {
|
|
_withMeShares = _withMeShares.where((s) => s.id != share.id).toList();
|
|
} else {
|
|
_byMeShares = _byMeShares.where((s) => s.id != share.id).toList();
|
|
}
|
|
notifyListeners();
|
|
}
|
|
return success;
|
|
}
|
|
}
|