mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	Fix conflicts in friendlist refresh.
This commit is contained in:
		@@ -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,9 +47,18 @@ public class FriendRefreshLoopRunnable implements Runnable {
 | 
			
		||||
                //Get the latest version of the list
 | 
			
		||||
                ArrayList<Friend> friendsList = friendsListHelper.download();
 | 
			
		||||
 | 
			
		||||
                //Save it (only in case of success)
 | 
			
		||||
                if(friendsList != null)
 | 
			
		||||
                    friendsDBHelper.update_list(friendsList);
 | 
			
		||||
                //Acquire a lock over the friend list
 | 
			
		||||
                FriendsListHelper.ListAccessLock.lock();
 | 
			
		||||
 | 
			
		||||
                try {
 | 
			
		||||
                    //Save it (only in case of success)
 | 
			
		||||
                    if (friendsList != null)
 | 
			
		||||
                        friendsDBHelper.update_list(friendsList);
 | 
			
		||||
 | 
			
		||||
                } finally {
 | 
			
		||||
                    //Release the lock
 | 
			
		||||
                    FriendsListHelper.ListAccessLock.unlock();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                try {
 | 
			
		||||
                    object.wait(500); //TODO: increase the value
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user