Skip to content

Commit

Permalink
a few example UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 26, 2024
1 parent 29c9e07 commit e96d81a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class ConnectWalletFragment : Fragment() {
viewModel.generateWallet()
}

binding.savedWalletButton.setOnClickListener {
viewModel.savedWallet()
}

val isConnectWalletAvailable = isConnectAvailable()
binding.connectButton.isEnabled = isConnectWalletAvailable
binding.connectError.isVisible = !isConnectWalletAvailable
Expand Down Expand Up @@ -115,6 +119,7 @@ class ConnectWalletFragment : Fragment() {
private fun showError(message: String) {
binding.progress.visibility = View.GONE
binding.generateButton.visibility = View.VISIBLE
binding.savedWalletButton.visibility = View.VISIBLE
binding.connectButton.visibility = View.VISIBLE
binding.connectError.isVisible = !isConnectAvailable()
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
Expand All @@ -125,6 +130,8 @@ class ConnectWalletFragment : Fragment() {
binding.generateButton.visibility = View.GONE
binding.connectButton.visibility = View.GONE
binding.connectError.visibility = View.GONE
binding.savedWalletButton.visibility = View.GONE

}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.web3j.utils.Numeric
import org.xmtp.android.example.ClientManager
import org.xmtp.android.example.account.WalletConnectV2Account
import org.xmtp.android.library.Client
Expand Down Expand Up @@ -98,6 +99,26 @@ class ConnectWalletViewModel(application: Application) : AndroidViewModel(applic
}
}

@UiThread
fun savedWallet() {
viewModelScope.launch(Dispatchers.IO) {
_uiState.value = ConnectUiState.Loading
try {
val privateKeyData = Numeric.hexStringToByteArray("0x2429cd5b39334e854cb26dfe2037293cd1ccc980e366a35fa6a09cdbef070bda")
// Use hardcoded privateKey
val privateKey = PrivateKeyBuilder.buildFromPrivateKeyData(privateKeyData)
val wallet = PrivateKeyBuilder(privateKey)
val client = Client().create(wallet, ClientManager.clientOptions(getApplication()))
_uiState.value = ConnectUiState.Success(
wallet.getAddress(),
PrivateKeyBundleV1Builder.encodeData(client.privateKeyBundleV1)
)
} catch (e: XMTPException) {
_uiState.value = ConnectUiState.Error(e.message.orEmpty())
}
}
}

@UiThread
fun connectWallet(approvedSession: Modal.Model.ApprovedSession) {
viewModelScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class ConversationDetailActivity : AppCompatActivity() {
setSupportActionBar(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.subtitle = if (peerAddress != null && peerAddress!!.contains(",")) {
val addresses = peerAddress?.split(",")?.toMutableList()
addresses?.joinToString(" -- ") {
val addresses = peerAddress?.split(",")?.toMutableList()?.drop(1)
addresses?.joinToString(" & ") {
it.truncatedAddress()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ConversationViewHolder(
fun bind(item: MainViewModel.MainListItem.ConversationItem) {
conversation = item.conversation
binding.peerAddress.text = if (item.conversation.peerAddress.contains(",")) {
val addresses = item.conversation.peerAddress.split(",")
addresses.joinToString(" -- ") {
val addresses = item.conversation.peerAddress.split(",").drop(1)
addresses.joinToString(" & ") {
it.truncatedAddress()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MessageViewHolder(
binding.root.resources.getColor(R.color.teal_700, binding.root.context.theme)

fun bind(item: ConversationDetailViewModel.MessageListItem.Message) {
val isFromMe = ClientManager.client.address == item.message.senderAddress
val isFromMe = ClientManager.client.address.lowercase() == item.message.senderAddress.lowercase()
val params = binding.messageContainer.layoutParams as ConstraintLayout.LayoutParams
if (isFromMe) {
params.rightToRight = PARENT_ID
Expand Down
13 changes: 12 additions & 1 deletion example/src/main/res/layout/fragment_connect_wallet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/savedWalletButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding"
android:text="Saved Wallet"
app:layout_constraintBottom_toTopOf="@id/connectButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/generateButton" />

<com.google.android.material.button.MaterialButton
android:id="@+id/connectButton"
android:layout_width="match_parent"
Expand All @@ -43,7 +54,7 @@
android:layout_marginEnd="@dimen/padding"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/generateButton" />
app:layout_constraintTop_toBottomOf="@id/savedWalletButton" />

<TextView
android:id="@+id/connectError"
Expand Down

0 comments on commit e96d81a

Please sign in to comment.