-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #413 from capacitor-community/feat/to_kotlin
feat(android): Java to Kotlin
- Loading branch information
Showing
57 changed files
with
2,475 additions
and
2,366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
...entity/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...identity/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.getcapacitor.android | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see [Testing documentation](http://d.android.com/tools/testing) | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
@Throws(Exception::class) | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
|
||
Assert.assertEquals("com.getcapacitor.android", appContext.packageName) | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
...tity/android/src/main/java/com/getcapacitor/community/stripe/identity/StripeIdentity.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
...entity/android/src/main/java/com/getcapacitor/community/stripe/identity/StripeIdentity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.getcapacitor.community.stripe.identity | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import androidx.core.util.Supplier | ||
import com.getcapacitor.Bridge | ||
import com.getcapacitor.JSObject | ||
import com.getcapacitor.Logger | ||
import com.getcapacitor.PluginCall | ||
import com.getcapacitor.community.stripe.identity.models.Executor | ||
import com.google.android.gms.common.util.BiConsumer | ||
import com.stripe.android.identity.IdentityVerificationSheet | ||
|
||
class StripeIdentity( | ||
contextSupplier: Supplier<Context>, | ||
activitySupplier: Supplier<Activity>, | ||
notifyListenersFunction: BiConsumer<String, JSObject>, | ||
pluginLogTag: String | ||
) : Executor( | ||
contextSupplier, | ||
activitySupplier, | ||
notifyListenersFunction, | ||
pluginLogTag, | ||
"StripeIdentityExecutor" | ||
) { | ||
var verificationSheet: IdentityVerificationSheet? = null | ||
private val emptyObject = JSObject() | ||
|
||
private var verificationId: String? = null | ||
private var ephemeralKeySecret: String? = null | ||
|
||
init { | ||
this.contextSupplier = contextSupplier | ||
} | ||
|
||
fun initialize(call: PluginCall) { | ||
call.resolve() | ||
} | ||
|
||
fun create(call: PluginCall) { | ||
verificationId = call.getString("verificationId", null) | ||
ephemeralKeySecret = call.getString("ephemeralKeySecret", null) | ||
|
||
if (verificationId == null || ephemeralKeySecret == null) { | ||
val errorText = | ||
"Invalid Params. This method require verificationId or ephemeralKeySecret." | ||
notifyListeners( | ||
IdentityVerificationSheetEvent.FailedToLoad.webEventName, | ||
JSObject().put("error", errorText) | ||
) | ||
call.reject(errorText) | ||
return | ||
} | ||
|
||
this.notifyListeners(IdentityVerificationSheetEvent.Loaded.webEventName, emptyObject) | ||
call.resolve() | ||
} | ||
|
||
fun present(call: PluginCall) { | ||
try { | ||
verificationSheet!!.present( | ||
verificationId!!, | ||
ephemeralKeySecret!! | ||
) | ||
Logger.info("Presented Identity Verification Sheet") | ||
} catch (ex: Exception) { | ||
call.reject(ex.localizedMessage, ex) | ||
} | ||
} | ||
|
||
fun onVerificationCompleted(bridge: Bridge, callbackId: String?) { | ||
val call = bridge.getSavedCall(callbackId) | ||
notifyListeners(IdentityVerificationSheetEvent.Completed.webEventName, emptyObject) | ||
call.resolve( | ||
JSObject().put( | ||
"identityVerificationResult", | ||
IdentityVerificationSheetEvent.Completed.webEventName | ||
) | ||
) | ||
} | ||
|
||
fun onVerificationCancelled(bridge: Bridge, callbackId: String?) { | ||
val call = bridge.getSavedCall(callbackId) | ||
notifyListeners(IdentityVerificationSheetEvent.Canceled.webEventName, emptyObject) | ||
call.resolve( | ||
JSObject().put( | ||
"identityVerificationResult", | ||
IdentityVerificationSheetEvent.Canceled.webEventName | ||
) | ||
) | ||
} | ||
|
||
fun onVerificationFailed(bridge: Bridge, callbackId: String?) { | ||
val call = bridge.getSavedCall(callbackId) | ||
notifyListeners(IdentityVerificationSheetEvent.Failed.webEventName, emptyObject) | ||
call.resolve( | ||
JSObject().put( | ||
"identityVerificationResult", | ||
IdentityVerificationSheetEvent.Failed.webEventName | ||
) | ||
) | ||
} | ||
} |
Oops, something went wrong.