mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
add theme
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parent
92e864db71
commit
477b1728a4
2 changed files with 47 additions and 13 deletions
|
|
@ -5,26 +5,32 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
|
|
@ -46,15 +52,32 @@ class BookmarkCategoriesFragment : DaggerFragment() {
|
|||
return ComposeView(requireContext()).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
setContent {
|
||||
MaterialTheme {
|
||||
MaterialTheme(
|
||||
colorScheme = if (isSystemInDarkTheme()) darkColorScheme(
|
||||
primary = colorResource(R.color.primaryDarkColor),
|
||||
surface = colorResource(R.color.main_background_dark),
|
||||
background = colorResource(R.color.main_background_dark)
|
||||
) else lightColorScheme(
|
||||
primary = colorResource(R.color.primaryColor),
|
||||
surface = colorResource(R.color.main_background_light),
|
||||
background = colorResource(R.color.main_background_light)
|
||||
)
|
||||
) {
|
||||
val listOfBookmarks by bookmarkCategoriesDao.getAllCategories()
|
||||
.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
if (listOfBookmarks.isEmpty()) {
|
||||
Text(text = stringResource(R.string.bookmark_empty))
|
||||
Text(
|
||||
text = stringResource(R.string.bookmark_empty),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = if (isSystemInDarkTheme()) Color(0xB3FFFFFF)
|
||||
else Color(
|
||||
0x8A000000
|
||||
)
|
||||
)
|
||||
} else {
|
||||
LazyColumn {
|
||||
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||
items(items = listOfBookmarks) { bookmarkItem ->
|
||||
CategoryItem(
|
||||
categoryName = bookmarkItem.categoryName,
|
||||
|
|
@ -88,14 +111,20 @@ class BookmarkCategoriesFragment : DaggerFragment() {
|
|||
}) {
|
||||
ListItem(
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Image(
|
||||
modifier = Modifier.size(48.dp),
|
||||
painter = painterResource(R.drawable.commons),
|
||||
contentDescription = null
|
||||
)
|
||||
},
|
||||
headlineContent = {
|
||||
Text(text = categoryName)
|
||||
Text(
|
||||
text = categoryName,
|
||||
maxLines = 2,
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -104,6 +133,9 @@ class BookmarkCategoriesFragment : DaggerFragment() {
|
|||
@Preview
|
||||
@Composable
|
||||
private fun CategoryItemPreview() {
|
||||
CategoryItem(onClick = {}, categoryName = "Test Category")
|
||||
CategoryItem(
|
||||
onClick = {},
|
||||
categoryName = "Test Category"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,13 +223,15 @@ class CategoryDetailsActivity : BaseActivity(),
|
|||
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
||||
menu?.run {
|
||||
val bookmarkMenuItem = findItem(R.id.menu_bookmark_current_category)
|
||||
val icon = if(viewModel.bookmarkState.value){
|
||||
R.drawable.menu_ic_round_star_filled_24px
|
||||
} else {
|
||||
R.drawable.menu_ic_round_star_border_24px
|
||||
}
|
||||
if (bookmarkMenuItem != null) {
|
||||
val icon = if(viewModel.bookmarkState.value){
|
||||
R.drawable.menu_ic_round_star_filled_24px
|
||||
} else {
|
||||
R.drawable.menu_ic_round_star_border_24px
|
||||
}
|
||||
|
||||
bookmarkMenuItem.setIcon(icon)
|
||||
bookmarkMenuItem.setIcon(icon)
|
||||
}
|
||||
}
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue