-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crypto Transfer Component - ViewModel (#224)
* Add base view and viewModel * Add all ViewModel logic * Add PreQuote * More tests * More more tests * Update kover to 0.7.4 * 100% coverage * Refactor AssetPipe trade to preQuote
- Loading branch information
1 parent
7cf7de8
commit ff3b579
Showing
21 changed files
with
1,330 additions
and
27 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
78 changes: 78 additions & 0 deletions
78
SDKAndroid/src/main/kotlin/app/cybrid/sdkandroid/components/CryptoTransferView.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,78 @@ | ||
package app.cybrid.sdkandroid.components | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.compose.material.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import app.cybrid.sdkandroid.R | ||
import app.cybrid.sdkandroid.components.cryptoTransfer.compose.CryptoTransferView_Loading | ||
import app.cybrid.sdkandroid.components.cryptoTransfer.view.CryptoTransferViewModel | ||
import app.cybrid.sdkandroid.components.wallets.compose.ExternalWalletsView_CreateWallet | ||
import app.cybrid.sdkandroid.components.wallets.compose.ExternalWalletsView_Loading | ||
import app.cybrid.sdkandroid.components.wallets.compose.ExternalWalletsView_Wallet | ||
import app.cybrid.sdkandroid.components.wallets.compose.ExternalWalletsView_Wallets | ||
import app.cybrid.sdkandroid.core.Constants | ||
|
||
class CryptoTransferView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyle: Int = 0): | ||
Component(context, attrs, defStyle) | ||
{ | ||
|
||
enum class State { LOADING, CONTENT, ERROR } | ||
enum class ModalState { LOADING, QUOTE, DONE, ERROR } | ||
|
||
private var cryptoTransferViewModel: CryptoTransferViewModel? = null | ||
|
||
init { | ||
|
||
LayoutInflater.from(context).inflate(R.layout.base_component, this, true) | ||
this.composeView = findViewById(R.id.composeContent) | ||
} | ||
|
||
fun setViewModel(cryptoTransferViewModel: CryptoTransferViewModel) { | ||
|
||
this.cryptoTransferViewModel = cryptoTransferViewModel | ||
this.initComposeView() | ||
/*this.externalWalletViewModel?.viewModelScope?.launch { | ||
externalWalletViewModel.fetchExternalWallets() | ||
}*/ | ||
} | ||
|
||
private fun initComposeView() { | ||
|
||
this.composeView?.let { compose -> | ||
compose.setContent { | ||
CryptoTransferView(cryptoTransferViewModel = cryptoTransferViewModel!!) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun CryptoTransferView( | ||
cryptoTransferViewModel: CryptoTransferViewModel | ||
) { | ||
|
||
// -- Content | ||
Surface( | ||
modifier = Modifier | ||
.testTag(Constants.AccountsViewTestTags.Surface.id) | ||
) { | ||
|
||
when(cryptoTransferViewModel.uiState.value) { | ||
|
||
CryptoTransferView.State.LOADING -> { | ||
CryptoTransferView_Loading() | ||
} | ||
|
||
else -> { | ||
CryptoTransferView_Loading() | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...droid/src/main/kotlin/app/cybrid/sdkandroid/components/activity/CryptoTransferActivity.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,25 @@ | ||
package app.cybrid.sdkandroid.components.activity | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import app.cybrid.sdkandroid.R | ||
import app.cybrid.sdkandroid.components.CryptoTransferView | ||
import app.cybrid.sdkandroid.components.cryptoTransfer.view.CryptoTransferViewModel | ||
|
||
class CryptoTransferActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
|
||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_crypto_transfer) | ||
|
||
// -- Creating viewModel | ||
val cryptoTransferViewModel: CryptoTransferViewModel by viewModels() | ||
|
||
// -- Finding the view | ||
val cryptoTransferView: CryptoTransferView = findViewById(R.id.view) | ||
|
||
// -- Set ViewModel to the View | ||
cryptoTransferView.setViewModel(cryptoTransferViewModel) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...lin/app/cybrid/sdkandroid/components/cryptoTransfer/compose/CryptoTransferView_Loading.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,31 @@ | ||
package app.cybrid.sdkandroid.components.cryptoTransfer.compose | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import app.cybrid.sdkandroid.R | ||
import app.cybrid.sdkandroid.components.Component | ||
|
||
@Composable | ||
fun CryptoTransferView_Loading() { | ||
|
||
ConstraintLayout( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
|
||
// -- Vars | ||
val (loader) = createRefs() | ||
|
||
// -- Content | ||
Component.CreateLoader(modifier = | ||
Modifier.constrainAs(loader) { | ||
centerHorizontallyTo(parent) | ||
centerVerticallyTo(parent) | ||
}, | ||
message = stringResource(id = R.string.crypto_transfer_view_loading_title) | ||
) | ||
} | ||
} |
Oops, something went wrong.