Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 15791423ea | |||
| 2f5a6b4ce0 | |||
| 53bc6d5360 | |||
| f50359b4eb | |||
| 9994a1f3fa | |||
| 4aa31a2e44 | |||
| dfce3e7b5c | |||
| 564a334cdc | |||
| db329c7299 | |||
| 0a2ff5c3fb |
@@ -0,0 +1,29 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import 'errors/marianumconnect_error.dart';
|
||||
import 'marianumconnect_api.dart';
|
||||
import 'marianumconnect_endpoint.dart';
|
||||
|
||||
/// Shared base for MarianumConnect API queries. Owns the [dio] client (the
|
||||
/// shared authenticated singleton by default) and routes calls through [guard]
|
||||
/// so every query maps a DioException to the app's typed AppExceptions the same
|
||||
/// way instead of repeating the try/catch. Subclasses with bespoke error or
|
||||
/// lifecycle handling (own dio, silent failure, custom status mapping) may skip
|
||||
/// [guard] and still reuse [dio]/[endpoint].
|
||||
abstract class MarianumConnectQuery {
|
||||
final Dio dio;
|
||||
|
||||
MarianumConnectQuery({Dio? dio}) : dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
/// Resolves [path] against the active mobile-API base URL.
|
||||
String endpoint(String path) => MarianumConnectEndpoint.resolve(path);
|
||||
|
||||
/// Runs [body], converting any DioException into the matching AppException.
|
||||
Future<T> guard<T>(Future<T> Function() body) async {
|
||||
try {
|
||||
return await body();
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,27 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../auth/token_storage.dart';
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'auth_login_response.dart';
|
||||
|
||||
/// Performs the Marianum-Connect bearer login. Used both by the foreground
|
||||
/// login flow and by the auth interceptor's silent re-auth on 401. Does *not*
|
||||
/// run through the shared dio instance — that one has the interceptor, which
|
||||
/// would attempt to re-auth us into a loop if our credentials are wrong.
|
||||
class AuthLogin {
|
||||
class AuthLogin extends MarianumConnectQuery {
|
||||
static const Duration _connectTimeout = Duration(seconds: 10);
|
||||
static const Duration _receiveTimeout = Duration(seconds: 15);
|
||||
|
||||
final MarianumConnectTokenStorage _tokenStorage;
|
||||
final Dio _dio;
|
||||
|
||||
AuthLogin({
|
||||
MarianumConnectTokenStorage tokenStorage =
|
||||
const MarianumConnectTokenStorage(),
|
||||
Dio? dio,
|
||||
}) : _tokenStorage = tokenStorage,
|
||||
_dio =
|
||||
dio ??
|
||||
Dio(
|
||||
super(dio: dio ?? _buildDio());
|
||||
|
||||
static Dio _buildDio() => Dio(
|
||||
BaseOptions(
|
||||
connectTimeout: _connectTimeout,
|
||||
receiveTimeout: _receiveTimeout,
|
||||
@@ -37,10 +35,9 @@ class AuthLogin {
|
||||
required String username,
|
||||
required String password,
|
||||
required String tokenName,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _dio.post<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('auth/login'),
|
||||
}) => guard(() async {
|
||||
final response = await dio.post<Map<String, dynamic>>(
|
||||
endpoint('auth/login'),
|
||||
data: {
|
||||
'username': username,
|
||||
'password': password,
|
||||
@@ -54,8 +51,5 @@ class AuthLogin {
|
||||
expiresAt: payload.expiresAt,
|
||||
);
|
||||
return payload;
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../auth/token_storage.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Revokes the stored MC bearer token both server-side and locally. Best-effort
|
||||
/// — a network error still clears the local token so the user isn't stuck with
|
||||
/// an unusable session.
|
||||
class AuthLogout {
|
||||
class AuthLogout extends MarianumConnectQuery {
|
||||
final MarianumConnectTokenStorage _tokenStorage;
|
||||
final Dio _dio;
|
||||
|
||||
AuthLogout({
|
||||
MarianumConnectTokenStorage tokenStorage =
|
||||
const MarianumConnectTokenStorage(),
|
||||
Dio? dio,
|
||||
}) : _tokenStorage = tokenStorage,
|
||||
_dio = dio ?? MarianumConnectApi.dio();
|
||||
super.dio,
|
||||
}) : _tokenStorage = tokenStorage;
|
||||
|
||||
Future<void> run() async {
|
||||
try {
|
||||
await _dio.post<void>(MarianumConnectEndpoint.resolve('auth/logout'));
|
||||
await dio.post<void>(endpoint('auth/logout'));
|
||||
} on DioException catch (_) {
|
||||
// ignore — local clear below still happens
|
||||
} finally {
|
||||
|
||||
@@ -2,8 +2,7 @@ import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../errors/auth_exception.dart';
|
||||
import '../../auth/token_storage.dart';
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Probes that the stored bearer token still maps to the given credentials.
|
||||
/// Server returns 200 only when the credentials belong to the user that the
|
||||
@@ -12,21 +11,20 @@ import '../../marianumconnect_endpoint.dart';
|
||||
///
|
||||
/// Bypasses the shared dio singleton so the auth interceptor doesn't kick in
|
||||
/// and obscure a real 401 with a silent re-login.
|
||||
class AuthVerify {
|
||||
class AuthVerify extends MarianumConnectQuery {
|
||||
static const Duration _connectTimeout = Duration(seconds: 10);
|
||||
static const Duration _receiveTimeout = Duration(seconds: 15);
|
||||
|
||||
final MarianumConnectTokenStorage _tokenStorage;
|
||||
final Dio _dio;
|
||||
|
||||
AuthVerify({
|
||||
MarianumConnectTokenStorage tokenStorage =
|
||||
const MarianumConnectTokenStorage(),
|
||||
Dio? dio,
|
||||
}) : _tokenStorage = tokenStorage,
|
||||
_dio =
|
||||
dio ??
|
||||
Dio(
|
||||
super(dio: dio ?? _buildDio());
|
||||
|
||||
static Dio _buildDio() => Dio(
|
||||
BaseOptions(
|
||||
connectTimeout: _connectTimeout,
|
||||
sendTimeout: _connectTimeout,
|
||||
@@ -49,14 +47,12 @@ class AuthVerify {
|
||||
technicalDetails: 'AuthVerify: no bearer token in storage',
|
||||
);
|
||||
}
|
||||
try {
|
||||
await _dio.post<void>(
|
||||
MarianumConnectEndpoint.resolve('auth/verify'),
|
||||
return guard(() async {
|
||||
await dio.post<void>(
|
||||
endpoint('auth/verify'),
|
||||
data: {'username': username, 'password': password},
|
||||
options: Options(headers: {'Authorization': 'Bearer $token'}),
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,14 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'get_breakers_response.dart';
|
||||
|
||||
/// Fetches the app maintenance breaker rules from `GET /api/mobile/v1/breaker`.
|
||||
/// The endpoint is public: the bearer token is attached if present but not
|
||||
/// required, so this also works before login (e.g. to block the whole app).
|
||||
class GetBreakers {
|
||||
final Dio _dio;
|
||||
class GetBreakers extends MarianumConnectQuery {
|
||||
GetBreakers({super.dio});
|
||||
|
||||
GetBreakers({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<GetBreakersResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('breaker'),
|
||||
);
|
||||
Future<GetBreakersResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(endpoint('breaker'));
|
||||
return GetBreakersResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'get_capabilities_response.dart';
|
||||
|
||||
/// Fetches the current user's mobile capability flags from
|
||||
/// `GET /api/mobile/v1/me/capabilities`. Goes through the shared dio singleton
|
||||
/// so the bearer token is attached automatically.
|
||||
class GetCapabilities {
|
||||
final Dio _dio;
|
||||
class GetCapabilities extends MarianumConnectQuery {
|
||||
GetCapabilities({super.dio});
|
||||
|
||||
GetCapabilities({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<CapabilitiesResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('me/capabilities'),
|
||||
Future<CapabilitiesResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('me/capabilities'),
|
||||
);
|
||||
return CapabilitiesResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import '../../models/mc_holiday.dart';
|
||||
|
||||
class GetHolidays {
|
||||
final Dio _dio;
|
||||
class GetHolidays extends MarianumConnectQuery {
|
||||
GetHolidays({super.dio});
|
||||
|
||||
GetHolidays({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<List<McHoliday>> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('holidays'),
|
||||
);
|
||||
Future<List<McHoliday>> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(endpoint('holidays'));
|
||||
return response.data!
|
||||
.map((e) => McHoliday.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Downloads the raw PDF bytes of a Marianum Message from
|
||||
/// `GET /api/mobile/v1/newsletter/{id}/file`.
|
||||
@@ -12,23 +10,16 @@ import '../../marianumconnect_endpoint.dart';
|
||||
/// Goes through the shared MC dio so the bearer token is attached automatically;
|
||||
/// the bytes are handed to `SfPdfViewer.memory` so no auth header has to be
|
||||
/// plumbed into the viewer itself.
|
||||
class GetNewsletterFile {
|
||||
class GetNewsletterFile extends MarianumConnectQuery {
|
||||
final String id;
|
||||
final Dio _dio;
|
||||
|
||||
GetNewsletterFile(this.id, {Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
GetNewsletterFile(this.id, {super.dio});
|
||||
|
||||
Future<Uint8List> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<int>>(
|
||||
MarianumConnectEndpoint.resolve(
|
||||
'newsletter/${Uri.encodeComponent(id)}/file',
|
||||
),
|
||||
Future<Uint8List> run() => guard(() async {
|
||||
final response = await dio.get<List<int>>(
|
||||
endpoint('newsletter/${Uri.encodeComponent(id)}/file'),
|
||||
options: Options(responseType: ResponseType.bytes),
|
||||
);
|
||||
return Uint8List.fromList(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'get_ticker_response.dart';
|
||||
|
||||
/// Fetches the current "Aktuelles" ticker post from
|
||||
/// `GET /api/mobile/v1/ticker`. Bearer token is attached by the shared dio.
|
||||
class GetTicker {
|
||||
final Dio _dio;
|
||||
class GetTicker extends MarianumConnectQuery {
|
||||
GetTicker({super.dio});
|
||||
|
||||
GetTicker({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TickerResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('ticker'),
|
||||
);
|
||||
Future<TickerResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(endpoint('ticker'));
|
||||
return TickerResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'get_ticker_nav_response.dart';
|
||||
|
||||
/// Fetches the filtered ticker page tree from
|
||||
/// `GET /api/mobile/v1/ticker/pages`.
|
||||
class GetTickerNav {
|
||||
final Dio _dio;
|
||||
class GetTickerNav extends MarianumConnectQuery {
|
||||
GetTickerNav({super.dio});
|
||||
|
||||
GetTickerNav({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TickerNavResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('ticker/pages'),
|
||||
Future<TickerNavResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('ticker/pages'),
|
||||
);
|
||||
return TickerNavResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../errors/ticker_content_unavailable_exception.dart';
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'get_ticker_page_response.dart';
|
||||
|
||||
/// Fetches a single ticker page from
|
||||
@@ -15,19 +14,17 @@ import 'get_ticker_page_response.dart';
|
||||
/// 404 `{ "error": "CONTENT_UNAVAILABLE", "webUrl": ... }`; that case is mapped
|
||||
/// to a dedicated [TickerContentUnavailableException] carrying the browser
|
||||
/// fallback URL, so the detail screen can offer "open in browser" instead of a
|
||||
/// generic error.
|
||||
class GetTickerPage {
|
||||
/// generic error. The bespoke 404 handling is why this keeps its own try/catch
|
||||
/// instead of the base [guard].
|
||||
class GetTickerPage extends MarianumConnectQuery {
|
||||
final String slug;
|
||||
final Dio _dio;
|
||||
|
||||
GetTickerPage(this.slug, {Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
GetTickerPage(this.slug, {super.dio});
|
||||
|
||||
Future<TickerPageResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve(
|
||||
'ticker/pages/${Uri.encodeComponent(slug)}',
|
||||
),
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('ticker/pages/${Uri.encodeComponent(slug)}'),
|
||||
);
|
||||
return TickerPageResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
|
||||
@@ -44,6 +44,12 @@ class TickerPageResponse {
|
||||
/// when the page has never been published.
|
||||
final String? publishedAt;
|
||||
|
||||
/// PROXIED_FILE only: ISO timestamp of the last successful re-fetch of the
|
||||
/// file by the server proxy (`ticker_pages.proxy_last_success_at`) — the
|
||||
/// document's data currency, shown as "Aktualisiert am …" instead of
|
||||
/// [publishedAt]. Null for other kinds / files never fetched yet.
|
||||
final String? fileFetchedAt;
|
||||
|
||||
TickerPageResponse({
|
||||
required this.schemaVersion,
|
||||
this.slug,
|
||||
@@ -58,6 +64,7 @@ class TickerPageResponse {
|
||||
this.hash,
|
||||
this.webUrl,
|
||||
this.publishedAt,
|
||||
this.fileFetchedAt,
|
||||
});
|
||||
|
||||
factory TickerPageResponse.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -21,6 +21,7 @@ TickerPageResponse _$TickerPageResponseFromJson(Map<String, dynamic> json) =>
|
||||
hash: json['hash'] as String?,
|
||||
webUrl: json['webUrl'] as String?,
|
||||
publishedAt: json['publishedAt'] as String?,
|
||||
fileFetchedAt: json['fileFetchedAt'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TickerPageResponseToJson(TickerPageResponse instance) =>
|
||||
@@ -38,4 +39,5 @@ Map<String, dynamic> _$TickerPageResponseToJson(TickerPageResponse instance) =>
|
||||
'hash': instance.hash,
|
||||
'webUrl': instance.webUrl,
|
||||
'publishedAt': instance.publishedAt,
|
||||
'fileFetchedAt': instance.fileFetchedAt,
|
||||
};
|
||||
|
||||
@@ -2,9 +2,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Downloads the raw bytes of a PROXIED_FILE ticker page from
|
||||
/// `GET /api/mobile/v1/ticker/pages/{slug}/file`.
|
||||
@@ -12,24 +10,16 @@ import '../../marianumconnect_endpoint.dart';
|
||||
/// Goes through the shared MC dio so the bearer token is attached automatically
|
||||
/// (server enforces page visibility); the bytes are handed to `SfPdfViewer.memory`
|
||||
/// so no auth header has to be plumbed into the viewer itself.
|
||||
class GetTickerPageFile {
|
||||
class GetTickerPageFile extends MarianumConnectQuery {
|
||||
final String slug;
|
||||
final Dio _dio;
|
||||
|
||||
GetTickerPageFile(this.slug, {Dio? dio})
|
||||
: _dio = dio ?? MarianumConnectApi.dio();
|
||||
GetTickerPageFile(this.slug, {super.dio});
|
||||
|
||||
Future<Uint8List> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<int>>(
|
||||
MarianumConnectEndpoint.resolve(
|
||||
'ticker/pages/${Uri.encodeComponent(slug)}/file',
|
||||
),
|
||||
Future<Uint8List> run() => guard(() async {
|
||||
final response = await dio.get<List<int>>(
|
||||
endpoint('ticker/pages/${Uri.encodeComponent(slug)}/file'),
|
||||
options: Options(responseType: ResponseType.bytes),
|
||||
);
|
||||
return Uint8List.fromList(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Registers (upserts) this device's push subscription with MarianumConnect via
|
||||
/// `PUT /api/mobile/v1/me/push-device`. The backend verifies the Nextcloud
|
||||
/// device-identifier signature, stores the routing metadata and starts
|
||||
/// forwarding Nextcloud pushes to this device's FCM token. Responds 204.
|
||||
class PushDeviceRegister {
|
||||
final Dio _dio;
|
||||
|
||||
PushDeviceRegister({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
class PushDeviceRegister extends MarianumConnectQuery {
|
||||
PushDeviceRegister({super.dio});
|
||||
|
||||
Future<void> run({
|
||||
required String deviceIdentifier,
|
||||
@@ -21,10 +15,9 @@ class PushDeviceRegister {
|
||||
required String platform,
|
||||
required String registrationType,
|
||||
String? appVersion,
|
||||
}) async {
|
||||
try {
|
||||
await _dio.put<void>(
|
||||
MarianumConnectEndpoint.resolve('me/push-device'),
|
||||
}) => guard(() async {
|
||||
await dio.put<void>(
|
||||
endpoint('me/push-device'),
|
||||
data: {
|
||||
'deviceIdentifier': deviceIdentifier,
|
||||
'deviceIdentifierSignature': deviceIdentifierSignature,
|
||||
@@ -37,8 +30,5 @@ class PushDeviceRegister {
|
||||
'appVersion': ?appVersion,
|
||||
},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Triggers a test push to all of the current user's registered devices via
|
||||
/// `POST /api/mobile/v1/me/push-device/test`. Returns the number of devices the
|
||||
/// backend dispatched to (0 when none are registered).
|
||||
class PushDeviceTest {
|
||||
final Dio _dio;
|
||||
class PushDeviceTest extends MarianumConnectQuery {
|
||||
PushDeviceTest({super.dio});
|
||||
|
||||
PushDeviceTest({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<int> run() async {
|
||||
try {
|
||||
final response = await _dio.post<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('me/push-device/test'),
|
||||
Future<int> run() => guard(() async {
|
||||
final response = await dio.post<Map<String, dynamic>>(
|
||||
endpoint('me/push-device/test'),
|
||||
);
|
||||
return (response.data?['devices'] as num?)?.toInt() ?? 0;
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Removes this device's push subscription from MarianumConnect via
|
||||
/// `DELETE /api/mobile/v1/me/push-device?deviceIdentifier=...`. Idempotent
|
||||
/// (204 even when the row is already gone).
|
||||
class PushDeviceUnregister {
|
||||
final Dio _dio;
|
||||
class PushDeviceUnregister extends MarianumConnectQuery {
|
||||
PushDeviceUnregister({super.dio});
|
||||
|
||||
PushDeviceUnregister({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<void> run({required String deviceIdentifier}) async {
|
||||
try {
|
||||
await _dio.delete<void>(
|
||||
MarianumConnectEndpoint.resolve('me/push-device'),
|
||||
Future<void> run({required String deviceIdentifier}) => guard(() async {
|
||||
await dio.delete<void>(
|
||||
endpoint('me/push-device'),
|
||||
queryParameters: {'deviceIdentifier': deviceIdentifier},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Sends a single client-side error report to MarianumConnect
|
||||
/// (`POST client-errors`). The endpoint is public, so reports that happen
|
||||
/// before login are still captured; when a bearer token is present the shared
|
||||
/// dio interceptor attaches it and the server attributes the report to that user.
|
||||
class ReportClientError {
|
||||
final Dio _dio;
|
||||
|
||||
ReportClientError({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
class ReportClientError extends MarianumConnectQuery {
|
||||
ReportClientError({super.dio});
|
||||
|
||||
Future<void> run({
|
||||
required String errorType,
|
||||
@@ -21,10 +15,9 @@ class ReportClientError {
|
||||
String? platform,
|
||||
String? appVersion,
|
||||
String? deviceModel,
|
||||
}) async {
|
||||
try {
|
||||
await _dio.post<void>(
|
||||
MarianumConnectEndpoint.resolve('client-errors'),
|
||||
}) => guard(() async {
|
||||
await dio.post<void>(
|
||||
endpoint('client-errors'),
|
||||
data: {
|
||||
'errorType': errorType,
|
||||
'message': ?message,
|
||||
@@ -35,8 +28,5 @@ class ReportClientError {
|
||||
'deviceModel': ?deviceModel,
|
||||
},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,32 +3,26 @@ import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Submits user feedback to MarianumConnect (`POST me/feedback`, bearer-auth).
|
||||
/// The optional screenshot is sent base64-encoded. Replaces the legacy mhsl.eu
|
||||
/// `server/feedback` endpoint — the user no longer needs to be sent explicitly,
|
||||
/// the bearer token identifies them.
|
||||
class SubmitFeedback {
|
||||
final Dio _dio;
|
||||
|
||||
SubmitFeedback({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
class SubmitFeedback extends MarianumConnectQuery {
|
||||
SubmitFeedback({super.dio});
|
||||
|
||||
Future<void> run({
|
||||
required String message,
|
||||
Uint8List? screenshot,
|
||||
String screenshotContentType = 'image/png',
|
||||
}) async {
|
||||
try {
|
||||
}) => guard(() async {
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
final screenshotBase64 = screenshot != null ? base64Encode(screenshot) : null;
|
||||
await _dio.post<void>(
|
||||
MarianumConnectEndpoint.resolve('me/feedback'),
|
||||
await dio.post<void>(
|
||||
endpoint('me/feedback'),
|
||||
data: {
|
||||
'message': message,
|
||||
'screenshot': ?screenshotBase64,
|
||||
@@ -39,10 +33,7 @@ class SubmitFeedback {
|
||||
'deviceModel': await _deviceModel(),
|
||||
},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
static String? _platform() {
|
||||
if (Platform.isAndroid) return 'android';
|
||||
|
||||
@@ -3,14 +3,11 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../../../../push/push_registration_store.dart';
|
||||
import '../../../../push/push_registration_type.dart';
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'telemetry_device_id.dart';
|
||||
|
||||
/// Sends a telemetry heartbeat to MarianumConnect (`POST me/telemetry`) —
|
||||
@@ -19,10 +16,8 @@ import 'telemetry_device_id.dart';
|
||||
/// (so a fresh registration isn't under-reported until the next launch).
|
||||
/// Bearer-authenticated via the shared dio interceptor. Replaces the legacy
|
||||
/// mhsl.eu `server/userIndex/update` call.
|
||||
class TelemetryHeartbeat {
|
||||
final Dio _dio;
|
||||
|
||||
TelemetryHeartbeat({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
class TelemetryHeartbeat extends MarianumConnectQuery {
|
||||
TelemetryHeartbeat({super.dio});
|
||||
|
||||
/// Fire-and-forget: schedules a heartbeat and swallows any error, so a failed
|
||||
/// send never disrupts app start. Used from the app shell's initState and
|
||||
@@ -35,8 +30,7 @@ class TelemetryHeartbeat {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> send({required bool notificationsEnabled}) async {
|
||||
try {
|
||||
Future<void> send({required bool notificationsEnabled}) => guard(() async {
|
||||
final info = DeviceInfoPlugin();
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
final deviceIdentifier = await TelemetryDeviceId.resolve();
|
||||
@@ -61,8 +55,8 @@ class TelemetryHeartbeat {
|
||||
raw = appleInfo.data;
|
||||
}
|
||||
|
||||
await _dio.post<void>(
|
||||
MarianumConnectEndpoint.resolve('me/telemetry'),
|
||||
await dio.post<void>(
|
||||
endpoint('me/telemetry'),
|
||||
data: {
|
||||
'deviceIdentifier': deviceIdentifier,
|
||||
// `pushDeviceIdentifier` reflects a *completed* registration and is
|
||||
@@ -79,8 +73,5 @@ class TelemetryHeartbeat {
|
||||
'deviceInfo': jsonEncode(raw),
|
||||
},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+7
-17
@@ -1,23 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../mhsl/custom_timetable_event/custom_timetable_event.dart';
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
class TimetableCustomEventsAdd {
|
||||
final Dio _dio;
|
||||
class TimetableCustomEventsAdd extends MarianumConnectQuery {
|
||||
TimetableCustomEventsAdd({super.dio});
|
||||
|
||||
TimetableCustomEventsAdd({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<void> run(CustomTimetableEvent event) async {
|
||||
try {
|
||||
await _dio.post<void>(
|
||||
MarianumConnectEndpoint.resolve('timetable/custom-events'),
|
||||
Future<void> run(CustomTimetableEvent event) => guard(() async {
|
||||
await dio.post<void>(
|
||||
endpoint('timetable/custom-events'),
|
||||
data: event.toJson(),
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+7
-17
@@ -1,23 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../mhsl/custom_timetable_event/get/get_custom_timetable_event_response.dart';
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
class TimetableCustomEventsGet {
|
||||
final Dio _dio;
|
||||
class TimetableCustomEventsGet extends MarianumConnectQuery {
|
||||
TimetableCustomEventsGet({super.dio});
|
||||
|
||||
TimetableCustomEventsGet({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<GetCustomTimetableEventResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/custom-events'),
|
||||
Future<GetCustomTimetableEventResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/custom-events'),
|
||||
);
|
||||
return GetCustomTimetableEventResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+6
-19
@@ -1,22 +1,9 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
class TimetableCustomEventsRemove extends MarianumConnectQuery {
|
||||
TimetableCustomEventsRemove({super.dio});
|
||||
|
||||
class TimetableCustomEventsRemove {
|
||||
final Dio _dio;
|
||||
|
||||
TimetableCustomEventsRemove({Dio? dio})
|
||||
: _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<void> run(String id) async {
|
||||
try {
|
||||
await _dio.delete<void>(
|
||||
MarianumConnectEndpoint.resolve('timetable/custom-events/$id'),
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
Future<void> run(String id) => guard(() async {
|
||||
await dio.delete<void>(endpoint('timetable/custom-events/$id'));
|
||||
});
|
||||
}
|
||||
|
||||
+7
-18
@@ -1,24 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../mhsl/custom_timetable_event/custom_timetable_event.dart';
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
class TimetableCustomEventsUpdate {
|
||||
final Dio _dio;
|
||||
class TimetableCustomEventsUpdate extends MarianumConnectQuery {
|
||||
TimetableCustomEventsUpdate({super.dio});
|
||||
|
||||
TimetableCustomEventsUpdate({Dio? dio})
|
||||
: _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<void> run(String id, CustomTimetableEvent event) async {
|
||||
try {
|
||||
await _dio.put<void>(
|
||||
MarianumConnectEndpoint.resolve('timetable/custom-events/$id'),
|
||||
Future<void> run(String id, CustomTimetableEvent event) => guard(() async {
|
||||
await dio.put<void>(
|
||||
endpoint('timetable/custom-events/$id'),
|
||||
data: event.toJson(),
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_classes_response.dart';
|
||||
|
||||
class TimetableGetClasses {
|
||||
final Dio _dio;
|
||||
class TimetableGetClasses extends MarianumConnectQuery {
|
||||
TimetableGetClasses({super.dio});
|
||||
|
||||
TimetableGetClasses({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetClassesResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/elements/classes'),
|
||||
Future<TimetableGetClassesResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/elements/classes'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McTimetableClass.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetClassesResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+7
-17
@@ -1,35 +1,25 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import '../timetable_get_week/timetable_get_week_response.dart';
|
||||
import 'timetable_element_type.dart';
|
||||
|
||||
/// Fetches a foreign element's weekly timetable from
|
||||
/// `timetable/{student|teacher|room|class}/{id}`. The response shape is
|
||||
/// identical to `timetable/me`, so [TimetableGetWeekResponse] is reused.
|
||||
class TimetableGetElementWeek {
|
||||
final Dio _dio;
|
||||
|
||||
TimetableGetElementWeek({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
class TimetableGetElementWeek extends MarianumConnectQuery {
|
||||
TimetableGetElementWeek({super.dio});
|
||||
|
||||
Future<TimetableGetWeekResponse> run({
|
||||
required TimetableElementType type,
|
||||
required int id,
|
||||
required DateTime from,
|
||||
required DateTime until,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/${type.pathSegment}/$id'),
|
||||
}) => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/${type.pathSegment}/$id'),
|
||||
queryParameters: {'from': _format(from), 'until': _format(until)},
|
||||
);
|
||||
return TimetableGetWeekResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
String _format(DateTime d) =>
|
||||
'${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_holidays_response.dart';
|
||||
|
||||
class TimetableGetHolidays {
|
||||
final Dio _dio;
|
||||
class TimetableGetHolidays extends MarianumConnectQuery {
|
||||
TimetableGetHolidays({super.dio});
|
||||
|
||||
TimetableGetHolidays({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetHolidaysResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/holidays'),
|
||||
Future<TimetableGetHolidaysResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/holidays'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McHoliday.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetHolidaysResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,14 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_rooms_response.dart';
|
||||
|
||||
class TimetableGetRooms {
|
||||
final Dio _dio;
|
||||
class TimetableGetRooms extends MarianumConnectQuery {
|
||||
TimetableGetRooms({super.dio});
|
||||
|
||||
TimetableGetRooms({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetRoomsResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/rooms'),
|
||||
);
|
||||
Future<TimetableGetRoomsResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(endpoint('timetable/rooms'));
|
||||
final list = response.data!
|
||||
.map((e) => McRoom.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetRoomsResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+7
-17
@@ -1,23 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_schoolyear_response.dart';
|
||||
|
||||
class TimetableGetSchoolyear {
|
||||
final Dio _dio;
|
||||
class TimetableGetSchoolyear extends MarianumConnectQuery {
|
||||
TimetableGetSchoolyear({super.dio});
|
||||
|
||||
TimetableGetSchoolyear({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetSchoolyearResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/schoolyear'),
|
||||
Future<TimetableGetSchoolyearResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/schoolyear'),
|
||||
);
|
||||
return TimetableGetSchoolyearResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_students_response.dart';
|
||||
|
||||
class TimetableGetStudents {
|
||||
final Dio _dio;
|
||||
class TimetableGetStudents extends MarianumConnectQuery {
|
||||
TimetableGetStudents({super.dio});
|
||||
|
||||
TimetableGetStudents({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetStudentsResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/elements/students'),
|
||||
Future<TimetableGetStudentsResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/elements/students'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McTimetableStudent.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetStudentsResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_subjects_response.dart';
|
||||
|
||||
class TimetableGetSubjects {
|
||||
final Dio _dio;
|
||||
class TimetableGetSubjects extends MarianumConnectQuery {
|
||||
TimetableGetSubjects({super.dio});
|
||||
|
||||
TimetableGetSubjects({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetSubjectsResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/subjects'),
|
||||
Future<TimetableGetSubjectsResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/subjects'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McSubject.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetSubjectsResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,29 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_teachers_response.dart';
|
||||
|
||||
class TimetableGetTeachers {
|
||||
final Dio _dio;
|
||||
class TimetableGetTeachers extends MarianumConnectQuery {
|
||||
TimetableGetTeachers({super.dio});
|
||||
|
||||
TimetableGetTeachers({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetTeachersResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/elements/teachers'),
|
||||
Future<TimetableGetTeachersResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/elements/teachers'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map(
|
||||
(e) =>
|
||||
McTimetableTeacherElement.fromJson(e as Map<String, dynamic>),
|
||||
)
|
||||
.map((e) => McTimetableTeacherElement.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetTeachersResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_timegrid_response.dart';
|
||||
|
||||
class TimetableGetTimegrid {
|
||||
final Dio _dio;
|
||||
class TimetableGetTimegrid extends MarianumConnectQuery {
|
||||
TimetableGetTimegrid({super.dio});
|
||||
|
||||
TimetableGetTimegrid({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetTimegridResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/timegrid'),
|
||||
Future<TimetableGetTimegridResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/timegrid'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McTimegridUnit.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetTimegridResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,32 +1,19 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'timetable_get_week_response.dart';
|
||||
|
||||
class TimetableGetWeek {
|
||||
final Dio _dio;
|
||||
|
||||
TimetableGetWeek({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
class TimetableGetWeek extends MarianumConnectQuery {
|
||||
TimetableGetWeek({super.dio});
|
||||
|
||||
Future<TimetableGetWeekResponse> run({
|
||||
required DateTime from,
|
||||
required DateTime until,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/me'),
|
||||
queryParameters: {
|
||||
'from': _format(from),
|
||||
'until': _format(until),
|
||||
},
|
||||
}) => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/me'),
|
||||
queryParameters: {'from': _format(from), 'until': _format(until)},
|
||||
);
|
||||
return TimetableGetWeekResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
String _format(DateTime d) =>
|
||||
'${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
|
||||
|
||||
+7
-18
@@ -1,25 +1,14 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Entfernt die persönliche Farbe eines Fachs (Fach fällt auf die Status-Farbe
|
||||
/// zurück). Schlüssel ist das Fach-Kürzel (`shortName`).
|
||||
class TimetableSubjectColorRemove {
|
||||
final Dio _dio;
|
||||
class TimetableSubjectColorRemove extends MarianumConnectQuery {
|
||||
TimetableSubjectColorRemove({super.dio});
|
||||
|
||||
TimetableSubjectColorRemove({Dio? dio})
|
||||
: _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<void> run(String subjectShort) async {
|
||||
try {
|
||||
await _dio.delete<void>(
|
||||
MarianumConnectEndpoint.resolve('timetable/subject-colors'),
|
||||
Future<void> run(String subjectShort) => guard(() async {
|
||||
await dio.delete<void>(
|
||||
endpoint('timetable/subject-colors'),
|
||||
queryParameters: {'subject': subjectShort},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+7
-17
@@ -1,24 +1,14 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Setzt (oder überschreibt) die persönliche Farbe eines Fachs. Der Schlüssel
|
||||
/// ist das Fach-Kürzel (`shortName`); die Farbe ist ein Palette-Name.
|
||||
class TimetableSubjectColorSet {
|
||||
final Dio _dio;
|
||||
class TimetableSubjectColorSet extends MarianumConnectQuery {
|
||||
TimetableSubjectColorSet({super.dio});
|
||||
|
||||
TimetableSubjectColorSet({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<void> run(String subjectShort, String color) async {
|
||||
try {
|
||||
await _dio.put<void>(
|
||||
MarianumConnectEndpoint.resolve('timetable/subject-colors'),
|
||||
Future<void> run(String subjectShort, String color) => guard(() async {
|
||||
await dio.put<void>(
|
||||
endpoint('timetable/subject-colors'),
|
||||
data: {'subject': subjectShort, 'color': color},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,20 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'user_search_response.dart';
|
||||
|
||||
/// Searches active users (students, teachers, staff) via the MarianumConnect
|
||||
/// mobile API. Returns each match's Nextcloud username plus role, so the Talk
|
||||
/// search can start a direct chat and label results without hitting Nextcloud.
|
||||
class UserSearch {
|
||||
final Dio _dio;
|
||||
class UserSearch extends MarianumConnectQuery {
|
||||
UserSearch({super.dio});
|
||||
|
||||
UserSearch({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<UserSearchResponse> run(String query) async {
|
||||
try {
|
||||
final response = await _dio.get<List<dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('users/search'),
|
||||
Future<UserSearchResponse> run(String query) => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('users/search'),
|
||||
queryParameters: {'q': query},
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McUserSearchResult.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return UserSearchResponse(result: list);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ extension DateTimeFormatting on DateTime {
|
||||
|
||||
String formatRelative() => Jiffy.parseFromDateTime(this).fromNow();
|
||||
|
||||
/// Compact `yyyyMMdd` key, e.g. to identify a week-start in timetable caches.
|
||||
String weekKey() => Jiffy.parseFromDateTime(this).format(pattern: 'yyyyMMdd');
|
||||
|
||||
String timeRangeTo(DateTime end) => '${formatHm()} - ${end.formatHm()}';
|
||||
|
||||
String formatDateRelativeShort({DateTime? now}) {
|
||||
|
||||
@@ -37,8 +37,10 @@ import '../view/pages/talk/talk_navigator.dart';
|
||||
import '../view/pages/ticker/ticker_page_view.dart';
|
||||
import '../view/pages/timetable/custom_events/custom_events_view.dart';
|
||||
import '../view/pages/timetable/subject_colors/subject_colors_view.dart';
|
||||
import '../widget/avatar_crop_page.dart';
|
||||
import '../widget/debug/cache_view.dart';
|
||||
import '../widget/file_viewer.dart';
|
||||
import '../widget/large_profile_picture_view.dart';
|
||||
import '../widget/user_avatar.dart';
|
||||
|
||||
/// Single entry point for full-page navigations. Dialogs and bottom sheets
|
||||
@@ -95,6 +97,30 @@ class AppRoutes {
|
||||
pushScreen(context, withNavBar: false, screen: const SubjectColorsView());
|
||||
}
|
||||
|
||||
/// Opens the full-screen cropper on [imageBytes] and resolves to the cropped
|
||||
/// bytes (or null if cancelled). [aspectRatio] defaults to 1:1 for avatars;
|
||||
/// pass null for a free-form crop (e.g. chat backgrounds).
|
||||
static Future<Uint8List?> openAvatarCrop(
|
||||
BuildContext context, {
|
||||
required Uint8List imageBytes,
|
||||
double? aspectRatio = 1,
|
||||
}) {
|
||||
return Navigator.of(context).push<Uint8List>(
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) =>
|
||||
AvatarCropPage(imageBytes: imageBytes, aspectRatio: aspectRatio),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Opens the tappable, zoomable profile-picture viewer for [id].
|
||||
static void openLargeProfilePicture(BuildContext context, String id) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(builder: (_) => LargeProfilePictureView(id: id)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Opens the picker for choosing a foreign timetable element and resolves to
|
||||
/// the selected element (or null if dismissed). The timetable view renders
|
||||
/// the chosen plan inline. Gated behind the `viewForeignTimetables`
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../../api/marianumconnect/queries/timetable_get_element_week/timetable_element_type.dart';
|
||||
import '../../../../../api/marianumconnect/queries/timetable_get_week/timetable_get_week_response.dart';
|
||||
import '../../../../../extensions/date_time.dart';
|
||||
@@ -24,7 +22,6 @@ class ForeignTimetableBloc
|
||||
TimetableState,
|
||||
ForeignTimetableRepository
|
||||
> {
|
||||
static final DateFormat _weekKeyFormat = DateFormat('yyyyMMdd');
|
||||
|
||||
final TimetableElementType type;
|
||||
// Named `elementId` rather than `id` to avoid shadowing HydratedMixin's
|
||||
@@ -183,7 +180,7 @@ class ForeignTimetableBloc
|
||||
}
|
||||
|
||||
void _writeWeekToCache(DateTime weekStart, TimetableGetWeekResponse week) {
|
||||
final key = _weekKeyFormat.format(weekStart);
|
||||
final key = weekStart.weekKey();
|
||||
add(
|
||||
Emit((s) {
|
||||
final updated = Map<String, TimetableGetWeekResponse>.of(s.weekCache);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../../api/marianumconnect/queries/timetable_custom_events/custom_events_migration.dart';
|
||||
import '../../../../../api/marianumconnect/queries/timetable_get_week/timetable_get_week_response.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/custom_timetable_event.dart';
|
||||
@@ -19,8 +17,6 @@ class TimetableBloc
|
||||
TimetableState,
|
||||
TimetableRepository
|
||||
> {
|
||||
static final DateFormat _weekKeyFormat = DateFormat('yyyyMMdd');
|
||||
|
||||
DateTime _lastWeekRequestStart = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
|
||||
/// Set by [retry] to force the next [gatherData] to bypass cache freshness
|
||||
@@ -247,7 +243,7 @@ class TimetableBloc
|
||||
}
|
||||
|
||||
void _writeWeekToCache(DateTime weekStart, TimetableGetWeekResponse week) {
|
||||
final key = _weekKeyFormat.format(weekStart);
|
||||
final key = weekStart.weekKey();
|
||||
add(
|
||||
Emit((s) {
|
||||
final updated = Map<String, TimetableGetWeekResponse>.of(s.weekCache);
|
||||
|
||||
@@ -19,7 +19,11 @@ class PostLoginSplash extends StatefulWidget {
|
||||
try {
|
||||
_darkComposition ??= await AssetLottie(_darkAsset).load();
|
||||
_lightComposition ??= await AssetLottie(_lightAsset).load();
|
||||
} catch (_) {}
|
||||
} catch (e) {
|
||||
// Precache is a best-effort warm-up; the splash falls back to loading the
|
||||
// composition on demand. Log so a broken asset is at least diagnosable.
|
||||
debugPrint('PostLoginSplash.precache failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
final VoidCallback onComplete;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../state/app/modules/files/bloc/files_bloc.dart';
|
||||
import '../../../../widget/async_action_button.dart';
|
||||
import '../../../../widget/demo_restricted.dart';
|
||||
import '../../../../widget/details_bottom_sheet.dart';
|
||||
import '../../../../widget/file_pick.dart';
|
||||
import '../../../../widget/prompt_dialog.dart';
|
||||
|
||||
/// Opens the "Element hinzufügen" sheet (create folder, upload, take photo, …).
|
||||
/// [onPickedFiles] receives selected/captured file paths (gallery, file picker
|
||||
@@ -59,27 +59,15 @@ void showAddFileSheet(
|
||||
}
|
||||
|
||||
void showCreateFolderDialog(BuildContext context, FilesBloc bloc) {
|
||||
final inputController = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogCtx) => AlertDialog(
|
||||
title: const Text('Neuer Ordner'),
|
||||
content: TextField(
|
||||
controller: inputController,
|
||||
decoration: const InputDecoration(labelText: 'Name'),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
AsyncDialogAction(
|
||||
confirmLabel: 'Ordner erstellen',
|
||||
onConfirm: () async {
|
||||
if (inputController.text.trim().isEmpty) {
|
||||
showPromptDialog(
|
||||
context,
|
||||
title: 'Neuer Ordner',
|
||||
confirmButton: 'Ordner erstellen',
|
||||
onConfirm: (name) async {
|
||||
if (name.isEmpty) {
|
||||
throw Exception('Bitte einen Namen eingeben.');
|
||||
}
|
||||
await bloc.createFolder(inputController.text.trim());
|
||||
await bloc.createFolder(name);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import '../../../../widget/demo_restricted.dart';
|
||||
import '../../../../widget/details_bottom_sheet.dart';
|
||||
import '../../../../widget/downloads/download_trigger.dart';
|
||||
import '../../../../widget/info_dialog.dart';
|
||||
import '../../../../widget/prompt_dialog.dart';
|
||||
import '../../talk/widgets/highlighted_linkify.dart';
|
||||
import '../sharing/share_sheet.dart';
|
||||
import 'file_details_sheet.dart';
|
||||
@@ -136,52 +137,30 @@ class _FileElementState extends State<FileElement>
|
||||
String _joinPath(String folder, String name, {required bool isDirectory}) =>
|
||||
isDirectory ? '$folder$name/' : '$folder$name';
|
||||
|
||||
Future<void> _rename() async {
|
||||
void _rename() {
|
||||
if (guardDemoAction(context)) return;
|
||||
final controller = TextEditingController(text: widget.file.name);
|
||||
try {
|
||||
final newName = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (dialogCtx) => AlertDialog(
|
||||
title: const Text('Umbenennen'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(labelText: 'Neuer Name'),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogCtx).pop(),
|
||||
child: const Text('Abbrechen'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogCtx).pop(controller.text.trim()),
|
||||
child: const Text('Umbenennen'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (newName == null || newName.isEmpty || newName == widget.file.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
showPromptDialog(
|
||||
context,
|
||||
title: 'Umbenennen',
|
||||
label: 'Neuer Name',
|
||||
confirmButton: 'Umbenennen',
|
||||
initialValue: widget.file.name,
|
||||
onConfirm: (newName) async {
|
||||
if (newName.isEmpty || newName == widget.file.name) return;
|
||||
final parent = _parentPathOf(widget.file.path);
|
||||
final destination = _joinPath(
|
||||
parent,
|
||||
newName,
|
||||
isDirectory: widget.file.isDirectory,
|
||||
);
|
||||
await _runWebdavOp(() async {
|
||||
final webdav = await WebdavApi.webdav;
|
||||
await webdav.move(
|
||||
PathUri.parse(widget.file.path),
|
||||
PathUri.parse(destination),
|
||||
);
|
||||
}, errorTitle: 'Umbenennen fehlgeschlagen');
|
||||
} finally {
|
||||
controller.dispose();
|
||||
}
|
||||
widget.refetch();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _putOnClipboard({required bool copy}) {
|
||||
@@ -218,19 +197,6 @@ class _FileElementState extends State<FileElement>
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _runWebdavOp(
|
||||
Future<void> Function() action, {
|
||||
required String errorTitle,
|
||||
}) async {
|
||||
try {
|
||||
await action();
|
||||
widget.refetch();
|
||||
} on Object catch (e) {
|
||||
if (!mounted) return;
|
||||
InfoDialog.show(context, e.toString(), title: errorTitle, copyable: true);
|
||||
}
|
||||
}
|
||||
|
||||
void _showActionSheet() {
|
||||
Haptics.longPress();
|
||||
showDetailsBottomSheet(
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../../api/marianumconnect/queries/get_newsletter_file/get_newsletter_file.dart';
|
||||
import '../../../widget/app_progress_indicator.dart';
|
||||
import '../../../widget/confirm_dialog.dart';
|
||||
import '../../../widget/placeholder_view.dart';
|
||||
|
||||
@@ -33,7 +34,7 @@ class _MessageViewState extends State<MessageView> {
|
||||
);
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
}
|
||||
return SfPdfViewer.memory(
|
||||
snapshot.data!,
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../../api/marianumcloud/cloud_users/cloud_users_actions.dart';
|
||||
import '../../../../api/marianumconnect/queries/auth_logout/auth_logout.dart';
|
||||
import '../../../../model/account_data.dart';
|
||||
import '../../../../push/push_registration.dart';
|
||||
import '../../../../routing/app_routes.dart';
|
||||
import '../../../../state/app/modules/account/bloc/account_bloc.dart';
|
||||
import '../../../../state/app/modules/account/bloc/account_state.dart';
|
||||
import '../../../../widget/app_progress_indicator.dart';
|
||||
@@ -12,7 +13,6 @@ import '../../../../widget/async_action_button.dart';
|
||||
import '../../../../widget/avatar_actions_sheet.dart';
|
||||
import '../../../../widget/confirm_dialog.dart';
|
||||
import '../../../../widget/demo_restricted.dart';
|
||||
import '../../../../widget/large_profile_picture_view.dart';
|
||||
import '../../../../widget/user_avatar.dart';
|
||||
|
||||
// Display-name is process-wide stable until the user logs out; cache it so
|
||||
@@ -107,12 +107,8 @@ class _AccountSectionState extends State<AccountSection> {
|
||||
children: [
|
||||
Center(
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) =>
|
||||
LargeProfilePictureView(id: username),
|
||||
),
|
||||
),
|
||||
onTap: () =>
|
||||
AppRoutes.openLargeProfilePicture(context, username),
|
||||
child: UserAvatar(
|
||||
key: ValueKey(_avatarVersion),
|
||||
id: username,
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../../storage/haptic_settings.dart';
|
||||
import '../../../../theming/app_theme.dart';
|
||||
import '../../../../utils/haptics.dart';
|
||||
import '../widgets/settings_dropdown_tile.dart';
|
||||
|
||||
class AppearanceSection extends StatelessWidget {
|
||||
const AppearanceSection({super.key});
|
||||
@@ -14,58 +15,28 @@ class AppearanceSection extends StatelessWidget {
|
||||
final settings = context.watch<SettingsCubit>();
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.dark_mode_outlined),
|
||||
title: const Text('Farbgebung'),
|
||||
trailing: DropdownButton<ThemeMode>(
|
||||
SettingsDropdownTile<ThemeMode>(
|
||||
icon: Icons.dark_mode_outlined,
|
||||
title: 'Farbgebung',
|
||||
value: settings.val().appTheme,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: ThemeMode.values
|
||||
.map(
|
||||
(e) => DropdownMenuItem<ThemeMode>(
|
||||
value: e,
|
||||
enabled: e != settings.val().appTheme,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(AppTheme.getDisplayOptions(e).icon),
|
||||
const SizedBox(width: 10),
|
||||
Text(AppTheme.getDisplayOptions(e).displayName),
|
||||
],
|
||||
options: ThemeMode.values,
|
||||
optionIcon: (e) => AppTheme.getDisplayOptions(e).icon,
|
||||
optionLabel: (e) => AppTheme.getDisplayOptions(e).displayName,
|
||||
onChanged: (e) => settings.val(write: true).appTheme = e,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (e) => settings.val(write: true).appTheme = e!,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.vibration_outlined),
|
||||
title: const Text('Haptisches Feedback'),
|
||||
trailing: DropdownButton<HapticLevel>(
|
||||
SettingsDropdownTile<HapticLevel>(
|
||||
icon: Icons.vibration_outlined,
|
||||
title: 'Haptisches Feedback',
|
||||
value: settings.val().hapticSettings.level,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: HapticLevel.values
|
||||
.map(
|
||||
(e) => DropdownMenuItem<HapticLevel>(
|
||||
value: e,
|
||||
enabled: e != settings.val().hapticSettings.level,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(_hapticIcon(e)),
|
||||
const SizedBox(width: 10),
|
||||
Text(_hapticLabel(e)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
options: HapticLevel.values,
|
||||
optionIcon: _hapticIcon,
|
||||
optionLabel: _hapticLabel,
|
||||
onChanged: (e) {
|
||||
settings.val(write: true).hapticSettings.level = e!;
|
||||
settings.val(write: true).hapticSettings.level = e;
|
||||
// Sofortiges Probe-Feedback in der neu gewählten Stufe.
|
||||
Haptics.longPress();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import 'package:hydrated_bloc/hydrated_bloc.dart';
|
||||
import '../../../../routing/app_routes.dart';
|
||||
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../../storage/settings.dart' as model;
|
||||
import '../../../../utils/haptics.dart';
|
||||
import '../../../../widget/centered_leading.dart';
|
||||
import '../../../../widget/confirm_dialog.dart';
|
||||
import '../../../../widget/debug/cache_view.dart';
|
||||
import '../../../../widget/debug/json_viewer.dart';
|
||||
import '../../../../widget/details_bottom_sheet.dart';
|
||||
import '../widgets/endpoint_picker.dart';
|
||||
import '../widgets/settings_checkbox_tile.dart';
|
||||
|
||||
class DevToolsSection extends StatefulWidget {
|
||||
final SettingsCubit settings;
|
||||
@@ -41,49 +41,32 @@ class _DevToolsSectionState extends State<DevToolsSection> {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.auto_graph_outlined),
|
||||
title: const Text('Performance graph'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.auto_graph_outlined,
|
||||
title: 'Performance graph',
|
||||
value: dev.showPerformanceOverlay,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
widget.settings
|
||||
onChanged: (e) => widget.settings
|
||||
.val(write: true)
|
||||
.devToolsSettings
|
||||
.showPerformanceOverlay = e!;
|
||||
},
|
||||
.showPerformanceOverlay = e,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(
|
||||
Icons.screen_search_desktop_outlined,
|
||||
),
|
||||
title: const Text('Indicate offscreen layers'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.screen_search_desktop_outlined,
|
||||
title: 'Indicate offscreen layers',
|
||||
value: dev.checkerboardOffscreenLayers,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
widget.settings
|
||||
onChanged: (e) => widget.settings
|
||||
.val(write: true)
|
||||
.devToolsSettings
|
||||
.checkerboardOffscreenLayers = e!;
|
||||
},
|
||||
.checkerboardOffscreenLayers = e,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.imagesearch_roller_outlined),
|
||||
title: const Text('Indicate raster cache images'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.imagesearch_roller_outlined,
|
||||
title: 'Indicate raster cache images',
|
||||
value: dev.checkerboardRasterCacheImages,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
widget.settings
|
||||
onChanged: (e) => widget.settings
|
||||
.val(write: true)
|
||||
.devToolsSettings
|
||||
.checkerboardRasterCacheImages = e!;
|
||||
},
|
||||
),
|
||||
.checkerboardRasterCacheImages = e,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../../utils/haptics.dart';
|
||||
import '../widgets/settings_checkbox_tile.dart';
|
||||
|
||||
class FilesSection extends StatelessWidget {
|
||||
const FilesSection({super.key});
|
||||
@@ -12,30 +12,20 @@ class FilesSection extends StatelessWidget {
|
||||
final settings = context.watch<SettingsCubit>();
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.drive_folder_upload_outlined),
|
||||
title: const Text('Ordner in Dateien nach oben sortieren'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.drive_folder_upload_outlined,
|
||||
title: 'Ordner in Dateien nach oben sortieren',
|
||||
value: settings.val().fileSettings.sortFoldersToTop,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
settings.val(write: true).fileSettings.sortFoldersToTop = e!;
|
||||
},
|
||||
onChanged: (e) =>
|
||||
settings.val(write: true).fileSettings.sortFoldersToTop = e,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.open_in_new_outlined),
|
||||
title: const Text('Dateien immer mit Systemdialog öffnen'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.open_in_new_outlined,
|
||||
title: 'Dateien immer mit Systemdialog öffnen',
|
||||
value: settings.val().fileViewSettings.alwaysOpenExternally,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
settings
|
||||
.val(write: true)
|
||||
.fileViewSettings
|
||||
.alwaysOpenExternally = e!;
|
||||
},
|
||||
),
|
||||
onChanged: (e) =>
|
||||
settings.val(write: true).fileViewSettings.alwaysOpenExternally =
|
||||
e,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -6,9 +6,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../push/push_registration.dart';
|
||||
import '../../../../routing/app_routes.dart';
|
||||
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../../utils/haptics.dart';
|
||||
import '../../../../widget/centered_leading.dart';
|
||||
import '../widgets/push_status_sheet.dart';
|
||||
import '../widgets/settings_checkbox_tile.dart';
|
||||
|
||||
class TalkSection extends StatelessWidget {
|
||||
const TalkSection({super.key});
|
||||
@@ -20,27 +20,19 @@ class TalkSection extends StatelessWidget {
|
||||
final notificationSettings = settings.val().notificationSettings;
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.star_border),
|
||||
title: const Text('Favoriten im Talk nach oben sortieren'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.star_border,
|
||||
title: 'Favoriten im Talk nach oben sortieren',
|
||||
value: talkSettings.sortFavoritesToTop,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
settings.val(write: true).talkSettings.sortFavoritesToTop = e!;
|
||||
},
|
||||
onChanged: (e) =>
|
||||
settings.val(write: true).talkSettings.sortFavoritesToTop = e,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.mark_email_unread_outlined),
|
||||
title: const Text('Ungelesene Chats nach oben sortieren'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.mark_email_unread_outlined,
|
||||
title: 'Ungelesene Chats nach oben sortieren',
|
||||
value: talkSettings.sortUnreadToTop,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
settings.val(write: true).talkSettings.sortUnreadToTop = e!;
|
||||
},
|
||||
),
|
||||
onChanged: (e) =>
|
||||
settings.val(write: true).talkSettings.sortUnreadToTop = e,
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.wallpaper_outlined),
|
||||
@@ -49,19 +41,12 @@ class TalkSection extends StatelessWidget {
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () => AppRoutes.openChatBackgroundSettings(context),
|
||||
),
|
||||
ListTile(
|
||||
leading: const CenteredLeading(
|
||||
Icon(Icons.notifications_active_outlined),
|
||||
),
|
||||
title: const Text('Push-Benachrichtigungen'),
|
||||
subtitle: const Text(
|
||||
'Benachrichtigungen bei neuen Talk-Nachrichten erhalten',
|
||||
),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.notifications_active_outlined,
|
||||
title: 'Push-Benachrichtigungen',
|
||||
subtitle: 'Benachrichtigungen bei neuen Talk-Nachrichten erhalten',
|
||||
value: notificationSettings.enabled,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
final enabled = e ?? false;
|
||||
onChanged: (enabled) {
|
||||
settings.val(write: true).notificationSettings.enabled = enabled;
|
||||
// Turning off does NOT unregister: the device stays subscribed so
|
||||
// silent sync pushes keep arriving; the message handler and iOS
|
||||
@@ -89,7 +74,6 @@ class TalkSection extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.monitor_heart_outlined)),
|
||||
title: const Text('Push-Status'),
|
||||
|
||||
@@ -3,8 +3,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../routing/app_routes.dart';
|
||||
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../../utils/haptics.dart';
|
||||
import '../../../../view/pages/timetable/data/timetable_name_mode.dart';
|
||||
import '../widgets/settings_checkbox_tile.dart';
|
||||
import '../widgets/settings_dropdown_tile.dart';
|
||||
|
||||
class TimetableSection extends StatelessWidget {
|
||||
const TimetableSection({super.key});
|
||||
@@ -15,47 +16,23 @@ class TimetableSection extends StatelessWidget {
|
||||
final timetableSettings = settings.val().timetableSettings;
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.abc_outlined),
|
||||
title: const Text('Fachbezeichnung'),
|
||||
trailing: DropdownButton<TimetableNameMode>(
|
||||
SettingsDropdownTile<TimetableNameMode>(
|
||||
icon: Icons.abc_outlined,
|
||||
title: 'Fachbezeichnung',
|
||||
value: timetableSettings.timetableNameMode,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: TimetableNameMode.values
|
||||
.map(
|
||||
(e) => DropdownMenuItem(
|
||||
value: e,
|
||||
enabled: e != timetableSettings.timetableNameMode,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(TimetableNameModes.getDisplayOptions(e).icon),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
TimetableNameModes.getDisplayOptions(e).displayName,
|
||||
options: TimetableNameMode.values,
|
||||
optionIcon: (e) => TimetableNameModes.getDisplayOptions(e).icon,
|
||||
optionLabel: (e) => TimetableNameModes.getDisplayOptions(e).displayName,
|
||||
onChanged: (e) =>
|
||||
settings.val(write: true).timetableSettings.timetableNameMode = e,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) =>
|
||||
settings.val(write: true).timetableSettings.timetableNameMode =
|
||||
value!,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.calendar_view_day_outlined),
|
||||
title: const Text('Doppelstunden zusammenhängend anzeigen'),
|
||||
trailing: Checkbox(
|
||||
SettingsCheckboxTile(
|
||||
icon: Icons.calendar_view_day_outlined,
|
||||
title: 'Doppelstunden zusammenhängend anzeigen',
|
||||
value: timetableSettings.connectDoubleLessons,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
settings
|
||||
.val(write: true)
|
||||
.timetableSettings
|
||||
.connectDoubleLessons = e!;
|
||||
},
|
||||
),
|
||||
onChanged: (e) =>
|
||||
settings.val(write: true).timetableSettings.connectDoubleLessons =
|
||||
e,
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.palette_outlined),
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../utils/haptics.dart';
|
||||
import '../../../../widget/centered_leading.dart';
|
||||
|
||||
/// Settings row with a trailing checkbox. Fires [Haptics.selection] before
|
||||
/// invoking [onChanged] (with the resolved non-null value), so the sections
|
||||
/// don't repeat that. The leading icon is vertically centered when a [subtitle]
|
||||
/// is present, matching the surrounding settings styling.
|
||||
class SettingsCheckboxTile extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final bool value;
|
||||
final ValueChanged<bool> onChanged;
|
||||
|
||||
const SettingsCheckboxTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.subtitle,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final leadingIcon = Icon(icon);
|
||||
return ListTile(
|
||||
leading: subtitle == null ? leadingIcon : CenteredLeading(leadingIcon),
|
||||
title: Text(title),
|
||||
subtitle: subtitle == null ? null : Text(subtitle!),
|
||||
trailing: Checkbox(
|
||||
value: value,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
onChanged(e ?? false);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Settings row with a trailing [DropdownButton]. Each option renders as an
|
||||
/// icon + label row; the currently selected option is disabled in the menu,
|
||||
/// matching the settings styling. [onChanged] receives the picked (non-null)
|
||||
/// value.
|
||||
class SettingsDropdownTile<T> extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final T value;
|
||||
final List<T> options;
|
||||
final IconData Function(T) optionIcon;
|
||||
final String Function(T) optionLabel;
|
||||
final ValueChanged<T> onChanged;
|
||||
|
||||
const SettingsDropdownTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.options,
|
||||
required this.optionIcon,
|
||||
required this.optionLabel,
|
||||
required this.onChanged,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(icon),
|
||||
title: Text(title),
|
||||
trailing: DropdownButton<T>(
|
||||
value: value,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: options
|
||||
.map(
|
||||
(e) => DropdownMenuItem<T>(
|
||||
value: e,
|
||||
enabled: e != value,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(optionIcon(e)),
|
||||
const SizedBox(width: 10),
|
||||
Text(optionLabel(e)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (e) {
|
||||
if (e != null) onChanged(e);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import '../../../state/app/infrastructure/loadable_state/view/loadable_state_con
|
||||
import '../../../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
|
||||
import '../../../state/app/modules/chat_list/bloc/chat_list_state.dart';
|
||||
import '../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../widget/app_progress_indicator.dart';
|
||||
import '../../../widget/info_dialog.dart';
|
||||
import '../../../widget/placeholder_view.dart';
|
||||
import '../files/files_upload_dialog.dart';
|
||||
@@ -275,6 +276,6 @@ Future<void> _showBlockingSpinner(BuildContext context) => showDialog<void>(
|
||||
barrierDismissible: false,
|
||||
builder: (_) => const PopScope(
|
||||
canPop: false,
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
child: Center(child: AppProgressIndicator.large()),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../../../../state/app/modules/ticker/bloc/ticker_page_bloc.dart';
|
||||
import '../../../../state/app/modules/ticker/bloc/ticker_page_state.dart';
|
||||
import '../../../../state/app/modules/ticker/repository/ticker_page_repository.dart';
|
||||
import '../../../../theming/app_theme.dart';
|
||||
import '../../../../widget/app_progress_indicator.dart';
|
||||
import '../../../../widget/placeholder_view.dart';
|
||||
import '../../../../widget/prosemirror/pm_json_view.dart';
|
||||
import 'ticker_content_card.dart';
|
||||
@@ -89,11 +90,13 @@ class _TickerPageContentState extends State<_TickerPageContent> {
|
||||
widget.onRedirect?.call();
|
||||
});
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
case TickerPageKind.proxiedFile:
|
||||
return Column(
|
||||
children: [
|
||||
TickerUpdatedBar(publishedAt: page.publishedAt),
|
||||
// For proxied files the data currency is the last successful
|
||||
// proxy fetch, not the page's publish date.
|
||||
TickerUpdatedBar(publishedAt: page.fileFetchedAt ?? page.publishedAt),
|
||||
Expanded(
|
||||
child: _ProxiedFileView(
|
||||
repo: context.read<TickerPageBloc>().repo,
|
||||
@@ -159,7 +162,7 @@ class _ProxiedFileViewState extends State<_ProxiedFileView> {
|
||||
future: _bytes,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
}
|
||||
final error = snapshot.error;
|
||||
if (error != null) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import 'avatar_crop_page.dart';
|
||||
import '../routing/app_routes.dart';
|
||||
import 'file_pick.dart';
|
||||
|
||||
/// Result of the user's choice inside [showAvatarActionsSheet]. The sheet
|
||||
@@ -107,10 +107,5 @@ Future<Uint8List?> _pickAndCrop(
|
||||
if (picked == null) return null;
|
||||
final bytes = await picked.readAsBytes();
|
||||
if (!context.mounted) return null;
|
||||
return Navigator.of(context).push<Uint8List>(
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => AvatarCropPage(imageBytes: bytes),
|
||||
),
|
||||
);
|
||||
return AppRoutes.openAvatarCrop(context, imageBytes: bytes);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import 'avatar_crop_page.dart';
|
||||
import '../routing/app_routes.dart';
|
||||
import 'file_pick.dart';
|
||||
|
||||
/// Bottom sheet with "from gallery" and "take photo" actions for choosing a
|
||||
@@ -61,12 +61,7 @@ Future<Uint8List?> showChatBackgroundPickerSheet(BuildContext context) async {
|
||||
Future<Uint8List?> cropChatBackgroundImage(
|
||||
BuildContext context,
|
||||
Uint8List bytes,
|
||||
) => Navigator.of(context).push<Uint8List>(
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => AvatarCropPage(imageBytes: bytes, aspectRatio: null),
|
||||
),
|
||||
);
|
||||
) => AppRoutes.openAvatarCrop(context, imageBytes: bytes, aspectRatio: null);
|
||||
|
||||
Future<Uint8List?> _pickRaw(Future<XFile?> Function() pick) async {
|
||||
final picked = await pick();
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:localstore/localstore.dart';
|
||||
|
||||
import '../../../widget/placeholder_view.dart';
|
||||
import '../../api/request_cache.dart';
|
||||
import '../app_progress_indicator.dart';
|
||||
import 'json_viewer.dart';
|
||||
|
||||
class CacheView extends StatefulWidget {
|
||||
@@ -71,7 +72,7 @@ class _CacheViewState extends State<CacheView> {
|
||||
},
|
||||
);
|
||||
} else if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
} else {
|
||||
return const Center(
|
||||
child: PlaceholderView(
|
||||
|
||||
+20
-479
@@ -3,8 +3,6 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:chewie/chewie.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -12,34 +10,20 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:open_filex/open_filex.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import '../model/account_data.dart';
|
||||
import '../model/endpoint_data.dart';
|
||||
import '../routing/app_routes.dart';
|
||||
import '../share_intent/remote_file_ref.dart';
|
||||
import '../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import 'app_progress_indicator.dart';
|
||||
import 'centered_leading.dart';
|
||||
import 'file_viewer/code_line.dart';
|
||||
import 'file_viewer/deferred_pdf_viewer.dart';
|
||||
import 'file_viewer/file_kind.dart';
|
||||
import 'file_viewer/media_player.dart';
|
||||
import 'file_viewer/unknown_preview_block.dart';
|
||||
import 'info_dialog.dart';
|
||||
import 'share_position_origin.dart';
|
||||
|
||||
/// Nextcloud's `/index.php/core/preview` endpoint — returns a rasterized
|
||||
/// thumbnail for any file the server has a preview provider for (images,
|
||||
/// PDFs with the right backend, Office in some setups). Falls back to an
|
||||
/// HTTP 404 when no preview is available, which lets [CachedNetworkImage]
|
||||
/// trigger its `errorWidget`. Prefers `fileId` because the path variant
|
||||
/// is unreliable on some server configurations.
|
||||
String _ncPreviewUrl(RemoteFileRef remote, {int width = 1024}) {
|
||||
final host = EndpointData().nextcloud().full();
|
||||
final id = remote.fileId;
|
||||
final selector = id != null
|
||||
? 'fileId=$id'
|
||||
: 'file=${Uri.encodeQueryComponent(remote.path)}';
|
||||
return 'https://$host/index.php/core/preview?$selector&x=$width&y=-1&a=1';
|
||||
}
|
||||
|
||||
class FileViewer extends StatefulWidget {
|
||||
final String path;
|
||||
final bool openExternal;
|
||||
@@ -61,133 +45,12 @@ class FileViewer extends StatefulWidget {
|
||||
|
||||
enum FileViewingActions { openExternal, share, save, sendToChat, saveToCloud }
|
||||
|
||||
enum _FileKind { image, svg, pdf, text, video, audio, unknown }
|
||||
|
||||
const Set<String> _imageExtensions = {
|
||||
'png',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'webp',
|
||||
'gif',
|
||||
'bmp',
|
||||
'wbmp',
|
||||
};
|
||||
|
||||
const Set<String> _videoExtensions = {
|
||||
'mp4',
|
||||
'm4v',
|
||||
'mov',
|
||||
'webm',
|
||||
'mkv',
|
||||
'3gp',
|
||||
};
|
||||
|
||||
/// ogg/opus/flac are Android-only; iOS init errors fall through to the
|
||||
/// "format not supported" message.
|
||||
const Set<String> _audioExtensions = {
|
||||
'mp3',
|
||||
'm4a',
|
||||
'aac',
|
||||
'wav',
|
||||
'flac',
|
||||
'ogg',
|
||||
'oga',
|
||||
'opus',
|
||||
};
|
||||
|
||||
/// Unknown extensions still get a content sniff via [_looksLikeText].
|
||||
const Set<String> _textExtensions = {
|
||||
'txt', 'md', 'markdown', 'rst', 'log',
|
||||
'json', 'json5', 'xml', 'yaml', 'yml', 'toml',
|
||||
'csv', 'tsv', 'tab',
|
||||
'ini', 'conf', 'cfg', 'env', 'properties',
|
||||
'html', 'htm', 'xhtml',
|
||||
'css', 'scss', 'sass', 'less',
|
||||
'js', 'mjs', 'cjs', 'ts', 'jsx', 'tsx',
|
||||
'dart', 'java', 'kt', 'kts', 'groovy', 'scala', 'swift',
|
||||
'py', 'rb', 'pl', 'lua', 'r',
|
||||
'go', 'rs', 'zig',
|
||||
'c', 'cpp', 'cc', 'cxx', 'h', 'hpp', 'cs', 'm', 'mm',
|
||||
'php', 'sh', 'bash', 'zsh', 'fish', 'ps1', 'bat', 'cmd',
|
||||
'sql', 'graphql', 'gql',
|
||||
'gitignore', 'gitattributes', 'editorconfig', 'dockerignore',
|
||||
'dockerfile', 'makefile', 'cmake',
|
||||
'tex', 'bib',
|
||||
'srt', 'vtt',
|
||||
};
|
||||
|
||||
/// 8 KB sniff: NUL bytes or non-UTF-8 sequences disqualify.
|
||||
Future<bool> _looksLikeText(String path) async {
|
||||
final file = File(path);
|
||||
RandomAccessFile? raf;
|
||||
try {
|
||||
final length = await file.length();
|
||||
if (length == 0) return true;
|
||||
raf = await file.open();
|
||||
final sample = await raf.read(min(length, 8192));
|
||||
if (sample.contains(0)) return false;
|
||||
utf8.decode(sample);
|
||||
return true;
|
||||
} on Object {
|
||||
return false;
|
||||
} finally {
|
||||
await raf?.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// SfPdfViewer asserts on `localToGlobal` if mounted during the page-push
|
||||
/// animation. Defer until the route enter animation completes.
|
||||
class _DeferredPdfViewer extends StatefulWidget {
|
||||
const _DeferredPdfViewer({required this.path});
|
||||
final String path;
|
||||
|
||||
@override
|
||||
State<_DeferredPdfViewer> createState() => _DeferredPdfViewerState();
|
||||
}
|
||||
|
||||
class _DeferredPdfViewerState extends State<_DeferredPdfViewer> {
|
||||
bool _ready = false;
|
||||
Animation<double>? _routeAnimation;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_ready || _routeAnimation != null) return;
|
||||
final animation = ModalRoute.of(context)?.animation;
|
||||
if (animation == null || animation.isCompleted) {
|
||||
_ready = true;
|
||||
return;
|
||||
}
|
||||
_routeAnimation = animation..addStatusListener(_onAnimationStatus);
|
||||
}
|
||||
|
||||
void _onAnimationStatus(AnimationStatus status) {
|
||||
if (status == AnimationStatus.completed && mounted) {
|
||||
setState(() => _ready = true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_routeAnimation?.removeStatusListener(_onAnimationStatus);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_ready) {
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
}
|
||||
return SfPdfViewer.file(File(widget.path));
|
||||
}
|
||||
}
|
||||
|
||||
class _FileViewerState extends State<FileViewer> {
|
||||
final PhotoViewController photoViewController = PhotoViewController();
|
||||
|
||||
late SettingsCubit settings = context.read<SettingsCubit>();
|
||||
late bool openExternal;
|
||||
Future<_FileKind>? _fileKind;
|
||||
Future<FileKind>? _fileKind;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -200,7 +63,7 @@ class _FileViewerState extends State<FileViewer> {
|
||||
(_) => _openExternallyAndPop(),
|
||||
);
|
||||
} else {
|
||||
_fileKind = _detectKind();
|
||||
_fileKind = detectFileKind(widget.path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,18 +82,6 @@ class _FileViewerState extends State<FileViewer> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<_FileKind> _detectKind() async {
|
||||
final ext = widget.path.split('.').last.toLowerCase();
|
||||
if (_imageExtensions.contains(ext)) return _FileKind.image;
|
||||
if (ext == 'svg') return _FileKind.svg;
|
||||
if (ext == 'pdf') return _FileKind.pdf;
|
||||
if (_videoExtensions.contains(ext)) return _FileKind.video;
|
||||
if (_audioExtensions.contains(ext)) return _FileKind.audio;
|
||||
if (_textExtensions.contains(ext)) return _FileKind.text;
|
||||
if (await _looksLikeText(widget.path)) return _FileKind.text;
|
||||
return _FileKind.unknown;
|
||||
}
|
||||
|
||||
Future<void> _handleAction(FileViewingActions value) async {
|
||||
switch (value) {
|
||||
case FileViewingActions.openExternal:
|
||||
@@ -360,7 +211,7 @@ class _FileViewerState extends State<FileViewer> {
|
||||
body: const Center(child: AppProgressIndicator.large()),
|
||||
);
|
||||
}
|
||||
return FutureBuilder<_FileKind>(
|
||||
return FutureBuilder<FileKind>(
|
||||
future: _fileKind,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
@@ -370,19 +221,19 @@ class _FileViewerState extends State<FileViewer> {
|
||||
);
|
||||
}
|
||||
switch (snapshot.data!) {
|
||||
case _FileKind.image:
|
||||
case FileKind.image:
|
||||
return _buildImageView();
|
||||
case _FileKind.svg:
|
||||
case FileKind.svg:
|
||||
return _buildSvgView();
|
||||
case _FileKind.pdf:
|
||||
case FileKind.pdf:
|
||||
return _buildPdfView();
|
||||
case _FileKind.video:
|
||||
case FileKind.video:
|
||||
return _buildVideoView();
|
||||
case _FileKind.audio:
|
||||
case FileKind.audio:
|
||||
return _buildAudioView();
|
||||
case _FileKind.text:
|
||||
case FileKind.text:
|
||||
return _buildTextView();
|
||||
case _FileKind.unknown:
|
||||
case FileKind.unknown:
|
||||
return _buildUnknownView();
|
||||
}
|
||||
},
|
||||
@@ -431,17 +282,17 @@ class _FileViewerState extends State<FileViewer> {
|
||||
);
|
||||
|
||||
Widget _buildPdfView() =>
|
||||
Scaffold(appBar: _appbar(), body: _DeferredPdfViewer(path: widget.path));
|
||||
Scaffold(appBar: _appbar(), body: DeferredPdfViewer(path: widget.path));
|
||||
|
||||
Widget _buildVideoView() => Scaffold(
|
||||
appBar: _appbar(),
|
||||
backgroundColor: Colors.black,
|
||||
body: _MediaPlayer(path: widget.path, isAudio: false),
|
||||
body: MediaPlayer(path: widget.path, isAudio: false),
|
||||
);
|
||||
|
||||
Widget _buildAudioView() => Scaffold(
|
||||
appBar: _appbar(),
|
||||
body: _MediaPlayer(
|
||||
body: MediaPlayer(
|
||||
path: widget.path,
|
||||
isAudio: true,
|
||||
filename: widget.path.split('/').last,
|
||||
@@ -485,7 +336,7 @@ class _FileViewerState extends State<FileViewer> {
|
||||
),
|
||||
SliverList.builder(
|
||||
itemCount: lines.length,
|
||||
itemBuilder: (context, i) => _CodeLine(
|
||||
itemBuilder: (context, i) => CodeLine(
|
||||
number: i + 1,
|
||||
text: lines[i],
|
||||
gutterWidth: gutterWidth,
|
||||
@@ -515,7 +366,7 @@ class _FileViewerState extends State<FileViewer> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
children: [
|
||||
_UnknownPreviewBlock(remoteFile: widget.remoteFile),
|
||||
UnknownPreviewBlock(remoteFile: widget.remoteFile),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
widget.path.split('/').last,
|
||||
@@ -596,313 +447,3 @@ class _TextPayload {
|
||||
final bool truncated;
|
||||
const _TextPayload({required this.content, required this.truncated});
|
||||
}
|
||||
|
||||
/// Header block for the "Vorschau nicht verfügbar" screen.
|
||||
///
|
||||
/// Two visual modes — kept layout-equivalent so the screen looks identical
|
||||
/// whether the server already said "no preview" or the probe failed late:
|
||||
/// * **No preview available** (server said no, no remoteFile, or probe
|
||||
/// errored): compact "file icon + 'Vorschau nicht verfügbar' text".
|
||||
/// * **Preview rendering / loaded**: mid-sized thumbnail without text.
|
||||
class _UnknownPreviewBlock extends StatefulWidget {
|
||||
final RemoteFileRef? remoteFile;
|
||||
const _UnknownPreviewBlock({required this.remoteFile});
|
||||
|
||||
@override
|
||||
State<_UnknownPreviewBlock> createState() => _UnknownPreviewBlockState();
|
||||
}
|
||||
|
||||
class _UnknownPreviewBlockState extends State<_UnknownPreviewBlock> {
|
||||
static const double _previewSize = 180;
|
||||
bool _failed = false;
|
||||
|
||||
Widget _compact(ThemeData theme) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.insert_drive_file_outlined, size: 60),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Vorschau nicht verfügbar',
|
||||
style: theme.textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final remote = widget.remoteFile;
|
||||
final canProbe =
|
||||
remote != null &&
|
||||
remote.hasPreview != false &&
|
||||
remote.fileId != null &&
|
||||
!_failed;
|
||||
if (!canProbe) return _compact(theme);
|
||||
return SizedBox(
|
||||
width: _previewSize,
|
||||
height: _previewSize,
|
||||
child: CachedNetworkImage(
|
||||
httpHeaders: AccountData().authHeaders(),
|
||||
imageUrl: _ncPreviewUrl(remote, width: 360),
|
||||
fadeInDuration: Duration.zero,
|
||||
fadeOutDuration: Duration.zero,
|
||||
// Late probe failure: re-render into the compact layout so the
|
||||
// screen doesn't keep a 180×180 box around a tiny icon. Deferred
|
||||
// to the next frame because setState during build is illegal.
|
||||
errorListener: (_) {
|
||||
if (!mounted) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) setState(() => _failed = true);
|
||||
});
|
||||
},
|
||||
placeholder: (_, _) =>
|
||||
const Center(child: AppProgressIndicator.large()),
|
||||
// Briefly empty while the post-frame setState swaps layouts.
|
||||
errorWidget: (_, _, _) => const SizedBox.shrink(),
|
||||
imageBuilder: (_, imageProvider) => ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.contain,
|
||||
width: _previewSize,
|
||||
height: _previewSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MediaPlayer extends StatefulWidget {
|
||||
final String path;
|
||||
final bool isAudio;
|
||||
final String? filename;
|
||||
const _MediaPlayer({
|
||||
required this.path,
|
||||
required this.isAudio,
|
||||
this.filename,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_MediaPlayer> createState() => _MediaPlayerState();
|
||||
}
|
||||
|
||||
class _MediaPlayerState extends State<_MediaPlayer> {
|
||||
VideoPlayerController? _video;
|
||||
ChewieController? _chewie;
|
||||
Object? _initError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initialize();
|
||||
}
|
||||
|
||||
Future<void> _initialize() async {
|
||||
final controller = VideoPlayerController.file(File(widget.path));
|
||||
try {
|
||||
await controller.initialize();
|
||||
} on Object catch (e) {
|
||||
await controller.dispose();
|
||||
if (!mounted) return;
|
||||
setState(() => _initError = e);
|
||||
return;
|
||||
}
|
||||
if (!mounted) {
|
||||
await controller.dispose();
|
||||
return;
|
||||
}
|
||||
if (widget.isAudio) {
|
||||
controller.addListener(_onAudioTick);
|
||||
setState(() => _video = controller);
|
||||
} else {
|
||||
setState(() {
|
||||
_video = controller;
|
||||
_chewie = ChewieController(
|
||||
videoPlayerController: controller,
|
||||
autoPlay: false,
|
||||
looping: false,
|
||||
allowFullScreen: true,
|
||||
allowPlaybackSpeedChanging: true,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onAudioTick() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_video?.removeListener(_onAudioTick);
|
||||
_chewie?.dispose();
|
||||
_video?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_initError != null) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error_outline, size: 48),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
widget.isAudio
|
||||
? 'Audio kann nicht abgespielt werden'
|
||||
: 'Video kann nicht abgespielt werden',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Format wird auf diesem Gerät nicht unterstützt. Über das Menü kannst du die Datei in einer anderen App öffnen.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (_video == null) {
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
}
|
||||
if (widget.isAudio) {
|
||||
return _AudioControls(
|
||||
controller: _video!,
|
||||
filename: widget.filename ?? '',
|
||||
);
|
||||
}
|
||||
return Chewie(controller: _chewie!);
|
||||
}
|
||||
}
|
||||
|
||||
class _AudioControls extends StatelessWidget {
|
||||
final VideoPlayerController controller;
|
||||
final String filename;
|
||||
const _AudioControls({required this.controller, required this.filename});
|
||||
|
||||
String _format(Duration d) {
|
||||
final m = d.inMinutes.remainder(60).toString().padLeft(2, '0');
|
||||
final s = d.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||
if (d.inHours > 0) return '${d.inHours}:$m:$s';
|
||||
return '$m:$s';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final value = controller.value;
|
||||
final duration = value.duration;
|
||||
final position = value.position;
|
||||
final maxMs = duration.inMilliseconds == 0 ? 1 : duration.inMilliseconds;
|
||||
final posMs = position.inMilliseconds.clamp(0, maxMs).toDouble();
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.audiotrack,
|
||||
size: 96,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
filename,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Slider(
|
||||
min: 0,
|
||||
max: maxMs.toDouble(),
|
||||
value: posMs,
|
||||
onChanged: (v) =>
|
||||
controller.seekTo(Duration(milliseconds: v.toInt())),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
_format(position),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
Text(
|
||||
_format(duration),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FloatingActionButton(
|
||||
heroTag: 'audioPlayPause',
|
||||
onPressed: () {
|
||||
if (value.isPlaying) {
|
||||
controller.pause();
|
||||
} else {
|
||||
controller.play();
|
||||
}
|
||||
},
|
||||
child: Icon(value.isPlaying ? Icons.pause : Icons.play_arrow),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CodeLine extends StatelessWidget {
|
||||
final int number;
|
||||
final String text;
|
||||
final double gutterWidth;
|
||||
const _CodeLine({
|
||||
required this.number,
|
||||
required this.text,
|
||||
required this.gutterWidth,
|
||||
});
|
||||
|
||||
static const TextStyle _codeStyle = TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 13,
|
||||
height: 1.4,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isEven = number.isEven;
|
||||
return Container(
|
||||
color: isEven ? theme.colorScheme.surfaceContainerLow : null,
|
||||
padding: const EdgeInsets.only(left: 4, right: 12),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SelectionContainer.disabled(
|
||||
child: SizedBox(
|
||||
width: gutterWidth,
|
||||
child: Text(
|
||||
'$number',
|
||||
textAlign: TextAlign.right,
|
||||
style: _codeStyle.copyWith(color: theme.hintColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(text.isEmpty ? ' ' : text, style: _codeStyle)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// A single line of the text/code viewer: a right-aligned, non-selectable line
|
||||
/// number gutter plus the selectable line content, with zebra striping.
|
||||
class CodeLine extends StatelessWidget {
|
||||
final int number;
|
||||
final String text;
|
||||
final double gutterWidth;
|
||||
const CodeLine({
|
||||
super.key,
|
||||
required this.number,
|
||||
required this.text,
|
||||
required this.gutterWidth,
|
||||
});
|
||||
|
||||
static const TextStyle _codeStyle = TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 13,
|
||||
height: 1.4,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isEven = number.isEven;
|
||||
return Container(
|
||||
color: isEven ? theme.colorScheme.surfaceContainerLow : null,
|
||||
padding: const EdgeInsets.only(left: 4, right: 12),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SelectionContainer.disabled(
|
||||
child: SizedBox(
|
||||
width: gutterWidth,
|
||||
child: Text(
|
||||
'$number',
|
||||
textAlign: TextAlign.right,
|
||||
style: _codeStyle.copyWith(color: theme.hintColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(text.isEmpty ? ' ' : text, style: _codeStyle)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
|
||||
import '../app_progress_indicator.dart';
|
||||
|
||||
/// SfPdfViewer asserts on `localToGlobal` if mounted during the page-push
|
||||
/// animation. Defer until the route enter animation completes.
|
||||
class DeferredPdfViewer extends StatefulWidget {
|
||||
const DeferredPdfViewer({super.key, required this.path});
|
||||
final String path;
|
||||
|
||||
@override
|
||||
State<DeferredPdfViewer> createState() => _DeferredPdfViewerState();
|
||||
}
|
||||
|
||||
class _DeferredPdfViewerState extends State<DeferredPdfViewer> {
|
||||
bool _ready = false;
|
||||
Animation<double>? _routeAnimation;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_ready || _routeAnimation != null) return;
|
||||
final animation = ModalRoute.of(context)?.animation;
|
||||
if (animation == null || animation.isCompleted) {
|
||||
_ready = true;
|
||||
return;
|
||||
}
|
||||
_routeAnimation = animation..addStatusListener(_onAnimationStatus);
|
||||
}
|
||||
|
||||
void _onAnimationStatus(AnimationStatus status) {
|
||||
if (status == AnimationStatus.completed && mounted) {
|
||||
setState(() => _ready = true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_routeAnimation?.removeStatusListener(_onAnimationStatus);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_ready) {
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
}
|
||||
return SfPdfViewer.file(File(widget.path));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
enum FileKind { image, svg, pdf, text, video, audio, unknown }
|
||||
|
||||
const Set<String> _imageExtensions = {
|
||||
'png',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'webp',
|
||||
'gif',
|
||||
'bmp',
|
||||
'wbmp',
|
||||
};
|
||||
|
||||
const Set<String> _videoExtensions = {
|
||||
'mp4',
|
||||
'm4v',
|
||||
'mov',
|
||||
'webm',
|
||||
'mkv',
|
||||
'3gp',
|
||||
};
|
||||
|
||||
/// ogg/opus/flac are Android-only; iOS init errors fall through to the
|
||||
/// "format not supported" message.
|
||||
const Set<String> _audioExtensions = {
|
||||
'mp3',
|
||||
'm4a',
|
||||
'aac',
|
||||
'wav',
|
||||
'flac',
|
||||
'ogg',
|
||||
'oga',
|
||||
'opus',
|
||||
};
|
||||
|
||||
/// Unknown extensions still get a content sniff via [_looksLikeText].
|
||||
const Set<String> _textExtensions = {
|
||||
'txt', 'md', 'markdown', 'rst', 'log',
|
||||
'json', 'json5', 'xml', 'yaml', 'yml', 'toml',
|
||||
'csv', 'tsv', 'tab',
|
||||
'ini', 'conf', 'cfg', 'env', 'properties',
|
||||
'html', 'htm', 'xhtml',
|
||||
'css', 'scss', 'sass', 'less',
|
||||
'js', 'mjs', 'cjs', 'ts', 'jsx', 'tsx',
|
||||
'dart', 'java', 'kt', 'kts', 'groovy', 'scala', 'swift',
|
||||
'py', 'rb', 'pl', 'lua', 'r',
|
||||
'go', 'rs', 'zig',
|
||||
'c', 'cpp', 'cc', 'cxx', 'h', 'hpp', 'cs', 'm', 'mm',
|
||||
'php', 'sh', 'bash', 'zsh', 'fish', 'ps1', 'bat', 'cmd',
|
||||
'sql', 'graphql', 'gql',
|
||||
'gitignore', 'gitattributes', 'editorconfig', 'dockerignore',
|
||||
'dockerfile', 'makefile', 'cmake',
|
||||
'tex', 'bib',
|
||||
'srt', 'vtt',
|
||||
};
|
||||
|
||||
/// Detects the [FileKind] of the file at [path] from its extension, falling
|
||||
/// back to an 8 KB content sniff ([_looksLikeText]) for unknown extensions.
|
||||
Future<FileKind> detectFileKind(String path) async {
|
||||
final ext = path.split('.').last.toLowerCase();
|
||||
if (_imageExtensions.contains(ext)) return FileKind.image;
|
||||
if (ext == 'svg') return FileKind.svg;
|
||||
if (ext == 'pdf') return FileKind.pdf;
|
||||
if (_videoExtensions.contains(ext)) return FileKind.video;
|
||||
if (_audioExtensions.contains(ext)) return FileKind.audio;
|
||||
if (_textExtensions.contains(ext)) return FileKind.text;
|
||||
if (await _looksLikeText(path)) return FileKind.text;
|
||||
return FileKind.unknown;
|
||||
}
|
||||
|
||||
/// 8 KB sniff: NUL bytes or non-UTF-8 sequences disqualify.
|
||||
Future<bool> _looksLikeText(String path) async {
|
||||
final file = File(path);
|
||||
RandomAccessFile? raf;
|
||||
try {
|
||||
final length = await file.length();
|
||||
if (length == 0) return true;
|
||||
raf = await file.open();
|
||||
final sample = await raf.read(min(length, 8192));
|
||||
if (sample.contains(0)) return false;
|
||||
utf8.decode(sample);
|
||||
return true;
|
||||
} on Object {
|
||||
return false;
|
||||
} finally {
|
||||
await raf?.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:chewie/chewie.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import '../app_progress_indicator.dart';
|
||||
|
||||
/// Plays a local video (via Chewie) or audio file (via [_AudioControls]).
|
||||
/// Reports an inline "format not supported" message when the platform can't
|
||||
/// initialize the file.
|
||||
class MediaPlayer extends StatefulWidget {
|
||||
final String path;
|
||||
final bool isAudio;
|
||||
final String? filename;
|
||||
const MediaPlayer({
|
||||
super.key,
|
||||
required this.path,
|
||||
required this.isAudio,
|
||||
this.filename,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MediaPlayer> createState() => _MediaPlayerState();
|
||||
}
|
||||
|
||||
class _MediaPlayerState extends State<MediaPlayer> {
|
||||
VideoPlayerController? _video;
|
||||
ChewieController? _chewie;
|
||||
Object? _initError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initialize();
|
||||
}
|
||||
|
||||
Future<void> _initialize() async {
|
||||
final controller = VideoPlayerController.file(File(widget.path));
|
||||
try {
|
||||
await controller.initialize();
|
||||
} on Object catch (e) {
|
||||
await controller.dispose();
|
||||
if (!mounted) return;
|
||||
setState(() => _initError = e);
|
||||
return;
|
||||
}
|
||||
if (!mounted) {
|
||||
await controller.dispose();
|
||||
return;
|
||||
}
|
||||
if (widget.isAudio) {
|
||||
controller.addListener(_onAudioTick);
|
||||
setState(() => _video = controller);
|
||||
} else {
|
||||
setState(() {
|
||||
_video = controller;
|
||||
_chewie = ChewieController(
|
||||
videoPlayerController: controller,
|
||||
autoPlay: false,
|
||||
looping: false,
|
||||
allowFullScreen: true,
|
||||
allowPlaybackSpeedChanging: true,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onAudioTick() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_video?.removeListener(_onAudioTick);
|
||||
_chewie?.dispose();
|
||||
_video?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_initError != null) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error_outline, size: 48),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
widget.isAudio
|
||||
? 'Audio kann nicht abgespielt werden'
|
||||
: 'Video kann nicht abgespielt werden',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Format wird auf diesem Gerät nicht unterstützt. Über das Menü kannst du die Datei in einer anderen App öffnen.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (_video == null) {
|
||||
return const Center(child: AppProgressIndicator.large());
|
||||
}
|
||||
if (widget.isAudio) {
|
||||
return _AudioControls(
|
||||
controller: _video!,
|
||||
filename: widget.filename ?? '',
|
||||
);
|
||||
}
|
||||
return Chewie(controller: _chewie!);
|
||||
}
|
||||
}
|
||||
|
||||
class _AudioControls extends StatelessWidget {
|
||||
final VideoPlayerController controller;
|
||||
final String filename;
|
||||
const _AudioControls({required this.controller, required this.filename});
|
||||
|
||||
String _format(Duration d) {
|
||||
final m = d.inMinutes.remainder(60).toString().padLeft(2, '0');
|
||||
final s = d.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||
if (d.inHours > 0) return '${d.inHours}:$m:$s';
|
||||
return '$m:$s';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final value = controller.value;
|
||||
final duration = value.duration;
|
||||
final position = value.position;
|
||||
final maxMs = duration.inMilliseconds == 0 ? 1 : duration.inMilliseconds;
|
||||
final posMs = position.inMilliseconds.clamp(0, maxMs).toDouble();
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.audiotrack,
|
||||
size: 96,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
filename,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Slider(
|
||||
min: 0,
|
||||
max: maxMs.toDouble(),
|
||||
value: posMs,
|
||||
onChanged: (v) =>
|
||||
controller.seekTo(Duration(milliseconds: v.toInt())),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
_format(position),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
Text(
|
||||
_format(duration),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FloatingActionButton(
|
||||
heroTag: 'audioPlayPause',
|
||||
onPressed: () {
|
||||
if (value.isPlaying) {
|
||||
controller.pause();
|
||||
} else {
|
||||
controller.play();
|
||||
}
|
||||
},
|
||||
child: Icon(value.isPlaying ? Icons.pause : Icons.play_arrow),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../model/account_data.dart';
|
||||
import '../../model/endpoint_data.dart';
|
||||
import '../../share_intent/remote_file_ref.dart';
|
||||
import '../app_progress_indicator.dart';
|
||||
|
||||
/// Nextcloud's `/index.php/core/preview` endpoint — returns a rasterized
|
||||
/// thumbnail for any file the server has a preview provider for (images,
|
||||
/// PDFs with the right backend, Office in some setups). Falls back to an
|
||||
/// HTTP 404 when no preview is available, which lets [CachedNetworkImage]
|
||||
/// trigger its `errorWidget`. Prefers `fileId` because the path variant
|
||||
/// is unreliable on some server configurations.
|
||||
String _ncPreviewUrl(RemoteFileRef remote, {int width = 1024}) {
|
||||
final host = EndpointData().nextcloud().full();
|
||||
final id = remote.fileId;
|
||||
final selector = id != null
|
||||
? 'fileId=$id'
|
||||
: 'file=${Uri.encodeQueryComponent(remote.path)}';
|
||||
return 'https://$host/index.php/core/preview?$selector&x=$width&y=-1&a=1';
|
||||
}
|
||||
|
||||
/// Header block for the "Vorschau nicht verfügbar" screen.
|
||||
///
|
||||
/// Two visual modes — kept layout-equivalent so the screen looks identical
|
||||
/// whether the server already said "no preview" or the probe failed late:
|
||||
/// * **No preview available** (server said no, no remoteFile, or probe
|
||||
/// errored): compact "file icon + 'Vorschau nicht verfügbar' text".
|
||||
/// * **Preview rendering / loaded**: mid-sized thumbnail without text.
|
||||
class UnknownPreviewBlock extends StatefulWidget {
|
||||
final RemoteFileRef? remoteFile;
|
||||
const UnknownPreviewBlock({super.key, required this.remoteFile});
|
||||
|
||||
@override
|
||||
State<UnknownPreviewBlock> createState() => _UnknownPreviewBlockState();
|
||||
}
|
||||
|
||||
class _UnknownPreviewBlockState extends State<UnknownPreviewBlock> {
|
||||
static const double _previewSize = 180;
|
||||
bool _failed = false;
|
||||
|
||||
Widget _compact(ThemeData theme) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.insert_drive_file_outlined, size: 60),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Vorschau nicht verfügbar',
|
||||
style: theme.textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final remote = widget.remoteFile;
|
||||
final canProbe =
|
||||
remote != null &&
|
||||
remote.hasPreview != false &&
|
||||
remote.fileId != null &&
|
||||
!_failed;
|
||||
if (!canProbe) return _compact(theme);
|
||||
return SizedBox(
|
||||
width: _previewSize,
|
||||
height: _previewSize,
|
||||
child: CachedNetworkImage(
|
||||
httpHeaders: AccountData().authHeaders(),
|
||||
imageUrl: _ncPreviewUrl(remote, width: 360),
|
||||
fadeInDuration: Duration.zero,
|
||||
fadeOutDuration: Duration.zero,
|
||||
// Late probe failure: re-render into the compact layout so the
|
||||
// screen doesn't keep a 180×180 box around a tiny icon. Deferred
|
||||
// to the next frame because setState during build is illegal.
|
||||
errorListener: (_) {
|
||||
if (!mounted) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) setState(() => _failed = true);
|
||||
});
|
||||
},
|
||||
placeholder: (_, _) =>
|
||||
const Center(child: AppProgressIndicator.large()),
|
||||
// Briefly empty while the post-frame setState swaps layouts.
|
||||
errorWidget: (_, _, _) => const SizedBox.shrink(),
|
||||
imageBuilder: (_, imageProvider) => ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.contain,
|
||||
width: _previewSize,
|
||||
height: _previewSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'async_action_button.dart';
|
||||
|
||||
/// Single-line text-input dialog. The confirm action runs [onConfirm] with the
|
||||
/// trimmed input via [AsyncDialogAction], so it shows a spinner and an inline
|
||||
/// error and only closes on success. Throw inside [onConfirm] to keep the
|
||||
/// dialog open with a message (e.g. for empty or duplicate input).
|
||||
void showPromptDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String confirmButton,
|
||||
required Future<void> Function(String value) onConfirm,
|
||||
String label = 'Name',
|
||||
String initialValue = '',
|
||||
AsyncErrorBuilder? errorBuilder,
|
||||
}) {
|
||||
final controller = TextEditingController(text: initialValue);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogCtx) => AlertDialog(
|
||||
title: Text(title),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(labelText: label),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
AsyncDialogAction(
|
||||
confirmLabel: confirmButton,
|
||||
onConfirm: () => onConfirm(controller.text.trim()),
|
||||
errorBuilder: errorBuilder,
|
||||
),
|
||||
],
|
||||
),
|
||||
).whenComplete(controller.dispose);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../app_progress_indicator.dart';
|
||||
import 'pm_document_view.dart';
|
||||
import 'pm_node.dart';
|
||||
|
||||
@@ -116,7 +117,7 @@ class _PmJsonViewState extends State<PmJsonView> {
|
||||
if (shown == null) {
|
||||
return const SizedBox(
|
||||
height: 160,
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
child: Center(child: AppProgressIndicator.large()),
|
||||
);
|
||||
}
|
||||
return PmDocumentView(doc: shown, onLinkTap: widget.onLinkTap);
|
||||
|
||||
@@ -115,6 +115,11 @@ void main() {
|
||||
final end = dt.add(const Duration(minutes: 45));
|
||||
expect(dt.timeRangeTo(end), '09:07 - 09:52');
|
||||
});
|
||||
|
||||
test('weekKey renders a zero-padded yyyyMMdd key', () {
|
||||
expect(dt.weekKey(), '20260508');
|
||||
expect(DateTime(2026, 12, 31).weekKey(), '20261231');
|
||||
});
|
||||
});
|
||||
|
||||
group('formatDateRelativeShort', () {
|
||||
|
||||
Reference in New Issue
Block a user