Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Improved copying of additive details
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasDissa committed Aug 2, 2023
1 parent 39ec3a3 commit 6dc77bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.suhasdissa.foode.backend.viewmodels

import android.content.ClipData
import android.content.ClipboardManager
import android.content.SharedPreferences
import android.util.Log
Expand Down Expand Up @@ -72,10 +73,6 @@ class AdditiveDetailViewModel(
}
}

fun getClipboard(): ClipboardManager {
return clipboard
}

fun getAdditive(id: Int) {
viewModelScope.launch {
additive = additivesRepository.getAdditive(id)
Expand All @@ -91,6 +88,16 @@ class AdditiveDetailViewModel(
}
}

fun copyToClipboard() {
val copyText = with(additive ?: return) {
"$eCode : $title\n${if (halalStatus == 1) "Halal Certified\n" else "\n"}$info"
}
viewModelScope.launch {
val clip: ClipData = ClipData.newPlainText("Additive Details", copyText)
clipboard.setPrimaryClip(clip)
}
}

companion object {
val Factory: ViewModelProvider.Factory = viewModelFactory {
initializer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.suhasdissa.foode.ui.screens

import android.content.ClipData
import android.view.SoundEffectConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
Expand Down Expand Up @@ -101,10 +100,7 @@ fun AdditiveDetailScreen(
}
FloatingActionButton(onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
val copyText =
"${additive.eCode} : ${additive.title}\n\nHalal Status : ${additive.halalStatus}\n\n${additive.info}"
val clip: ClipData = ClipData.newPlainText("Additive Details", copyText)
additiveViewModel.getClipboard().setPrimaryClip(clip)
additiveViewModel.copyToClipboard()
}) {
Icon(
imageVector = Icons.Default.ContentCopy,
Expand Down

0 comments on commit 6dc77bf

Please sign in to comment.