mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Fix conflicts in friendlist refresh.
This commit is contained in:
parent
e582053655
commit
889e65e4d6
@ -14,6 +14,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Friends list functions
|
||||
@ -32,6 +33,9 @@ public class FriendsListHelper {
|
||||
private FriendsListDbHelper fdbHelper;
|
||||
private Context mContext;
|
||||
|
||||
//Friends list access lock
|
||||
public static ReentrantLock ListAccessLock = new ReentrantLock();
|
||||
|
||||
/**
|
||||
* Public constructor
|
||||
*
|
||||
@ -56,10 +60,22 @@ public class FriendsListHelper {
|
||||
/**
|
||||
* Get and return the friends list
|
||||
*
|
||||
* @return The list of firned
|
||||
* @return The list of friends
|
||||
*/
|
||||
public ArrayList<Friend> get(){
|
||||
return fdbHelper.get_list();
|
||||
public ArrayList<Friend> get() {
|
||||
|
||||
//Acquire friends list lock
|
||||
FriendsListHelper.ListAccessLock.lock();
|
||||
|
||||
//Fetch the list
|
||||
ArrayList<Friend> list;
|
||||
try {
|
||||
list = fdbHelper.get_list();
|
||||
} finally {
|
||||
FriendsListHelper.ListAccessLock.unlock();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,10 +47,19 @@ public class FriendRefreshLoopRunnable implements Runnable {
|
||||
//Get the latest version of the list
|
||||
ArrayList<Friend> friendsList = friendsListHelper.download();
|
||||
|
||||
//Acquire a lock over the friend list
|
||||
FriendsListHelper.ListAccessLock.lock();
|
||||
|
||||
try {
|
||||
//Save it (only in case of success)
|
||||
if(friendsList != null)
|
||||
if (friendsList != null)
|
||||
friendsDBHelper.update_list(friendsList);
|
||||
|
||||
} finally {
|
||||
//Release the lock
|
||||
FriendsListHelper.ListAccessLock.unlock();
|
||||
}
|
||||
|
||||
try {
|
||||
object.wait(500); //TODO: increase the value
|
||||
} catch (Exception e) {
|
||||
|
Loading…
Reference in New Issue
Block a user