Skip to content

Commit 60f947e

Browse files
committed
Added mostread section and implemented local custom font
1 parent 8e056ad commit 60f947e

21 files changed

+224
-123
lines changed

.idea/deploymentTargetSelector.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ plugins {
44
alias(libs.plugins.kotlinSymbolProcessing)
55
alias(libs.plugins.daggerHilt)
66
alias(libs.plugins.compose.compiler)
7-
// kotlin("plugin.serialization") version "2.0.20"
8-
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.10"
9-
10-
7+
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.20"
118
}
129

1310
android {
@@ -112,9 +109,6 @@ dependencies {
112109
// Design System
113110
implementation(libs.androidx.material3)
114111

115-
// Google Fonts
116-
implementation(libs.androidx.ui.text.google.fonts)
117-
118112
// Debug Features
119113
implementation(libs.androidx.ui.tooling.preview)
120114
debugImplementation(libs.androidx.ui.tooling)

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
tools:targetApi="31">
1818
<activity
1919
android:name=".ui.main.MainActivity"
20+
android:windowSoftInputMode="adjustResize"
2021
android:exported="true"
2122
android:theme="@style/Theme.WikiNews">
2223
<intent-filter>

app/src/main/java/com/mubarak/wikinews/data/sources/remote/dto/ContentUrls.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mubarak.wikinews.data.sources.remote.dto
22

3-
43
import kotlinx.serialization.SerialName
54
import kotlinx.serialization.Serializable
65

app/src/main/java/com/mubarak/wikinews/data/sources/remote/dto/newsfeed/tfa/Tfa.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mubarak.wikinews.data.sources.remote.dto.newsfeed.tfa
22

3-
43
import com.mubarak.wikinews.data.sources.remote.dto.Thumbnail
54
import com.mubarak.wikinews.data.sources.remote.dto.Url
65
import kotlinx.serialization.SerialName
@@ -21,7 +20,7 @@ data class Tfa( // today featured content
2120
val normalizedTitle: String,
2221

2322
@SerialName("thumbnail")
24-
val thumbnail: Thumbnail,
23+
val thumbnail: Thumbnail?= null,
2524

2625
@SerialName("tid")
2726
val tid: String,

app/src/main/java/com/mubarak/wikinews/ui/WikiNewsApp.kt

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import com.mubarak.wikinews.ui.home.HomeScreen
1818
fun WikiNewsApp(
1919
modifier: Modifier = Modifier
2020
) {
21-
2221
var currentDestination by rememberSaveable { mutableStateOf(TopLevelDestination.FEATURED) }
2322
NavigationSuiteScaffold(
2423
navigationSuiteItems = {

app/src/main/java/com/mubarak/wikinews/ui/home/HomeScreen.kt

+93-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.mubarak.wikinews.ui.home
22

33
import android.content.res.Configuration
4-
import android.util.Log
54
import android.widget.Toast
65
import androidx.compose.foundation.clickable
76
import androidx.compose.foundation.horizontalScroll
@@ -13,7 +12,9 @@ import androidx.compose.foundation.layout.PaddingValues
1312
import androidx.compose.foundation.layout.Row
1413
import androidx.compose.foundation.layout.Spacer
1514
import androidx.compose.foundation.layout.fillMaxSize
15+
import androidx.compose.foundation.layout.fillMaxWidth
1616
import androidx.compose.foundation.layout.height
17+
import androidx.compose.foundation.layout.heightIn
1718
import androidx.compose.foundation.layout.padding
1819
import androidx.compose.foundation.layout.width
1920
import androidx.compose.foundation.layout.wrapContentSize
@@ -36,22 +37,24 @@ import androidx.compose.material3.TopAppBarScrollBehavior
3637
import androidx.compose.material3.TopAppBarState
3738
import androidx.compose.material3.rememberTopAppBarState
3839
import androidx.compose.runtime.Composable
40+
import androidx.compose.runtime.remember
3941
import androidx.compose.ui.Alignment
4042
import androidx.compose.ui.Modifier
43+
import androidx.compose.ui.draw.blur
44+
import androidx.compose.ui.draw.clip
4145
import androidx.compose.ui.input.nestedscroll.nestedScroll
4246
import androidx.compose.ui.platform.LocalContext
4347
import androidx.compose.ui.res.stringResource
4448
import androidx.compose.ui.tooling.preview.Preview
4549
import androidx.compose.ui.unit.dp
4650
import androidx.hilt.navigation.compose.hiltViewModel
4751
import com.mubarak.wikinews.R
48-
import com.mubarak.wikinews.data.sources.remote.dto.Mobile
49-
import com.mubarak.wikinews.data.sources.remote.dto.Thumbnail
50-
import com.mubarak.wikinews.data.sources.remote.dto.Url
5152
import com.mubarak.wikinews.data.sources.remote.dto.newsfeed.NewsFeed
53+
import com.mubarak.wikinews.data.sources.remote.dto.newsfeed.mostread.article.Article
5254
import com.mubarak.wikinews.data.sources.remote.dto.newsfeed.news.News
55+
import com.mubarak.wikinews.data.sources.remote.dto.newsfeed.onthisday.Onthisday
5356
import com.mubarak.wikinews.data.sources.remote.dto.newsfeed.tfa.Tfa
54-
import com.mubarak.wikinews.utils.DateFormatter
57+
import com.mubarak.wikinews.utils.TimeStampConvertor
5558

5659
@Composable
5760
fun HomeScreen(
@@ -76,7 +79,8 @@ fun HomeScreen(
7679
}) {
7780
when (uiState) {
7881
HomeUiState.Error -> {
79-
Toast.makeText(context, "Some sort of error Happened!", Toast.LENGTH_SHORT).show()
82+
// TODO: show error screen
83+
Toast.makeText(context, "Some sort of error Happened!\n Check Internet Connection", Toast.LENGTH_SHORT).show()
8084
}
8185

8286
HomeUiState.Loading -> {
@@ -99,8 +103,6 @@ fun NewsFeed(
99103
modifier: Modifier = Modifier,
100104
newsFeed: NewsFeed,
101105
) {
102-
103-
Log.d("dateRime", "NewsFeed: ${DateFormatter.formattedDate}")
104106
LazyColumn(
105107
modifier = modifier,
106108
contentPadding = PaddingValues(0.dp),
@@ -111,9 +113,8 @@ fun NewsFeed(
111113

112114
val onThisDayNews = newsFeed.onThisDay ?: emptyList()
113115
if (onThisDayNews.isNotEmpty() && onThisDayNews[0].pages.isNotEmpty()) {
114-
items(items = onThisDayNews.take(8)) {
115-
OnThisDaySection(onThisDay = it, modifier = modifier)
116-
NewsItemDivider()
116+
item {
117+
OnThisDaySection(onThisDay = onThisDayNews)
117118
}
118119
}
119120

@@ -123,6 +124,67 @@ fun NewsFeed(
123124
FeedListNewsSection(news = newsFeedArticle) // news
124125
}
125126
}
127+
128+
val mostReadArticles = newsFeed.mostRead?.articles ?: emptyList()
129+
if (mostReadArticles.isNotEmpty()) {
130+
items(mostReadArticles.take(8)){
131+
MostReadArticleSection(article = it)
132+
}
133+
}
134+
}
135+
}
136+
137+
@Composable
138+
fun MostReadArticleSection(
139+
modifier: Modifier = Modifier,
140+
article:Article
141+
) {
142+
MostReadArticles(article = article, modifier = modifier)
143+
NewsItemDivider()
144+
}
145+
146+
@Composable
147+
fun MostReadArticles(
148+
modifier: Modifier = Modifier,
149+
article: Article
150+
) {
151+
152+
val timeStamp = remember(article.timestamp) {
153+
TimeStampConvertor.formatTimestampToUtc(article.timestamp)
154+
}
155+
Column(
156+
modifier = modifier
157+
.fillMaxWidth()
158+
.padding(16.dp)
159+
) {
160+
val imgModifier = Modifier
161+
.heightIn(min = 180.dp, max = 200.dp)
162+
.fillMaxWidth()
163+
.clip(shape = MaterialTheme.shapes.small)
164+
.blur(90.dp) // change it to appropriate
165+
166+
NewsFeedImage(
167+
modifier = imgModifier,
168+
imgUrl = article.thumbnail?.imgUrl
169+
)
170+
Spacer(modifier = Modifier.height(16.dp))
171+
172+
NewsTitle(
173+
text = article.longDescription,
174+
modifier = Modifier.padding(bottom = 8.dp)
175+
)
176+
Text(
177+
text = timeStamp,
178+
style = MaterialTheme.typography.bodySmall
179+
)
180+
}
181+
}
182+
183+
@Composable
184+
fun OnThisDaySection(modifier: Modifier = Modifier, onThisDay: List<Onthisday>) {
185+
for (onThisDayItem in onThisDay) {
186+
OnThisDaySection(onThisDay = onThisDayItem, modifier = modifier)
187+
NewsItemDivider()
126188
}
127189
}
128190

@@ -150,18 +212,22 @@ fun TfaSection(
150212
NewsTitle(
151213
text = stringResource(id = R.string.today_featured_article),
152214
color = MaterialTheme.colorScheme.onTertiaryContainer,
153-
modifier = Modifier.padding(
215+
modifier = modifier.padding(
154216
start = 16.dp, top = 16.dp, end = 16.dp
155217
)
156218
)
157219

158-
tfa?.let {
220+
tfa?.let {
159221
TodayFeaturedArticle(tfa = tfa, modifier = Modifier.clickable { })
160222
}
161223

162224
NewsItemDivider()
163-
164-
NewsTitle(text = "On This Day Happened",color = MaterialTheme.colorScheme.onTertiaryContainer, modifier = Modifier.padding(16.dp))
225+
226+
NewsTitle(
227+
text = stringResource(id = R.string.onThis_day_happened),
228+
color = MaterialTheme.colorScheme.onTertiaryContainer,
229+
modifier = Modifier.padding(16.dp)
230+
)
165231
}
166232

167233

@@ -181,21 +247,27 @@ fun FeedListNewsSection(
181247
.height(IntrinsicSize.Max)
182248
.padding(16.dp), horizontalArrangement = Arrangement.spacedBy(16.dp)
183249
) {
184-
for (newsitem in news) {
185-
if (newsitem.newsArticles.isNotEmpty()) {
186-
NewsArticlesFeed(news = newsitem.newsArticles[0], modifier = modifier)
250+
for (newsItem in news) {
251+
if (newsItem.newsArticles.isNotEmpty()) {
252+
NewsArticlesFeed(news = newsItem.newsArticles[0], modifier = modifier)
187253
}
188254
}
189255
}
190-
Spacer(modifier = Modifier.height(16.dp))
191-
NewsItemDivider()
256+
257+
NewsTitle(
258+
text = stringResource(id = R.string.most_read),
259+
color = MaterialTheme.colorScheme.onTertiaryContainer,
260+
modifier = Modifier.padding(
261+
start = 16.dp, top = 16.dp, end = 16.dp
262+
)
263+
)
192264
}
193265
}
194266

195267
@Composable
196268
fun NewsItemDivider(modifier: Modifier = Modifier) {
197269
HorizontalDivider(
198-
modifier = Modifier.padding(horizontal = 14.dp),
270+
modifier = modifier.padding(horizontal = 14.dp),
199271
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.07f)
200272
)
201273
}

app/src/main/java/com/mubarak/wikinews/ui/home/NewsArticleFeed.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import androidx.compose.foundation.layout.height
77
import androidx.compose.foundation.layout.padding
88
import androidx.compose.foundation.layout.width
99
import androidx.compose.material3.Card
10-
import androidx.compose.material3.CardDefaults
1110
import androidx.compose.material3.MaterialTheme
1211
import androidx.compose.material3.Text
1312
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.remember
1414
import androidx.compose.ui.Modifier
1515
import androidx.compose.ui.text.style.TextOverflow
1616
import androidx.compose.ui.tooling.preview.Preview
@@ -25,10 +25,12 @@ import com.mubarak.wikinews.utils.TimeStampConvertor
2525
@Composable
2626
fun NewsArticlesFeed(
2727
modifier: Modifier = Modifier,
28-
news: NewsArticles,
29-
timeStamp: String = TimeStampConvertor.formatTimestampToUtc(news.timestamp)
28+
news: NewsArticles
3029
) {
3130

31+
val timeStamp: String = remember(news.timestamp) {
32+
TimeStampConvertor.formatTimestampToUtc(news.timestamp)
33+
}
3234
Card(
3335
modifier = modifier.width(280.dp), shape = MaterialTheme.shapes.medium
3436
) {
@@ -78,5 +80,5 @@ val fakeNewsArticles: NewsArticles = NewsArticles(
7880
@Preview
7981
@Composable
8082
private fun NewsArticlePreview() {
81-
NewsArticlesFeed(news = fakeNewsArticles, timeStamp = "September 9, 2024")
83+
NewsArticlesFeed(news = fakeNewsArticles)
8284
}

app/src/main/java/com/mubarak/wikinews/ui/home/NewsCard.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
package com.mubarak.wikinews.ui.home
22

3-
import androidx.compose.foundation.basicMarquee
43
import androidx.compose.material3.MaterialTheme
54
import androidx.compose.material3.Text
65
import androidx.compose.runtime.Composable
76
import androidx.compose.ui.Modifier
87
import androidx.compose.ui.graphics.Color
98
import androidx.compose.ui.layout.ContentScale
9+
import androidx.compose.ui.platform.LocalContext
1010
import androidx.compose.ui.res.painterResource
11-
import androidx.compose.ui.res.stringResource
1211
import androidx.compose.ui.text.font.FontWeight
1312
import androidx.compose.ui.text.style.TextOverflow
1413
import coil.compose.AsyncImage
14+
import coil.request.ImageRequest
1515
import com.mubarak.wikinews.R
1616

1717
@Composable
1818
fun NewsFeedImage(
1919
modifier: Modifier = Modifier,
2020
imgUrl: String?
2121
) {
22+
val context = LocalContext.current
2223
AsyncImage(
23-
model = imgUrl,
24+
model = ImageRequest.Builder(context = context).data(imgUrl)
25+
.crossfade(true).build(),
2426
error = painterResource(id = R.drawable.news_placeholder),
27+
placeholder = painterResource(id = R.drawable.loading_placeholder),
2528
contentDescription = null,
2629
modifier = modifier,
2730
contentScale = ContentScale.Crop

app/src/main/java/com/mubarak/wikinews/ui/home/NewsFeedOTD.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.size
1010
import androidx.compose.material3.MaterialTheme
1111
import androidx.compose.material3.Text
1212
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.remember
1314
import androidx.compose.ui.Alignment
1415
import androidx.compose.ui.Modifier
1516
import androidx.compose.ui.draw.clip
@@ -23,6 +24,10 @@ fun OnThisDaySection(
2324
modifier: Modifier = Modifier,
2425
onThisDay: Onthisday
2526
) {
27+
28+
val timeStamp = remember(onThisDay.pages[0].timestamp) {
29+
TimeStampConvertor.formatTimestampToUtc(onThisDay.pages[0].timestamp)
30+
}
2631
Row(
2732
modifier = Modifier, verticalAlignment = Alignment.CenterVertically
2833
) { // TODO: provide accessibility service to consider this as a whole item
@@ -50,7 +55,7 @@ fun OnThisDaySection(
5055
}
5156
Spacer(modifier = Modifier.height(6.dp))
5257
Text(
53-
text = TimeStampConvertor.formatTimestampToUtc(onThisDay.pages[0].timestamp),
58+
text = timeStamp,
5459
style = MaterialTheme.typography.bodySmall
5560
)
5661
}

0 commit comments

Comments
 (0)