Skip to content

Instantly share code, notes, and snippets.

@catalinghita8
Last active June 23, 2021 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catalinghita8/c3bbab4b07d837e95387925248cb436a to your computer and use it in GitHub Desktop.
Save catalinghita8/c3bbab4b07d837e95387925248cb436a to your computer and use it in GitHub Desktop.
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.codingtroops.composesample.R
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { MainActivityComposable() }
}
}
@Composable
fun MainActivityComposable() {
Surface(
modifier = Modifier.fillMaxSize(),
color = Helper.getGreenColor()
)
{ ProfileCardComposable() }
}
@Composable
fun ProfileCardComposable() {
Card(
modifier = Modifier
.wrapContentSize()
.clip(RoundedCornerShape(4.dp))
.background(color = Helper.getWhiteColor())
.padding(16.dp),
) {
Row(modifier = Modifier.height(intrinsicSize = IntrinsicSize.Max)) {
ProfilePictureComposable()
ProfileContentComposable()
}
}
}
@Composable
fun ProfilePictureComposable() {
Card(
shape = CircleShape,
border = BorderStroke(2.dp, color = Helper.getGreenColor()),
modifier = Modifier.size(48.dp),
elevation = 4.dp
) {
Image(
painter = painterResource(id = R.drawable.profile_picture),
contentScale = ContentScale.Crop,
modifier = Modifier.size(48.dp),
contentDescription = "Profile picture holder"
)
}
}
@Composable
fun ProfileContentComposable() {
Column(
modifier = Modifier
.fillMaxHeight()
.padding(start = 8.dp),
verticalArrangement = Arrangement.aligned(Alignment.CenterVertically)
) {
Text("Catalin Ghita", fontWeight = FontWeight.Bold)
Text(
text = "Active now",
style = MaterialTheme.typography.body2
)
}
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
MainActivityComposable()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment