Skip to content

Commit

Permalink
Update android example
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Aug 13, 2024
1 parent eeeef18 commit 3a8129a
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.bitwarden.myapplication

import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewTreeObserver
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -22,6 +24,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import com.bitwarden.core.DateTime
import com.bitwarden.vault.Folder
import com.bitwarden.core.InitOrgCryptoRequest
Expand Down Expand Up @@ -87,9 +90,31 @@ class MainActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
biometric = Biometric(this)
client = Client(null)

http = httpClient()

lifecycleScope.launch {
client = Client.factory(null)
}

// Set up an OnPreDrawListener to the root view.
val content: View = findViewById(android.R.id.content)
content.viewTreeObserver.addOnPreDrawListener(
object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
// Check whether the initial data is ready.
return if (client != null) {
// The content is ready. Start drawing.
content.viewTreeObserver.removeOnPreDrawListener(this)
true
} else {
// The content isn't ready. Suspend.
false
}
}
}
)

setContent {
MyApplicationTheme {
// A surface container using the 'background' color from the theme
Expand Down Expand Up @@ -161,7 +186,7 @@ class MainActivity : FragmentActivity() {
Button({
GlobalScope.launch {
client.destroy()
client = Client(null)
client = Client.factory(null)
outputText.value = "OK"
}
}) {
Expand Down

0 comments on commit 3a8129a

Please sign in to comment.