-
Notifications
You must be signed in to change notification settings - Fork 16
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
15 changed files
with
349 additions
and
7 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
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 |
---|---|---|
|
@@ -51,6 +51,7 @@ android { | |
|
||
buildFeatures { | ||
compose = true | ||
buildConfig = true | ||
} | ||
|
||
composeOptions { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.xinto.mauth.ui.component | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
|
||
@Composable | ||
fun rememberUriHandler(): UriHandler { | ||
val context = LocalContext.current | ||
return remember(context) { | ||
UriHandler(context) | ||
} | ||
} | ||
|
||
@Immutable | ||
class UriHandler(private val context: Context) { | ||
|
||
fun openUrl(url: String) { | ||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) | ||
} | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/xinto/mauth/ui/screen/about/AboutLinks.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,32 @@ | ||
package com.xinto.mauth.ui.screen.about | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.compose.runtime.Immutable | ||
import com.xinto.mauth.R | ||
|
||
@Immutable | ||
data class AboutLink( | ||
@DrawableRes | ||
val icon: Int, | ||
|
||
@StringRes | ||
val title: Int, | ||
|
||
val url: String | ||
) { | ||
companion object { | ||
val defaultLinks = setOf( | ||
AboutLink( | ||
icon = R.drawable.ic_github, | ||
title = R.string.about_links_source, | ||
url = "https://github.com/X1nto/Mauth" | ||
), | ||
AboutLink( | ||
icon = R.drawable.ic_bug, | ||
title = R.string.about_links_feedback, | ||
url = "https://github.com/X1nto/Mauth/issues" | ||
), | ||
) | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
app/src/main/java/com/xinto/mauth/ui/screen/about/AboutScreen.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,115 @@ | ||
package com.xinto.mauth.ui.screen.about | ||
|
||
import android.content.res.Configuration | ||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.LargeTopAppBar | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.MediumTopAppBar | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.xinto.mauth.BuildConfig | ||
import com.xinto.mauth.R | ||
import com.xinto.mauth.ui.component.rememberUriHandler | ||
import com.xinto.mauth.ui.screen.about.component.LinkedButton | ||
import com.xinto.mauth.ui.screen.about.component.LinkedButtonsRow | ||
import com.xinto.mauth.ui.theme.MauthTheme | ||
|
||
@Composable | ||
fun AboutScreen( | ||
modifier: Modifier = Modifier, | ||
onBack: () -> Unit, | ||
) { | ||
val uriHandler = rememberUriHandler() | ||
BackHandler(onBack = onBack) | ||
Scaffold( | ||
modifier = modifier, | ||
topBar = { | ||
TopAppBar( | ||
title = { Text(stringResource(R.string.about_title)) }, | ||
navigationIcon = { | ||
IconButton(onClick = onBack) { | ||
Icon( | ||
painter = painterResource(R.drawable.ic_arrow_back), | ||
contentDescription = null | ||
) | ||
} | ||
} | ||
) | ||
} | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(it) | ||
.padding(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
Surface( | ||
shape = CircleShape, | ||
color = MaterialTheme.colorScheme.tertiaryContainer | ||
) { | ||
Icon( | ||
modifier = Modifier.padding(0.dp), | ||
painter = painterResource(R.drawable.ic_launcher_foreground), | ||
contentDescription = null, | ||
) | ||
} | ||
Text( | ||
text = stringResource(R.string.app_name), | ||
style = MaterialTheme.typography.titleLarge | ||
) | ||
Text( | ||
text = stringResource(R.string.about_version, BuildConfig.VERSION_NAME), | ||
style = MaterialTheme.typography.bodyLarge, | ||
color = LocalContentColor.current.copy(alpha = 0.7f) | ||
) | ||
LinkedButtonsRow( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 16.dp) | ||
) { | ||
AboutLink.defaultLinks.forEach { | ||
LinkedButton( | ||
onClick = { uriHandler.openUrl(it.url) }, | ||
icon = { | ||
Icon( | ||
painter = painterResource(it.icon), | ||
contentDescription = null | ||
) | ||
}, | ||
title = { Text(stringResource(it.title)) } | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, showSystemUi = true) | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, showSystemUi = true) | ||
@Composable | ||
fun AboutScreenPreview() { | ||
MauthTheme { | ||
AboutScreen(onBack = {}) | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
app/src/main/java/com/xinto/mauth/ui/screen/about/component/LinkedButtons.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,106 @@ | ||
package com.xinto.mauth.ui.screen.about.component | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.heightIn | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.LocalTextStyle | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.xinto.mauth.R | ||
import com.xinto.mauth.ui.theme.MauthTheme | ||
|
||
@Composable | ||
fun LinkedButtonsRow( | ||
modifier: Modifier = Modifier, | ||
content: @Composable RowScope.() -> Unit | ||
) { | ||
Row( | ||
modifier = modifier | ||
.heightIn(min = 64.dp) | ||
.clip(MaterialTheme.shapes.extraLarge), | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(2.dp) | ||
) { | ||
content() | ||
} | ||
} | ||
|
||
@Composable | ||
fun RowScope.LinkedButton( | ||
onClick: () -> Unit, | ||
icon: @Composable () -> Unit, | ||
title: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Surface( | ||
modifier = modifier.weight(1f), | ||
onClick = onClick, | ||
shape = MaterialTheme.shapes.extraSmall, | ||
color = MaterialTheme.colorScheme.secondaryContainer | ||
) { | ||
Column( | ||
modifier = Modifier.padding(16.dp), | ||
verticalArrangement = Arrangement.spacedBy(4.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Box( | ||
modifier = Modifier.size(24.dp), | ||
propagateMinConstraints = true | ||
) { | ||
icon() | ||
} | ||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) { | ||
title() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) | ||
@Composable | ||
fun LinkedButtonsPreview() { | ||
MauthTheme { | ||
val data = remember { | ||
listOf( | ||
R.drawable.ic_info to "Info", | ||
R.drawable.ic_edit to "Edit", | ||
R.drawable.ic_settings to "Settings", | ||
) | ||
} | ||
LinkedButtonsRow { | ||
data.forEach { | ||
LinkedButton( | ||
onClick = { /*TODO*/ }, | ||
icon = { | ||
Icon( | ||
painter = painterResource(it.first), | ||
contentDescription = null | ||
) | ||
}, | ||
title = { | ||
Text(it.second) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} |
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.