Clone LocalSearch object before modifying it for unread/starred search

This commit is contained in:
cketti 2012-10-27 04:48:37 +02:00
parent faa666394c
commit 65b3a57340
4 changed files with 44 additions and 2 deletions

View File

@ -64,7 +64,6 @@ import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.misc.ExtendedAsyncTask;
import com.fsck.k9.activity.misc.NonConfigurationInstance;
import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.AccountSetupBasics;
import com.fsck.k9.activity.setup.Prefs;
import com.fsck.k9.activity.setup.WelcomeMessage;
@ -1788,7 +1787,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
LocalSearch search = null;
if (account instanceof SearchAccount) {
search = ((SearchAccount) account).getRelatedSearch();
search = ((SearchAccount) account).getRelatedSearch().clone();
search.setName(description);
} else {
search = new LocalSearch(description);

View File

@ -124,6 +124,35 @@ public class ConditionsTreeNode implements Parcelable {
}
/* package */ ConditionsTreeNode cloneTree() {
if (mParent != null) {
throw new IllegalStateException("Can't call cloneTree() for a non-root node");
}
ConditionsTreeNode copy = new ConditionsTreeNode(mCondition.clone());
copy.mLeftMPTTMarker = mLeftMPTTMarker;
copy.mRightMPTTMarker = mRightMPTTMarker;
copy.mLeft = (mLeft == null) ? null : mLeft.cloneNode(copy);
copy.mRight = (mRight == null) ? null : mRight.cloneNode(copy);
return copy;
}
private ConditionsTreeNode cloneNode(ConditionsTreeNode parent) {
ConditionsTreeNode copy = new ConditionsTreeNode(parent, mValue);
copy.mCondition = mCondition.clone();
copy.mLeftMPTTMarker = mLeftMPTTMarker;
copy.mRightMPTTMarker = mRightMPTTMarker;
copy.mLeft = (mLeft == null) ? null : mLeft.cloneNode(copy);
copy.mRight = (mRight == null) ? null : mRight.cloneNode(copy);
return copy;
}
///////////////////////////////////////////////////////////////
// Public modifiers
///////////////////////////////////////////////////////////////

View File

@ -80,6 +80,15 @@ public class LocalSearch implements SearchSpecification {
}
}
@Override
public LocalSearch clone() {
ConditionsTreeNode conditions = (mConditions == null) ? null : mConditions.cloneTree();
LocalSearch copy = new LocalSearch(mName, conditions, null, mPredefined);
copy.mAccountUuids = new HashSet<String>(mAccountUuids);
return copy;
}
///////////////////////////////////////////////////////////////
// Public manipulation methods

View File

@ -134,6 +134,11 @@ public interface SearchSpecification extends Parcelable {
this.field = Searchfield.values()[in.readInt()];
}
@Override
public SearchCondition clone() {
return new SearchCondition(field, attribute, value);
}
public String toHumanString() {
return field.toString() + attribute.toString();
}