Persisted file order options
This commit is contained in:
parent
53f1cdcda5
commit
28c98de9a7
lib
api/marianumcloud/talk
storage
view/pages/files
@ -38,8 +38,12 @@ abstract class TalkApi<T> extends ApiRequest {
|
||||
headers?.putIfAbsent("Accept", () => "application/json");
|
||||
headers?.putIfAbsent("OCS-APIRequest", () => "true");
|
||||
|
||||
http.Response? data = await request(endpoint, body, headers);
|
||||
if(data == null) {
|
||||
http.Response? data;
|
||||
|
||||
try {
|
||||
data = await request(endpoint, body, headers);
|
||||
if(data == null) throw Exception();
|
||||
} catch(e) {
|
||||
throw ApiError("Request could not be dispatched!");
|
||||
}
|
||||
//dynamic jsonData = jsonDecode(data.body);
|
||||
|
@ -3,6 +3,7 @@ import 'dart:developer';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../view/pages/files/files.dart';
|
||||
import '../file/fileSettings.dart';
|
||||
import '../gradeAverages/gradeAveragesSettings.dart';
|
||||
import '../holidays/holidaysSettings.dart';
|
||||
@ -92,6 +93,8 @@ class SettingsProvider extends ChangeNotifier {
|
||||
),
|
||||
fileSettings: FileSettings(
|
||||
sortFoldersToTop: true,
|
||||
ascending: true,
|
||||
sortBy: SortOption.name
|
||||
),
|
||||
holidaysSettings: HolidaysSettings(
|
||||
dismissedDisclaimer: false,
|
||||
|
@ -1,12 +1,17 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../view/pages/files/files.dart';
|
||||
|
||||
part 'fileSettings.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FileSettings {
|
||||
bool sortFoldersToTop;
|
||||
|
||||
FileSettings({required this.sortFoldersToTop});
|
||||
bool ascending;
|
||||
SortOption sortBy;
|
||||
|
||||
FileSettings({required this.sortFoldersToTop, required this.ascending, required this.sortBy});
|
||||
|
||||
factory FileSettings.fromJson(Map<String, dynamic> json) => _$FileSettingsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$FileSettingsToJson(this);
|
||||
|
@ -8,9 +8,19 @@ part of 'fileSettings.dart';
|
||||
|
||||
FileSettings _$FileSettingsFromJson(Map<String, dynamic> json) => FileSettings(
|
||||
sortFoldersToTop: json['sortFoldersToTop'] as bool,
|
||||
ascending: json['ascending'] as bool,
|
||||
sortBy: $enumDecode(_$SortOptionEnumMap, json['sortBy']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FileSettingsToJson(FileSettings instance) =>
|
||||
<String, dynamic>{
|
||||
'sortFoldersToTop': instance.sortFoldersToTop,
|
||||
'ascending': instance.ascending,
|
||||
'sortBy': _$SortOptionEnumMap[instance.sortBy]!,
|
||||
};
|
||||
|
||||
const _$SortOptionEnumMap = {
|
||||
SortOption.name: 'name',
|
||||
SortOption.date: 'date',
|
||||
SortOption.size: 'size',
|
||||
};
|
||||
|
@ -73,12 +73,16 @@ class _FilesState extends State<Files> {
|
||||
FilesProps props = FilesProps();
|
||||
ListFilesResponse? data;
|
||||
|
||||
late SettingsProvider settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
|
||||
SortOption currentSort = SortOption.name;
|
||||
bool currentSortDirection = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
currentSort = settings.val().fileSettings.sortBy;
|
||||
currentSortDirection = settings.val().fileSettings.ascending;
|
||||
_query();
|
||||
}
|
||||
|
||||
@ -131,6 +135,7 @@ class _FilesState extends State<Files> {
|
||||
onSelected: (e) {
|
||||
setState(() {
|
||||
currentSortDirection = e;
|
||||
settings.val(write: true).fileSettings.ascending = e;
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -152,6 +157,7 @@ class _FilesState extends State<Files> {
|
||||
onSelected: (e) {
|
||||
setState(() {
|
||||
currentSort = e;
|
||||
settings.val(write: true).fileSettings.sortBy = e;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user