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

Commit da1594b

Browse files
committed
UI: Add blur option & remove zh-rHK strings & remove custom shadow in home
Signed-off-by: Fung Gwo <[email protected]>
1 parent a0044a8 commit da1594b

File tree

20 files changed

+176
-452
lines changed

20 files changed

+176
-452
lines changed

mobile/src/main/kotlin/info/papdt/express/helper/support/PTSettings.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package info.papdt.express.helper.support
33
import android.content.Context
44
import android.os.Build
55
import android.support.annotation.IntDef
6+
import info.papdt.express.helper.ui.adapter.NewHomePackageListAdapter
67
import moe.feng.kotlinyan.common.SharedPreferencesProvider
78
import kotlin.properties.Delegates
89

@@ -23,10 +24,17 @@ class PTSettings(context: Context): SharedPreferencesProvider(context, "settings
2324
var shouldShowTips by booleanValue(defValue = true)
2425
var clickedDonate by booleanValue(defValue = false)
2526

26-
@ApiType var packageApiTypeInt by intValue(defValue = PackageApiType.KUAIDI100)
27+
@ApiType
28+
var packageApiTypeInt by intValue(defValue = PackageApiType.KUAIDI100)
2729

2830
var usingNewDatabase by booleanValue(defValue = false)
2931

32+
var enableAddDialogBackgroundBlur by booleanValue(defValue = true)
33+
34+
var lastFilter by intValue(defValue = NewHomePackageListAdapter.FILTER_ON_THE_WAY)
35+
36+
var lastSortBy by intValue(defValue = NewHomePackageListAdapter.SORT_BY_UPDATE_TIME)
37+
3038
}
3139

3240

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

+77-18
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
6060

6161
}
6262

63-
private val coordinatorLayout by lazy<CoordinatorLayout> { findViewById(R.id.coordinator_layout) }
63+
private val coordinatorLayout by lazy<CoordinatorLayout> {
64+
findViewById(R.id.coordinator_layout)
65+
}
6466
private val appBarLayout by lazy<AppBarLayout> { findViewById(R.id.app_bar_layout) }
6567
private val refreshLayout by lazy<SmartRefreshLayout> { findViewById(R.id.refresh_layout) }
6668
private val listView by lazy<RecyclerView> { findViewById(android.R.id.list) }
@@ -69,7 +71,19 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
6971
private val scanButton by lazy<View> { findViewById(R.id.scan_button) }
7072
private val moreButton by lazy<View> { findViewById(R.id.more_button) }
7173
private val bottomSheet by lazy<View> { findViewById(R.id.bottom_sheet_add_package) }
72-
private val bottomSheetBackground by lazy<FixedBlurLayout> { findViewById(R.id.bottom_sheet_background) }
74+
private val bottomSheetBackgroundBlur by lazy<FixedBlurLayout> {
75+
findViewById(R.id.bottom_sheet_background_blur)
76+
}
77+
private val bottomSheetBackgroundNormal by lazy<View> {
78+
findViewById(R.id.bottom_sheet_background_normal)
79+
}
80+
private val bottomSheetBackground: View get() {
81+
return if (SettingsInstance.enableAddDialogBackgroundBlur) {
82+
bottomSheetBackgroundBlur
83+
} else {
84+
bottomSheetBackgroundNormal
85+
}
86+
}
7387

7488
private val moreMenu: PopupMenu by lazy {
7589
PopupMenu(this, moreButton).also {
@@ -99,10 +113,15 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
99113
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
100114
bottomSheet.makeVisible()
101115
}
116+
117+
listAdapter.filter = SettingsInstance.lastFilter
118+
listAdapter.sortType = SettingsInstance.lastSortBy
102119
} else {
103120

104121
}
105122

123+
spinner.setSelection(listAdapter.filter)
124+
106125
addPackageViewHolder.onRestoreInstanceState(savedInstanceState)
107126
}
108127

@@ -124,12 +143,24 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
124143
listAdapter.notifyDataSetChanged()
125144
}
126145
}, action = ACTION_REQUEST_DELETE_PACK)
127-
bottomSheetBackground.startBlur()
146+
if (SettingsInstance.enableAddDialogBackgroundBlur) {
147+
bottomSheetBackgroundBlur.startBlur()
148+
}
128149
}
129150

130151
override fun onStop() {
131152
super.onStop()
132-
bottomSheetBackground.pauseBlur()
153+
if (SettingsInstance.enableAddDialogBackgroundBlur) {
154+
bottomSheetBackgroundBlur.pauseBlur()
155+
}
156+
}
157+
158+
private fun showBottomSheetBackground() {
159+
bottomSheetBackground.makeVisible()
160+
}
161+
162+
private fun hideBottomSheetBackground() {
163+
bottomSheetBackground.makeGone()
133164
}
134165

