Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MainActivity.kt #292

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions app/src/main/java/com/plaid/linksample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*

* Copyright (c) 2020 Plaid Technologies, Inc. <[email protected]>
*/

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() {

Expand All @@ -32,7 +32,7 @@ class MainActivity : AppCompatActivity() {
private val linkAccountToPlaid = registerForActivityResult(FastOpenPlaidLink()) { result ->
when (result) {
is LinkSuccess -> showSuccess(result)
is LinkExit -> showFailure(result)

}
}

Expand All @@ -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())
Expand All @@ -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 <client_id> <sandbox_secret>`", Toast.LENGTH_LONG).show()
private fun onLinkToken( Throwable) {
if (js java.net.ConnectException) {
Toast.makeText(this, "Please run `sh start_server.sh <client_id> <sandbox_secret>`",
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)
Expand All @@ -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 ?: )
}
}
}