Skip to content

Commit

Permalink
Fixed app crash when clipboard is null + notify user
Browse files Browse the repository at this point in the history
  • Loading branch information
tohrxyz committed Jan 15, 2023
1 parent 72784c6 commit cf31926
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
)
Expand Down Expand Up @@ -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"
}
Expand Down

0 comments on commit cf31926

Please sign in to comment.