Skip to content

Commit

Permalink
fix: Adjust paddings of UI after font change and some minor fixes (#222)
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <starry@krsh.dev>
  • Loading branch information
starry-shivam authored Sep 24, 2024
1 parent 6d4bb75 commit 54a8e9c
Show file tree
Hide file tree
Showing 20 changed files with 280 additions and 256 deletions.
28 changes: 28 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 29 additions & 30 deletions app/src/main/java/com/starry/myne/api/BookAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONException
import org.json.JSONObject
import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -152,7 +151,7 @@ class BookAPI(context: Context) {
json.decodeFromString(
BookSet.serializer(),
response.body!!.string()
)
).copy(isCached = response.cacheResponse != null)
)
)
}
Expand All @@ -174,44 +173,44 @@ class BookAPI(context: Context) {

override fun onResponse(call: Call, response: Response) {
response.use {
continuation.resume(parseExtraInfoJson(response.body!!.string()))
continuation.resume(
parseExtraInfoJson(
response.body!!.string(),
response.cacheResponse != null
)
)
}
}
})
}

// Helper function to parse extra info JSON.
private fun parseExtraInfoJson(jsonString: String): ExtraInfo? {
return try {
private fun parseExtraInfoJson(jsonString: String, isCached: Boolean): ExtraInfo? {
return runCatching {
val jsonObj = JSONObject(jsonString)
val totalItems = jsonObj.getInt("totalItems")
val totalItems = jsonObj.optInt("totalItems", 0)
if (totalItems != 0) {
val items = jsonObj.getJSONArray("items")
val item = items.getJSONObject(0)
val volumeInfo = item.getJSONObject("volumeInfo")
val imageLinks = volumeInfo.getJSONObject("imageLinks")
// Build Extra info.
val coverImage = imageLinks.getString("thumbnail").replace(
"http://", "https://"
)
val pageCount = try {
volumeInfo.getInt("pageCount")
} catch (exc: JSONException) {
0
}
val description = try {
volumeInfo.getString("description")
} catch (exc: JSONException) {
""
}
ExtraInfo(coverImage, pageCount, description)
jsonObj.optJSONArray("items")
?.optJSONObject(0)
?.optJSONObject("volumeInfo")
?.let { volumeInfo ->
val coverImage = volumeInfo
.optJSONObject("imageLinks")
?.optString("thumbnail", "")
?.replace("http://", "https://") ?: ""
val pageCount = volumeInfo.optInt("pageCount", 0)
val description = volumeInfo.optString("description", "")

ExtraInfo(
coverImage = coverImage,
pageCount = pageCount,
description = description,
isCached = isCached
)
}
} else {
null
}
} catch (exc: JSONException) {
exc.printStackTrace()
null
}
}.getOrNull()
}

}
5 changes: 4 additions & 1 deletion app/src/main/java/com/starry/myne/api/models/BookSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ data class BookSet(
@SerialName("previous")
val previous: String? = null,
@SerialName("results")
val books: List<Book> = listOf()
val books: List<Book> = listOf(),
// For checking if the book is cached or not
// Not part of the API response.
val isCached: Boolean = false
)
5 changes: 4 additions & 1 deletion app/src/main/java/com/starry/myne/api/models/ExtraInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ import androidx.annotation.Keep
data class ExtraInfo(
val coverImage: String = "",
val pageCount: Int = 0,
val description: String = ""
val description: String = "",
// Not part of the API response.
// Used to check if extra info is cached.
val isCached: Boolean = false
)
24 changes: 11 additions & 13 deletions app/src/main/java/com/starry/myne/ui/common/BookDetailTopUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,29 @@ fun BookDetailTopUI(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
) {
Spacer(Modifier.height(32.dp))
Text(
text = title,
modifier = Modifier
.padding(
start = 12.dp, end = 12.dp, top = 20.dp
)
.padding(horizontal = 12.dp)
.fillMaxWidth(),
fontSize = 24.sp,
fontSize = 22.sp,
fontFamily = poppinsFont,
maxLines = 3,
lineHeight = 28.sp,
overflow = TextOverflow.Ellipsis,
fontWeight = FontWeight.Bold,
fontWeight = FontWeight.SemiBold,
color = MaterialTheme.colorScheme.onBackground,
)

Text(
text = authors,
modifier = Modifier.padding(
start = 12.dp, end = 8.dp, top = 4.dp
start = 12.dp, end = 8.dp, top = 2.dp
),
fontSize = 18.sp,
fontSize = 16.sp,
fontFamily = poppinsFont,
fontWeight = FontWeight.SemiBold,
fontWeight = FontWeight.Medium,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onBackground,
Expand All @@ -158,10 +158,8 @@ fun BookDetailTopUI(
progressPercent?.let {
Text(
text = "$progressPercent% Completed",
modifier = Modifier.padding(
start = 12.dp, end = 8.dp, top = 8.dp
),
fontSize = 16.sp,
modifier = Modifier.padding(start = 12.dp, end = 8.dp),
fontSize = 15.sp,
fontFamily = poppinsFont,
fontWeight = FontWeight.Medium,
maxLines = 2,
Expand All @@ -180,7 +178,7 @@ fun BookDetailTopUI(
@Composable
private fun Preview() {
BookDetailTopUI(
title = "The Great Gatsby",
title = "The Complete works of william shakespeare",
authors = "F. Scott Fitzgerald",
imageData = null,
currentThemeMode = ThemeMode.Light
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/java/com/starry/myne/ui/common/BookItemCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
Expand Down Expand Up @@ -117,11 +118,11 @@ fun BookItemCard(
Text(
text = title,
modifier = Modifier
.padding(start = 12.dp, end = 8.dp)
.padding(start = 12.dp, end = 8.dp, top = 2.dp)
.fillMaxWidth()
.placeholder(isLoading = loadingEffect),
fontStyle = MaterialTheme.typography.headlineMedium.fontStyle,
fontSize = 18.sp,
fontSize = 16.sp,
fontFamily = poppinsFont,
fontWeight = FontWeight.Bold,
maxLines = 2,
Expand All @@ -133,23 +134,23 @@ fun BookItemCard(
text = author,
modifier = Modifier
.padding(start = 12.dp, end = 8.dp)
.placeholder(isLoading = loadingEffect),
.placeholder(isLoading = loadingEffect)
.offset(y = (-4).dp),
color = MaterialTheme.colorScheme.onSurface,
maxLines = 2,
lineHeight = 20.sp,
fontStyle = MaterialTheme.typography.bodySmall.fontStyle,
fontFamily = poppinsFont,
fontSize = 14.sp,
)

Spacer(modifier = Modifier.height(8.dp))

Text(
text = language,
modifier = Modifier
.padding(start = 12.dp, end = 8.dp)
.placeholder(isLoading = loadingEffect),
color = MaterialTheme.colorScheme.onSurface,
fontSize = 16.sp,
fontSize = 15.sp,
fontWeight = FontWeight.SemiBold,
fontStyle = MaterialTheme.typography.bodyMedium.fontStyle,
fontFamily = poppinsFont
Expand All @@ -165,7 +166,8 @@ fun BookItemCard(
overflow = TextOverflow.Ellipsis,
fontStyle = MaterialTheme.typography.bodySmall.fontStyle,
fontFamily = poppinsFont,
fontSize = 13.sp
fontSize = 13.sp,
lineHeight = 18.sp
)

Spacer(modifier = Modifier.weight(1f))
Expand Down
75 changes: 0 additions & 75 deletions app/src/main/java/com/starry/myne/ui/common/BookLanguageButton.kt

This file was deleted.

Loading

0 comments on commit 54a8e9c

Please sign in to comment.