135166
@SuppressLint("ClickableViewAccessibility")
@@ -152,18 +183,22 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
152183
position: Int,
153184
id: Long) {
154185
listAdapter.filter = position
186+
SettingsInstance.lastFilter = position
155187
}
156188

157189
}
158-
spinner.setSelection(listAdapter.filter)
159190

160191
addButton.setOnClickListener {
161192
if (refreshLayout.state == RefreshState.Refreshing) {
162193
Toast.makeText(this, R.string.toast_please_wait_for_finishing_refreshing,
163194
Toast.LENGTH_SHORT).show()
164195
} else {
165-
bottomSheetBackground.makeVisible()
166-
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
196+
if (bottomSheetBehavior.state == BottomSheetBehavior.STATE_HIDDEN) {
197+
showBottomSheetBackground()
198+
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
199+
} else {
200+
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
201+
}
167202
}
168203
}
169204

@@ -178,22 +213,38 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
178213
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)
179214
bottomSheetBehavior.setBottomSheetCallback(AddPackageBottomSheetCallback())
180215

216+
addPackageViewHolder = AddPackageViewHolder(bottomSheet)
217+
}
218+
219+
override fun onResume() {
220+
super.onResume()
221+
181222
bottomSheetBackground.setOnTouchListener { _, event ->
182223
if (event.actionMasked == KeyEvent.ACTION_DOWN) {
183224
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
184225
return@setOnTouchListener true
185226
}
186-
false
227+
return@setOnTouchListener false
187228
}
188-
189-
addPackageViewHolder = AddPackageViewHolder(bottomSheet)
190229
}
191230

192231
override fun onCreateOptionsMenu(menu: Menu): Boolean {
193232
menuInflater.inflate(R.menu.top_menu_home, menu)
194233
return super.onCreateOptionsMenu(menu)
195234
}
196235

