Skip to content

Commit

Permalink
Refactor code and optimize onTouchListener
Browse files Browse the repository at this point in the history
  • Loading branch information
G00fY2 committed Jan 9, 2020
1 parent 6109237 commit cd8596f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class AboutActivity : BaseActivity(), AboutContract.AboutView {
action { presenter.honorClicking() }
}
if (VERSION.SDK_INT >= VERSION_CODES.O_MR1) {
binding.aboutRootScrollview.doOnApplyWindowInsets { view, insets, padding, _ ->
view.updatePadding(bottom = padding.bottom + insets.systemWindowInsetBottom)
}
binding.aboutRootScrollview.apply {
doOnApplyWindowInsets { _, insets, padding, _ ->
updatePadding(bottom = padding.bottom + insets.systemWindowInsetBottom)
}
viewTreeObserver.addOnScrollChangedListener {
val scrollableRange = getChildAt(0).bottom - height + paddingBottom
if (!gesturalNavigationMode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.TooltipCompat
import androidx.core.content.res.ResourcesCompat
Expand Down Expand Up @@ -94,32 +93,30 @@ class AppsActivity : BaseActivity(true), AppsContract.AppsView {
}
})
setOnEditorActionListener { _, actionId, _ ->
val filterString = binding.filterEdittext.text.toString().trim()
val filterString = text.toString().trim()
if (actionId == EditorInfo.IME_ACTION_DONE && filterString.isNotEmpty() && !presenter.duplicateFilter(
filterString
)
) {
presenter.addAppFilter(filterString)
addFilterChip(filterString)
binding.filterEdittext.text.clear()
text.clear()
}
true
}
doAfterTextChanged {
presenter.updateFilter(it)
setCompoundDrawables(null, null, if (!it.isNullOrEmpty()) clearDrawable else null, null)
}
setOnTouchListener { v, event ->
var consumed = false
if (v is EditText) {
if (event.x >= v.width - v.totalPaddingRight) {
if (event.action == MotionEvent.ACTION_UP) {
binding.filterEdittext.text.clear()
}
consumed = true
setOnTouchListener { _, event ->
if (event.x >= width - totalPaddingRight) {
if (event.action == MotionEvent.ACTION_UP) {
performClick()
text.clear()
}
return@setOnTouchListener true
}
consumed
false
}
}
// necessary to measure the view heights for animations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class WidgetConfigActivity : BaseActivity(), WidgetConfigContract.WidgetConfigVi
toggleDeviceNameEdit(false)
}
}
setOnEditorActionListener { v, actionId, _ ->
setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
v.clearFocus()
clearFocus()
}
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ class SystemAppsDataProvider {
@SuppressLint("PrivateApi", "WebViewApiAvailability")
fun getWebViewImplementation(context: Context): String {
return when {
VERSION.SDK_INT >= VERSION_CODES.O -> WebView.getCurrentWebViewPackage()?.let {
context.packageManager.getApplicationLabel(
it.applicationInfo
).toString() + " " + it.versionName
} ?: ""
VERSION.SDK_INT >= VERSION_CODES.O -> {
WebView.getCurrentWebViewPackage()?.let {
context.packageManager.getApplicationLabel(it.applicationInfo).toString() + " " + it.versionName
} ?: ""
}
VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP -> {
try {
(Class.forName("android.webkit.WebViewFactory")
.getMethod("getLoadedPackageInfo")
.invoke(null) as PackageInfo?)?.let { context.packageManager.getApplicationLabel(it.applicationInfo).toString() + " " + it.versionName }
.invoke(null) as PackageInfo?)?.let {
context.packageManager.getApplicationLabel(it.applicationInfo).toString() + " " + it.versionName
}
?: ""
} catch (t: Throwable) {
""
}
}
Version(VERSION.RELEASE.toString()).isAtLeast("4.4.3") -> "WebView v33.0.0.0"
Version(VERSION.RELEASE).isAtLeast("4.4.3") -> "WebView v33.0.0.0"
VERSION.SDK_INT >= VERSION_CODES.KITKAT -> "WebView v30.0.0.0"
else -> try {
context.packageManager.getPackageInfo("com.google.android.webview", 0)
Expand Down

0 comments on commit cd8596f

Please sign in to comment.