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

Commit 96bdcda

Browse files
committed
UI: Use offsetByCodePoints to fix result is noto when getting first char
Signed-off-by: Fung Gwo <fython@163.com>
1 parent ee24eae commit 96bdcda

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

mobile/src/main/kotlin/info/papdt/express/helper/model/Kuaidi100Package.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ class Kuaidi100Package() : Parcelable {
8888
data = parcel.createTypedArrayList(Status.CREATOR)
8989
}
9090

91+
fun getFirstChar(): String {
92+
return try {
93+
name?.substring(
94+
name!!.offsetByCodePoints(0, 0),
95+
name!!.offsetByCodePoints(0, 1)
96+
)
97+
} catch (e: Exception) {
98+
name?.substring(0, 1)
99+
} ?: ""
100+
}
101+
91102
fun getState(): Int {
92103
return if (state != null) state!!.toInt() else STATUS_FAILED
93104
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import android.util.Log
1515
import android.view.*
1616
import android.widget.*
1717
import androidx.asynclayoutinflater.view.AsyncLayoutInflater
18-
import androidx.coordinatorlayout.widget.CoordinatorLayout
1918
import com.google.android.material.appbar.AppBarLayout
2019
import com.google.android.material.bottomsheet.BottomSheetBehavior
2120
import com.google.android.material.snackbar.Snackbar
@@ -86,9 +85,6 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
8685

8786
}
8887

89-
private val coordinatorLayout by lazy<CoordinatorLayout> {
90-
findViewById(R.id.coordinator_layout)
91-
}
9288
private val appBarLayout by lazy<AppBarLayout> { findViewById(R.id.app_bar_layout) }
9389
private val refreshLayout by lazy<SmartRefreshLayout> { findViewById(R.id.refresh_layout) }
9490
private val listView by lazy<RecyclerView> { findViewById(android.R.id.list) }

mobile/src/main/kotlin/info/papdt/express/helper/ui/items/PackageItemViewBinder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ object PackageItemViewBinder
9494
typeface = Typeface.DEFAULT
9595
paint.isFakeBoldText = true
9696
if (item.name?.isNotEmpty() == true) {
97-
text = item.name!!.substring(0, 1).toUpperCase()
97+
text = item.getFirstChar()
9898
} else if (item.companyChineseName?.isNotEmpty() == true) {
9999
text = item.companyChineseName!!.substring(0, 1).toUpperCase()
100100
}

mobile/src/main/kotlin/info/papdt/express/helper/ui/launcher/ListFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ListFactory(private val mContext: Context, intent: Intent) : RemoteViewsSe
7171
}
7272

7373
/** Set CircleImageView */
74-
views.setTextViewText(R.id.tv_first_char, p.name!!.substring(0, 1))
74+
views.setTextViewText(R.id.tv_first_char, p.getFirstChar())
7575
val packagePalette = p.getPaletteFromId()
7676
val b = ScreenUtils.drawableToBitmap(ColorDrawable(packagePalette["100"]))
7777
views.setImageViewBitmap(R.id.iv_logo, b)

0 commit comments

Comments
 (0)