Skip to content

Commit 770a77d

Browse files
committed
show empty status
1 parent 66d7479 commit 770a77d

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

app/src/main/java/io/github/mrtry/todolist/app/todo/viewmodel/ToDoViewModel.kt

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ToDoViewModel
2727
private val coroutineScope: CoroutineScope
2828
) : SwipeRefreshLayout.OnRefreshListener {
2929
val isRefreshing: MutableLiveData<Boolean> = MutableLiveData(false)
30+
val showEmptyStatus: MutableLiveData<Boolean> = MutableLiveData(false)
3031

3132
val items: ObservableList<ToDoListItemViewModel> = ObservableArrayList()
3233

@@ -53,6 +54,7 @@ class ToDoViewModel
5354
navigator.showSnackBar(R.string.to_do_activity_error_get_task_failed)
5455
} finally {
5556
isRefreshing.value = false
57+
showEmptyStatus.value = items.isEmpty()
5658
}
5759
}
5860
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="168dp" android:tint="#808080"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="168dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M14,10H2v2h12V10zM14,6H2v2h12V6zM2,16h8v-2H2V16zM21.5,11.5L23,13l-6.99,7l-4.51,-4.5L13,14l3.01,3L21.5,11.5z"/>
5+
</vector>

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

+42-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
<data>
66

7+
<import type="android.view.View" />
8+
79
<variable
810
name="viewModel"
911
type="io.github.mrtry.todolist.app.todo.viewmodel.ToDoViewModel" />
@@ -42,12 +44,48 @@
4244
app:layout_constraintTop_toBottomOf="@id/divider"
4345
app:layout_constraintBottom_toBottomOf="parent"
4446
app:onRefresh="@{viewModel}"
45-
app:refreshing="@{viewModel.isRefreshing}">
47+
app:refreshing="@{safeUnbox(viewModel.isRefreshing)}">
4648

47-
<androidx.recyclerview.widget.RecyclerView
48-
android:id="@+id/list"
49+
<FrameLayout
4950
android:layout_width="match_parent"
50-
android:layout_height="match_parent" />
51+
android:layout_height="match_parent">
52+
53+
<androidx.recyclerview.widget.RecyclerView
54+
android:id="@+id/list"
55+
android:layout_width="match_parent"
56+
android:layout_height="match_parent"
57+
android:visibility="@{safeUnbox(viewModel.showEmptyStatus) ? View.GONE : View.VISIBLE}" />
58+
59+
<androidx.constraintlayout.widget.ConstraintLayout
60+
android:layout_width="match_parent"
61+
android:layout_height="match_parent"
62+
android:visibility="@{safeUnbox(viewModel.showEmptyStatus) ? View.VISIBLE : View.GONE}">
63+
64+
<ImageView
65+
android:id="@+id/empty_icon"
66+
android:layout_width="wrap_content"
67+
android:layout_height="wrap_content"
68+
android:src="@drawable/ic_empty_status_app_icon"
69+
app:layout_constraintBottom_toTopOf="@id/empty_text"
70+
app:layout_constraintEnd_toEndOf="parent"
71+
app:layout_constraintVertical_bias="0.35"
72+
app:layout_constraintStart_toStartOf="parent"
73+
app:layout_constraintTop_toTopOf="parent"
74+
app:layout_constraintVertical_chainStyle="packed" />
75+
76+
<TextView
77+
android:id="@+id/empty_text"
78+
android:layout_width="wrap_content"
79+
android:layout_height="wrap_content"
80+
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
81+
android:text="@string/to_do_activity_empty_state_text"
82+
app:layout_constraintTop_toBottomOf="@id/empty_icon"
83+
app:layout_constraintBottom_toBottomOf="parent"
84+
app:layout_constraintStart_toStartOf="parent"
85+
app:layout_constraintEnd_toEndOf="parent"
86+
app:layout_constraintVertical_chainStyle="packed" />
87+
</androidx.constraintlayout.widget.ConstraintLayout>
88+
</FrameLayout>
5189
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
5290
</androidx.constraintlayout.widget.ConstraintLayout>
5391
</layout>

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<resources>
22
<string name="app_name">ToDoList</string>
3+
<string name="to_do_activity_empty_state_text">タスクがまだ登録されていません</string>
34
<string name="to_do_activity_error_add_task_failed">登録に失敗しました。再度お試しください。</string>
45
<string name="to_do_activity_error_get_task_failed">取得に失敗しました。再度お試しください。</string>
56
</resources>

0 commit comments

Comments
 (0)