Skip to content

Commit c762ffc

Browse files
Improved layouts and cards surface, background colors, styles. Minimized bindings, changed resources.
1 parent 489ae8f commit c762ffc

File tree

9 files changed

+142
-176
lines changed

9 files changed

+142
-176
lines changed

app/src/main/java/com/developerbreach/developerbreach/utils/Utilities.kt

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,24 @@ package com.developerbreach.developerbreach.utils
33
import android.app.Activity
44
import android.util.TypedValue
55
import android.view.View
6-
import androidx.activity.OnBackPressedCallback
7-
import androidx.fragment.app.FragmentActivity
8-
import androidx.navigation.NavController
96
import com.google.android.material.snackbar.Snackbar
10-
import java.util.*
117

128

13-
fun capitalizeWord(title: String): String {
14-
val splitTitle = title.lowercase(Locale.ROOT).split(" ".toRegex()).toTypedArray()
15-
val builder = StringBuilder()
16-
for (i in splitTitle.indices) {
17-
val currentWordInTitle = splitTitle[i]
18-
if (i > 0 && currentWordInTitle.isNotEmpty()) {
19-
builder.append(" ")
20-
}
21-
val capitalTitle = (currentWordInTitle.substring(0, 1).lowercase(Locale.ROOT)
22-
+ currentWordInTitle.substring(1))
23-
builder.append(capitalTitle)
24-
}
25-
return builder.toString()
26-
}
27-
28-
fun showSnackBar(message: String, activity: Activity) {
9+
fun showSnackBar(
10+
message: String,
11+
activity: Activity
12+
) {
2913
val decorView = activity.window.decorView
3014
val view: View = decorView.findViewById(android.R.id.content)
3115
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show()
3216
}
3317

34-
fun finishActivityOnBackPress(activity: FragmentActivity) {
35-
activity.onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
36-
override fun handleOnBackPressed() {
37-
activity.finish()
38-
}
39-
})
40-
}
41-
42-
fun navigateUpOnBackPress(activity: FragmentActivity, findNavController: NavController) {
43-
activity.onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
44-
override fun handleOnBackPressed() {
45-
findNavController.navigateUp()
46-
}
47-
})
48-
}
49-
50-
fun View.convertToDp(value: Float): Int {
51-
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, resources.displayMetrics)
52-
.toInt()
53-
}
54-
55-
// TODO Remove deprecated code
56-
fun showStatusBar(activity: Activity) {
57-
@Suppress("DEPRECATION")
58-
activity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
59-
}
60-
61-
fun hideStatusBar(activity: Activity) {
62-
@Suppress("DEPRECATION")
63-
activity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
18+
fun View.convertToDp(
19+
value: Float
20+
): Int {
21+
return TypedValue.applyDimension(
22+
TypedValue.COMPLEX_UNIT_DIP,
23+
value,
24+
resources.displayMetrics
25+
).toInt()
6426
}

app/src/main/res/layout/item_author.xml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@
1111
</data>
1212

1313
<com.google.android.material.card.MaterialCardView
14-
style="@style/CardView.Article.Item.List"
1514
android:layout_width="match_parent"
1615
android:layout_height="wrap_content"
17-
app:cardBackgroundColor="?attr/colorSecondary"
16+
android:stateListAnimator="@animator/item_selected"
17+
app:cardBackgroundColor="?attr/colorSurface"
18+
app:cardCornerRadius="@dimen/card_corner_radius_default"
19+
app:strokeWidth="@dimen/card_default_stroke_width"
1820
tools:cardUseCompatPadding="true"
19-
tools:theme="@style/AppTheme.MainTheme">
21+
tools:layout_margin="@dimen/layout_margin_8dp"
22+
tools:theme="@style/AppTheme.Blue">
2023

2124
<androidx.constraintlayout.widget.ConstraintLayout
2225
android:layout_width="match_parent"
2326
android:layout_height="wrap_content"
24-
android:padding="16dp">
27+
android:padding="@dimen/padding_16dp">
2528

2629
<ImageView
2730
android:id="@+id/item_author_avatar_image_view"
28-
android:layout_width="60dp"
29-
android:layout_height="60dp"
31+
android:layout_width="@dimen/item_author_placeholder_image_size"
32+
android:layout_height="@dimen/item_author_placeholder_image_size"
3033
app:bindAuthorProfileImage="@{author.authorAvatarUrl}"
3134
app:layout_constraintStart_toStartOf="parent"
3235
app:layout_constraintTop_toTopOf="parent"
3336
tools:ignore="ContentDescription"
34-
tools:src="@drawable/ic_author" />
37+
tools:src="@drawable/ic_author"
38+
tools:tint="?attr/colorOnSurface" />
3539

3640
<TextView
3741
android:id="@+id/item_author_name_text_view"
@@ -40,7 +44,7 @@
4044
android:layout_marginStart="@dimen/layout_margin_16dp"
4145
android:text="@{author.authorName}"
4246
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
43-
android:textColor="?attr/colorOnSecondary"
47+
android:textColor="?attr/colorOnSurface"
4448
app:layout_constraintBottom_toBottomOf="@id/item_author_avatar_image_view"
4549
app:layout_constraintStart_toEndOf="@id/item_author_avatar_image_view"
4650
app:layout_constraintTop_toTopOf="@id/item_author_avatar_image_view"

app/src/main/res/layout/item_categories.xml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,25 @@
1818
android:id="@+id/item_category_parent_card_view"
1919
android:layout_width="wrap_content"
2020
android:layout_height="wrap_content"
21-
android:background="?selectableItemBackgroundBorderless"
21+
android:stateListAnimator="@animator/item_selected"
2222
app:bindArticleListViewModel="@{viewModel}"
2323
app:bindItemCategoryParentListener="@{category}"
24-
app:cardBackgroundColor="?attr/colorSecondary"
25-
app:cardCornerRadius="8dp"
24+
app:cardBackgroundColor="?attr/colorSurface"
25+
app:cardCornerRadius="@dimen/card_corner_radius_default"
2626
tools:layout_gravity="center"
27-
tools:layout_marginEnd="16dp"
28-
tools:theme="@style/AppTheme.HomeTheme">
27+
tools:layout_marginEnd="@dimen/layout_margin_16dp"
28+
tools:theme="@style/AppTheme.Blue">
2929

3030
<androidx.constraintlayout.widget.ConstraintLayout
3131
android:layout_width="wrap_content"
3232
android:layout_height="wrap_content"
33-
android:paddingHorizontal="8dp"
34-
android:paddingVertical="8dp">
33+
android:padding="@dimen/padding_8dp">
3534

3635
<ImageView
3736
android:id="@+id/item_category_icon_image_view"
38-
android:layout_width="24dp"
39-
android:layout_height="24dp"
40-
android:layout_marginStart="12dp"
37+
android:layout_width="@dimen/default_icon_size"
38+
android:layout_height="@dimen/default_icon_size"
39+
android:layout_marginStart="@dimen/layout_margin_12dp"
4140
app:bindItemCategoryIconImageView="@{category}"
4241
app:bindItemCategoryParentCardView="@{itemCategoryParentCardView}"
4342
app:bindItemCategoryTitleTextView="@{itemCategoryTitleTextView}"
@@ -52,11 +51,11 @@
5251
android:id="@+id/item_category_title_text_view"
5352
android:layout_width="wrap_content"
5453
android:layout_height="wrap_content"
55-
android:paddingStart="12dp"
56-
android:paddingEnd="16dp"
54+
android:paddingStart="@dimen/padding_12dp"
55+
android:paddingEnd="@dimen/padding_16dp"
5756
android:text="@{category.categoryName}"
5857
android:textAppearance="?attr/textAppearanceSubtitle1"
59-
android:textColor="?attr/colorOnSecondary"
58+
android:textColor="?attr/colorOnSurface"
6059
app:layout_constraintBottom_toBottomOf="parent"
6160
app:layout_constraintEnd_toEndOf="parent"
6261
app:layout_constraintStart_toEndOf="@id/item_category_icon_image_view"

app/src/main/res/layout/item_favorites.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@
1616

1717
<com.google.android.material.card.MaterialCardView
1818
android:id="@+id/favorite_item_card_view"
19-
style="@style/CardView.Article.Item.List"
2019
android:layout_width="match_parent"
2120
android:layout_height="wrap_content"
21+
android:stateListAnimator="@animator/item_selected"
2222
android:transitionName="@{article.name}"
2323
app:bindArticleItemTitleTransition="@{favoriteArticleTitleItemTextView}"
2424
app:bindFavoriteToDetailClickListener="@{article.articleId}"
25-
app:cardBackgroundColor="?attr/colorSecondary"
26-
tools:cardUseCompatPadding="true">
25+
app:cardBackgroundColor="?attr/colorSurface"
26+
tools:cardUseCompatPadding="true"
27+
tools:layout_margin="@dimen/layout_margin_8dp"
28+
tools:theme="@style/AppTheme.Blue">
2729

2830
<androidx.constraintlayout.widget.ConstraintLayout
2931
android:layout_width="match_parent"
3032
android:layout_height="wrap_content">
3133

3234
<ImageView
3335
android:id="@+id/favorite_article_thumbnail_item_image_view"
34-
android:layout_width="@dimen/match_constraints"
35-
android:layout_height="@dimen/match_constraints"
36+
android:layout_width="@dimen/match_constraint"
37+
android:layout_height="@dimen/match_constraint"
3638
android:contentDescription="@string/article_banner_image_content_description"
3739
app:bindFavoriteItemBanner="@{article.banner}"
3840
app:layout_constraintDimensionRatio="3:2"
@@ -48,8 +50,9 @@
4850
android:layout_height="wrap_content"
4951
android:layout_margin="@dimen/layout_margin_16dp"
5052
android:gravity="center"
53+
android:text="@{article.name}"
5154
android:textAppearance="?attr/textAppearanceHeadline5"
52-
app:bindFavoriteItemTitle="@{article.name}"
55+
android:textColor="?attr/colorOnSurface"
5356
app:layout_constraintBottom_toBottomOf="parent"
5457
app:layout_constraintEnd_toEndOf="parent"
5558
app:layout_constraintStart_toStartOf="parent"
@@ -68,7 +71,8 @@
6871
app:bindFavoriteViewModel="@{viewModel}"
6972
app:bindItemCardView="@{favoriteItemCardView}"
7073
app:layout_constraintEnd_toEndOf="parent"
71-
app:layout_constraintTop_toTopOf="parent" />
74+
app:layout_constraintTop_toTopOf="parent"
75+
app:tint="?attr/colorOnSurface" />
7276

7377
</androidx.constraintlayout.widget.ConstraintLayout>
7478

app/src/main/res/layout/item_search.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
<FrameLayout
1414
android:id="@+id/search_item_parent"
1515
android:layout_width="match_parent"
16-
android:layout_height="wrap_content">
16+
android:layout_height="wrap_content"
17+
tools:theme="@style/AppTheme.Blue">
1718

1819
<TextView
1920
android:id="@+id/article_name_search_item_text_view"
20-
style="@style/TextAppearance.Article.Item.Search"
2121
android:layout_width="match_parent"
2222
android:layout_height="wrap_content"
23+
android:background="?attr/selectableItemBackground"
2324
android:paddingHorizontal="@dimen/padding_16dp"
2425
android:paddingVertical="@dimen/padding_16dp"
2526
android:text="@{search.name}"
27+
android:textAppearance="?attr/textAppearanceHeadline6"
28+
android:textColor="?attr/colorOnBackground"
2629
android:transitionName="@{search.name}"
2730
app:bindSearchItemViewGroup="@{searchItemParent}"
2831
app:bindSearchToDetailListener="@{search.articleId}"

app/src/main/res/layout/static_search_header.xml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
2+
<com.google.android.material.card.MaterialCardView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:layout_width="match_parent"
6-
android:layout_height="48dp"
7-
android:layout_marginHorizontal="16dp"
8-
android:layout_marginVertical="12dp"
9-
app:cardBackgroundColor="?attr/colorSecondary"
10-
app:cardCornerRadius="8dp"
11-
app:cardElevation="0dp"
7+
android:layout_height="@dimen/main_search_box_height"
8+
android:layout_marginHorizontal="@dimen/layout_margin_16dp"
9+
android:layout_marginVertical="@dimen/layout_margin_12dp"
10+
app:cardBackgroundColor="?attr/colorSurface"
11+
app:cardCornerRadius="@dimen/card_corner_radius_default"
12+
app:cardElevation="@dimen/card_default_stroke_width"
1213
app:layout_constraintStart_toStartOf="parent"
1314
app:layout_constraintTop_toTopOf="parent"
1415
tools:showIn="@layout/fragment_home">
@@ -19,9 +20,9 @@
1920

2021
<ImageView
2122
android:id="@+id/app_logo"
22-
android:layout_width="28dp"
23-
android:layout_height="28dp"
24-
android:layout_marginStart="16dp"
23+
android:layout_width="@dimen/search_box_logo_size"
24+
android:layout_height="@dimen/search_box_logo_size"
25+
android:layout_marginStart="@dimen/layout_margin_16dp"
2526
android:src="@drawable/ic_logo"
2627
app:layout_constraintBottom_toBottomOf="parent"
2728
app:layout_constraintStart_toStartOf="parent"
@@ -32,12 +33,12 @@
3233
android:id="@+id/search_title_text_view"
3334
android:layout_width="wrap_content"
3435
android:layout_height="wrap_content"
35-
android:layout_marginStart="20dp"
36-
android:layout_marginTop="4dp"
36+
android:layout_marginStart="@dimen/margin_layout_20dp"
37+
android:layout_marginTop="@dimen/layout_margin_4dp"
3738
android:alpha="0.5"
3839
android:text="@string/search_header_title"
3940
android:textAppearance="?attr/textAppearanceHeadline6"
40-
android:textColor="?attr/colorOnSecondary"
41+
android:textColor="?attr/colorOnSurface"
4142
app:layout_constraintBottom_toBottomOf="@id/app_logo"
4243
app:layout_constraintStart_toEndOf="@id/app_logo"
4344
app:layout_constraintTop_toTopOf="@id/app_logo" />
@@ -46,13 +47,13 @@
4647
android:id="@+id/search_icon_image_view"
4748
android:layout_width="wrap_content"
4849
android:layout_height="wrap_content"
49-
android:layout_marginEnd="16dp"
50+
android:layout_marginEnd="@dimen/layout_margin_16dp"
5051
android:alpha="0.8"
5152
android:src="@drawable/ic_search"
5253
app:layout_constraintBottom_toBottomOf="parent"
5354
app:layout_constraintEnd_toEndOf="parent"
5455
app:layout_constraintTop_toTopOf="parent"
55-
app:tint="?attr/colorOnSecondary"
56+
app:tint="?attr/colorOnSurface"
5657
tools:ignore="ContentDescription" />
5758

5859
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/dimens.xml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33

4-
<!-- RecyclerView -->
5-
<dimen name="recycler_view_spacing_dimen">10dp</dimen>
6-
7-
<!-- item_article, favorite, search -->
8-
<dimen name="detail_appbar_layout_height">278dp</dimen>
9-
10-
<dimen name="hor_guideline_width">1dp</dimen>
11-
124
<!-- Layout Margin, Padding -->
13-
<dimen name="layout_margin_12dp">12dp</dimen>
145
<dimen name="layout_margin_28dp">28dp</dimen>
156
<dimen name="layout_margin_24dp">24dp</dimen>
167
<dimen name="layout_margin_16dp">16dp</dimen>
17-
<dimen name="layout_margin_4dp">4dp</dimen>
8+
<dimen name="layout_margin_12dp">12dp</dimen>
9+
<dimen name="layout_margin_8dp">8dp</dimen>
1810
<dimen name="layout_margin_6dp">6dp</dimen>
11+
<dimen name="layout_margin_4dp">4dp</dimen>
12+
13+
<dimen name="padding_32dp">32dp</dimen>
14+
<dimen name="padding_20dp">20dp</dimen>
1915
<dimen name="padding_16dp">16dp</dimen>
2016
<dimen name="padding_12dp">12dp</dimen>
2117
<dimen name="padding_8dp">8dp</dimen>
22-
<dimen name="match_constraints">0dp</dimen>
23-
<dimen name="bottom_sheet_corner_radius">32dp</dimen>
24-
<dimen name="layout_margin_8dp">8dp</dimen>
2518

19+
<!-- RecyclerView -->
20+
<dimen name="recycler_view_spacing_dimen">10dp</dimen>
21+
22+
<!-- item_article, favorite, search -->
23+
<dimen name="detail_appbar_layout_height">278dp</dimen>
24+
25+
<dimen name="bottom_sheet_corner_radius">32dp</dimen>
26+
<dimen name="bottom_app_bar_inset_start">0dp</dimen>
27+
<dimen name="bottom_app_bar_icon_size">32dp</dimen>
28+
<dimen name="author_image_view_size">40dp</dimen>
29+
<dimen name="button_corner_radius">28dp</dimen>
30+
<dimen name="hor_guideline_width">1dp</dimen>
31+
<dimen name="horizontal_line_height">1dp</dimen>
32+
<dimen name="horizontal_separator">0.1dp</dimen>
33+
<dimen name="match_constraint">0dp</dimen>
34+
<dimen name="placeholder_image_height">200dp</dimen>
35+
<dimen name="banner_height_featured_image">300dp</dimen>
36+
<dimen name="margin_layout_20dp">20dp</dimen>
37+
<dimen name="card_corner_radius_default">8dp</dimen>
38+
<dimen name="card_default_stroke_width">0dp</dimen>
39+
<dimen name="item_author_placeholder_image_size">60dp</dimen>
40+
<dimen name="default_icon_size">24dp</dimen>
41+
<dimen name="main_search_box_height">48dp</dimen>
42+
<dimen name="search_box_logo_size">28dp</dimen>
43+
<dimen name="intro_screen_image_size">200dp</dimen>
44+
<dimen name="page_indicator_view_size">6dp</dimen>
2645
</resources>

0 commit comments

Comments
 (0)