Added support for force refresh without caching, using this system on chatList.dart
This commit is contained in:
parent
d5179d5e3d
commit
97551738b0
@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChat.dart';
|
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChat.dart';
|
||||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatParams.dart';
|
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatParams.dart';
|
||||||
@ -14,10 +15,13 @@ class GetChatCache extends RequestCache<GetChatResponse> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GetChatResponse> onLoad() {
|
Future<GetChatResponse> onLoad() {
|
||||||
|
log("LOAD");
|
||||||
return GetChat(
|
return GetChat(
|
||||||
chatToken,
|
chatToken,
|
||||||
GetChatParams(
|
GetChatParams(
|
||||||
lookIntoFuture: GetChatParamsSwitch.off
|
lookIntoFuture: GetChatParamsSwitch.off,
|
||||||
|
setReadMarker: GetChatParamsSwitch.on,
|
||||||
|
limit: 200,
|
||||||
)
|
)
|
||||||
).run();
|
).run();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomParams.dart';
|
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomParams.dart';
|
||||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.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';
|
import 'getRoom.dart';
|
||||||
|
|
||||||
class GetRoomCache extends RequestCache<GetRoomResponse> {
|
class GetRoomCache extends RequestCache<GetRoomResponse> {
|
||||||
GetRoomCache({onUpdate}) : super(RequestCache.cacheMinute, onUpdate) {
|
GetRoomCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
|
||||||
start("MarianumMobile", "nc-rooms");
|
start("MarianumMobile", "nc-rooms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@ abstract class RequestCache<T> {
|
|||||||
|
|
||||||
int maxCacheTime;
|
int maxCacheTime;
|
||||||
Function(T) onUpdate;
|
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 {
|
void start(String file, String document) async {
|
||||||
Map<String, dynamic>? tableData = await Localstore.instance.collection(file).doc(document).get();
|
Map<String, dynamic>? tableData = await Localstore.instance.collection(file).doc(document).get();
|
||||||
@ -20,7 +21,7 @@ abstract class RequestCache<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
|
if(DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
|
||||||
return;
|
if(renew == null || !renew!) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
T newValue = await onLoad();
|
T newValue = await onLoad();
|
||||||
|
@ -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/getRoomCache.dart';
|
||||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||||
@ -16,9 +15,9 @@ class ChatListProps extends DataHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run({renew}) {
|
||||||
log("RUN CACHE");
|
|
||||||
GetRoomCache(
|
GetRoomCache(
|
||||||
|
renew: renew,
|
||||||
onUpdate: (GetRoomResponse data) => {
|
onUpdate: (GetRoomResponse data) => {
|
||||||
_getRoomResponse = data,
|
_getRoomResponse = data,
|
||||||
notifyListeners(),
|
notifyListeners(),
|
||||||
|
@ -93,7 +93,7 @@ class _ChatListState extends State<ChatList> {
|
|||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
color: Theme.of(context).primaryColor,
|
color: Theme.of(context).primaryColor,
|
||||||
onRefresh: () {
|
onRefresh: () {
|
||||||
Provider.of<ChatListProps>(context, listen: false).run();
|
Provider.of<ChatListProps>(context, listen: false).run(renew: true);
|
||||||
return Future.delayed(const Duration(seconds: 3));
|
return Future.delayed(const Duration(seconds: 3));
|
||||||
},
|
},
|
||||||
child: ListView(children: chats),
|
child: ListView(children: chats),
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:marianum_mobile/data/timetable/timetableProps.dart';
|
import 'package:marianum_mobile/data/timetable/timetableProps.dart';
|
||||||
import 'package:marianum_mobile/screen/pages/timetable/weekView.dart';
|
import 'package:marianum_mobile/screen/pages/timetable/weekView.dart';
|
||||||
@ -24,6 +26,8 @@ class _TimetableState extends State<Timetable> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
double movement = 0;
|
||||||
|
|
||||||
return Consumer<TimetableProps>(
|
return Consumer<TimetableProps>(
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
if(value.primaryLoading()) {
|
if(value.primaryLoading()) {
|
||||||
@ -35,7 +39,14 @@ class _TimetableState extends State<Timetable> {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
child: WeekView(value),
|
child: Positioned(
|
||||||
|
left: movement,
|
||||||
|
child: WeekView(value),
|
||||||
|
),
|
||||||
|
onHorizontalDragUpdate: (details) {
|
||||||
|
log("${details.globalPosition.dx}");
|
||||||
|
movement = details.globalPosition.dx;
|
||||||
|
},
|
||||||
onHorizontalDragEnd: (details) {
|
onHorizontalDragEnd: (details) {
|
||||||
if(details.primaryVelocity! < 0) {
|
if(details.primaryVelocity! < 0) {
|
||||||
timetable.switchWeek();
|
timetable.switchWeek();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user