First pass at improving tag data members migration

pull/14/head
Sam Bosley 12 years ago
parent 9e09eb463c
commit 936e1c924b

@ -355,7 +355,7 @@ public class TagSettingsActivity extends FragmentActivity {
imm.hideSoftInputFromWindow(tagName.getWindowToken(), 0);
tagDataService.save(tagData);
tagMetadataDao.synchronizeMembers(tagData.getId(), tagData.getUuid(), members);
tagMetadataDao.synchronizeMembers(tagData, tagData.getValue(TagData.MEMBERS), tagData.getUuid(), members);
if (isNewTag) {
setResult(RESULT_OK, new Intent().putExtra(TOKEN_NEW_FILTER,

@ -9,6 +9,7 @@ import java.util.HashSet;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.ContentValues;
@ -146,7 +147,8 @@ public class TagMetadataDao extends DatabaseDao<TagMetadata> {
}
}
public void synchronizeMembers(long tagId, String tagUuid, JSONArray members) {
public void synchronizeMembers(TagData tagData, String legacyMembersString, String tagUuid, JSONArray members) {
long tagId = tagData.getId();
Set<String> emails = new HashSet<String>();
Set<String> ids = new HashSet<String>();
@ -163,6 +165,30 @@ public class TagMetadataDao extends DatabaseDao<TagMetadata> {
}
}
if (!TextUtils.isEmpty(legacyMembersString)) {
try {
JSONArray legacyMembers = new JSONArray(legacyMembersString);
for (int i = 0; i < legacyMembers.length(); i++) {
JSONObject user = legacyMembers.optJSONObject(i);
if (user != null) {
String id = user.optString("id"); //$NON-NLS-1$
String email = user.optString("email"); //$NON-NLS-1$
if (!TextUtils.isEmpty(id) && ids.contains(id)) {
createMemberLink(tagId, tagUuid, id, false);
} else if (!TextUtils.isEmpty(email) && emails.contains(email)) {
createMemberLink(tagId, tagUuid, email, false);
}
}
}
} catch (JSONException e) {
//
}
tagData.setValue(TagData.MEMBERS, ""); //$NON-NLS-1$
PluginServices.getTagDataDao().saveExisting(tagData);
}
TodorooCursor<TagMetadata> currentMembers = query(Query.select(TagMemberMetadata.USER_UUID).where(TagMetadataCriteria.byTagAndWithKey(tagUuid, TagMemberMetadata.KEY)));
try {
TagMetadata m = new TagMetadata();

Loading…
Cancel
Save