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