Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add share screen design #25

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ package com.alexmumo.presentation.home

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.outlined.Share
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
Expand All @@ -48,15 +51,19 @@ fun HomeScreen(
Scaffold(
topBar = {
TopAppBar(
modifier = Modifier.fillMaxWidth().testTag("title_test_tag"),
title = {
Text(
"News App",
fontSize = 20.sp,
fontFamily = FontFamily.Monospace,
fontStyle = FontStyle.Normal,
modifier = Modifier.testTag("title_test_tag")
fontWeight = FontWeight.Bold,
fontStyle = FontStyle.Normal
)
}
},
colors = topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
)
)
},
floatingActionButton = {
Expand All @@ -66,7 +73,7 @@ fun HomeScreen(
},
modifier = Modifier.testTag("share_fab_test_tag"),
icon = {
Icon(Icons.Default.Add, contentDescription = null)
Icon(Icons.Outlined.Share, contentDescription = "share")
},
text = {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,50 @@
*/
package com.alexmumo.presentation.share

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.toSize
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController

Expand All @@ -41,13 +68,28 @@ fun ShareScreen(
) {
Scaffold(
topBar = {
TopAppBar(title = {
Text(text = "Share")
})
TopAppBar(
modifier = Modifier.testTag("top_bar_test_tag"),
colors = topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
),
title = {
Text(
text = "Share",
fontWeight = FontWeight.Bold,
fontStyle = FontStyle.Normal,
fontSize = 18.sp
)
}
)
}
) { paddingValues ->
Column(
modifier = Modifier.padding(paddingValues)
modifier = Modifier
.padding(paddingValues)
.padding(all = 4.dp)
.testTag("share_screen_test_tag")
) {
val title by remember { mutableStateOf("") }
val description by remember { mutableStateOf("") }
Expand All @@ -56,27 +98,100 @@ fun ShareScreen(
OutlinedTextField(
value = title, onValueChange = {},
modifier = Modifier.fillMaxWidth(),
singleLine = true
singleLine = true,
placeholder = {
Text(text = "Title")
}
)
Spacer(modifier = Modifier.height(4.dp))
OutlinedTextField(
value = description, onValueChange = {},
modifier = Modifier.fillMaxWidth(),
singleLine = true,
maxLines = 3,
placeholder = {
Text(text = "Description")
}
)
Spacer(modifier = Modifier.height(4.dp))
OutlinedTextField(
value = date, onValueChange = {},
modifier = Modifier.fillMaxWidth(),
singleLine = true
singleLine = true,
placeholder = {
Text(text = "Location")
}
)
Spacer(modifier = Modifier.height(4.dp))
OutlinedTextField(
value = author, onValueChange = {},
modifier = Modifier.fillMaxWidth(),
singleLine = true
)

var selectedCategory by remember { mutableStateOf("") }
var expanded by remember { mutableStateOf(false) }
var categories = listOf("Technology", "Sports", "Health", "Others", "Education")
var textField by remember {
mutableStateOf(androidx.compose.ui.geometry.Size.Zero)
}
val icon = if (expanded)
Icons.Filled.ArrowDropDown
else
Icons.Filled.ArrowDropDown

Box {
OutlinedTextField(
value = selectedCategory,
onValueChange = { selectedCategory = it },
placeholder = { Text(text = "Category") },
singleLine = true,
modifier = Modifier
.fillMaxWidth()
.onGloballyPositioned { layoutCoordinates ->
textField = layoutCoordinates.size.toSize()
},
trailingIcon = {
Icon(icon, contentDescription = "Image", Modifier.clickable { expanded = !expanded })
}
)
DropdownMenu(
expanded = expanded, onDismissRequest = { expanded = false },
modifier = Modifier.width(with(LocalDensity.current) { textField.width.toDp() })
) {
categories.forEach { category ->
DropdownMenuItem(text = {
Text(text = category)
}, onClick = { selectedCategory = category })
}
}
}
Spacer(modifier = Modifier.height(4.dp))
Card(
modifier = Modifier
.fillMaxWidth()
.height(60.dp),
shape = RoundedCornerShape(4.dp),
elevation = CardDefaults.elevatedCardElevation(10.dp),
colors = CardDefaults.cardColors(
contentColor = Color.LightGray
)
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "+",
fontSize = 18.sp,
fontFamily = FontFamily.SansSerif,
fontStyle = FontStyle.Normal,
color = MaterialTheme.colorScheme.onBackground
)
}
}
Spacer(modifier = Modifier.height(4.dp))
Button(
onClick = { /*TODO*/ },
modifier = Modifier.fillMaxWidth().testTag("share_test_tag")
) {
Text(text = "Share")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@
*/
package com.alexmumo.presentation.share

class ShareScreenTest
import androidx.compose.ui.test.junit4.createComposeRule
import org.junit.Before
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.shadows.ShadowLog

@RunWith(RobolectricTestRunner::class)
class ShareScreenTest {

@get:Rule
val composeRule = createComposeRule()

@Before
fun setUp() {
ShadowLog.stream = System.out
}
}
Loading