Skip to content

Commit 4154099

Browse files
author
Gabor Keszthelyi
committed
Remove mAfterKeys compatibility workaround from ContentSet.
1 parent 42c9b8f commit 4154099

File tree

1 file changed

+2
-47
lines changed

1 file changed

+2
-47
lines changed

opentasks/src/main/java/org/dmfs/tasks/model/ContentSet.java

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
8383
*/
8484
private final Set<OnContentChangeListener> mPendingNotifications = new HashSet<OnContentChangeListener>();
8585

86-
/**
87-
* Holds the name of the keys we've updated in {@link #mAfterContentValues}.
88-
* <p>
89-
* Before Android SDK level 11 there is no {@link ContentValues#keySet()} method. To be able to determine the keys in there we have to maintain the set
90-
* ourselves.
91-
* <p>
92-
* Don't use this before calling {@link #ensureAfter()} at least once.
93-
*/
94-
private Set<String> mAfterKeys;
95-
9686
/**
9787
* Indicates that loading is in process.
9888
*/
@@ -136,7 +126,6 @@ public ContentSet(@NonNull ContentSet other)
136126
if (other.mAfterContentValues != null)
137127
{
138128
mAfterContentValues = new ContentValues(other.mAfterContentValues);
139-
mAfterKeys = new HashSet<String>(other.mAfterKeys);
140129
}
141130

142131
mUri = other.mUri;
@@ -202,7 +191,6 @@ public void delete(@NonNull Context context)
202191
context.getContentResolver().delete(mUri, null, null);
203192
mBeforeContentValues = null;
204193
mAfterContentValues = null;
205-
mAfterKeys = null;
206194
mUri = null;
207195
}
208196
else
@@ -285,7 +273,7 @@ public boolean updatesAnyKey(@NonNull Set<String> keys)
285273
return false;
286274
}
287275

288-
Set<String> keySet = new HashSet<>(mAfterKeys);
276+
Set<String> keySet = new HashSet<>(mAfterContentValues.keySet());
289277

290278
keySet.retainAll(keys);
291279

@@ -296,7 +284,7 @@ public boolean updatesAnyKey(@NonNull Set<String> keys)
296284

297285
public void ensureUpdates(@NonNull Set<String> keys)
298286
{
299-
if (mBeforeContentValues == null || keys == null || keys.isEmpty())
287+
if (mBeforeContentValues == null || keys.isEmpty())
300288
{
301289
// nothing to do
302290
return;
@@ -339,8 +327,6 @@ private ContentValues ensureAfter()
339327
{
340328
values = new ContentValues();
341329
mAfterContentValues = values;
342-
// also create mAfterKeys
343-
mAfterKeys = new HashSet<>();
344330
}
345331
return values;
346332
}
@@ -358,14 +344,12 @@ public void put(@NonNull String key, @Nullable Integer value)
358344
{
359345
// value equals before value, so remove it from after values
360346
mAfterContentValues.remove(key);
361-
mAfterKeys.remove(key);
362347
notifyUpdateListeners(key);
363348
return;
364349
}
365350
}
366351
// value has changed, update
367352
ensureAfter().put(key, value);
368-
mAfterKeys.add(key);
369353
notifyUpdateListeners(key);
370354
}
371355
}
@@ -395,13 +379,11 @@ public void put(@NonNull String key, @Nullable Long value)
395379
{
396380
// value equals before value, so remove it from after values
397381
mAfterContentValues.remove(key);
398-
mAfterKeys.remove(key);
399382
notifyUpdateListeners(key);
400383
return;
401384
}
402385
}
403386
ensureAfter().put(key, value);
404-
mAfterKeys.add(key);
405387
notifyUpdateListeners(key);
406388
}
407389
}
@@ -431,13 +413,11 @@ public void put(@NonNull String key, @Nullable String value)
431413
{
432414
// value equals before value, so remove it from after values
433415
mAfterContentValues.remove(key);
434-
mAfterKeys.remove(key);
435416
notifyUpdateListeners(key);
436417
return;
437418
}
438419
}
439420
ensureAfter().put(key, value);
440-
mAfterKeys.add(key);
441421
notifyUpdateListeners(key);
442422
}
443423
}
@@ -467,13 +447,11 @@ public void put(@NonNull String key, @Nullable Float value)
467447
{
468448
// value equals before value, so remove it from after values
469449
mAfterContentValues.remove(key);
470-
mAfterKeys.remove(key);
471450
notifyUpdateListeners(key);
472451
return;
473452
}
474453
}
475454
ensureAfter().put(key, value);
476-
mAfterKeys.add(key);
477455
notifyUpdateListeners(key);
478456
}
479457
}
@@ -543,12 +521,10 @@ public void remove(@NonNull String key)
543521
if (mAfterContentValues != null)
544522
{
545523
mAfterContentValues.putNull(key);
546-
mAfterKeys.add(key);
547524
}
548525
else if (mBeforeContentValues != null && mBeforeContentValues.get(key) != null)
549526
{
550527
ensureAfter().putNull(key);
551-
mAfterKeys.add(key);
552528
}
553529
}
554530

@@ -628,16 +604,6 @@ public void writeToParcel(Parcel dest, int flags)
628604
dest.writeParcelable(mUri, flags);
629605
dest.writeParcelable(mBeforeContentValues, flags);
630606
dest.writeParcelable(mAfterContentValues, flags);
631-
632-
if (mAfterContentValues != null)
633-
{
634-
// It's not possible to write a Set to a parcel, so write the number of members and each member individually.
635-
dest.writeInt(mAfterKeys.size());
636-
for (String key : mAfterKeys)
637-
{
638-
dest.writeString(key);
639-
}
640-
}
641607
}
642608

643609

@@ -647,17 +613,6 @@ private void readFromParcel(Parcel source)
647613
mUri = source.readParcelable(loader);
648614
mBeforeContentValues = source.readParcelable(loader);
649615
mAfterContentValues = source.readParcelable(loader);
650-
651-
if (mAfterContentValues != null)
652-
{
653-
int count = source.readInt();
654-
Set<String> keys = new HashSet<String>();
655-
while (--count >= 0)
656-
{
657-
keys.add(source.readString());
658-
}
659-
mAfterKeys = keys;
660-
}
661616
}
662617

663618

0 commit comments

Comments
 (0)