mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +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 org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Friends list functions
|
* Friends list functions
|
||||||
@ -32,6 +33,9 @@ public class FriendsListHelper {
|
|||||||
private FriendsListDbHelper fdbHelper;
|
private FriendsListDbHelper fdbHelper;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
|
//Friends list access lock
|
||||||
|
public static ReentrantLock ListAccessLock = new ReentrantLock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public constructor
|
* Public constructor
|
||||||
*
|
*
|
||||||
@ -56,10 +60,22 @@ public class FriendsListHelper {
|
|||||||
/**
|
/**
|
||||||
* Get and return the friends list
|
* Get and return the friends list
|
||||||
*
|
*
|
||||||
* @return The list of firned
|
* @return The list of friends
|
||||||
*/
|
*/
|
||||||
public ArrayList<Friend> get() {
|
public ArrayList<Friend> get() {
|
||||||
return fdbHelper.get_list();
|
|
||||||
|
//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
|
//Get the latest version of the list
|
||||||
ArrayList<Friend> friendsList = friendsListHelper.download();
|
ArrayList<Friend> friendsList = friendsListHelper.download();
|
||||||
|
|
||||||
|
//Acquire a lock over the friend list
|
||||||
|
FriendsListHelper.ListAccessLock.lock();
|
||||||
|
|
||||||
|
try {
|
||||||
//Save it (only in case of success)
|
//Save it (only in case of success)
|
||||||
if (friendsList != null)
|
if (friendsList != null)
|
||||||
friendsDBHelper.update_list(friendsList);
|
friendsDBHelper.update_list(friendsList);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
//Release the lock
|
||||||
|
FriendsListHelper.ListAccessLock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
object.wait(500); //TODO: increase the value
|
object.wait(500); //TODO: increase the value
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user