Apache License 2.0

项目介绍

DylanCaiCoding/ViewBindingKTX 是一个托管在 GitHub 上的开源项目,主要使用 Kotlin 编写,采用 Apache License 2.0 许可证,目前获得 819 个 Star、92 次 Fork。

仓库全名
DylanCaiCoding/ViewBindingKTX
开源许可证
Apache License 2.0
Star 数
819
Fork 数
92
未关闭 Issue
12

README 摘要

ViewBindingKTX English | 中文 ViewBinding reduces exceptions caused by id or type errors, which are recommended by both Google officials and Jake Wharton, but it can be a bit cumbersome to use, so this library can help you use ViewBinding with as little code as possible in any usage scenario. Feature Support for the usage of Kotlin and Java Support for the usage of reflection and non-reflection Support to modify your…

完整内容见 GitHub 原始 README 或本页 。

常见问题

ViewBindingKTX 用什么语言开发?

主要使用 Kotlin 编写,采用 Apache License 2.0 许可证,目前有 819 个 Star。

ViewBindingKTX 可以免费商用吗?

仓库采用 Apache License 2.0 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 ViewBindingKTX 的源码?

可以直接克隆仓库:git clone https://github.com/DylanCaiCoding/ViewBindingKTX.git,默认分支为 master;安装与运行步骤见仓库 README。

ViewBindingKTX 最近还在维护吗?

仓库最近一次更新为 2023年7月20日,当前有 12 个未关闭 Issue;Star 数为 819,可作为社区活跃度的参考。

关于

The most comprehensive utils of ViewBinding. (最全面的 ViewBinding 工具,支持 Kotlin 和 Java 用法,支持 BRVAH,支持封装到基类,支持 DataBinding,支持选择是否使用反射)

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
1007
价值分
518
活跃状态
活跃

语言占比

Kotlin

Release

README

ViewBindingKTX

English | 中文

ViewBinding reduces exceptions caused by id or type errors, which are recommended by both Google officials and Jake Wharton, but it can be a bit cumbersome to use, so this library can help you use ViewBinding with as little code as possible in any usage scenario.

Feature

  • Support for the usage of Kotlin and Java
  • Support for the usage of reflection and non-reflection
  • Support to modify your base class to support ViewBinding
  • Support for BaseRecyclerViewAdapterHelper
  • Support for Activity, Fragment, Dialog, Adapter
  • Support automatic release of binding class instance in Fragment
  • Support for custom combination view
  • Support for create PopupWindow
  • Support for TabLayout to set custom view
  • Support for NavigationView to set header view
  • Support for DataBinding to automatically set the lifecycle owner

Gradle

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        // ...
        maven { url 'https://www.jitpack.io' }
    }
}

Add dependencies and configurations:

android {
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    // The following are optional, please add as needed
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-ktx:2.1.0'
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-nonreflection-ktx:2.1.0'
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-base:2.1.0'
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-brvah:2.1.0'
}

Usage

:pencil: >> Usage documentation <<

Sample

Get the binding instance using the Kotlin property delegate:

class MainActivity : AppCompatActivity() {

  private val binding: ActivityMainBinding by binding()

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding.tvHelloWorld.text = "Hello Android!"
  }
}
class HomeFragment : Fragment(R.layout.fragment_home) {

  private val binding: FragmentHomeBinding by binding()
  private val childBinding: LayoutChildBinding by binding(Method.INFLATE)
  
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    binding.container.addView(childBinding.root)
  }
}

Use in the base class:

class MainActivity : BaseBindingActivity<ActivityMainBinding>() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding.tvHelloWorld.text = "Hello Android!"
  }
}
class HomeFragment: BaseBindingFragment<FragmentHomeBinding>() {

  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    binding.tvHelloWorld.text = "Hello Android!"
  }
}

Use in BaseRecyclerViewAdapterHelper:

class FooAdapter : BaseQuickAdapter<Foo, BaseViewHolder>(R.layout.item_foo) {

  override fun convert(holder: BaseViewHolder, item: Foo) {
    holder.getBinding(ItemFooBinding::bind).apply {
      tvFoo.text = item.value
    }
  }
}

See the usage documentation for more usage.

Change log

Releases

Author’s other libraries

Library Description
Longan Probably the best Kotlin utils library for Android.
LoadingStateView Decoupling the code of toolbar or loading status view.
MMKV-KTX Use MMKV with property delegates.
Tracker A lightweight tracking framework based on the tracking idea of Buzzvideo.

Thanks

Thanks ViewBindingPropertyDelegate for providing an idea without reflection

License

Copyright (C) 2020. Dylan Cai

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

评论

暂无评论