Add drag feature

pull/1557/head
Rob Orgiu 4 months ago
parent 420076f01a
commit 4e62d0c084

@ -16,8 +16,15 @@
package com.google.samples.apps.nowinandroid.core.ui
import android.content.ClipData
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.view.View
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.draganddrop.dragAndDropSource
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@ -45,6 +52,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draganddrop.DragAndDropTransferData
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalInspectionMode
@ -77,6 +85,7 @@ import java.util.Locale
* [NewsResource] card used on the following screens: For You, Saved
*/
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun NewsResourceCardExpanded(
userNewsResource: UserNewsResource,
@ -88,6 +97,13 @@ fun NewsResourceCardExpanded(
modifier: Modifier = Modifier,
) {
val clickActionLabel = stringResource(R.string.core_ui_card_tap_action)
val dragAndDropFlags = if (VERSION.SDK_INT >= VERSION_CODES.N) {
View.DRAG_FLAG_GLOBAL
} else {
0
}
Card(
onClick = onClick,
shape = RoundedCornerShape(16.dp),
@ -112,7 +128,22 @@ fun NewsResourceCardExpanded(
Row {
NewsResourceTitle(
userNewsResource.title,
modifier = Modifier.fillMaxWidth((.8f)),
modifier = Modifier.fillMaxWidth((.8f))
.dragAndDropSource {
detectTapGestures(
onLongPress = {
startTransfer(
DragAndDropTransferData(
ClipData.newPlainText(
"Feed sharing",
userNewsResource.title + ": " + userNewsResource.url,
),
flags = dragAndDropFlags,
),
)
},
)
},
)
Spacer(modifier = Modifier.weight(1f))
BookmarkButton(isBookmarked, onToggleBookmark)

Loading…
Cancel
Save