Merge pull request #1557 from tiwiz/drag-feature-only

Add drag feature
pull/1578/head
Roberto Orgiu 2 months ago committed by GitHub
commit 6de7c8f42a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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,19 @@ fun NewsResourceCardExpanded(
modifier: Modifier = Modifier,
) {
val clickActionLabel = stringResource(R.string.core_ui_card_tap_action)
val sharingLabel = stringResource(R.string.core_ui_feed_sharing)
val sharingContent = stringResource(
R.string.core_ui_feed_sharing_data,
userNewsResource.title,
userNewsResource.url,
)
val dragAndDropFlags = if (VERSION.SDK_INT >= VERSION_CODES.N) {
View.DRAG_FLAG_GLOBAL
} else {
0
}
Card(
onClick = onClick,
shape = RoundedCornerShape(16.dp),
@ -112,7 +134,23 @@ fun NewsResourceCardExpanded(
Row {
NewsResourceTitle(
userNewsResource.title,
modifier = Modifier.fillMaxWidth((.8f)),
modifier = Modifier
.fillMaxWidth((.8f))
.dragAndDropSource {
detectTapGestures(
onLongPress = {
startTransfer(
DragAndDropTransferData(
ClipData.newPlainText(
sharingLabel,
sharingContent,
),
flags = dragAndDropFlags,
),
)
},
)
},
)
Spacer(modifier = Modifier.weight(1f))
BookmarkButton(isBookmarked, onToggleBookmark)

@ -29,4 +29,6 @@
<string name="core_ui_interests_card_follow_button_content_desc">Follow interest</string>
<string name="core_ui_interests_card_unfollow_button_content_desc">Unfollow interest</string>
<string name="core_ui_feed_sharing">Feed sharing</string>
<string name="core_ui_feed_sharing_data">%1$s: %2$s</string>
</resources>

Loading…
Cancel
Save