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.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.ListItem
|
import androidx.compose.material3.ListItem
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.darkColorScheme
|
||||||
|
import androidx.compose.material3.lightColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.ComposeView
|
import androidx.compose.ui.platform.ComposeView
|
||||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||||
|
import androidx.compose.ui.res.colorResource
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
|
@ -46,15 +52,32 @@ class BookmarkCategoriesFragment : DaggerFragment() {
|
||||||
return ComposeView(requireContext()).apply {
|
return ComposeView(requireContext()).apply {
|
||||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||||
setContent {
|
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()
|
val listOfBookmarks by bookmarkCategoriesDao.getAllCategories()
|
||||||
.collectAsStateWithLifecycle(initialValue = emptyList())
|
.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||||
Surface(modifier = Modifier.fillMaxSize()) {
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Box(contentAlignment = Alignment.Center) {
|
||||||
if (listOfBookmarks.isEmpty()) {
|
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 {
|
} else {
|
||||||
LazyColumn {
|
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||||
items(items = listOfBookmarks) { bookmarkItem ->
|
items(items = listOfBookmarks) { bookmarkItem ->
|
||||||
CategoryItem(
|
CategoryItem(
|
||||||
categoryName = bookmarkItem.categoryName,
|
categoryName = bookmarkItem.categoryName,
|
||||||
|
|
@ -88,14 +111,20 @@ class BookmarkCategoriesFragment : DaggerFragment() {
|
||||||
}) {
|
}) {
|
||||||
ListItem(
|
ListItem(
|
||||||
leadingContent = {
|
leadingContent = {
|
||||||
Icon(
|
Image(
|
||||||
modifier = Modifier.size(48.dp),
|
modifier = Modifier.size(48.dp),
|
||||||
painter = painterResource(R.drawable.commons),
|
painter = painterResource(R.drawable.commons),
|
||||||
contentDescription = null
|
contentDescription = null
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
headlineContent = {
|
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
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun CategoryItemPreview() {
|
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 {
|
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
||||||
menu?.run {
|
menu?.run {
|
||||||
val bookmarkMenuItem = findItem(R.id.menu_bookmark_current_category)
|
val bookmarkMenuItem = findItem(R.id.menu_bookmark_current_category)
|
||||||
val icon = if(viewModel.bookmarkState.value){
|
if (bookmarkMenuItem != null) {
|
||||||
R.drawable.menu_ic_round_star_filled_24px
|
val icon = if(viewModel.bookmarkState.value){
|
||||||
} else {
|
R.drawable.menu_ic_round_star_filled_24px
|
||||||
R.drawable.menu_ic_round_star_border_24px
|
} else {
|
||||||
}
|
R.drawable.menu_ic_round_star_border_24px
|
||||||
|
}
|
||||||
|
|
||||||
bookmarkMenuItem.setIcon(icon)
|
bookmarkMenuItem.setIcon(icon)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.onPrepareOptionsMenu(menu)
|
return super.onPrepareOptionsMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue