mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(templates): use View.OnClickListener for icon click listeners in text field parameter
This commit is contained in:
@@ -15,20 +15,6 @@
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with AndroidIDE. If not,
|
||||
* see <https:></https:>//www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.itsaky.androidide.fragments
|
||||
|
||||
import android.content.Intent
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.itsaky.androidide.templates
|
||||
|
||||
import android.view.View
|
||||
import androidx.annotation.StringRes
|
||||
import com.itsaky.androidide.templates.Language.Java
|
||||
import com.itsaky.androidide.templates.Language.Kotlin
|
||||
@@ -226,24 +227,24 @@ abstract class TextFieldParameter<T>(@StringRes name: Int,
|
||||
@StringRes description: Int?, default: T,
|
||||
val startIcon: ((TextFieldParameter<T>) -> Int)?,
|
||||
val endIcon: ((TextFieldParameter<T>) -> Int)?,
|
||||
val onStartIconClick: (() -> Unit)?,
|
||||
val onEndIconClick: (() -> Unit)?,
|
||||
val onStartIconClick: View.OnClickListener?,
|
||||
val onEndIconClick: View.OnClickListener?,
|
||||
constraints: List<ParameterConstraint>
|
||||
) : Parameter<T>(name, description, default, constraints)
|
||||
|
||||
abstract class TextFieldParameterBuilder<T>(
|
||||
var startIcon: ((TextFieldParameter<T>) -> Int)? = null,
|
||||
var endIcon: ((TextFieldParameter<T>) -> Int)? = null,
|
||||
var onStartIconClick: (() -> Unit)? = null,
|
||||
var onEndIconClick: (() -> Unit)? = null
|
||||
var onStartIconClick: View.OnClickListener? = null,
|
||||
var onEndIconClick: View.OnClickListener? = null
|
||||
) : ParameterBuilder<T>()
|
||||
|
||||
class StringParameter(@StringRes name: Int, @StringRes description: Int?,
|
||||
default: String,
|
||||
startIcon: ((TextFieldParameter<String>) -> Int)?,
|
||||
endIcon: ((TextFieldParameter<String>) -> Int)?,
|
||||
onStartIconClick: (() -> Unit)?,
|
||||
onEndIconClick: (() -> Unit)?,
|
||||
onStartIconClick: View.OnClickListener?,
|
||||
onEndIconClick: View.OnClickListener?,
|
||||
constraints: List<ParameterConstraint>
|
||||
) : TextFieldParameter<String>(name, description, default, startIcon, endIcon,
|
||||
onStartIconClick, onEndIconClick, constraints)
|
||||
@@ -262,8 +263,8 @@ class EnumParameter<T : Enum<*>>(@StringRes name: Int,
|
||||
@StringRes description: Int?, default: T,
|
||||
startIcon: ((TextFieldParameter<T>) -> Int)?,
|
||||
endIcon: ((TextFieldParameter<T>) -> Int)?,
|
||||
onStartIconClick: (() -> Unit)?,
|
||||
onEndIconClick: (() -> Unit)?,
|
||||
onStartIconClick: View.OnClickListener?,
|
||||
onEndIconClick: View.OnClickListener?,
|
||||
constraints: List<ParameterConstraint>,
|
||||
val displayName: ((T) -> String)? = null,
|
||||
val filter: ((T) -> Boolean)? = null
|
||||
|
||||
+2
-6
@@ -214,16 +214,12 @@ class TemplateWidgetViewProviderImpl : ITemplateWidgetViewProvider {
|
||||
) {
|
||||
startIcon?.let {
|
||||
root.startIconDrawable = ContextCompat.getDrawable(context, it(this))
|
||||
onStartIconClick?.let { onClick ->
|
||||
root.setStartIconOnClickListener { onClick() }
|
||||
}
|
||||
onStartIconClick?.let(root::setStartIconOnClickListener)
|
||||
}
|
||||
|
||||
endIcon?.let {
|
||||
root.endIconDrawable = ContextCompat.getDrawable(context, it(this))
|
||||
onEndIconClick?.let { onClick ->
|
||||
root.setEndIconOnClickListener { onClick() }
|
||||
}
|
||||
onEndIconClick?.let(root::setEndIconOnClickListener)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user