@@ -60,7 +60,9 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
60
60
61
61
}
62
62
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
+ }
64
66
private val appBarLayout by lazy<AppBarLayout > { findViewById(R .id.app_bar_layout) }
65
67
private val refreshLayout by lazy<SmartRefreshLayout > { findViewById(R .id.refresh_layout) }
66
68
private val listView by lazy<RecyclerView > { findViewById(android.R .id.list) }
@@ -69,7 +71,19 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
69
71
private val scanButton by lazy<View > { findViewById(R .id.scan_button) }
70
72
private val moreButton by lazy<View > { findViewById(R .id.more_button) }
71
73
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
+ }
73
87
74
88
private val moreMenu: PopupMenu by lazy {
75
89
PopupMenu (this , moreButton).also {
@@ -99,10 +113,15 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
99
113
bottomSheetBehavior.state = BottomSheetBehavior .STATE_HIDDEN
100
114
bottomSheet.makeVisible()
101
115
}
116
+
117
+ listAdapter.filter = SettingsInstance .lastFilter
118
+ listAdapter.sortType = SettingsInstance .lastSortBy
102
119
} else {
103
120
104
121
}
105
122
123
+ spinner.setSelection(listAdapter.filter)
124
+
106
125
addPackageViewHolder.onRestoreInstanceState(savedInstanceState)
107
126
}
108
127
@@ -124,12 +143,24 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
124
143
listAdapter.notifyDataSetChanged()
125
144
}
126
145
}, action = ACTION_REQUEST_DELETE_PACK )
127
- bottomSheetBackground.startBlur()
146
+ if (SettingsInstance .enableAddDialogBackgroundBlur) {
147
+ bottomSheetBackgroundBlur.startBlur()
148
+ }
128
149
}
129
150
130
151
override fun onStop () {
131
152
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()
133
164
}
134
165
135
166
@SuppressLint(" ClickableViewAccessibility" )
@@ -152,18 +183,22 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
152
183
position : Int ,
153
184
id : Long ) {
154
185
listAdapter.filter = position
186
+ SettingsInstance .lastFilter = position
155
187
}
156
188
157
189
}
158
- spinner.setSelection(listAdapter.filter)
159
190
160
191
addButton.setOnClickListener {
161
192
if (refreshLayout.state == RefreshState .Refreshing ) {
162
193
Toast .makeText(this , R .string.toast_please_wait_for_finishing_refreshing,
163
194
Toast .LENGTH_SHORT ).show()
164
195
} 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
+ }
167
202
}
168
203
}
169
204
@@ -178,22 +213,38 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
178
213
bottomSheetBehavior = BottomSheetBehavior .from(bottomSheet)
179
214
bottomSheetBehavior.setBottomSheetCallback(AddPackageBottomSheetCallback ())
180
215
216
+ addPackageViewHolder = AddPackageViewHolder (bottomSheet)
217
+ }
218
+
219
+ override fun onResume () {
220
+ super .onResume()
221
+
181
222
bottomSheetBackground.setOnTouchListener { _, event ->
182
223
if (event.actionMasked == KeyEvent .ACTION_DOWN ) {
183
224
bottomSheetBehavior.state = BottomSheetBehavior .STATE_HIDDEN
184
225
return @setOnTouchListener true
185
226
}
186
- false
227
+ return @setOnTouchListener false
187
228
}
188
-
189
- addPackageViewHolder = AddPackageViewHolder (bottomSheet)
190
229
}
191
230
192
231
override fun onCreateOptionsMenu (menu : Menu ): Boolean {
193
232
menuInflater.inflate(R .menu.top_menu_home, menu)
194
233
return super .onCreateOptionsMenu(menu)
195
234
}
196
235
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
+
197
248
override fun onOptionsItemSelected (item : MenuItem ): Boolean = when (item.itemId) {
198
249
R .id.action_read_all -> {
199
250
async(UI ) {
@@ -227,16 +278,19 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
227
278
R .id.action_sort_by_create_time -> {
228
279
item.isChecked = true
229
280
listAdapter.sortType = NewHomePackageListAdapter .SORT_BY_CREATE_TIME
281
+ SettingsInstance .lastSortBy = listAdapter.sortType
230
282
true
231
283
}
232
284
R .id.action_sort_by_name -> {
233
285
item.isChecked = true
234
286
listAdapter.sortType = NewHomePackageListAdapter .SORT_BY_NAME
287
+ SettingsInstance .lastSortBy = listAdapter.sortType
235
288
true
236
289
}
237
290
R .id.action_sort_by_update_time -> {
238
291
item.isChecked = true
239
292
listAdapter.sortType = NewHomePackageListAdapter .SORT_BY_UPDATE_TIME
293
+ SettingsInstance .lastSortBy = listAdapter.sortType
240
294
true
241
295
}
242
296
else -> super .onOptionsItemSelected(item)
@@ -334,13 +388,16 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
334
388
private inner class AddPackageBottomSheetCallback : BottomSheetBehavior .BottomSheetCallback () {
335
389
336
390
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
342
400
}
343
- bottomSheetBackground.alpha = progress
344
401
}
345
402
bottomSheetBackground.postInvalidate()
346
403
}
@@ -383,7 +440,9 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
383
440
val layoutManager = recyclerView.layoutManager!! as LinearLayoutManager
384
441
val shouldLift = layoutManager.findFirstCompletelyVisibleItemPosition() != 0
385
442
386
- bottomSheetBackground.postInvalidate()
443
+ if (SettingsInstance .enableAddDialogBackgroundBlur) {
444
+ bottomSheetBackgroundBlur.postInvalidate()
445
+ }
387
446
388
447
if (animatorDirection != shouldLift) {
389
448
if (elevationAnimator?.isRunning == true ) {
@@ -392,7 +451,7 @@ class HomeActivity : AbsActivity(), OnRefreshListener {
392
451
}
393
452
animatorDirection = shouldLift
394
453
if (elevationAnimator?.isRunning != true
395
- && appBarLayout.elevation != statedElevation[shouldLift]!! ) {
454
+ && appBarLayout.elevation != statedElevation[shouldLift]) {
396
455
elevationAnimator = ObjectAnimator .ofFloat(
397
456
appBarLayout,
398
457
" elevation" ,
0 commit comments