Skip to content

Commit 8d31b51

Browse files
committed
refactor: total price to dialog and refactoring
1 parent 9e14073 commit 8d31b51

File tree

9 files changed

+510
-14
lines changed

9 files changed

+510
-14
lines changed

app/src/main/java/com/patika/getir_lite/feature/basket/BasketUiState.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ import com.patika.getir_lite.util.TopLevelException.GenericOperationFail
55
sealed interface BasketUiState {
66
data object Idle : BasketUiState
77
data object Completed : BasketUiState
8-
data object Cleaned : BasketUiState
98
data class Error(val exception: GenericOperationFail) : BasketUiState
109
}

app/src/main/java/com/patika/getir_lite/feature/basket/BasketViewModel.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,11 @@ class BasketViewModel @Inject constructor(
1818
private val _basketUiState = MutableStateFlow<BasketUiState>(BasketUiState.Idle)
1919
val basketUiState = _basketUiState.asStateFlow()
2020

21-
fun onClearBasketClick() {
21+
fun onClearAndFinishBasketClick() {
2222
viewModelScope.launch {
23-
val result = productRepository.clearBasket()
23+
val isCleaned = productRepository.clearBasket()
2424
when {
25-
result -> _basketUiState.update { BasketUiState.Cleaned }
26-
else -> _basketUiState.update { BasketUiState.Error(GenericOperationFail()) }
27-
}
28-
}
29-
}
30-
31-
fun onFinishOrderClick() {
32-
viewModelScope.launch {
33-
val result = productRepository.clearBasket()
34-
when {
35-
result -> _basketUiState.update { BasketUiState.Completed }
25+
isCleaned -> _basketUiState.update { BasketUiState.Completed }
3626
else -> _basketUiState.update { BasketUiState.Error(GenericOperationFail()) }
3727
}
3828
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="@color/getir_background"
8+
tools:context=".feature.basket.BasketFragment">
9+
10+
<include
11+
android:id="@+id/layout_toolbar"
12+
layout="@layout/toolbar" />
13+
14+
<ImageButton
15+
android:id="@+id/btn_delete_basket"
16+
android:layout_width="wrap_content"
17+
android:layout_height="wrap_content"
18+
android:layout_marginEnd="8dp"
19+
android:background="@null"
20+
android:clickable="true"
21+
android:contentDescription="@string/cancel"
22+
android:focusable="true"
23+
android:foreground="?attr/selectableItemBackgroundBorderless"
24+
android:padding="8dp"
25+
android:src="@drawable/ic_trash_big"
26+
app:layout_constraintBottom_toBottomOf="@id/layout_toolbar"
27+
app:layout_constraintEnd_toEndOf="parent"
28+
app:layout_constraintTop_toTopOf="@id/layout_toolbar"
29+
app:tint="?attr/colorSurface" />
30+
31+
<androidx.recyclerview.widget.RecyclerView
32+
android:id="@+id/rv_basket"
33+
android:layout_width="match_parent"
34+
android:layout_height="0dp"
35+
android:orientation="vertical"
36+
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
37+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
38+
app:layout_constraintBottom_toTopOf="@id/frameLayout"
39+
app:layout_constraintTop_toBottomOf="@id/layout_toolbar"
40+
tools:itemCount="3"
41+
tools:listitem="@layout/item_basket" />
42+
43+
<FrameLayout
44+
android:id="@+id/frameLayout"
45+
android:layout_width="match_parent"
46+
android:layout_height="@dimen/bottom_bar_height"
47+
android:background="?attr/colorSurface"
48+
app:layout_constraintBottom_toBottomOf="parent"
49+
app:layout_constraintEnd_toEndOf="parent"
50+
app:layout_constraintStart_toStartOf="parent">
51+
52+
<androidx.constraintlayout.widget.ConstraintLayout
53+
android:layout_width="match_parent"
54+
android:layout_height="match_parent"
55+
android:padding="12dp">
56+
57+
<Button
58+
android:id="@+id/btn_complete_basket"
59+
android:layout_width="0dp"
60+
android:layout_height="50dp"
61+
android:layout_marginEnd="12dp"
62+
android:background="@drawable/bg_button_basket"
63+
android:foreground="?attr/selectableItemBackground"
64+
android:text="@string/basket_button_text"
65+
android:textStyle="bold"
66+
app:layout_constraintBottom_toBottomOf="parent"
67+
app:layout_constraintEnd_toStartOf="@id/ll_total_price"
68+
app:layout_constraintStart_toStartOf="parent"
69+
app:layout_constraintTop_toTopOf="parent" />
70+
71+
<LinearLayout
72+
android:id="@+id/ll_total_price"
73+
android:layout_width="wrap_content"
74+
android:layout_height="wrap_content"
75+
android:gravity="center"
76+
android:orientation="vertical"
77+
app:layout_constraintBottom_toBottomOf="parent"
78+
app:layout_constraintEnd_toEndOf="parent"
79+
app:layout_constraintTop_toTopOf="parent">
80+
81+
<TextView
82+
android:id="@+id/tv_old_price"
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:textColor="#697488"
86+
android:textFontWeight="600"
87+
android:textSize="12sp"
88+
tools:text="@string/_2000_00" />
89+
90+
<TextView
91+
android:id="@+id/tv_final_price"
92+
android:layout_width="wrap_content"
93+
android:layout_height="wrap_content"
94+
android:textColor="?attr/colorPrimary"
95+
android:textSize="20sp"
96+
android:textStyle="bold"
97+
tools:text="@string/_2000_00" />
98+
99+
</LinearLayout>
100+
101+
102+
</androidx.constraintlayout.widget.ConstraintLayout>
103+
104+
<View
105+
android:layout_width="match_parent"
106+
android:layout_height="10dp"
107+
android:background="@drawable/bg_bottom_shadow" />
108+
109+
</FrameLayout>
110+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="?attr/colorSurface"
8+
tools:context=".feature.detail.DetailFragment">
9+
10+
<Toolbar
11+
android:id="@+id/toolbar"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:background="?attr/colorPrimary"
15+
app:layout_constraintEnd_toEndOf="parent"
16+
app:layout_constraintStart_toStartOf="parent"
17+
app:layout_constraintTop_toTopOf="parent" />
18+
19+
<TextView
20+
android:id="@+id/textView"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:text="@string/product_details"
24+
android:textColor="?attr/colorSurface"
25+
android:textStyle="bold"
26+
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
27+
app:layout_constraintEnd_toEndOf="parent"
28+
app:layout_constraintStart_toStartOf="parent"
29+
app:layout_constraintTop_toTopOf="@+id/toolbar" />
30+
31+
<ImageButton
32+
android:id="@+id/btn_cancel"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:layout_marginStart="16dp"
36+
android:background="@null"
37+
android:contentDescription="@string/cancel"
38+
android:src="@drawable/ic_cancel"
39+
app:layout_constraintBottom_toBottomOf="@id/toolbar"
40+
app:layout_constraintStart_toStartOf="parent"
41+
app:layout_constraintTop_toTopOf="@id/toolbar" />
42+
43+
<include
44+
android:id="@+id/layout_total_price_card"
45+
layout="@layout/total_price_card"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:layout_marginEnd="8dp"
49+
android:visibility="gone"
50+
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
51+
app:layout_constraintEnd_toEndOf="parent"
52+
app:layout_constraintTop_toTopOf="@+id/toolbar" />
53+
54+
<ScrollView
55+
android:id="@+id/scrollView"
56+
android:layout_width="0dp"
57+
android:layout_height="0dp"
58+
app:layout_constraintBottom_toTopOf="@id/frameLayout"
59+
app:layout_constraintEnd_toEndOf="parent"
60+
app:layout_constraintStart_toStartOf="parent"
61+
app:layout_constraintTop_toBottomOf="@id/toolbar">
62+
63+
<LinearLayout
64+
android:layout_width="match_parent"
65+
android:layout_height="wrap_content"
66+
android:layout_marginBottom="16dp"
67+
android:gravity="center"
68+
android:orientation="vertical">
69+
70+
<ImageView
71+
android:id="@+id/iv_food"
72+
android:layout_width="@dimen/detail_image_size"
73+
android:layout_height="@dimen/detail_image_size"
74+
android:layout_marginTop="16dp"
75+
android:contentDescription="@string/food_image"
76+
android:scaleType="centerCrop"
77+
tools:src="@drawable/food" />
78+
79+
<TextView
80+
android:id="@+id/tv_food_price"
81+
android:layout_width="match_parent"
82+
android:layout_height="wrap_content"
83+
android:layout_marginHorizontal="16dp"
84+
android:layout_marginTop="16dp"
85+
android:ellipsize="end"
86+
android:gravity="center"
87+
android:maxLines="1"
88+
android:textColor="?attr/colorPrimary"
89+
android:textSize="20sp"
90+
android:textStyle="bold"
91+
tools:text="@string/_0_00" />
92+
93+
<TextView
94+
android:id="@+id/tv_product_name"
95+
android:layout_width="match_parent"
96+
android:layout_height="wrap_content"
97+
android:layout_marginHorizontal="16dp"
98+
android:ellipsize="end"
99+
android:gravity="center"
100+
android:maxLines="2"
101+
android:textColor="?attr/colorOnSurface"
102+
android:textAlignment="center"
103+
android:textFontWeight="600"
104+
android:textSize="16sp"
105+
tools:text="Product Name" />
106+
107+
<TextView
108+
android:id="@+id/tv_product_attribute"
109+
android:layout_width="match_parent"
110+
android:layout_height="wrap_content"
111+
android:layout_marginHorizontal="16dp"
112+
android:ellipsize="end"
113+
android:gravity="center"
114+
android:maxLines="1"
115+
android:textColor="?attr/colorSecondary"
116+
android:textFontWeight="600"
117+
android:textSize="12sp"
118+
tools:text="Attribute" />
119+
120+
<View
121+
android:layout_width="match_parent"
122+
android:layout_height="3dp"
123+
android:layout_marginTop="16dp"
124+
android:background="@drawable/bg_top_shadow" />
125+
</LinearLayout>
126+
127+
</ScrollView>
128+
129+
130+
<FrameLayout
131+
android:id="@+id/frameLayout"
132+
android:layout_width="match_parent"
133+
android:layout_height="90dp"
134+
android:background="?attr/colorSurface"
135+
app:layout_constraintBottom_toBottomOf="parent"
136+
app:layout_constraintEnd_toEndOf="parent"
137+
app:layout_constraintStart_toStartOf="parent">
138+
139+
<Button
140+
android:id="@+id/btn_add_to_basket"
141+
android:layout_width="match_parent"
142+
android:layout_height="54dp"
143+
android:layout_gravity="center"
144+
android:layout_marginHorizontal="16dp"
145+
android:layout_marginTop="5dp"
146+
android:background="@drawable/bg_button"
147+
android:foreground="?attr/selectableItemBackground"
148+
android:text="@string/add_to_basket"
149+
android:textStyle="bold"
150+
android:visibility="gone" />
151+
152+
<com.patika.getir_lite.ui.ActionCardView
153+
android:id="@+id/item_action_view"
154+
android:layout_width="wrap_content"
155+
android:layout_height="wrap_content"
156+
android:layout_gravity="center"
157+
android:translationZ="3dp"
158+
android:visibility="visible" />
159+
160+
<View
161+
android:layout_width="match_parent"
162+
android:layout_height="10dp"
163+
android:background="@drawable/bg_top_shadow" />
164+
</FrameLayout>
165+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)