-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
155 additions
and
143 deletions.
There are no files selected for viewing
62 changes: 8 additions & 54 deletions
62
android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/button/TestMethodButton.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 |
---|---|---|
@@ -1,82 +1,36 @@ | ||
package net.mullvad.mullvadvpn.compose.button | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.tooling.preview.PreviewParameter | ||
import net.mullvad.mullvadvpn.R | ||
import net.mullvad.mullvadvpn.compose.component.MullvadCircularProgressIndicatorSmall | ||
import net.mullvad.mullvadvpn.compose.preview.TestMethodButtonPreviewParameterProvider | ||
import net.mullvad.mullvadvpn.lib.model.TestApiAccessMethodState | ||
import net.mullvad.mullvadvpn.lib.theme.AppTheme | ||
import net.mullvad.mullvadvpn.lib.theme.Dimens | ||
import net.mullvad.mullvadvpn.lib.theme.color.selected | ||
|
||
@Preview | ||
@Composable | ||
private fun PreviewTestMethodButton( | ||
@PreviewParameter(provider = TestMethodButtonPreviewParameterProvider::class) | ||
state: TestApiAccessMethodState? | ||
@PreviewParameter(provider = TestMethodButtonPreviewParameterProvider::class) isTesting: Boolean | ||
) { | ||
AppTheme { TestMethodButton(testMethodState = state, onTestMethod = {}) } | ||
AppTheme { TestMethodButton(isTesting = isTesting, onTestMethod = {}) } | ||
} | ||
|
||
@Composable | ||
fun TestMethodButton( | ||
modifier: Modifier = Modifier, | ||
testMethodState: TestApiAccessMethodState?, | ||
onTestMethod: () -> Unit | ||
) { | ||
fun TestMethodButton(modifier: Modifier = Modifier, isTesting: Boolean, onTestMethod: () -> Unit) { | ||
PrimaryButton( | ||
modifier = modifier, | ||
leadingIcon = { Icon(testMethodState = testMethodState) }, | ||
onClick = onTestMethod, | ||
isEnabled = testMethodState !is TestApiAccessMethodState.Testing, | ||
isEnabled = !isTesting, | ||
text = | ||
stringResource( | ||
id = | ||
when (testMethodState) { | ||
TestApiAccessMethodState.Result.Successful -> R.string.api_reachable | ||
TestApiAccessMethodState.Result.Failure -> R.string.api_unreachable | ||
TestApiAccessMethodState.Testing -> R.string.testing | ||
null -> R.string.test_method | ||
if (isTesting) { | ||
R.string.testing | ||
} else { | ||
R.string.test_method | ||
} | ||
), | ||
) | ||
} | ||
|
||
@Composable | ||
private fun Icon(testMethodState: TestApiAccessMethodState?) { | ||
when (testMethodState) { | ||
TestApiAccessMethodState.Result.Failure -> | ||
Box( | ||
modifier = | ||
Modifier.padding(start = Dimens.mediumPadding) | ||
.size(Dimens.relayCircleSize) | ||
.background(color = MaterialTheme.colorScheme.error, shape = CircleShape) | ||
) | ||
TestApiAccessMethodState.Result.Successful -> { | ||
Box( | ||
modifier = | ||
Modifier.padding(start = Dimens.mediumPadding) | ||
.size(Dimens.relayCircleSize) | ||
.background(color = MaterialTheme.colorScheme.selected, shape = CircleShape) | ||
) | ||
} | ||
TestApiAccessMethodState.Testing -> { | ||
MullvadCircularProgressIndicatorSmall( | ||
modifier = Modifier.padding(start = Dimens.mediumPadding) | ||
) | ||
} | ||
null -> { | ||
/*Show nothing*/ | ||
} | ||
} | ||
} |
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
12 changes: 2 additions & 10 deletions
12
...kotlin/net/mullvad/mullvadvpn/compose/preview/TestMethodButtonPreviewParameterProvider.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 |
---|---|---|
@@ -1,15 +1,7 @@ | ||
package net.mullvad.mullvadvpn.compose.preview | ||
|
||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider | ||
import net.mullvad.mullvadvpn.lib.model.TestApiAccessMethodState | ||
|
||
class TestMethodButtonPreviewParameterProvider : | ||
PreviewParameterProvider<TestApiAccessMethodState?> { | ||
override val values: Sequence<TestApiAccessMethodState?> = | ||
sequenceOf( | ||
null, | ||
TestApiAccessMethodState.Testing, | ||
TestApiAccessMethodState.Result.Successful, | ||
TestApiAccessMethodState.Result.Failure | ||
) | ||
class TestMethodButtonPreviewParameterProvider : PreviewParameterProvider<Boolean> { | ||
override val values: Sequence<Boolean> = sequenceOf(false, true) | ||
} |
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
Oops, something went wrong.