Skip to content

Commit

Permalink
Merge pull request #1 from RampNetwork/feature/different-context-inje…
Browse files Browse the repository at this point in the history
…ction

replaced context with activity and moved from constructor
  • Loading branch information
macbem authored Aug 16, 2021
2 parents 31257cd + 2914a91 commit f46e0c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions demo/src/main/java/ramp/network/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

rampSdk = RampSDK(this)
rampSdk = RampSDK()

button.setOnClickListener {
// 3. Fill configuration object with your data
// 3. Fill configuration object with your data
val config = Config(
hostLogoUrl = "https://example.com/logo.png",
hostLogoUrl = "https://ramp.network/assets/images/Logo.svg",
hostAppName = "My App",
userAddress = "0x4b7f8e04b82ad7f9e4b4cc9e1f81c5938e1b719f",
url = "https://ri-widget-staging.firebaseapp.com/",
Expand All @@ -32,7 +32,7 @@ class MainActivity : AppCompatActivity() {
fiatValue = "10",
selectedCountryCode = "US"
)
// 4. Implement callbacks
// 4. Implement callbacks
val callback = object : RampCallback {
override fun onPurchaseFailed() {

Expand All @@ -50,8 +50,8 @@ class MainActivity : AppCompatActivity() {

}
}
// 5. Start widget
rampSdk.startTransaction(config, callback)
// 5. Start widget
rampSdk.startTransaction(this, config, callback)

}
}
Expand Down
9 changes: 5 additions & 4 deletions rampsdk/src/main/java/network/ramp/sdk/facade/RampSDK.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package network.ramp.sdk.facade

import android.app.Activity
import android.content.Context
import android.content.Intent
import network.ramp.sdk.BuildConfig
Expand All @@ -12,7 +13,7 @@ import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import timber.log.Timber

class RampSDK(private val context: Context) {
class RampSDK {

private var callback: RampCallback? = null

Expand All @@ -22,15 +23,15 @@ class RampSDK(private val context: Context) {
}
}

fun startTransaction(config: Config, callback: RampCallback) {
fun startTransaction(activity: Activity, config: Config, callback: RampCallback) {
release()
this.callback = callback
EventBus.getDefault().register(this)
val intent = Intent(context, RampWidgetActivity::class.java)
val intent = Intent(activity, RampWidgetActivity::class.java)
intent.putExtra(
CONFIG_EXTRA, config
)
context.startActivity(intent)
activity.startActivity(intent)
}

private fun release() {
Expand Down

0 comments on commit f46e0c4

Please sign in to comment.