Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.

Commit cf9ebe0

Browse files
committed
UI: Add empty view for home list
Signed-off-by: Fung Gwo <[email protected]>
1 parent 0a42a0e commit cf9ebe0

15 files changed

+217
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package info.papdt.express.helper.model
2+
3+
data class HomeListEmptyViewModel(
4+
val type: Int
5+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package info.papdt.express.helper.model
2+
3+
class HomeListNoResultViewModel

mobile/src/main/kotlin/info/papdt/express/helper/services/ClipboardDetectService.kt

+16-15
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,23 @@ class ClipboardDetectService : Service(), ClipboardManager.OnPrimaryClipChangedL
6565
}
6666

6767
override fun onPrimaryClipChanged() {
68-
mLastNumber = getPackageNumber(clipboardManager.primaryClip.toString())
69-
if (TextUtils.isEmpty(mLastNumber)) return
70-
try {
71-
windowManager.addView(mLayout, mLayoutParams)
72-
mIconView.scaleX = 0.5f
73-
mIconView.scaleY = 0.5f
74-
mIconView.animate()
75-
.scaleX(1f)
76-
.scaleY(1f)
77-
.setListener(null)
78-
.setDuration(500).setInterpolator(BounceInterpolator()).start()
79-
mHandler.sendEmptyMessageDelayed(0, 4500)
80-
} catch (e: Exception) {
81-
e.printStackTrace()
68+
clipboardManager.primaryClip?.let {
69+
mLastNumber = getPackageNumber(it.toString())
70+
if (TextUtils.isEmpty(mLastNumber)) return
71+
try {
72+
windowManager.addView(mLayout, mLayoutParams)
73+
mIconView.scaleX = 0.5f
74+
mIconView.scaleY = 0.5f
75+
mIconView.animate()
76+
.scaleX(1f)
77+
.scaleY(1f)
78+
.setListener(null)
79+
.setDuration(500).setInterpolator(BounceInterpolator()).start()
80+
mHandler.sendEmptyMessageDelayed(0, 4500)
81+
} catch (e: Exception) {
82+
e.printStackTrace()
83+
}
8284
}
83-
8485
}
8586

8687
private fun initPopupView() {

mobile/src/main/kotlin/info/papdt/express/helper/ui/adapter/CompanyListAdapter.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class CompanyListAdapter(
2929
return ItemHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_list_company, parent, false))
3030
}
3131

32-
override fun onBindViewHolder(holder: SimpleRecyclerViewAdapter.ClickableViewHolder, pos: Int) {
33-
super.onBindViewHolder(holder, pos)
34-
val item = getItem(pos)
32+
override fun onBindViewHolder(holder: SimpleRecyclerViewAdapter.ClickableViewHolder, position: Int) {
33+
super.onBindViewHolder(holder, position)
34+
val item = getItem(position)
3535
if (holder is ItemHolder) {
3636
holder.titleText.text = item.name
3737
holder.otherText.text = if (item.phone != null) item.phone else item.website

mobile/src/main/kotlin/info/papdt/express/helper/ui/adapter/HomeToolbarSpinnerAdapter.kt

-6
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,4 @@ class HomeToolbarSpinnerAdapter(
6060
}
6161
}
6262

63-
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
64-
return super.getDropDownView(position, convertView, parent).also {
65-
val textView = it.findViewById<TextView>(android.R.id.text1)
66-
}
67-
}
68-
6963
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package info.papdt.express.helper.ui.adapter
2+
3+
import android.content.Context
4+
import android.view.View
5+
import androidx.recyclerview.widget.RecyclerView
6+
7+
abstract class ItemViewHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) {
8+
9+
val context: Context get() = itemView.context
10+
11+
var item: T? = null
12+
13+
fun bind(item: T) {
14+
this.item = item
15+
onBind(item)
16+
}
17+
18+
protected abstract fun onBind(item: T)
19+
20+
}

mobile/src/main/kotlin/info/papdt/express/helper/ui/adapter/NewHomePackageListAdapter.kt

+27-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package info.papdt.express.helper.ui.adapter
22

