From cf319261c7aadd82354fa315d5c8ee48cd25be9a Mon Sep 17 00:00:00 2001 From: tomashrib Date: Sun, 15 Jan 2023 15:39:04 +0100 Subject: [PATCH] Fixed app crash when clipboard is null + notify user --- .../zephyruswallet/ui/wallet/SendScreen.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/xyz/tomashrib/zephyruswallet/ui/wallet/SendScreen.kt b/app/src/main/java/xyz/tomashrib/zephyruswallet/ui/wallet/SendScreen.kt index c99d3cb..73a7ca8 100644 --- a/app/src/main/java/xyz/tomashrib/zephyruswallet/ui/wallet/SendScreen.kt +++ b/app/src/main/java/xyz/tomashrib/zephyruswallet/ui/wallet/SendScreen.kt @@ -91,10 +91,15 @@ internal fun SendScreen(navController: NavController, context: Context){ .align(Alignment.End) //upon click, the address from clipboard is inserted into recipientAddress input field .clickable { - if(pasteFromClipboard(context) != "Wrong format"){ - recipientAddress.value = pasteFromClipboard(context) - } else { - Toast.makeText(context, "Wrong address format", Toast.LENGTH_SHORT).show() + try{ + if(pasteFromClipboard(context) != "Wrong format"){ + recipientAddress.value = pasteFromClipboard(context) + } else { + Toast.makeText(context, "Wrong address format", Toast.LENGTH_SHORT).show() + } + }catch (e: Exception){ + Toast.makeText(context, "Empty clipboard", Toast.LENGTH_SHORT).show() + Log.i(TAG, "Error while pasting from clipboard: $e") } } ) @@ -358,7 +363,7 @@ private fun pasteFromClipboard(context: Context): String{ val item = clipboardManager.primaryClip!!.getItemAt(0) //check if null - if(item == null || item.text == null){ + if(item == null || item.text == null || clipboardManager.primaryClip == null){ return "Wrong format" //could return "Null input" }