Skip to content

Commit

Permalink
[ui] layout & colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Husseinfo committed Aug 31, 2024
1 parent a1437d6 commit 928d573
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 48 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "io.github.husseinfo.countin"
minSdk 26
targetSdk 34
versionCode 17
versionName "1.0.7"
versionCode 18
versionName "1.0.8"
}

signingConfigs {
Expand Down Expand Up @@ -69,6 +69,7 @@ dependencies {
implementation "androidx.compose.material3:material3:1.2.1"
implementation "androidx.compose.ui:ui:1.6.8"
implementation 'androidx.activity:activity-compose:1.9.1'
implementation 'androidx.compose.ui:ui-tooling-preview:1.6.8'
debugImplementation "androidx.compose.ui:ui-tooling:1.6.8"
implementation 'com.github.Husseinfo:material-icons-extended-search:1.0.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package io.github.husseinfo.countin.activities

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import io.github.husseinfo.countin.data.AppDatabase
import io.github.husseinfo.countin.isFirstRun
import io.github.husseinfo.countin.theme.AppTheme
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope

Expand All @@ -28,18 +25,10 @@ class MainActivity : ComponentActivity(), CoroutineScope by MainScope() {

private fun updateUI() {
setContent {
AppTheme {
Column {
Header()
CountsList(items = AppDatabase.getDb(baseContext)!!.countDAO()?.all!!)
FAB()
}
}
MainUI(AppDatabase.getDb(baseContext)!!.countDAO()?.all!!)
}
}

fun openSettings(view: View) = startActivity(Intent(baseContext, SettingsActivity::class.java))

override fun onDestroy() {
super.onDestroy()
AppDatabase.getDb(applicationContext)?.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun CountsList(
items: List<CountModel>
) {
val context = LocalContext.current
LazyColumn(modifier = Modifier.padding(top = 5.dp)) {
LazyColumn {
items(items.size) { item ->
Row(
Modifier
Expand Down Expand Up @@ -75,7 +75,8 @@ fun CountsList(
}) {
Text(
text = items[item].title,
style = Typography.titleSmall
style = Typography.titleSmall,
color = if (isSystemInDarkTheme()) Color.LightGray else Color.DarkGray
)
Text(
text = items[item].getPeriod(),
Expand All @@ -86,7 +87,7 @@ fun CountsList(
Spacer(modifier = Modifier.weight(1f))


if (items[item].list != null)
if (items[item].list != null && items[item].list!!.isNotEmpty())
ListShape(item = items[item])
}
}
Expand Down Expand Up @@ -117,12 +118,12 @@ fun Header() {
Box(
modifier = Modifier
.fillMaxWidth()
.height(100.dp),
.height(50.dp),
contentAlignment = Alignment.Center
) {
Image(
painter = painterResource(id = R.drawable.ic_baseline_timeline_primary),
contentDescription = null, // Optional: use stringResource(R.string.image)
contentDescription = stringResource(R.string.image),
contentScale = ContentScale.Fit,
modifier = Modifier
.width(200.dp)
Expand All @@ -133,43 +134,48 @@ fun Header() {
}
}


@Composable
fun FAB() {
fun MainUI(items: List<CountModel>) {
val context = LocalContext.current
Box(
modifier = Modifier
.padding(25.dp)
.fillMaxSize(),
contentAlignment = Alignment.BottomEnd
) {
FloatingActionButton(
onClick = {
context.startActivity(Intent(context, AddItemActivity::class.java))
},
content = {
Icon(
imageVector = Icons.Default.AddCircle,
contentDescription = stringResource(id = R.string.add_item)
AppTheme {
Column {
Header()
Box(modifier = Modifier.fillMaxSize()) {
CountsList(
items
)
FloatingActionButton(
onClick = {
context.startActivity(
Intent(
context,
AddItemActivity::class.java
)
)
},
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp)
) {
Icon(
imageVector = Icons.Default.AddCircle,
contentDescription = stringResource(id = R.string.add_item)
)
}
}
)
}
}
}

@Preview(showBackground = true)
@Composable
fun MainPreview() {
AppTheme {
Column {
Header()
CountsList(
listOf(
CountModel("First", 1703100000000, false, null, "Travel"),
CountModel("Second", 1672100000000, true, null, null),
CountModel("Third", 1643102000000, false, null, "Life"),
)
)
FAB()
}
}
MainUI(
listOf(
CountModel("First", 1703100000000, false, null, "Travel"),
CountModel("Second", 1672100000000, true, null, null),
CountModel("Third", 1643102000000, false, null, "Life"),
)
)
}

0 comments on commit 928d573

Please sign in to comment.