Skip to content

Commit e60e875

Browse files
committed
Use a compose scaffold for the license screen.
Remove the activity_license.xml file.
1 parent b200072 commit e60e875

File tree

4 files changed

+60
-83
lines changed

4 files changed

+60
-83
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
android:name=".about.LicenseActivity"
166166
android:label="@string/license_title"
167167
android:parentActivityName=".about.AboutActivity"
168+
android:theme="@style/AppTheme.NoActionBar"
168169
tools:ignore="UnusedAttribute">
169170
<!-- Parent activity meta-data to support 4.0 -->
170171
<meta-data

app/src/main/kotlin/ca/rmen/android/poetassistant/about/LicenseActivity.kt

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ import android.content.Context
2323
import android.content.Intent
2424
import android.os.Bundle
2525
import android.util.Log
26+
import androidx.activity.compose.setContent
27+
import androidx.activity.enableEdgeToEdge
2628
import androidx.annotation.WorkerThread
2729
import androidx.appcompat.app.AppCompatActivity
28-
import androidx.core.view.updatePadding
29-
import androidx.databinding.DataBindingUtil
3030
import ca.rmen.android.poetassistant.Constants
31-
import ca.rmen.android.poetassistant.R
3231
import ca.rmen.android.poetassistant.dagger.DaggerHelper
33-
import ca.rmen.android.poetassistant.databinding.ActivityLicenseBinding
34-
import ca.rmen.android.poetassistant.fixStatusBarViewForInsets
35-
import ca.rmen.android.poetassistant.getInsets
32+
import ca.rmen.android.poetassistant.theme.AppTheme
3633
import java.io.BufferedReader
3734
import java.io.IOException
3835
import java.io.InputStreamReader
@@ -44,42 +41,33 @@ class LicenseActivity : AppCompatActivity() {
4441
private const val EXTRA_LICENSE_TEXT_ASSET_FILE = "license_text_asset_file"
4542

4643
fun start(context: Context, title: String, licenseText: String) {
47-
context.startActivity(Intent(context, LicenseActivity::class.java)
44+
context.startActivity(
45+
Intent(context, LicenseActivity::class.java)
4846
.putExtra(EXTRA_TITLE, title)
49-
.putExtra(EXTRA_LICENSE_TEXT_ASSET_FILE, licenseText))
47+
.putExtra(EXTRA_LICENSE_TEXT_ASSET_FILE, licenseText)
48+
)
5049
}
5150
}
5251

53-
private lateinit var mBinding: ActivityLicenseBinding
54-
5552
override fun onCreate(savedInstanceState: Bundle?) {
5653
super.onCreate(savedInstanceState)
57-
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_license)
58-
supportActionBar?.let {
59-
it.setDisplayHomeAsUpEnabled(true)
60-
it.setTitle(R.string.license_title)
61-
}
62-
54+
enableEdgeToEdge()
6355
val title = intent.getStringExtra(EXTRA_TITLE)!!
6456
val licenseFile = intent.getStringExtra(EXTRA_LICENSE_TEXT_ASSET_FILE)!!
65-
getInsets(mBinding.licenseContent) { view, insets ->
66-
view.updatePadding(
67-
left = insets.left,
68-
right = insets.right,
69-
bottom = insets.bottom,
70-
)
71-
fixStatusBarViewForInsets(mBinding.statusBarView, insets)
72-
}
7357
val threading = DaggerHelper.getMainScreenComponent(this).getThreading()
74-
threading.execute({ readFile(licenseFile) },
75-
{
76-
mBinding.licenseContent.setContent {
58+
threading.execute(
59+
{ readFile(licenseFile) },
60+
{
61+
setContent {
62+
AppTheme {
7763
LicenseScreen(
7864
title = title,
7965
licenseText = it,
66+
onBack = onBackPressedDispatcher::onBackPressed
8067
)
8168
}
82-
})
69+
}
70+
})
8371
}
8472

8573
@WorkerThread

app/src/main/kotlin/ca/rmen/android/poetassistant/about/LicenseScreen.kt

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ import androidx.compose.foundation.layout.Column
2323
import androidx.compose.foundation.layout.padding
2424
import androidx.compose.foundation.rememberScrollState
2525
import androidx.compose.foundation.verticalScroll
26+
import androidx.compose.material.icons.Icons
27+
import androidx.compose.material.icons.automirrored.filled.ArrowBack
28+
import androidx.compose.material3.ExperimentalMaterial3Api
29+
import androidx.compose.material3.Icon
30+
import androidx.compose.material3.IconButton
2631
import androidx.compose.material3.MaterialTheme
32+
import androidx.compose.material3.Scaffold
2733
import androidx.compose.material3.Text
34+
import androidx.compose.material3.TopAppBar
2835
import androidx.compose.runtime.Composable
2936
import androidx.compose.ui.Modifier
3037
import androidx.compose.ui.res.stringResource
@@ -33,29 +40,49 @@ import androidx.compose.ui.unit.dp
3340
import ca.rmen.android.poetassistant.ExcludeFromJacocoGeneratedReport
3441
import ca.rmen.android.poetassistant.R
3542

43+
@OptIn(ExperimentalMaterial3Api::class)
3644
@Composable
3745
fun LicenseScreen(
3846
title: String,
3947
licenseText: String,
4048
modifier: Modifier = Modifier,
49+
onBack: () -> Unit = {}
4150
) {
4251
val horizontalScrollState = rememberScrollState()
4352
val verticalScrollState = rememberScrollState()
44-
Column(
45-
modifier = modifier
46-
.padding(16.dp)
47-
.horizontalScroll(enabled = true, state = horizontalScrollState)
48-
.verticalScroll(enabled = true, state = verticalScrollState)
49-
) {
50-
Text(
51-
text = title,
52-
style = MaterialTheme.typography.headlineSmall,
53-
modifier = Modifier.padding(bottom = 16.dp),
54-
)
55-
Text(
56-
text = licenseText,
57-
style = MaterialTheme.typography.bodySmall,
58-
)
53+
Scaffold(
54+
modifier = modifier, topBar = {
55+
TopAppBar(
56+
title = {
57+
Text(stringResource(R.string.license_title))
58+
},
59+
navigationIcon = {
60+
IconButton(onClick = onBack) {
61+
Icon(
62+
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
63+
contentDescription = stringResource(R.string.abc_action_bar_up_description),
64+
)
65+
}
66+
}
67+
)
68+
}) { innerPadding ->
69+
Column(
70+
modifier = Modifier
71+
.padding(innerPadding)
72+
.padding(16.dp)
73+
.horizontalScroll(enabled = true, state = horizontalScrollState)
74+
.verticalScroll(enabled = true, state = verticalScrollState)
75+
) {
76+
Text(
77+
text = title,
78+
style = MaterialTheme.typography.headlineSmall,
79+
modifier = Modifier.padding(bottom = 16.dp),
80+
)
81+
Text(
82+
text = licenseText,
83+
style = MaterialTheme.typography.bodySmall,
84+
)
85+
}
5986
}
6087
}
6188

@@ -93,4 +120,4 @@ fun LicenseScreenPreview() {
93120
""".trimIndent()
94121
)
95122

96-
}
123+
}

app/src/main/res/layout/activity_license.xml

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)