import UriInputField from '@/mdx-components/UriInputField';
import InlineNotification from '@/ds-components/InlineNotification';
import Steps from '@/mdx-components/Steps';
import Step from '@/mdx-components/Step';

<Steps>

<Step
  title="Integrate Logto Android SDK"
  subtitle="Add Logto SDK as a dependency"
>

<InlineNotification>The minimum supported Android API is level 24</InlineNotification>

Add the `mavenCentral()` repository to your Gradle project build file:

```kotlin
repositories {
    mavenCentral()
}
```

Add Logto Android SDK to your dependencies:

```groovy
dependencies {
    implementation 'io.logto.sdk:android:1.0.0'
}
```

</Step>

<Step
  title="Init LogtoClient"
  subtitle="1 step"
>

<pre>
  <code className="language-java">
    {`import io.logto.sdk.android.LogtoClient;
import io.logto.sdk.android.type.LogtoConfig;

public class MainActivity extends AppCompatActivity {
    private LogtoClient logtoClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LogtoConfig logtoConfig = new LogtoConfig(
            "${props.endpoint}",
            "${props.app.id}",
            null,
            null,
            true
        );

        logtoClient = new LogtoClient(logtoConfig, getApplication());
    }
}`}
  </code>
</pre>

</Step>

<Step
  title="Sign in"
  subtitle="2 steps"
>

### Configure Redirect URI

First, let’s configure your redirect URI. E.g. `io.logto.android://io.logto.sample/callback`

<UriInputField name="redirectUris" />

Go back to your IDE/editor, use the following code to implement sign-in:

<pre>
  <code className="language-java">
    {`logtoClient.signIn(this, "${
      props.redirectUris[0] ?? '<your-redirect-uri>'
    }", logtoException -> {
    // User signed in successfully if \`logtoException\` is null.
});`}
  </code>
</pre>

After signing in successfully, `logtoClient.isAuthenticated` will be `true`.

</Step>

<Step
  title="Sign out"
  subtitle="1 step"
>

Calling `.signOut(completion)` will always clear local credentials even if errors occurred.

```java
logtoClient.signOut(logtoException -> {
    // Local credentials are cleared regardless of whether `logtoException` is null.
});
```

</Step>

</Steps>
