Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/com/example/cahier/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class MainActivity : ComponentActivity() {
setContent {
CahierAppTheme {
Surface(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
CahierApp(noteId = noteId, noteType = noteType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@

package com.example.cahier.core.utils

import android.app.Activity
import android.app.PendingIntent
import android.content.ClipData
import android.content.ClipDescription
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.view.DragAndDropPermissions
import android.view.View
import androidx.activity.ComponentActivity
import androidx.annotation.RequiresApi
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.draganddrop.dragAndDropSource
import androidx.compose.ui.Modifier
import androidx.compose.ui.draganddrop.DragAndDropEvent
import androidx.compose.ui.draganddrop.DragAndDropTarget
import androidx.compose.ui.draganddrop.DragAndDropTransferData
import androidx.compose.ui.draganddrop.toAndroidDragEvent
import com.example.cahier.AppArgs
import com.example.cahier.core.data.Note

@OptIn(ExperimentalFoundationApi::class)
fun createDropTarget(
Expand All @@ -43,3 +56,38 @@ fun createDropTarget(
}
}
}

fun Modifier.createDragAndDropSource(
activity: Activity?,
note: Note
): Modifier = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
dragAndDropSource { _ ->
activity?.let {
DragAndDropTransferData(
clipData = getClipData(it, note),
flags = View.DRAG_FLAG_GLOBAL_SAME_APPLICATION or View.DRAG_FLAG_START_INTENT_SENDER_ON_UNHANDLED_DRAG,
)
}
}
} else {
this
}

@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
fun getClipData(activity: Activity, note: Note): ClipData {
val componentName = activity.componentName
val intent = Intent.makeMainActivity(componentName).apply {
putExtra(AppArgs.NOTE_ID_KEY, note.id)
putExtra(AppArgs.NOTE_TYPE_KEY, note.type)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_MULTIPLE_TASK or
Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT
}
val pendingIntent = PendingIntent.getActivity(
activity, 0, intent, PendingIntent.FLAG_IMMUTABLE
)
return ClipData(
AppArgs.NOTE_ID_KEY, arrayOf(ClipDescription.MIMETYPE_TEXT_INTENT),
ClipData.Item.Builder().setIntentSender(pendingIntent.intentSender).build()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.example.cahier.features.home

import androidx.activity.compose.LocalActivity
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand Down Expand Up @@ -75,6 +76,7 @@ import com.example.cahier.R
import com.example.cahier.core.data.Note
import com.example.cahier.core.data.NoteType
import com.example.cahier.core.ui.theme.CahierAppTheme
import com.example.cahier.core.utils.createDragAndDropSource
import com.example.cahier.features.drawing.DrawingDetailThumbnail

@Composable
Expand Down Expand Up @@ -203,17 +205,20 @@ fun NoteItem(
modifier: Modifier = Modifier
) {
OutlinedCard(
onClick = onClick,
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
colors = CardDefaults.cardColors(
containerColor = if (isSelected) MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.surfaceContainerLow
),
modifier = modifier
.fillMaxWidth()
.clip(CardDefaults.outlinedShape)
.clickable { onClick() }
modifier = modifier.fillMaxWidth()
) {
NoteItemContent(note)
NoteItemContent(
note = note,
modifier = Modifier
.fillMaxWidth()
.createDragAndDropSource(LocalActivity.current, note)
)
NoteItemActions(onToggleFavorite, note, onDelete, onNewWindow, isCompact)
}
}
Expand Down
Loading