Complete settings controls and refresh behavior
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package se.ajpanton.notificationlog
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.CheckBox
|
||||
import android.widget.LinearLayout
|
||||
@@ -25,11 +26,36 @@ class EventSettingsFragment : Fragment(R.layout.fragment_event_settings) {
|
||||
store = LoggingRuleStore(requireContext())
|
||||
binding!!.pageTitle.setText(requireArguments().getInt(ARG_TITLE))
|
||||
bindRule()
|
||||
binding!!.appListRefresh.setOnRefreshListener { reloadAppList(); binding!!.appListRefresh.isRefreshing = false }
|
||||
binding!!.appListRefresh.setOnRefreshListener(::refreshAppList)
|
||||
var touchStartY = 0f
|
||||
val scroll = binding!!.appScroll
|
||||
scroll.setOnTouchListener { _, event ->
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> touchStartY = event.y
|
||||
MotionEvent.ACTION_UP -> {
|
||||
val atBottom = scroll.scrollY >= (scroll.getChildAt(0).height - scroll.height).coerceAtLeast(0)
|
||||
if (atBottom && event.y < touchStartY) {
|
||||
refreshAppList()
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() { binding = null; super.onDestroyView() }
|
||||
|
||||
private fun refreshAppList() {
|
||||
val currentBinding = binding ?: return
|
||||
currentBinding.appListRefresh.isRefreshing = true
|
||||
currentBinding.appListRefresh.post {
|
||||
if (binding === currentBinding) {
|
||||
reloadAppList()
|
||||
currentBinding.appListRefresh.isRefreshing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindRule() {
|
||||
val rule = store.ruleFor(type)
|
||||
listOf(
|
||||
|
||||
Reference in New Issue
Block a user