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

Unverified Commit 9cefce5e authored by Marten Gajda's avatar Marten Gajda Committed by GitHub
Browse files

Remove obsolete code, implements #834 (#835)

It's no longer necessary to update all values which affect recurrence in the same update. The provider can handle updates of individual fields.
parent 80922258
Loading
Loading
Loading
Loading
+7 −21
Original line number Diff line number Diff line
@@ -25,12 +25,6 @@ import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@@ -71,12 +65,16 @@ import org.dmfs.tasks.widget.ListenableScrollView;
import org.dmfs.tasks.widget.ListenableScrollView.OnScrollListener;
import org.dmfs.tasks.widget.TaskEdit;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader;


/**
 * Fragment to edit task details.
@@ -105,12 +103,6 @@ public class EditTaskFragment extends SupportFragment implements LoaderManager.L

    public static final String KEY_NEW_TASK = "new_event";

    /**
     * A set of values that may affect the recurrence set of a task. If one of these values changes we have to submit all of them.
     */
    private final static Set<String> RECURRENCE_VALUES = new HashSet<String>(Arrays.asList(Tasks.DUE, Tasks.DTSTART, Tasks.TZ, Tasks.IS_ALLDAY,
            Tasks.RRULE, Tasks.RDATE, Tasks.EXDATE));

    /**
     * Projection into the task list.
     */
@@ -717,12 +709,6 @@ public class EditTaskFragment extends SupportFragment implements LoaderManager.L

            if (!TextUtils.isEmpty(TaskFieldAdapters.TITLE.get(mValues)) || mValues.isUpdate())
            {

                if (mValues.updatesAnyKey(RECURRENCE_VALUES))
                {
                    mValues.ensureUpdates(RECURRENCE_VALUES);
                }

                if (mValues.isInsert())
                {
                    // update recently used lists
+0 −105
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;

@@ -81,16 +80,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
     */
    private final Set<OnContentChangeListener> mPendingNotifications = new HashSet<OnContentChangeListener>();

    /**
     * Holds the name of the keys we've updated in {@link #mAfterContentValues}.
     * <p>
     * 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
     * ourselves.
     * <p>
     * Don't use this before calling {@link #ensureAfter()} at least once.
     */
    private Set<String> mAfterKeys;

    /**
     * Indicates that loading is in process.
     */
@@ -144,7 +133,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
        if (other.mAfterContentValues != null)
        {
            mAfterContentValues = new ContentValues(other.mAfterContentValues);
            mAfterKeys = new HashSet<String>(other.mAfterKeys);
        }

        mUri = other.mUri;
@@ -210,7 +198,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
                context.getContentResolver().delete(mUri, null, null);
                mBeforeContentValues = null;
                mAfterContentValues = null;
                mAfterKeys = null;
                mUri = null;
            }
            else
@@ -269,65 +256,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
    }


    public boolean persistsKey(String key)
    {
        return mAfterContentValues != null && mAfterContentValues.containsKey(key);
    }


    public boolean updatesAnyKey(Set<String> keys)
    {
        if (mAfterContentValues == null)
        {
            return false;
        }

        Set<String> keySet = new HashSet<String>(mAfterKeys);

        keySet.retainAll(keys);

        // if there is any element left in keySet both sets had at least one element in common
        return !keySet.isEmpty();
    }


    public void ensureUpdates(Set<String> keys)
    {
        if (mBeforeContentValues == null || keys == null || keys.isEmpty())
        {
            // nothing to do
            return;
        }

        ContentValues tempValues = new ContentValues(mBeforeContentValues);
        /*
         * Remove all values from tempValues that already are in mAfterContentValues or that are not required to be updated.
         *
         * This is tricky because we can't rely on ContentValues.keySet(). That's why we have to iterate all keys and remove the ones we don't have to update.
         * Since we can't modify tempValues while iterating over its keys we have to create a temporary Set.
         *
         * TODO: find a better way to solve this
         */
        for (Entry<String, Object> entry : new HashSet<Entry<String, Object>>(tempValues.valueSet()))
        {
            String key = entry.getKey();
            if (!keys.contains(key) || persistsKey(key))
            {
                tempValues.remove(key);
            }
        }

        if (mAfterContentValues != null)
        {
            mAfterContentValues.putAll(tempValues);
        }
        else
        {
            mAfterContentValues = tempValues;
        }
    }


    private ContentValues ensureAfter()
    {
        ContentValues values = mAfterContentValues;
@@ -335,8 +263,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
        {
            values = new ContentValues();
            mAfterContentValues = values;
            // also create mAfterKeys
            mAfterKeys = new HashSet<String>();
        }
        return values;
    }
@@ -354,14 +280,12 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
                {
                    // value equals before value, so remove it from after values
                    mAfterContentValues.remove(key);
                    mAfterKeys.remove(key);
                    notifyUpdateListeners(key);
                    return;
                }
            }
            // value has changed, update
            ensureAfter().put(key, value);
            mAfterKeys.add(key);
            notifyUpdateListeners(key);
        }
    }
@@ -390,13 +314,11 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
                {
                    // value equals before value, so remove it from after values
                    mAfterContentValues.remove(key);
                    mAfterKeys.remove(key);
                    notifyUpdateListeners(key);
                    return;
                }
            }
            ensureAfter().put(key, value);
            mAfterKeys.add(key);
            notifyUpdateListeners(key);
        }
    }
@@ -425,13 +347,11 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
                {
                    // value equals before value, so remove it from after values
                    mAfterContentValues.remove(key);
                    mAfterKeys.remove(key);
                    notifyUpdateListeners(key);
                    return;
                }
            }
            ensureAfter().put(key, value);
            mAfterKeys.add(key);
            notifyUpdateListeners(key);
        }
    }
@@ -460,13 +380,11 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
                {
                    // value equals before value, so remove it from after values
                    mAfterContentValues.remove(key);
                    mAfterKeys.remove(key);
                    notifyUpdateListeners(key);
                    return;
                }
            }
            ensureAfter().put(key, value);
            mAfterKeys.add(key);
            notifyUpdateListeners(key);
        }
    }
@@ -534,12 +452,10 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
        if (mAfterContentValues != null)
        {
            mAfterContentValues.putNull(key);
            mAfterKeys.add(key);
        }
        else if (mBeforeContentValues != null && mBeforeContentValues.get(key) != null)
        {
            ensureAfter().putNull(key);
            mAfterKeys.add(key);
        }
    }

@@ -619,16 +535,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
        dest.writeParcelable(mUri, flags);
        dest.writeParcelable(mBeforeContentValues, flags);
        dest.writeParcelable(mAfterContentValues, flags);

        if (mAfterContentValues != null)
        {
            // It's not possible to write a Set to a parcel, so write the number of members and each member individually.
            dest.writeInt(mAfterKeys.size());
            for (String key : mAfterKeys)
            {
                dest.writeString(key);
            }
        }
    }


@@ -638,17 +544,6 @@ public final class ContentSet implements OnContentLoadedListener, Parcelable
        mUri = source.readParcelable(loader);
        mBeforeContentValues = source.readParcelable(loader);
        mAfterContentValues = source.readParcelable(loader);

        if (mAfterContentValues != null)
        {
            int count = source.readInt();
            Set<String> keys = new HashSet<String>();
            while (--count >= 0)
            {
                keys.add(source.readString());
            }
            mAfterKeys = keys;
        }
    }