Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec09d741 authored by Wysie's avatar Wysie
Browse files

Cleaned up code slightly. Still unable to remove GroupMembership rows.

parent 399be400
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -2267,7 +2267,6 @@ public final class ContactsListActivity extends ListActivity
    		do {
                    getContentResolver().update(ContentUris.withAppendedId(People.CONTENT_URI, c.getLong(0)),
                    	values, null, null);
                    Log.d("HERE", "WE GO");
               } while(c.moveToNext());
	}
    } 
+21 −14
Original line number Diff line number Diff line
@@ -2513,6 +2513,7 @@ public final class EditContactActivity extends Activity implements View.OnClickL
        CharSequence[] groupsCharSeq = null;           
        boolean[] checkedValues = null;
        
        // If selected groups already has something inside, we use it
        if (selectedGroups.size() > 0) {

            groupsCharSeq = groups.toArray(
@@ -2550,6 +2551,8 @@ public final class EditContactActivity extends Activity implements View.OnClickL
                }

                groupsCharSeq = groups.toArray(new CharSequence[groups.size()]);
                
                if (!(mState == STATE_INSERT)) {
                long personId = ContentUris.parseId(mUri);

                Cursor groupCursor = mResolver.query(GroupMembership.CONTENT_URI,
@@ -2580,6 +2583,7 @@ public final class EditContactActivity extends Activity implements View.OnClickL
                    cur.close();
                    groupCursor.close();
                }
                }

                checkedValues = new boolean[groups.size()];

@@ -2587,6 +2591,8 @@ public final class EditContactActivity extends Activity implements View.OnClickL
                    b = false;
                }
                
                if (!(mState == STATE_INSERT)) {

                for (int i = 0; i < currentMembership.size(); i++) {
                    int j = groups.indexOf(currentMembership.get(i));

@@ -2595,6 +2601,7 @@ public final class EditContactActivity extends Activity implements View.OnClickL
                        selectedGroups.add(groups.get(j));
                    }
                }
                }
            } finally {
                cursor.close();
            }
@@ -2630,26 +2637,26 @@ public final class EditContactActivity extends Activity implements View.OnClickL
    };

    private void saveGroups() {

        long personId = ContentUris.parseId(mUri);
        
        //Wysie_Soh: Remove all group memberships               
        Cursor c = getContentResolver().query(GroupMembership.CONTENT_URI,
        //Wysie_Soh: Remove all group memberships (not working)
        Cursor c = mResolver.query(GroupMembership.CONTENT_URI,
                GROUP_MEMBERSHIP_PROJECTION,
                GroupMembership.PERSON_ID + "='" + personId + "'", null, null);
                            
        if (c.moveToFirst()) {
            do {                
                /*int i = mResolver.delete(
                        ContentUris.withAppendedId(GroupMembership.CONTENT_URI, c.getLong(0)),
                        null,
                        null);*/
            } while (c.moveToNext());
            while (c.moveToNext()) {                
                int i = mResolver.delete(ContentUris.withAppendedId(
                GroupMembership.CONTENT_URI, c.getLong(0)),
                        GroupMembership.PERSON_ID + "='" + personId + "'",
                        null);
                Log.d("ROWS DEL", "" + i);
            }
            
            c.close();
        }        
        
        //Wysie_Soh: Added all selectedGroups
        //Wysie_Soh: Added all selectedGroups (working)
        for (int i = 0; i < selectedGroups.size(); i++) {        
            Cursor cursor = mResolver.query(Groups.CONTENT_URI,
                        GROUPS_PROJECTION, 
+10 −1
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/** Bluetooth Transfer related import */
@@ -1112,6 +1113,7 @@ public class ViewContactActivity extends ListActivity
        	}
        	cur.close();
        	groupCursor.close();
        	removeDuplicates(groupNamesArray);
        	java.util.Collections.sort(groupNamesArray);        	
        	StringBuilder groups = new StringBuilder();
        	
@@ -1133,6 +1135,13 @@ public class ViewContactActivity extends ListActivity
        }
    }
    
    private void removeDuplicates(ArrayList al) {
        HashSet h = new HashSet(al);
        al.clear();
        al.addAll(h);
  }


    String buildActionString(int actionResId, CharSequence type, boolean lowerCase) {
        // If there is no type just display an empty string
        if (type == null) {