Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

Commit 5eda5e7

Browse files
committed
Add illustration when user hasn't placed any orders
1 parent cfd1e80 commit 5eda5e7

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

app/src/main/java/com/marknkamau/justjava/ui/orders/OrdersActivity.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class OrdersActivity : AppCompatActivity() {
4949
tvOrderId.text = order.id
5050
tvOrderDate.text = DateTime.fromTimestamp(order.datePlaced).format("hh:mm a, d MMM yyyy")
5151
tvOrderStatus.text = order.status.s.capitalize().replace("_", " ")
52-
tvOrderItems.text = order.items.joinToString{ it.productName }
52+
tvOrderItems.text = order.items.joinToString { it.productName }
5353
tvOrderTotal.text = getString(R.string.price_listing, CurrencyFormatter.format(order.totalPrice))
5454

55-
when(order.status){
55+
when (order.status) {
5656
OrderStatus.PENDING -> tvOrderStatus.setBackgroundResource(R.drawable.bg_order_pending)
5757
OrderStatus.CONFIRMED -> tvOrderStatus.setBackgroundResource(R.drawable.bg_order_confirmed)
5858
OrderStatus.IN_PROGRESS -> tvOrderStatus.setBackgroundResource(R.drawable.bg_order_in_progress)
@@ -72,7 +72,16 @@ class OrdersActivity : AppCompatActivity() {
7272

7373
ordersViewModel.orders.observe(this, Observer { resource ->
7474
when (resource) {
75-
is Resource.Success -> adapter.setItems(resource.data.sortedBy { it.datePlaced }.reversed())
75+
is Resource.Success -> {
76+
if (resource.data.isEmpty()) {
77+
llNoOrders.visibility = View.VISIBLE
78+
rvOrders.visibility = View.GONE
79+
} else {
80+
llNoOrders.visibility = View.GONE
81+
rvOrders.visibility = View.VISIBLE
82+
adapter.setItems(resource.data.sortedBy { it.datePlaced }.reversed())
83+
}
84+
}
7685
is Resource.Failure -> toast(resource.response.message, Toast.LENGTH_LONG)
7786
}
7887
})

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,36 @@
66
android:layout_height="match_parent"
77
tools:context="com.marknkamau.justjava.ui.orders.OrdersActivity">
88

9+
<LinearLayout
10+
android:id="@+id/llNoOrders"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:orientation="vertical"
14+
android:visibility="gone"
15+
app:layout_constraintBottom_toBottomOf="parent"
16+
app:layout_constraintEnd_toEndOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintTop_toTopOf="parent"
19+
tools:visibility="visible">
20+
21+
<ImageView
22+
android:id="@+id/imageView2"
23+
android:layout_width="172dp"
24+
android:layout_height="172dp"
25+
android:layout_gravity="center"
26+
android:contentDescription="@null"
27+
app:srcCompat="@drawable/il_no_orders" />
28+
29+
<TextView
30+
android:id="@+id/textView3"
31+
style="@style/AppTheme.Text.18Primary"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:layout_gravity="center"
35+
android:layout_marginTop="32dp"
36+
android:text="You haven't made any orders" />
37+
</LinearLayout>
38+
939
<ProgressBar
1040
android:id="@+id/pbLoading"
1141
style="?android:attr/progressBarStyle"

0 commit comments

Comments
 (0)