add disableClipboard

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-11-04 15:47:44 +01:00 committed by Alper Öztürk
parent 3134ab1936
commit f682715292

View file

@ -10,10 +10,13 @@ import android.app.Activity
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.RestrictionsManager
import android.text.TextUtils import android.text.TextUtils
import android.widget.Toast import android.widget.Toast
import com.nextcloud.utils.extensions.getRestriction
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.utils.appConfig.AppConfigKeys
/** /**
* Helper implementation to copy a string into the system clipboard. * Helper implementation to copy a string into the system clipboard.
@ -25,6 +28,15 @@ object ClipboardUtil {
@JvmOverloads @JvmOverloads
@Suppress("TooGenericExceptionCaught") @Suppress("TooGenericExceptionCaught")
fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) {
val restrictionsManager = activity.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
val disableClipboard = restrictionsManager.getRestriction(
AppConfigKeys.DisableClipboard.key,
activity.resources.getBoolean(R.bool.disable_clipboard)
)
if (disableClipboard) {
return
}
if (!TextUtils.isEmpty(text)) { if (!TextUtils.isEmpty(text)) {
try { try {
val clip = ClipData.newPlainText( val clip = ClipData.newPlainText(