添加无数据的状态展示。

This commit is contained in:
ocean 2025-09-19 16:14:53 +08:00
parent 61733e9198
commit 2089866c61
6 changed files with 60 additions and 4 deletions

View File

@ -68,7 +68,12 @@ class HomeFrag : BaseFrag(), MainActivity.SortableFragment {
viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
PdfRepository.getInstance().getAllDocuments().collect { list -> PdfRepository.getInstance().getAllDocuments().collect { list ->
val sortedList = sortDocuments(list) val sortedList = sortDocuments(list)
adapter.updateData(sortedList) if (list.isNotEmpty()) {
adapter.updateData(sortedList)
binding.noFilesLayout.visibility = View.GONE
} else {
binding.noFilesLayout.visibility = View.VISIBLE
}
logDebug("更新adapter数据排序方式: ${appStore.documentSortType}") logDebug("更新adapter数据排序方式: ${appStore.documentSortType}")
} }
} }

View File

@ -46,7 +46,7 @@ class RecentlyFrag : BaseFrag() {
// 下拉刷新示例 // 下拉刷新示例
binding.swipeRefreshLayout.setOnRefreshListener { binding.swipeRefreshLayout.setOnRefreshListener {
observeDocuments{ observeDocuments {
binding.swipeRefreshLayout.isRefreshing = false binding.swipeRefreshLayout.isRefreshing = false
} }
} }
@ -56,8 +56,13 @@ class RecentlyFrag : BaseFrag() {
lifecycleScope.launch { lifecycleScope.launch {
viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
PdfRepository.getInstance().getRecentlyOpenedDocuments().collect { list -> PdfRepository.getInstance().getRecentlyOpenedDocuments().collect { list ->
adapter.updateData(list) if (list.isNotEmpty()) {
onComplete() adapter.updateData(list)
onComplete()
binding.noFilesLayout.visibility = View.GONE
} else {
binding.noFilesLayout.visibility = View.VISIBLE
}
logDebug("更新adapter数据") logDebug("更新adapter数据")
} }
} }

View File

@ -10,6 +10,28 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" /> android:layout_height="0dp" />
<LinearLayout
android:id="@+id/noFilesLayout"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/img_no_files_yet" />
<TextView
style="@style/TextViewFont_PopMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_files_yet"
android:textColor="#B6BFCC"
android:textSize="20sp" />
</LinearLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout" android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -10,6 +10,29 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" /> android:layout_height="0dp" />
<LinearLayout
android:id="@+id/noFilesLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/img_no_files_yet" />
<TextView
style="@style/TextViewFont_PopMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_files_yet"
android:textColor="#B6BFCC"
android:textSize="20sp" />
</LinearLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout" android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent" android:layout_width="match_parent"

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -118,4 +118,5 @@
<string name="delete_bookmarks_title">Delete Bookmarks</string> <string name="delete_bookmarks_title">Delete Bookmarks</string>
<string name="delete_bookmarks_desc">Are you sure you want to delete all Bookmarks?</string> <string name="delete_bookmarks_desc">Are you sure you want to delete all Bookmarks?</string>
<string name="bookmark_loading">Loading bookmarks, please try again later</string> <string name="bookmark_loading">Loading bookmarks, please try again later</string>
<string name="no_files_yet">no files yet</string>
</resources> </resources>