Skip to content

Commit

Permalink
style: horizontal layout glorified
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay2211 committed Jun 5, 2021
1 parent 077270f commit a49d949
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,50 @@ fun BookmarksScreenComposable(
)

} else {
LazyColumn {
itemsIndexed(resultList.value) { _, element ->
Column(Modifier.fillMaxWidth()) {
LazyColumn(
modifier = Modifier
.width(600.dp)
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
) {
itemsIndexed(resultList.value) { _, element ->

Row(modifier = Modifier
.clickable {
navController.navigate("${MainDestinations.POST_ROUTE}/${element.id}/${MainDestinations.BOOKMARK_ROUTE}")
}
.padding(16.dp, 0.dp)
.height(88.dp)) {
Image(
painter = rememberCoilPainter(
request = element.urlLarge,
previewPlaceholder = android.R.color.darker_gray,
fadeIn = true
), contentDescription = element.title,
contentScale = ContentScale.Crop,
modifier = Modifier
.size(72.dp)
.clip(CircleShape)
.align(Alignment.CenterVertically)
)
Text(
text = element.title ?: "empty",
style = MaterialTheme.typography.h6,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.padding(16.dp, 0.dp, 0.dp, 0.dp)
.align(Alignment.CenterVertically)
.fillMaxWidth()
Row(modifier = Modifier
.clickable {
navController.navigate("${MainDestinations.POST_ROUTE}/${element.id}/${MainDestinations.BOOKMARK_ROUTE}")
}

)
.padding(16.dp, 0.dp)
.height(88.dp)) {
Image(
painter = rememberCoilPainter(
request = element.urlLarge,
previewPlaceholder = android.R.color.darker_gray,
fadeIn = true
), contentDescription = element.title,
contentScale = ContentScale.Crop,
modifier = Modifier
.size(72.dp)
.clip(CircleShape)
.align(Alignment.CenterVertically)
)
Text(
text = element.title ?: "empty",
style = MaterialTheme.typography.h6,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.padding(16.dp, 0.dp, 0.dp, 0.dp)
.align(Alignment.CenterVertically)
.fillMaxWidth()

}
Spacer(Modifier.height(16.dp))
)

}
Spacer(Modifier.height(16.dp))

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ import io.ak1.nytimes.model.Results
import io.ak1.nytimes.utility.timeAgo

@Composable
fun PostElementExpanded(results: State<Results>) {
fun PostElementExpanded(results: State<Results>, modifier: Modifier) {
val story = results.value
val context = LocalContext.current
LazyColumn(
Modifier
.fillMaxWidth()
.padding(16.dp)
) {
LazyColumn(modifier) {
val keepTagsHidden = true
item {
Card(elevation = 5.dp) {
Card(
elevation = 5.dp, modifier = Modifier
.padding(16.dp)
) {
Image(
painter = rememberCoilPainter(
request = story.urlLarge,
Expand All @@ -53,72 +52,74 @@ fun PostElementExpanded(results: State<Results>) {
contentScale = ContentScale.Crop
)
}
Spacer(Modifier.height(16.dp))


Text(
text = story.title ?: "empty",
style = MaterialTheme.typography.h5,
modifier = Modifier
.fillMaxWidth()
)
Spacer(Modifier.height(16.dp))
Column(Modifier.padding(16.dp, 0.dp)) {

Text(
text = story.abstractText ?: "empty",
style = MaterialTheme.typography.body1,
modifier = Modifier
.fillMaxWidth()
)
Spacer(Modifier.height(8.dp))
Text(
text = story.byline?.trim() ?: "",
style = MaterialTheme.typography.caption,
modifier = Modifier
.wrapContentWidth(Alignment.End)
)
Text(
text = story.title ?: "empty",
style = MaterialTheme.typography.h5,
modifier = Modifier
.fillMaxWidth()
)
Spacer(Modifier.height(16.dp))

Spacer(Modifier.height(8.dp))
Text(
text = story.publishedDate.timeAgo(),
style = MaterialTheme.typography.caption,
modifier = Modifier
.wrapContentWidth(Alignment.End)
)
Text(
text = story.abstractText ?: "empty",
style = MaterialTheme.typography.body1,
modifier = Modifier
.fillMaxWidth()
)
Spacer(Modifier.height(8.dp))
Text(
text = story.byline?.trim() ?: "",
style = MaterialTheme.typography.caption,
modifier = Modifier
.wrapContentWidth(Alignment.End)
)

val tags = story.desFacet.trim().split(",")
if (!keepTagsHidden) {
LazyRow(
Spacer(Modifier.height(8.dp))
Text(
text = story.publishedDate.timeAgo(),
style = MaterialTheme.typography.caption,
modifier = Modifier
.padding(0.dp, 0.dp, 0.dp, 16.dp)
) {
items(tags) {
Text(
text = it,
style = MaterialTheme.typography.caption,
modifier = Modifier
.padding(16.dp, 0.dp, 0.dp, 0.dp)
.wrapContentSize()
.background(
MaterialTheme.colors.secondary,
RoundedCornerShape(20.dp)
)
.padding(18.dp, 10.dp)
)
.wrapContentWidth(Alignment.End)
)

}
val tags = story.desFacet.trim().split(",")
if (!keepTagsHidden) {
LazyRow(
modifier = Modifier
.padding(0.dp, 0.dp, 0.dp, 16.dp)
) {
items(tags) {
Text(
text = it,
style = MaterialTheme.typography.caption,
modifier = Modifier
.padding(16.dp, 0.dp, 0.dp, 0.dp)
.wrapContentSize()
.background(
MaterialTheme.colors.secondary,
RoundedCornerShape(20.dp)
)
.padding(18.dp, 10.dp)
)

}


}
}

}
Spacer(Modifier.height(16.dp))

Button(
onClick = {
Intent(Intent.ACTION_VIEW, Uri.parse(story.shortUrl ?: "")).let {
context.startActivity(it)
}
},
modifier = Modifier.wrapContentWidth()
}, modifier = Modifier
.padding(16.dp)
.wrapContentWidth()
) {
Image(
painter = painterResource(R.drawable.ic_external_link),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.ak1.nytimes.ui.screens.home

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.itemsIndexed
Expand All @@ -10,7 +12,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
Expand Down Expand Up @@ -52,6 +56,10 @@ fun HomeScreenComposable(
onRefresh = {
stories.refresh.invoke()
},
modifier = Modifier
.width(600.dp)
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
) {
when (networkState.value.state) {
State.RUNNING -> {
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/io/ak1/nytimes/ui/screens/post/PostScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package io.ak1.nytimes.ui.screens.post
import android.widget.Toast
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import io.ak1.nytimes.R
import io.ak1.nytimes.model.Results
Expand Down Expand Up @@ -45,7 +49,13 @@ fun PostScreenComposable(
viewModel.addBookmark(story.value, coroutineScope)
}
}
PostElementExpanded(results = story)
PostElementExpanded(
results = story,
modifier = Modifier
.width(600.dp)
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
)
}
CustomAlertDialog(
titleId = R.string.deletion_confirmation,
Expand Down
Loading

0 comments on commit a49d949

Please sign in to comment.