236+
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
237+
when (SettingsInstance.lastSortBy) {
238+
NewHomePackageListAdapter.SORT_BY_UPDATE_TIME ->
239+
menu.findItem(R.id.action_sort_by_update_time).isChecked = true
240+
NewHomePackageListAdapter.SORT_BY_NAME ->
241+
menu.findItem(R.id.action_sort_by_name).isChecked = true
242+
NewHomePackageListAdapter.SORT_BY_CREATE_TIME ->
243+
menu.findItem(R.id.action_sort_by_create_time).isChecked = true
244+
}
245+
return super.onPrepareOptionsMenu(menu)
246+
}
247+
197248
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
198249
R.id.action_read_all -> {
199250
async(UI) {
@@ -227,16 +278,19 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
227278
R.id.action_sort_by_create_time -> {
228279
item.isChecked = true
229280
listAdapter.sortType = NewHomePackageListAdapter.SORT_BY_CREATE_TIME
281+
SettingsInstance.lastSortBy = listAdapter.sortType
230282
true
231283
}
232284
R.id.action_sort_by_name -> {
233285
item.isChecked = true
234286
listAdapter.sortType = NewHomePackageListAdapter.SORT_BY_NAME
287+
SettingsInstance.lastSortBy = listAdapter.sortType
235288
true
236289
}
237290
R.id.action_sort_by_update_time -> {
238291
item.isChecked = true
239292
listAdapter.sortType = NewHomePackageListAdapter.SORT_BY_UPDATE_TIME
293+
SettingsInstance.lastSortBy = listAdapter.sortType
240294
true
241295
}
242296
else -> super.onOptionsItemSelected(item)
@@ -334,13 +388,16 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
334388
private inner class AddPackageBottomSheetCallback : BottomSheetBehavior.BottomSheetCallback() {
335389

336390
override fun onSlide(v: View, slideOffset: Float) {
337-
bottomSheetBackground.post {
338-
val progress = if (slideOffset.isNaN()) {
339-
1f
340-
} else {
341-
1f + Math.max(slideOffset, -1f)
391+
val progress = if (slideOffset.isNaN())
392+
1f else 1f + Math.max(slideOffset, -1f)
393+
if (SettingsInstance.enableAddDialogBackgroundBlur) {
394+
bottomSheetBackgroundBlur.post {
395+
bottomSheetBackgroundBlur.alpha = progress
396+
}
397+
} else {
398+
bottomSheetBackgroundNormal.post {
399+
bottomSheetBackgroundNormal.alpha = progress * 0.35f
342400
}
343-
bottomSheetBackground.alpha = progress
344401
}
345402
bottomSheetBackground.postInvalidate()
346403
}
@@ -383,7 +440,9 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
383440
val layoutManager = recyclerView.layoutManager!! as LinearLayoutManager
384441
val shouldLift = layoutManager.findFirstCompletelyVisibleItemPosition() != 0
385442

386-
bottomSheetBackground.postInvalidate()
443+
if (SettingsInstance.enableAddDialogBackgroundBlur) {
444+
bottomSheetBackgroundBlur.postInvalidate()
445+
}
387446

388447
if (animatorDirection != shouldLift) {
389448
if (elevationAnimator?.isRunning == true) {
@@ -392,7 +451,7 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
392451
}
393452
animatorDirection = shouldLift
394453
if (elevationAnimator?.isRunning != true
395-
&& appBarLayout.elevation != statedElevation[shouldLift]!!) {
454+
&& appBarLayout.elevation != statedElevation[shouldLift]) {
396455
elevationAnimator = ObjectAnimator.ofFloat(
397456
appBarLayout,
398457
"elevation",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class NewHomePackageListAdapter : MultiTypeAdapter() {
9696
}
9797
SORT_BY_CREATE_TIME -> {
9898
val newList = mutableListOf<Any>()
99-
newList.addAll(data)
99+
newList.addAll(data.reversed())
100100

101101
if (notify) {
102102
setupItemsWithDiffUtils(newList)

mobile/src/main/kotlin/info/papdt/express/helper/ui/fragment/settings/SettingsUi.kt

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ import moe.shizuku.preference.SwitchPreference
1212
class SettingsUi : AbsPrefFragment(), Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
1313

1414
// User interface preference
15-
private val mPrefNightMode: ListPreference by PreferenceProperty("night_mode")
16-
private val mPrefShowTipsAgain: Preference by PreferenceProperty("show_tips_again")
17-
private val mPrefDarkIcon: SwitchPreference? by NullablePreferenceProperty("dark_launcher_icon")
15+
private val mPrefNightMode: ListPreference
16+
by PreferenceProperty("night_mode")
17+
private val mPrefShowTipsAgain: Preference
18+
by PreferenceProperty("show_tips_again")
19+
private val mPrefDarkIcon: SwitchPreference?
20+
by NullablePreferenceProperty("dark_launcher_icon")
21+
private val mPrefBlurOnAddDialogBg: SwitchPreference
22+
by PreferenceProperty("enable_blur_on_add_dialog_background")
1823

1924
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
2025
addPreferencesFromResource(R.xml.settings_ui)
@@ -25,11 +30,13 @@ class SettingsUi : AbsPrefFragment(), Preference.OnPreferenceChangeListener, Pre
2530
}
2631

2732
mPrefDarkIcon?.isChecked = LauncherIconUtils.isDarkLauncherIcon(activity!!)
33+
mPrefBlurOnAddDialogBg.isChecked = SettingsInstance.enableAddDialogBackgroundBlur
2834

2935
// UI
3036
mPrefNightMode.onPreferenceChangeListener = this
3137
mPrefShowTipsAgain.onPreferenceClickListener = this
3238
mPrefDarkIcon?.onPreferenceChangeListener = this
39+
mPrefBlurOnAddDialogBg.onPreferenceChangeListener = this
3340
}
3441

3542
override fun onPreferenceClick(pref: Preference): Boolean {
@@ -58,6 +65,10 @@ class SettingsUi : AbsPrefFragment(), Preference.OnPreferenceChangeListener, Pre
5865
LauncherIconUtils.setDarkLauncherIcon(activity!!, value)
5966
true
6067
}
68+
mPrefBlurOnAddDialogBg -> {
69+
SettingsInstance.enableAddDialogBackgroundBlur = newValue as Boolean
70+
true
71+
}
6172
else -> false
6273
}
6374
}

mobile/src/main/kotlin/info/papdt/express/helper/view/VerticalStepIconView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
9696
mPaint.color = iconColor
9797
mIconBounds!!.top = mBounds!!.centerY() - iconSize / 2 + pointOffsetY
9898
mIconBounds!!.bottom = mBounds!!.centerY() + iconSize / 2 + pointOffsetY
99-
canvas.drawBitmap(centerIconBitmap, null, mIconBounds, mPaint)
99+
canvas.drawBitmap(centerIconBitmap!!, null, mIconBounds!!, mPaint)
100100
}
101101
}
102102

mobile/src/main/res/drawable/bottom_app_bar_shadow.xml

-9
This file was deleted.

0 commit comments

Comments
 (0)