在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):MarcinMoskala/KotlinAndroidViewBindings开源软件地址(OpenSource Url):https://github.com/MarcinMoskala/KotlinAndroidViewBindings开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):KotlinAndroidViewBindingsBindings for properties with Kotlin types (Boolean, String) to layout traits (visibility, text). Library allows to bind properties of basic types (String, Int, functional) to view element properties. Example: var email: String by bindToTextView(R.id.emailView)
val emailRequestFocus: ()->Unit by bindToRequestFocus(R.id.emailView)
var emailErrorId: Int? by bindToErrorId(R.id.emailView) This allows to make clear and simple MVP. Example: LoginView.kt interface LoginView {
var progressVisible: Boolean
var email: String
val emailRequestFocus: ()->Unit
var emailErrorId: Int?
var password: String
val passwordRequestFocus: ()->Unit
var passwordErrorId: Int?
var loginButtonClickedCallback: ()->Unit
} LoginActivity.kt class LoginActivity : AppCompatActivity(), LoginView {
override var progressVisible by bindToLoading(R.id.progressView, R.id.loginFormView)
override var email by bindToTextView(R.id.emailView)
override val emailRequestFocus by bindToRequestFocus(R.id.emailView)
override var emailErrorId by bindToErrorId(R.id.emailView)
override var password by bindToTextView(R.id.passwordView)
override val passwordRequestFocus by bindToRequestFocus(R.id.passwordView)
override var passwordErrorId by bindToErrorId(R.id.passwordView)
override var loginButtonClickedCallback by bindToClick(R.id.loginButton)
//...
} Presenter.kt class LoginPresenter(val view: LoginView) {
fun onCreate() {
view.loginButtonClickedCallback = { attemptLogin() }
}
//...
} This makes presenters fully unit-testable while keeping Activities short and simple. Full example here. Library usage in wider context here. InstallationTo add KotlinAndroidViewBindings to the project, add to dependencies {
implementation 'com.github.MarcinMoskala:KotlinAndroidViewBindings:0.12'
} While library is located on JitPack, remember to add to module repositories {
maven { url 'https://jitpack.io' }
} MediaOther librariesIf you like it, remember to leave the star and check out my other libraries:
License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论