33
import androidx.recyclerview.widget.DiffUtil
44
import info.papdt.express.helper.dao.PackageDatabase
5+
import info.papdt.express.helper.model.HomeListEmptyViewModel
6+
import info.papdt.express.helper.model.HomeListNoResultViewModel
57
import info.papdt.express.helper.model.Kuaidi100Package
68
import info.papdt.express.helper.support.DateHelper
79
import info.papdt.express.helper.ui.items.DateSubheadViewBinder
10+
import info.papdt.express.helper.ui.items.HomeListEmptyViewBinder
11+
import info.papdt.express.helper.ui.items.HomeListNoResultViewBinder
812
import info.papdt.express.helper.ui.items.PackageItemViewBinder
913
import me.drakeet.multitype.MultiTypeAdapter
1014
import java.text.Collator
@@ -60,6 +64,8 @@ class NewHomePackageListAdapter : MultiTypeAdapter() {
6064
init {
6165
register(Long::class.javaObjectType, DateSubheadViewBinder)
6266
register(Kuaidi100Package::class.java, PackageItemViewBinder)
67+
register(HomeListEmptyViewModel::class.java, HomeListEmptyViewBinder)
68+
register(HomeListNoResultViewModel::class.java, HomeListNoResultViewBinder)
6369
}
6470

6571
fun setPackages(packages: List<Kuaidi100Package>, notify: Boolean = true) {
@@ -99,6 +105,26 @@ class NewHomePackageListAdapter : MultiTypeAdapter() {
99105
}
100106
}
101107
return@filter true
108+
}?.let { filteredData ->
109+
if (filteredData.isEmpty()) {
110+
val newList = mutableListOf<Any>()
111+
112+
if (filterKeyword == null && filterCompany == null) {
113+
newList += HomeListEmptyViewModel(filter)
114+
} else {
115+
newList += HomeListNoResultViewModel()
116+
}
117+
118+
if (notify) {
119+
setupItemsWithDiffUtils(newList)
120+
} else {
121+
items = newList
122+
}
123+
124+
return@let null
125+
} else {
126+
return@let filteredData
127+
}
102128
}?.let { data ->
103129
when (sortType) {
104130
SORT_BY_UPDATE_TIME -> {
@@ -109,11 +135,7 @@ class NewHomePackageListAdapter : MultiTypeAdapter() {
109135
pack.getFirstStatusTime().let { time ->
110136
val diffDays = DateHelper.getDifferenceDaysForGroup(time.time)
111137
// Fix unstable group
112-
if (diffDays < 0) {
113-
-1
114-
} else {
115-
diffDays
116-
}
138+
if (diffDays < 0) -1 else diffDays
117139
}
118140
}
119141
for ((groupDate, packagesInGroup) in groups) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package info.papdt.express.helper.ui.items
2+
3+
import android.view.LayoutInflater
4+
import android.view.View
5+
import android.view.ViewGroup
6+
import android.widget.TextView
7+
import info.papdt.express.helper.R
8+
import info.papdt.express.helper.model.HomeListEmptyViewModel
9+
import info.papdt.express.helper.ui.adapter.ItemViewHolder
10+
import info.papdt.express.helper.ui.adapter.NewHomePackageListAdapter
11+
import me.drakeet.multitype.ItemViewBinder
12+
13+
object HomeListEmptyViewBinder
14+
: ItemViewBinder<HomeListEmptyViewModel, HomeListEmptyViewBinder.ViewHolder>() {
15+
16+
override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
17+
return ViewHolder(inflater.inflate(R.layout.home_list_empty_view_layout, parent, false))
18+
}
19+
20+
override fun onBindViewHolder(holder: ViewHolder, item: HomeListEmptyViewModel) {
21+
holder.bind(item)
22+
}
23+
24+
class ViewHolder(itemView: View) : ItemViewHolder<HomeListEmptyViewModel>(itemView) {
25+
26+
private val textView: TextView = itemView.findViewById(android.R.id.text1)
27+
28+
override fun onBind(item: HomeListEmptyViewModel) {
29+
textView.setText(when (item.type) {
30+
NewHomePackageListAdapter.FILTER_ALL -> R.string.frame_empty_tip_all
31+
NewHomePackageListAdapter.FILTER_ON_THE_WAY -> R.string.frame_empty_tip_delivering
32+
NewHomePackageListAdapter.FILTER_DELIVERED -> R.string.frame_empty_tip_delivered
33+
else -> 0
34+
})
35+
}
36+
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package info.papdt.express.helper.ui.items
2+
3+
import android.view.LayoutInflater
4+
import android.view.View
5+
import android.view.ViewGroup
6+
import info.papdt.express.helper.R
7+
import info.papdt.express.helper.model.HomeListNoResultViewModel
8+
import info.papdt.express.helper.ui.adapter.ItemViewHolder
9+
import me.drakeet.multitype.ItemViewBinder
10+
11+
object HomeListNoResultViewBinder
12+
: ItemViewBinder<HomeListNoResultViewModel, HomeListNoResultViewBinder.ViewHolder>() {
13+
14+
override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
15+
return ViewHolder(inflater.inflate(R.layout.home_list_no_result_view_layout, parent, false))
16+
}
17+
18+
override fun onBindViewHolder(holder: ViewHolder, item: HomeListNoResultViewModel) {
19+
holder.bind(item)
20+
}
21+
22+
class ViewHolder(itemView: View) : ItemViewHolder<HomeListNoResultViewModel>(itemView) {
23+
24+
override fun onBind(item: HomeListNoResultViewModel) {
25+
26+
}
27+
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:shape="rectangle">
5+
6+
<corners android:radius="6dp"/>
7+
8+
<stroke android:width="1dp" android:color="@color/flat_card_border_color"/>
9+
10+
</shape>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:orientation="vertical"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:gravity="center">
8+
9+
<ImageView
10+
android:id="@android:id/icon"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:importantForAccessibility="no"
14+
android:src="@drawable/ic_empty_inbox"/>
15+
16+
<TextView
17+
android:id="@android:id/text1"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_marginTop="16dp"
21+
android:layout_marginBottom="?android:attr/actionBarSize"
22+
tools:text="@string/frame_empty_tip"/>
23+
24+
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:orientation="horizontal"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:background="@drawable/flat_card_background"
8+
android:paddingTop="16dp"
9+
android:paddingBottom="16dp"
10+
android:layout_marginStart="16dp"
11+
android:layout_marginEnd="16dp"
12+
android:layout_marginTop="16dp"
13+
android:layout_marginBottom="16dp">
14+
15+
<ImageView
16+
android:id="@android:id/icon"
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:layout_marginStart="16dp"
20+
android:importantForAccessibility="no"
21+
android:src="@drawable/ic_error_outline_black_24dp"
22+
android:tint="?android:attr/textColorPrimary"
23+
android:tintMode="src_in"/>
24+
25+
<TextView
26+
android:id="@android:id/text1"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:layout_marginStart="16dp"
30+
android:layout_marginEnd="16dp"
31+
android:textColor="?android:attr/textColorPrimary"
32+
android:text="@string/home_list_no_result_text"/>
33+
34+
</LinearLayout>

mobile/src/main/res/values-night/colors.xml

+2
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@
4848
<string name="packageIconForegroundColorKey">900</string>
4949
<string name="packageStatusIconColorKey">200</string>
5050

51+
<color name="flat_card_border_color">@color/grey_700</color>
52+
5153
</resources>

mobile/src/main/res/values/colors.xml

+2
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@
5151
<string name="packageIconBackgroundColorKey">100</string>
5252
<string name="packageIconForegroundColorKey">800</string>
5353
<string name="packageStatusIconColorKey">800</string>
54+
55+
<color name="flat_card_border_color">@color/grey_500</color>
5456

5557
</resources>

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
<string name="label_shortcut_scan">Scan barcode</string>
88

99
<!-- Home design -->
10-
<string name="tap_target_tips_1_title">New Home Design!</string>
11-
<string name="tap_target_tips_1_desc">We redesigned the interface in Package Tracker 3.0. Now you got a search box and you can add/find a package from here.</string>
12-
<string name="tap_target_tips_2_title">Scan barcode</string>
13-
<string name="tap_target_tips_2_desc">Read package number quickly from camera.</string>
14-
<string name="tap_target_tips_3_title">Get latest status</string>
15-
<string name="tap_target_tips_3_desc">You can swipe down to refresh status. Set up auto refresh or use more power-saving FCM-based push service in background.</string>
16-
1710
<string name="navigation_item_all">All</string>
1811
<string name="navigation_item_delivered">Delivered</string>
1912
<string name="navigation_item_on_the_way">On the way</string>
@@ -344,4 +337,6 @@
344337
<string name="unset">Unset</string>
345338
<string name="search_by_type_title">Search by specific type</string>
346339

340+
<string name="home_list_no_result_text">No result according to current filter conditions.\nPlease try to change/clear filter.</string>
341+
347342
</resources>

0 commit comments

Comments
 (0)