From 97551738b0a2350a0d19a48fbf1e9f75a369e3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Tue, 21 Feb 2023 14:58:31 +0100 Subject: [PATCH] Added support for force refresh without caching, using this system on chatList.dart --- lib/api/marianumcloud/talk/chat/getChatCache.dart | 6 +++++- lib/api/marianumcloud/talk/room/getRoomCache.dart | 3 +-- lib/api/requestCache.dart | 5 +++-- lib/data/chatList/chatListProps.dart | 5 ++--- lib/screen/pages/talk/chatList.dart | 2 +- lib/screen/pages/timetable/timetable.dart | 13 ++++++++++++- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/api/marianumcloud/talk/chat/getChatCache.dart b/lib/api/marianumcloud/talk/chat/getChatCache.dart index a645faf..0fa369a 100644 --- a/lib/api/marianumcloud/talk/chat/getChatCache.dart +++ b/lib/api/marianumcloud/talk/chat/getChatCache.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:developer'; import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChat.dart'; import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatParams.dart'; @@ -14,10 +15,13 @@ class GetChatCache extends RequestCache { @override Future onLoad() { + log("LOAD"); return GetChat( chatToken, GetChatParams( - lookIntoFuture: GetChatParamsSwitch.off + lookIntoFuture: GetChatParamsSwitch.off, + setReadMarker: GetChatParamsSwitch.on, + limit: 200, ) ).run(); } diff --git a/lib/api/marianumcloud/talk/room/getRoomCache.dart b/lib/api/marianumcloud/talk/room/getRoomCache.dart index 6090948..03b1419 100644 --- a/lib/api/marianumcloud/talk/room/getRoomCache.dart +++ b/lib/api/marianumcloud/talk/room/getRoomCache.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:developer'; import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomParams.dart'; import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart'; @@ -8,7 +7,7 @@ import 'package:marianum_mobile/api/requestCache.dart'; import 'getRoom.dart'; class GetRoomCache extends RequestCache { - GetRoomCache({onUpdate}) : super(RequestCache.cacheMinute, onUpdate) { + GetRoomCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) { start("MarianumMobile", "nc-rooms"); } diff --git a/lib/api/requestCache.dart b/lib/api/requestCache.dart index 9b9182e..fbe8075 100644 --- a/lib/api/requestCache.dart +++ b/lib/api/requestCache.dart @@ -10,8 +10,9 @@ abstract class RequestCache { int maxCacheTime; Function(T) onUpdate; + bool? renew; - RequestCache(this.maxCacheTime, this.onUpdate); + RequestCache(this.maxCacheTime, this.onUpdate, {this.renew = false}); void start(String file, String document) async { Map? tableData = await Localstore.instance.collection(file).doc(document).get(); @@ -20,7 +21,7 @@ abstract class RequestCache { } if(DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) { - return; + if(renew == null || !renew!) return; } T newValue = await onLoad(); diff --git a/lib/data/chatList/chatListProps.dart b/lib/data/chatList/chatListProps.dart index e0dca12..654d144 100644 --- a/lib/data/chatList/chatListProps.dart +++ b/lib/data/chatList/chatListProps.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomCache.dart'; import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart'; @@ -16,9 +15,9 @@ class ChatListProps extends DataHolder { } @override - void run() { - log("RUN CACHE"); + void run({renew}) { GetRoomCache( + renew: renew, onUpdate: (GetRoomResponse data) => { _getRoomResponse = data, notifyListeners(), diff --git a/lib/screen/pages/talk/chatList.dart b/lib/screen/pages/talk/chatList.dart index c3f52e7..d0843d3 100644 --- a/lib/screen/pages/talk/chatList.dart +++ b/lib/screen/pages/talk/chatList.dart @@ -93,7 +93,7 @@ class _ChatListState extends State { return RefreshIndicator( color: Theme.of(context).primaryColor, onRefresh: () { - Provider.of(context, listen: false).run(); + Provider.of(context, listen: false).run(renew: true); return Future.delayed(const Duration(seconds: 3)); }, child: ListView(children: chats), diff --git a/lib/screen/pages/timetable/timetable.dart b/lib/screen/pages/timetable/timetable.dart index 98b70b9..725f199 100644 --- a/lib/screen/pages/timetable/timetable.dart +++ b/lib/screen/pages/timetable/timetable.dart @@ -1,4 +1,6 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:marianum_mobile/data/timetable/timetableProps.dart'; import 'package:marianum_mobile/screen/pages/timetable/weekView.dart'; @@ -24,6 +26,8 @@ class _TimetableState extends State { @override Widget build(BuildContext context) { + double movement = 0; + return Consumer( builder: (context, value, child) { if(value.primaryLoading()) { @@ -35,7 +39,14 @@ class _TimetableState extends State { children: [ Expanded( child: GestureDetector( - child: WeekView(value), + child: Positioned( + left: movement, + child: WeekView(value), + ), + onHorizontalDragUpdate: (details) { + log("${details.globalPosition.dx}"); + movement = details.globalPosition.dx; + }, onHorizontalDragEnd: (details) { if(details.primaryVelocity! < 0) { timetable.switchWeek();