diff options
| author | 2024-02-08 16:17:56 -0800 | |
|---|---|---|
| committer | 2024-02-09 04:21:53 +0000 | |
| commit | 1831ffd4f04f1be892fe6b69ddd4d687cb0f67c8 (patch) | |
| tree | 52106908e92b7ed0fd2d711c30e107711c21c4ad /java/src | |
| parent | 4a5e78828127b5c1bcd304883163f6dc23db244b (diff) | |
Shareousel selection change callback component
A building block for payload toggling functinality. A component that
selectin change callback invocation.
Bug: 302691505
Test: IntentResolver-tests-unit
Change-Id: I02d99dedb6166568ecae1e52973df90598601c9d
Diffstat (limited to 'java/src')
| -rw-r--r-- | java/src/com/android/intentresolver/contentpreview/PayloadToggleInteractor.kt | 3 | ||||
| -rw-r--r-- | java/src/com/android/intentresolver/contentpreview/SelectionChangeCallback.kt | 70 |
2 files changed, 73 insertions, 0 deletions
diff --git a/java/src/com/android/intentresolver/contentpreview/PayloadToggleInteractor.kt b/java/src/com/android/intentresolver/contentpreview/PayloadToggleInteractor.kt index 87f53e85..ca868226 100644 --- a/java/src/com/android/intentresolver/contentpreview/PayloadToggleInteractor.kt +++ b/java/src/com/android/intentresolver/contentpreview/PayloadToggleInteractor.kt @@ -17,6 +17,7 @@ package com.android.intentresolver.contentpreview import android.net.Uri +import android.service.chooser.ChooserAction import android.util.SparseArray import java.io.Closeable import kotlinx.coroutines.flow.Flow @@ -51,6 +52,8 @@ class PayloadToggleInteractor { val previewUri: Uri?, ) + data class CallbackResult(val customActions: List<ChooserAction>?) + interface CursorReader : Closeable { val count: Int val hasMoreBefore: Boolean diff --git a/java/src/com/android/intentresolver/contentpreview/SelectionChangeCallback.kt b/java/src/com/android/intentresolver/contentpreview/SelectionChangeCallback.kt new file mode 100644 index 00000000..2cc58a97 --- /dev/null +++ b/java/src/com/android/intentresolver/contentpreview/SelectionChangeCallback.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.intentresolver.contentpreview + +import android.content.ContentInterface +import android.content.Intent +import android.content.Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS +import android.content.Intent.EXTRA_INTENT +import android.net.Uri +import android.os.Bundle +import android.service.chooser.ChooserAction +import com.android.intentresolver.contentpreview.PayloadToggleInteractor.CallbackResult + +// TODO: replace with the new API AdditionalContentContract$MethodNames#ON_SELECTION_CHANGED +private const val MethodName = "onSelectionChanged" + +/** + * Encapsulates payload change callback invocation to the sharing app; handles callback arguments + * and result format mapping. + */ +class SelectionChangeCallback( + private val uri: Uri, + private val chooserIntent: Intent, + private val contentResolver: ContentInterface, +) : (Intent) -> CallbackResult? { + fun onSelectionChanged(targetIntent: Intent): CallbackResult? = + contentResolver + .call( + requireNotNull(uri.authority) { "URI authority can not be null" }, + MethodName, + uri.toString(), + Bundle().apply { + putParcelable( + EXTRA_INTENT, + Intent(chooserIntent).apply { putExtra(EXTRA_INTENT, targetIntent) } + ) + } + ) + ?.let { bundle -> + val actions = + if (bundle.containsKey(EXTRA_CHOOSER_CUSTOM_ACTIONS)) { + bundle + .getParcelableArray( + EXTRA_CHOOSER_CUSTOM_ACTIONS, + ChooserAction::class.java + ) + ?.filterNotNull() + ?: emptyList() + } else { + null + } + CallbackResult(actions) + } + + override fun invoke(targetIntent: Intent) = onSelectionChanged(targetIntent) +} |