mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Show cached conversations list before getting list from the server
This commit is contained in:
@ -33,23 +33,34 @@ class _ConversationScreenState extends State<ConversationsScreen> {
|
||||
|
||||
void setLoading(bool loading) => setState(() => _loading = loading);
|
||||
|
||||
/// Get the list of conversations, once from the cache, once from the server
|
||||
Future<void> _loadConversations() async {
|
||||
await _loadConversationsList(true);
|
||||
await _loadConversationsList(false);
|
||||
}
|
||||
|
||||
void _gotLoadingError() {
|
||||
setLoading(false);
|
||||
setError(_list == null ? LoadErrorLevel.MAJOR : LoadErrorLevel.MINOR);
|
||||
}
|
||||
|
||||
/// Load the list of conversations
|
||||
Future<void> _loadConversations() async {
|
||||
Future<void> _loadConversationsList(bool cached) async {
|
||||
setError(LoadErrorLevel.NONE);
|
||||
setLoading(true);
|
||||
|
||||
//Process the list of conversations
|
||||
final list = await _conversationsHelper.downloadList();
|
||||
//Get the list of conversations
|
||||
var list;
|
||||
if(cached)
|
||||
list = await _conversationsHelper.getCachedList();
|
||||
else
|
||||
list = await _conversationsHelper.downloadList();
|
||||
|
||||
if (list == null) return _gotLoadingError();
|
||||
|
||||
//Get information about the members of the conversations
|
||||
list.users = await _usersHelper.getUsersInfo(list.allUsersID);
|
||||
if(list.users == null) return _gotLoadingError();
|
||||
if (list.users == null) return _gotLoadingError();
|
||||
|
||||
//Save list
|
||||
setState(() {
|
||||
@ -65,7 +76,7 @@ class _ConversationScreenState extends State<ConversationsScreen> {
|
||||
tr("Could not retrieve the list of conversations!"),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: _loadConversations,
|
||||
onPressed: () => _loadConversationsList(true),
|
||||
child: Text(
|
||||
tr("Retry").toUpperCase(),
|
||||
style: TextStyle(
|
||||
@ -83,14 +94,39 @@ class _ConversationScreenState extends State<ConversationsScreen> {
|
||||
if (_list == null) return buildCenteredProgressBar();
|
||||
|
||||
// Show the list of conversations
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
return ConversationTile(
|
||||
conversation: _list.elementAt(index),
|
||||
usersList: _list.users,
|
||||
);
|
||||
},
|
||||
itemCount: _list.length,
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: _error == LoadErrorLevel.MINOR ? _buildErrorCard() : null,
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
return ConversationTile(
|
||||
conversation: _list.elementAt(index),
|
||||
usersList: _list.users,
|
||||
);
|
||||
},
|
||||
itemCount: _list.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
top: 8.0,
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
child: Container(
|
||||
child: !_loading
|
||||
? null
|
||||
: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user