Added option to open FileViewer always with system dialog, enabled by default on iOS
This commit is contained in:
parent
bdb29029c9
commit
d6ebc43e5c
@ -1,19 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'listFilesResponse.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// JsonSerializableGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
ListFilesResponse _$ListFilesResponseFromJson(Map<String, dynamic> json) =>
|
|
||||||
ListFilesResponse(
|
|
||||||
(json['files'] as List<dynamic>)
|
|
||||||
.map((e) => CacheableFile.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toSet(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> _$ListFilesResponseToJson(ListFilesResponse instance) =>
|
|
||||||
<String, dynamic>{
|
|
||||||
'files': instance.files.map((e) => e.toJson()).toList(),
|
|
||||||
};
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
import '../file/fileSettings.dart';
|
import '../file/fileSettings.dart';
|
||||||
|
import '../fileView/fileViewSettings.dart';
|
||||||
import '../gradeAverages/gradeAveragesSettings.dart';
|
import '../gradeAverages/gradeAveragesSettings.dart';
|
||||||
import '../holidays/holidaysSettings.dart';
|
import '../holidays/holidaysSettings.dart';
|
||||||
import '../talk/talkSettings.dart';
|
import '../talk/talkSettings.dart';
|
||||||
@ -23,6 +24,7 @@ class Settings {
|
|||||||
TalkSettings talkSettings;
|
TalkSettings talkSettings;
|
||||||
FileSettings fileSettings;
|
FileSettings fileSettings;
|
||||||
HolidaysSettings holidaysSettings;
|
HolidaysSettings holidaysSettings;
|
||||||
|
FileViewSettings fileViewSettings;
|
||||||
|
|
||||||
Settings({
|
Settings({
|
||||||
required this.appTheme,
|
required this.appTheme,
|
||||||
@ -32,6 +34,7 @@ class Settings {
|
|||||||
required this.talkSettings,
|
required this.talkSettings,
|
||||||
required this.fileSettings,
|
required this.fileSettings,
|
||||||
required this.holidaysSettings,
|
required this.holidaysSettings,
|
||||||
|
required this.fileViewSettings,
|
||||||
});
|
});
|
||||||
|
|
||||||
static String _themeToJson(ThemeMode m) => m.name;
|
static String _themeToJson(ThemeMode m) => m.name;
|
||||||
|
@ -19,6 +19,8 @@ Settings _$SettingsFromJson(Map<String, dynamic> json) => Settings(
|
|||||||
FileSettings.fromJson(json['fileSettings'] as Map<String, dynamic>),
|
FileSettings.fromJson(json['fileSettings'] as Map<String, dynamic>),
|
||||||
holidaysSettings: HolidaysSettings.fromJson(
|
holidaysSettings: HolidaysSettings.fromJson(
|
||||||
json['holidaysSettings'] as Map<String, dynamic>),
|
json['holidaysSettings'] as Map<String, dynamic>),
|
||||||
|
fileViewSettings: FileViewSettings.fromJson(
|
||||||
|
json['fileViewSettings'] as Map<String, dynamic>),
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{
|
Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{
|
||||||
@ -29,4 +31,5 @@ Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{
|
|||||||
'talkSettings': instance.talkSettings.toJson(),
|
'talkSettings': instance.talkSettings.toJson(),
|
||||||
'fileSettings': instance.fileSettings.toJson(),
|
'fileSettings': instance.fileSettings.toJson(),
|
||||||
'holidaysSettings': instance.holidaysSettings.toJson(),
|
'holidaysSettings': instance.holidaysSettings.toJson(),
|
||||||
|
'fileViewSettings': instance.fileViewSettings.toJson(),
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:marianum_mobile/storage/fileView/fileViewSettings.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../../view/pages/files/files.dart';
|
import '../../view/pages/files/files.dart';
|
||||||
@ -100,6 +102,9 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
dismissedDisclaimer: false,
|
dismissedDisclaimer: false,
|
||||||
showPastEvents: false,
|
showPastEvents: false,
|
||||||
),
|
),
|
||||||
|
fileViewSettings: FileViewSettings(
|
||||||
|
alwaysOpenExternally: Platform.isIOS,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
13
lib/storage/fileView/fileViewSettings.dart
Normal file
13
lib/storage/fileView/fileViewSettings.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'fileViewSettings.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class FileViewSettings {
|
||||||
|
bool alwaysOpenExternally;
|
||||||
|
|
||||||
|
FileViewSettings({required this.alwaysOpenExternally});
|
||||||
|
|
||||||
|
factory FileViewSettings.fromJson(Map<String, dynamic> json) => _$FileViewSettingsFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$FileViewSettingsToJson(this);
|
||||||
|
}
|
17
lib/storage/fileView/fileViewSettings.g.dart
Normal file
17
lib/storage/fileView/fileViewSettings.g.dart
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'fileViewSettings.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
FileViewSettings _$FileViewSettingsFromJson(Map<String, dynamic> json) =>
|
||||||
|
FileViewSettings(
|
||||||
|
alwaysOpenExternally: json['alwaysOpenExternally'] as bool,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$FileViewSettingsToJson(FileViewSettings instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'alwaysOpenExternally': instance.alwaysOpenExternally,
|
||||||
|
};
|
@ -139,6 +139,19 @@ class _SettingsState extends State<Settings> {
|
|||||||
|
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.open_in_new_outlined),
|
||||||
|
title: const Text("Dateien immer mit Systemdialog öffnen"),
|
||||||
|
trailing: Checkbox(
|
||||||
|
value: settings.val().fileViewSettings.alwaysOpenExternally,
|
||||||
|
onChanged: (e) {
|
||||||
|
settings.val(write: true).fileViewSettings.alwaysOpenExternally = e!;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
const Divider(),
|
||||||
|
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.live_help_outlined),
|
leading: const Icon(Icons.live_help_outlined),
|
||||||
title: const Text("Informationen und Lizenzen"),
|
title: const Text("Informationen und Lizenzen"),
|
||||||
|
@ -3,17 +3,17 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:better_open_file/better_open_file.dart';
|
import 'package:better_open_file/better_open_file.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:marianum_mobile/storage/base/settingsProvider.dart';
|
||||||
import 'package:photo_view/photo_view.dart';
|
import 'package:photo_view/photo_view.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||||
|
|
||||||
import 'confirmDialog.dart';
|
|
||||||
import 'placeholderView.dart';
|
import 'placeholderView.dart';
|
||||||
|
|
||||||
class FileViewer extends StatefulWidget {
|
class FileViewer extends StatefulWidget {
|
||||||
final String path;
|
final String path;
|
||||||
final bool openExternal;
|
final bool openExternal;
|
||||||
final bool allowExternal;
|
const FileViewer({super.key, required this.path, this.openExternal = false});
|
||||||
const FileViewer({super.key, required this.path, this.openExternal = false, this.allowExternal = true});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<FileViewer> createState() => _FileViewerState();
|
State<FileViewer> createState() => _FileViewerState();
|
||||||
@ -22,30 +22,38 @@ class FileViewer extends StatefulWidget {
|
|||||||
class _FileViewerState extends State<FileViewer> {
|
class _FileViewerState extends State<FileViewer> {
|
||||||
PhotoViewController photoViewController = PhotoViewController();
|
PhotoViewController photoViewController = PhotoViewController();
|
||||||
|
|
||||||
|
late SettingsProvider settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||||
|
late bool openExternal;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
openExternal = settings.val().fileViewSettings.alwaysOpenExternally || widget.openExternal;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
AppBar appbar({List actions = const []}) {
|
AppBar appbar({List actions = const []}) {
|
||||||
return AppBar(
|
return AppBar(
|
||||||
title: Text(widget.path.split("/").last),
|
title: Text(widget.path.split("/").last),
|
||||||
actions: [
|
actions: [
|
||||||
Visibility(
|
IconButton(
|
||||||
visible: widget.allowExternal,
|
onPressed: () => Navigator.of(context).push(
|
||||||
child: IconButton(onPressed: () => ConfirmDialog(
|
MaterialPageRoute(builder: (context) => FileViewer(path: widget.path, openExternal: true))
|
||||||
title: "Extern öffnen",
|
),
|
||||||
content: "Möchtest du die Datei mit dem Systemdialog öffnen?",
|
icon: const Icon(Icons.open_in_new)
|
||||||
onConfirm: () => Navigator.of(context).push(MaterialPageRoute(builder: (context) => FileViewer(path: widget.path, openExternal: true))),
|
|
||||||
confirmButton: "Öffnen",
|
|
||||||
).asDialog(context), icon: const Icon(Icons.open_in_new)),
|
|
||||||
),
|
),
|
||||||
...actions
|
...actions
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(widget.openExternal ? "" : widget.path.split(".").last) {
|
switch(openExternal ? "" : widget.path.split(".").last.toLowerCase()) {
|
||||||
case "png":
|
case "png":
|
||||||
case "jpg":
|
case "jpg":
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
|
case "webp":
|
||||||
|
case "gif":
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: appbar(
|
appBar: appbar(
|
||||||
actions: [
|
actions: [
|
||||||
@ -84,7 +92,15 @@ class _FileViewerState extends State<FileViewer> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return const PlaceholderView(text: "Datei wird extern geöffnet...", icon: Icons.open_in_new);
|
|
||||||
|
return PlaceholderView(
|
||||||
|
text: "Datei extern geöffnet",
|
||||||
|
icon: Icons.open_in_new,
|
||||||
|
button: TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: const Text("Zurück"),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user