All Projects → Jintin → BindingExtension

Jintin / BindingExtension

Licence: Apache-2.0 license
Android ViewBinding extension to provide simpler usage in Activity, Fragment and ViewHolder.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to BindingExtension

Inlineactivityresult
Receive the activity result directly after the startActivityForResult with InlineActivityResult
Stars: ✭ 264 (+915.38%)
Mutual labels:  fragment, activity
My Android Garage
A quick reference guide for Android development.
Stars: ✭ 66 (+153.85%)
Mutual labels:  fragment, activity
solid
Solid Android components
Stars: ✭ 33 (+26.92%)
Mutual labels:  fragment, activity
Base
🍁 Base是针对于Android开发封装好一些常用的基类,主要包括通用的Adapter、Activity、Fragment、Dialog等、和一些常用的Util类,只为更简单。
Stars: ✭ 249 (+857.69%)
Mutual labels:  fragment, activity
Navigator
Android Multi-module navigator, trying to find a way to navigate into a modularized android project
Stars: ✭ 131 (+403.85%)
Mutual labels:  fragment, activity
RxComponentLifecycle
Rx binding of new Android Architecture Component Lifecycle
Stars: ✭ 57 (+119.23%)
Mutual labels:  fragment, activity
Viewtooltip
A fluent tooltip for Android
Stars: ✭ 1,029 (+3857.69%)
Mutual labels:  fragment, activity
Thirtyinch
a MVP library for Android favoring a stateful Presenter
Stars: ✭ 1,052 (+3946.15%)
Mutual labels:  fragment, activity
Tieguanyin
Activity Builder.
Stars: ✭ 113 (+334.62%)
Mutual labels:  fragment, activity
Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (+203.85%)
Mutual labels:  fragment, activity
Binding
Simple API implement DataBinding and ViewBinding. 简单的 API 实现 DataBinding 和 ViewBinding,欢迎 star
Stars: ✭ 169 (+550%)
Mutual labels:  fragment, activity
Rxlifecycle
Rx binding of stock Android Activities & Fragment Lifecycle, avoiding memory leak
Stars: ✭ 131 (+403.85%)
Mutual labels:  fragment, activity
Bundler
🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.
Stars: ✭ 195 (+650%)
Mutual labels:  fragment, activity
Android Multibackstack
Persistent bottom navigation like in instagram
Stars: ✭ 223 (+757.69%)
Mutual labels:  fragment
Neteasecloudmusic
仿网易云音乐安卓客户端V6.0
Stars: ✭ 213 (+719.23%)
Mutual labels:  fragment
drag-to-close
Android library that provides a view group which allows to finish an activity by dragging a view.
Stars: ✭ 69 (+165.38%)
Mutual labels:  activity
Bracer
Pass parameters safely and quickly between activities or fragments.
Stars: ✭ 57 (+119.23%)
Mutual labels:  fragment
Bookshelf
📖 书柜 BookShelf Android App
Stars: ✭ 205 (+688.46%)
Mutual labels:  fragment
dflow
A lightweight library for designing and executing workflows in .NET Core
Stars: ✭ 23 (-11.54%)
Mutual labels:  activity
RecyclerAdapter
简单易懂的 RecyclerView adapter 封装
Stars: ✭ 27 (+3.85%)
Mutual labels:  viewbinding

BindingExtension

CircleCI jitpack

ViewBinding is an amazing tool for Android but it's not so fit in Android development as we still have to do some config. BindingExtension is built to provide a simpler usage.

Install

Add Jitpack repository to your root build.grable:

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

Then add dependency in your module build.gradle:

dependencies {
  implementation 'com.github.jintin:BindingExtension:3.1.0'
}

Usage

First of all, BindingExtension using refelction a lot to link many things internally in order to provide simple usage. To prevent having trouble with proguard, please remember to exclude ViewBinding related method in your proguard-rules file like this:

-keepclassmembers class * implements androidx.viewbinding.ViewBinding {
     public static ** inflate(...);
}

Activity

Extend from BindingActivity with your ViewBinding type then you can use binding directly after calling super.onCreate(savedInstanceState) and you don't have to call setContentView anymore:

class MainActivity : BindingActivity<ActivityMainBinding>() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding.label.setText(R.string.activity_label)
    }
}

Fragment

Extend from BindingFragment with your ViewBinding type then you can use binding directly after super.onCreateView(inflater, container, savedInstanceState) is called:

class MainFragment : BindingFragment<FragmentMainBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.button.setOnClickListener {
            binding.button.setText(R.string.fragment_label)
        }
    }
}

ViewHolder

BindingExtension provide an extension function for ViewGroup, you can call ViewGroup.toBinding() in onCreateViewHolder to get your desire type of ViewBinding. And ViewHolder can than access ViewBinding directly without further transformation.

// inside adapter
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    return MainViewHolder(parent.toBinding())
}

// ViewHolder
class MainViewHolder(private val binding: AdapterMainBinding) :
    RecyclerView.ViewHolder(binding.root) {

    fun bind(data: String) {
        binding.name.text = data
    }
}

You can go to ./app module for more information.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Jintin/BindingExtension.

Buy Me A Coffee

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].