1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Cache the list of friends

This commit is contained in:
2019-05-04 19:35:03 +02:00
parent 62125d7c3d
commit 67a6befc02
6 changed files with 100 additions and 12 deletions

View File

@ -47,7 +47,13 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
_loadList();
_getList();
}
/// Initialize list retrieving
Future<void> _getList() async {
await _loadList(false);
await _loadList(true);
}
/// Refresh the list of friends
@ -56,11 +62,14 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
}
/// Load the list of friends
Future<void> _loadList() async {
Future<void> _loadList(bool online) async {
error = _ErrorsLevel.NONE;
// Get the list of friends
final list = await _friendsHelper.downloadList();
final list = await _friendsHelper.getList(online: online);
// Check if there is no cache yet
if(!online && list.isEmpty) return;
// Check for errors
if (list == null) return _gotError();
@ -73,7 +82,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
// Apply new information
setState(() {
_friendsList = list;
_friendsList = list..sort();
_usersInfo = users;
});
error = _ErrorsLevel.NONE;
@ -107,7 +116,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
Expanded(
child: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: _loadList,
onRefresh: () => _loadList(true),
child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
itemCount: _friendsList.length,