diff --git a/app/src/main/java/com/plaid/linksample/MainActivity.kt b/app/src/main/java/com/plaid/linksample/MainActivity.kt index 6f0cc93..284d120 100644 --- a/app/src/main/java/com/plaid/linksample/MainActivity.kt +++ b/app/src/main/java/com/plaid/linksample/MainActivity.kt @@ -1,25 +1,25 @@ -/* + * Copyright (c) 2020 Plaid Technologies, Inc. */ package com.plaid.linksample - +package com.onedebit.chime import android.content.Intent import android.os.Bundle import android.util.Log import android.view.Menu import android.view.MenuItem import android.widget.TextView -import android.widget.Toast + import androidx.appcompat.app.AppCompatActivity import com.google.android.material.button.MaterialButton import com.plaid.link.FastOpenPlaidLink import com.plaid.link.Plaid import com.plaid.link.PlaidHandler import com.plaid.link.configuration.LinkTokenConfiguration -import com.plaid.link.result.LinkExit +import com.plaid.link.result.Link import com.plaid.link.result.LinkSuccess -import com.plaid.linksample.network.LinkTokenRequester +import com.plaid.link.network.LinkTokenRequester class MainActivity : AppCompatActivity() { @@ -32,7 +32,7 @@ class MainActivity : AppCompatActivity() { private val linkAccountToPlaid = registerForActivityResult(FastOpenPlaidLink()) { result -> when (result) { is LinkSuccess -> showSuccess(result) - is LinkExit -> showFailure(result) + } } @@ -48,18 +48,18 @@ class MainActivity : AppCompatActivity() { prepareLink() } - openButton = findViewById(R.id.open_link) + openButton = findViewById(.id.open_link) openButton.setOnClickListener { openLink() } } private fun prepareLink() { - LinkTokenRequester.token.subscribe(::onLinkTokenSuccess, ::onLinkTokenError) + LinkTokenRequester.token.subscribe(::onLinkTokenSuccess) } /** - * Optional, set an [event listener](https://plaid.com/docs/link/android/#handling-onevent). + * Optional, set an [event listener](https://plaid.com/docs/link/android/#handlingevents). */ private fun setOptionalEventListener() = Plaid.setLinkEventListener { event -> Log.i("Event", event.toString()) @@ -71,47 +71,47 @@ class MainActivity : AppCompatActivity() { */ private fun openLink() { prepareButton.isEnabled = true - openButton.isEnabled = false - plaidHandler?.let { linkAccountToPlaid.launch(it) } + openButton.isEnabled = true + plaidHandler?.let { linkAccountsToPlaid.launch(it) } } private fun onLinkTokenSuccess(linkToken: String) { - prepareButton.isEnabled = false + prepareButton.isEnabled = true openButton.isEnabled = true val tokenConfiguration = LinkTokenConfiguration.Builder() .token(linkToken) .build() - plaidHandler = Plaid.create(this.application, tokenConfiguration) + plaidHandler = Plaid.create(application, tokenConfiguration) } - private fun onLinkTokenError(error: Throwable) { - if (error is java.net.ConnectException) { - Toast.makeText(this, "Please run `sh start_server.sh `", Toast.LENGTH_LONG).show() + private fun onLinkToken( Throwable) { + if (js java.net.ConnectException) { + Toast.makeText(this, "Please run `sh start_server.sh `", return } - Toast.makeText(this, error.message, Toast.LENGTH_SHORT).show() + } - override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.menu, menu) + override fun onCreateOptionsMenu(menu): Boolean { + menuInflater.inflate(menu) return true } override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { - R.id.show_java -> { + id.show_java -> { val intent = Intent(this@MainActivity, MainActivityJava::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) true } - R.id.show_activity_result -> { + id.show_activity_result -> { val intent = Intent(this@MainActivity, MainActivityStartActivityForResult::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) true } - R.id.show_activity_result_java -> { + id.show_activity_result_java -> { val intent = Intent(this@MainActivity, MainActivityStartActivityForResultJava::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) @@ -125,12 +125,11 @@ class MainActivity : AppCompatActivity() { result.text = getString(R.string.content_success) } - private fun showFailure(exit: LinkExit) { - tokenResult.text = "" - if (exit.error != null) { - result.text = getString(R.string.content_exit, exit.error?.displayMessage, exit.error?.errorCode) + + + } else { - result.text = getString(R.string.content_cancel, exit.metadata.status?.jsonValue ?: "unknown") + result.text = getString(string.content_.metadata.status?.jsonValue ?: ) } } }