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

Commit 4b70833a authored by Ben Reich's avatar Ben Reich
Browse files

Update cancellation to set the activity to RESULT_CANCELED

We currently set the pick activity to RESULT_OK when the cancel button
is clicked. This doesn't idiomatically follow the same expectation as
the back arrow which sets the result CANCELED. Update all the picker
buttons to cancel instead.

Fix: 417598909
Test: atest com.android.documentsui.PickActivityTest
Flag: com.android.documentsui.flags.use_material3
Change-Id: Iee6a8561d3ab3f3b3565e67c1ae152f0a819ec2b
parent bd578399
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -504,6 +504,20 @@ class ActionHandler<T extends FragmentActivity & Addons> extends AbstractActionH
        }
    }

    /** Cancels the picking by first setting the last accessed location first. */
    void cancelPicking() {
        new SetLastAccessedStackTask(mActivity, mLastAccessed, mState.stack, this::onPickCanceled)
                .executeOnExecutor(getExecutorForCurrentDirectory());
    }

    /** Sets the activity result to canceled and finishes the current activity. */
    private void onPickCanceled() {
        if (DEBUG) Log.d(TAG, "onPickCanceled()");

        mActivity.setResult(FragmentActivity.RESULT_CANCELED, /* intent= */ null, 0);
        mActivity.finish();
    }

    void finishPicking(Uri... docs) {
        new SetLastAccessedStackTask(
                mActivity,
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class PickFilesFragment : Fragment() {

    private val cancelListener: View.OnClickListener = object : View.OnClickListener {
        override fun onClick(v: View?) {
            actionHandler!!.finishPicking()
            actionHandler!!.cancelPicking()
        }
    }

+7 −6
Original line number Diff line number Diff line
@@ -202,10 +202,11 @@ public class SaveFragment extends Fragment {

    };

    private View.OnClickListener mCancelListener = new View.OnClickListener() {
    private View.OnClickListener mCancelListener =
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
            mInjector.actions.finishPicking();
                    mInjector.actions.cancelPicking();
                }
            };

+1 −4
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;

import android.app.Activity;
import android.app.Instrumentation;
@@ -319,9 +318,7 @@ public class PickActivityTest {

        // Check that the files weren't picked.
        Instrumentation.ActivityResult result = mRule.getActivityResult();
        assertThat(result.getResultCode()).isEqualTo(Activity.RESULT_OK);
        ClipData clipData = result.getResultData().getClipData();
        assertNull(clipData);
        assertThat(result.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);

        // Check that the activity is finishing.
        assertThat(pickActivity.isFinishing()).isTrue();