Skip to content

Commit

Permalink
Compose About: add website and privacy button.
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed May 11, 2022
1 parent 7812995 commit 9eb6d17
Showing 1 changed file with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ import android.os.Bundle
import android.view.MenuItem
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SmallTopAppBar
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.ui.SeriesGuidePreferences
import com.battlelancer.seriesguide.util.Utils
import com.google.android.material.composethemeadapter3.Mdc3Theme

/**
Expand All @@ -21,20 +37,59 @@ class AboutActivity : ComponentActivity() {

setContent {
Mdc3Theme {
About()
About(
onBackPressed = { onBackPressed() },
onOpenWebsite = { viewUrl(R.string.url_website) },
onOpenPrivacyPolicy = { viewUrl(R.string.url_privacy) }
)
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun About() {
Text(text = "About SeriesGuide")
fun About(
onBackPressed: () -> Unit,
onOpenWebsite: () -> Unit,
onOpenPrivacyPolicy: () -> Unit
) {
Scaffold(
topBar = {
SmallTopAppBar(
title = { Text(text = stringResource(id = R.string.prefs_category_about)) },
navigationIcon = {
IconButton(onClick = onBackPressed) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.navigate_back)
)
}
}
)
},
content = { scaffoldPadding ->
Box(modifier = Modifier.padding(scaffoldPadding)) {
Column() {
Button(onClick = onOpenWebsite) {
Text(text = stringResource(id = R.string.website))
}
Button(onClick = onOpenPrivacyPolicy) {
Text(text = stringResource(id = R.string.privacy_policy))
}
}
}
}
)
}

@Preview
@Composable
fun AboutPreview() {
About()
About(
{},
{},
{}
)
}

// private fun setupActionBar() {
Expand All @@ -53,4 +108,8 @@ class AboutActivity : ComponentActivity() {
}
}

private fun viewUrl(@StringRes urlResId: Int) {
Utils.launchWebsite(this, getString(urlResId))
}

}

0 comments on commit 9eb6d17

Please sign in to comment.