From a1e4b2221ced780cd5acc69ed8af90d136d4ba3e Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 16 Nov 2023 09:27:37 +0100 Subject: [PATCH] Convert to kt Signed-off-by: alperozturk --- .../ui/activity/CopyToClipboardActivity.kt | 26 ++++---- .../FileDetailsSharingProcessFragment.kt | 2 +- .../owncloud/android/utils/ClipboardUtil.kt | 60 +++++++++---------- 3 files changed, 38 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.kt index 16bdab55a069..197a0b97a3cd 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.kt @@ -18,26 +18,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +package com.owncloud.android.ui.activity -package com.owncloud.android.ui.activity; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; - -import com.owncloud.android.utils.ClipboardUtil; +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import com.owncloud.android.utils.ClipboardUtil /** * Activity copying the text of the received Intent into the system clipboard. */ -public class CopyToClipboardActivity extends Activity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - ClipboardUtil.copyToClipboard(this, getIntent().getCharSequenceExtra(Intent.EXTRA_TEXT).toString()); - - finish(); +class CopyToClipboardActivity : Activity() { + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + ClipboardUtil.copyToClipboard(this, intent.getCharSequenceExtra(Intent.EXTRA_TEXT).toString()) + finish() } } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt index 43036e056011..4c6d72573fac 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt @@ -545,7 +545,7 @@ class FileDetailsSharingProcessFragment : ) // copy the share link if available if (!TextUtils.isEmpty(share?.shareLink)) { - ClipboardUtil.copyToClipboard(activity, share?.shareLink) + ClipboardUtil.copyToClipboard(requireActivity(), share?.shareLink) } } diff --git a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt index 8c6f62756773..99afa92c784a 100644 --- a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt +++ b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt @@ -17,51 +17,45 @@ * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see . */ +package com.owncloud.android.utils -package com.owncloud.android.utils; - -import android.app.Activity; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.text.TextUtils; -import android.widget.Toast; - -import com.owncloud.android.R; -import com.owncloud.android.lib.common.utils.Log_OC; +import android.app.Activity +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.text.TextUtils +import android.widget.Toast +import com.owncloud.android.R +import com.owncloud.android.lib.common.utils.Log_OC /** * Helper implementation to copy a string into the system clipboard. */ -public final class ClipboardUtil { - private static final String TAG = ClipboardUtil.class.getName(); - - private ClipboardUtil() { - } +object ClipboardUtil { + private val TAG = ClipboardUtil::class.java.name - public static void copyToClipboard(Activity activity, String text) { - copyToClipboard(activity, text, true); - } - - public static void copyToClipboard(Activity activity, String text, boolean showToast) { + @JvmStatic + @JvmOverloads + fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { if (!TextUtils.isEmpty(text)) { try { - ClipData clip = ClipData.newPlainText( - activity.getString( - R.string.clipboard_label, activity.getString(R.string.app_name)), - text - ); - ((ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip); - + val clip = ClipData.newPlainText( + activity.getString( + R.string.clipboard_label, + activity.getString(R.string.app_name) + ), + text + ) + (activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(clip) if (showToast) { - Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show() } - } catch (Exception e) { - Toast.makeText(activity, R.string.clipboard_unexpected_error, Toast.LENGTH_SHORT).show(); - Log_OC.e(TAG, "Exception caught while copying to clipboard", e); + } catch (e: Exception) { + Toast.makeText(activity, R.string.clipboard_unexpected_error, Toast.LENGTH_SHORT).show() + Log_OC.e(TAG, "Exception caught while copying to clipboard", e) } } else { - Toast.makeText(activity, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show() } } }