Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
android:name=".about.LicenseActivity"
android:label="@string/license_title"
android:parentActivityName=".about.AboutActivity"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="UnusedAttribute">
<!-- Parent activity meta-data to support 4.0 -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.annotation.WorkerThread
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.updatePadding
import androidx.databinding.DataBindingUtil
import ca.rmen.android.poetassistant.Constants
import ca.rmen.android.poetassistant.R
import ca.rmen.android.poetassistant.dagger.DaggerHelper
import ca.rmen.android.poetassistant.databinding.ActivityLicenseBinding
import ca.rmen.android.poetassistant.fixStatusBarViewForInsets
import ca.rmen.android.poetassistant.getInsets
import ca.rmen.android.poetassistant.theme.AppTheme
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
Expand All @@ -44,42 +41,33 @@ class LicenseActivity : AppCompatActivity() {
private const val EXTRA_LICENSE_TEXT_ASSET_FILE = "license_text_asset_file"

fun start(context: Context, title: String, licenseText: String) {
context.startActivity(Intent(context, LicenseActivity::class.java)
context.startActivity(
Intent(context, LicenseActivity::class.java)
.putExtra(EXTRA_TITLE, title)
.putExtra(EXTRA_LICENSE_TEXT_ASSET_FILE, licenseText))
.putExtra(EXTRA_LICENSE_TEXT_ASSET_FILE, licenseText)
)
}
}

private lateinit var mBinding: ActivityLicenseBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_license)
supportActionBar?.let {
it.setDisplayHomeAsUpEnabled(true)
it.setTitle(R.string.license_title)
}

enableEdgeToEdge()
val title = intent.getStringExtra(EXTRA_TITLE)!!
val licenseFile = intent.getStringExtra(EXTRA_LICENSE_TEXT_ASSET_FILE)!!
getInsets(mBinding.licenseContent) { view, insets ->
view.updatePadding(
left = insets.left,
right = insets.right,
bottom = insets.bottom,
)
fixStatusBarViewForInsets(mBinding.statusBarView, insets)
}
val threading = DaggerHelper.getMainScreenComponent(this).getThreading()
threading.execute({ readFile(licenseFile) },
{
mBinding.licenseContent.setContent {
threading.execute(
{ readFile(licenseFile) },
{
setContent {
AppTheme {
LicenseScreen(
title = title,
licenseText = it,
onBack = onBackPressedDispatcher::onBackPressed
)
}
})
}
})
}

@WorkerThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand All @@ -33,29 +40,49 @@ import androidx.compose.ui.unit.dp
import ca.rmen.android.poetassistant.ExcludeFromJacocoGeneratedReport
import ca.rmen.android.poetassistant.R

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LicenseScreen(
title: String,
licenseText: String,
modifier: Modifier = Modifier,
onBack: () -> Unit = {}
) {
val horizontalScrollState = rememberScrollState()
val verticalScrollState = rememberScrollState()
Column(
modifier = modifier
.padding(16.dp)
.horizontalScroll(enabled = true, state = horizontalScrollState)
.verticalScroll(enabled = true, state = verticalScrollState)
) {
Text(
text = title,
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(bottom = 16.dp),
)
Text(
text = licenseText,
style = MaterialTheme.typography.bodySmall,
)
Scaffold(
modifier = modifier, topBar = {
TopAppBar(
title = {
Text(stringResource(R.string.license_title))
},
navigationIcon = {
IconButton(onClick = onBack) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(R.string.abc_action_bar_up_description),
)
}
}
)
}) { innerPadding ->
Column(
modifier = Modifier
.padding(innerPadding)
.padding(16.dp)
.horizontalScroll(enabled = true, state = horizontalScrollState)
.verticalScroll(enabled = true, state = verticalScrollState)
) {
Text(
text = title,
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(bottom = 16.dp),
)
Text(
text = licenseText,
style = MaterialTheme.typography.bodySmall,
)
}
}
}

Expand Down Expand Up @@ -93,4 +120,4 @@ fun LicenseScreenPreview() {
""".trimIndent()
)

}
}
22 changes: 22 additions & 0 deletions app/src/main/kotlin/ca/rmen/android/poetassistant/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ca.rmen.android.poetassistant.theme

import androidx.compose.ui.graphics.Color


val LightBackground = Color(0xFFFFFFFF)
val LightError = Color(0xFFFF0000)
val LightOnBackground = Color(0xFF212121)
val LightOnPrimary = Color(0xFFFFFFFF)
val LightOnSecondary = Color(0xFF727272)
val LightOnSurface = Color(0xDE000000)
val LightPrimary = Color(0xFF607D8B)
val LightSurface = Color(0xFFF6F7F9)

val DarkBackground = Color(0xFF181818)
val DarkError = Color(0xFFFF8888)
val DarkOnBackground = Color(0xFFCCCCCC)
val DarkOnPrimary = Color(0xFF000000)
val DarkOnSecondary = Color(0xFF727272)
val DarkOnSurface = Color(0xDEFFFFFF)
val DarkPrimary = Color(0xFFA5B7C0)
val DarkSurface = Color(0xFF181818)
38 changes: 38 additions & 0 deletions app/src/main/kotlin/ca/rmen/android/poetassistant/theme/Theme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ca.rmen.android.poetassistant.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import com.google.android.material.color.utilities.DynamicColor

val lightColorTheme = lightColorScheme(
background = LightBackground,
error = LightError,
onPrimary = LightOnPrimary,
onSurface = LightOnSurface,
primary = LightPrimary,
surface = LightSurface,
onBackground = LightOnBackground,
onSecondary = LightOnSecondary,
)

val darkColorTheme = darkColorScheme(
background = DarkBackground,
error = DarkError,
onPrimary = DarkOnPrimary,
onSurface = DarkOnSurface,
primary = DarkPrimary,
surface = DarkSurface,
onBackground = DarkOnBackground,
onSecondary = DarkOnSecondary,
)

@Composable
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit,
) {
MaterialTheme(colorScheme = if (darkTheme) darkColorTheme else lightColorTheme, content = content)
}
39 changes: 0 additions & 39 deletions app/src/main/res/layout/activity_license.xml

This file was deleted.