All Projects → EranBoudjnah → solid

EranBoudjnah / solid

Licence: MIT license
Solid Android components

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to solid

Binding
Simple API implement DataBinding and ViewBinding. 简单的 API 实现 DataBinding 和 ViewBinding,欢迎 star
Stars: ✭ 169 (+412.12%)
Mutual labels:  recyclerview, fragment, activity
My Android Garage
A quick reference guide for Android development.
Stars: ✭ 66 (+100%)
Mutual labels:  recyclerview, fragment, activity
Base
🍁 Base是针对于Android开发封装好一些常用的基类,主要包括通用的Adapter、Activity、Fragment、Dialog等、和一些常用的Util类,只为更简单。
Stars: ✭ 249 (+654.55%)
Mutual labels:  fragment, activity
GeneralRecyclerViewFragment
Can automatically pull down the refresh, pull up the page of RecyclerviewFragment(能够自动下拉刷新,上拉翻页的RecyclerviewFragment)
Stars: ✭ 56 (+69.7%)
Mutual labels:  recyclerview, fragment
aspnet-mvc5-starter-template
Asp.Net MVC 5 Starter Kit is a S.O.L.I.D, clean and globalized template with all the necessary boilerplate, ready to go.
Stars: ✭ 39 (+18.18%)
Mutual labels:  solid, dependency-injection
Navigator
Android Multi-module navigator, trying to find a way to navigate into a modularized android project
Stars: ✭ 131 (+296.97%)
Mutual labels:  fragment, activity
Rxlifecycle
Rx binding of stock Android Activities & Fragment Lifecycle, avoiding memory leak
Stars: ✭ 131 (+296.97%)
Mutual labels:  fragment, activity
movie-booking
An example for booking movie seat, combined of Android Data Binding, State Design Pattern and Multibinding + Autofactory. iOS version is: https://github.com/lizhiquan/MovieBooking
Stars: ✭ 80 (+142.42%)
Mutual labels:  recyclerview, dependency-injection
Viewtooltip
A fluent tooltip for Android
Stars: ✭ 1,029 (+3018.18%)
Mutual labels:  fragment, activity
Zenject Hero
Zenject 7 - Game example (WIP)
Stars: ✭ 44 (+33.33%)
Mutual labels:  solid, dependency-injection
Service Pattern Go
Simple clean Go REST API architecture with dependency injection and mocking example, following SOLID principles.
Stars: ✭ 449 (+1260.61%)
Mutual labels:  solid, dependency-injection
No Framework Tutorial
A small tutorial to show how to create a PHP application without a framework.
Stars: ✭ 1,357 (+4012.12%)
Mutual labels:  solid, dependency-injection
Tieguanyin
Activity Builder.
Stars: ✭ 113 (+242.42%)
Mutual labels:  fragment, activity
Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (+139.39%)
Mutual labels:  fragment, activity
Bundler
🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.
Stars: ✭ 195 (+490.91%)
Mutual labels:  fragment, activity
Thirtyinch
a MVP library for Android favoring a stateful Presenter
Stars: ✭ 1,052 (+3087.88%)
Mutual labels:  fragment, activity
Inlineactivityresult
Receive the activity result directly after the startActivityForResult with InlineActivityResult
Stars: ✭ 264 (+700%)
Mutual labels:  fragment, activity
Solid
Книга о принципах объектно-ориентированного дизайна SOLID
Stars: ✭ 280 (+748.48%)
Mutual labels:  solid, dependency-injection
RxComponentLifecycle
Rx binding of new Android Architecture Component Lifecycle
Stars: ✭ 57 (+72.73%)
Mutual labels:  fragment, activity
BindingExtension
Android ViewBinding extension to provide simpler usage in Activity, Fragment and ViewHolder.
Stars: ✭ 26 (-21.21%)
Mutual labels:  fragment, activity

SOLID Components

Version - Application

Version - Activity Version - Fragment Version - Service

Version - RecyclerView

Build Status License Platform

SOLID Components are an attempt at following good engineering standards and best practices such as SOLID and DRY where Google neglected to.

Icon

Installation

And the implementation dependencies below. You can add just the components you need.

dependencies {
    implementation "com.mitteloupe.solid:solidapplication:1.0.8"

    implementation "com.mitteloupe.solid:solidactivity:1.0.8"
    implementation "com.mitteloupe.solid:solidfragment:1.0.7"
    implementation "com.mitteloupe.solid:solidservice:1.0.8"

    implementation "com.mitteloupe.solid:solidrecyclerview:1.0.5"
}

Usage

Application

Make your app Application instance extend SolidApplication. To implement functionality, simply override lifecycleHandlers, configurationChangeHandlers or memoryHandlers, providing relevant handlers.

Activity

Use SolidActivity as the parent activity of any activity in your app. Instead of having a BaseActivity, you can now provide common activity code by overriding one or more of the handler lists, providing a list of handlers.

Common use cases can include dependency injection, analytics, logging, setting up of ViewHolders.

A Koin injection handler will look as follows:

class KoinActivityScopeHandler(
    private val activity: Activity,
    private val currentScope: Scope
) : LifecycleHandler {
    override fun onCreate(savedInstanceState: Bundle?) {
        currentScope.declare(activity)
    }
}

Implement an activity using the handler as follows:

class MainActivity : SolidActivity() {
    override val lifecycleHandlers = listOf(
        KoinActivityScopeHandler(this, currentScope),
        ...
    )

    ...
}

Fragment

Use SolidFragment as the parent fragment of any fragment in your app. Instead of having a BaseFragment, you can now provide common fragment code by overriding one or more of the handler lists, providing a list of handlers.

Common use cases can include dependency injection, analytics, logging, setting up of ViewHolders.

A Koin injection handler will look as follows:

class KoinFragmentScopeHandler(
    private val fragment: Fragment,
    private val currentScope: Scope
) : LifecycleHandler {
    override fun onCreate(savedInstanceState: Bundle?) {
        currentScope.declare(fragment)
    }
}

Implement an fragment using the handler as follows:

class MainFragment : SolidFragment() {
    override val lifecycleHandlers = listOf(
        KoinFragmentScopeHandler(this, currentScope),
        ...
    )

    ...
}

Service

SolidService allows composing services instead of inheriting from base services.

As an example, an IntentService using SolidService would look like this:

class SolidIntentService : SolidService() {
    override val lifecycleHandlers = listOf(
        IntentHandler(this, { intent -> handleIntent(intent) })
    )

    private fun handleIntent(intent: Intent?) {
        ...
    }
}

Adapter

Instead of setting a RecyclerView.Adapter to your RecyclerView, simply set a SolidAdapter.

SolidAdapter has a few constructor-injected dependencies that define its behaviour:

  1. ViewProvider - this will provide child Views for your RecyclerView. A handy InflatedViewProvider is available for simple layout inflation.

  2. viewHolderProvider - this is a lambda that, given a View, returns a ViewHolder. It is worth noting that when using a SolidAdapter, ViewHolder do just that. They hold references to Views (commonly obtained by calling findViewById()). This is their sole responsibility.

  3. ViewBinder - this will bind a data item to views provided by a ViewHolder.

  4. itemsSynchronizerProvider - this is a lambda that, given a RecyclerView.Adapter, returns an ItemsSynchronizer. The responsibility of ItemsSynchronizer is to hold the data items and synchronize changes with the RecyclerView.Adapter. If not provided, the SolidAdapter uses a default SimpleItemsSynchronizer, which provides most common functionality.

  5. positionToType - this is a lambda that, given an ItemsSynchronizer instance and a position, returns the view type for that position. By default, it always returns ITEM_TYPE_DEFAULT.

Comparison

Let's take a look at a simple, common RecyclerView.Adapter implementation:

Without SolidAdapter:

class MoodViewHolder(
    override val containerView: View
) : RecyclerView.ViewHolder(containerView), LayoutContainer {
    val iconView: ImageView = layoutIconView
    val titleView: TextView = layoutTitleView

    override fun bindData(moodItem: MoodUiModel) {
        iconView.setImageDrawable(
            AppCompatResources.getDrawable(context, data.iconResourceId)
        )
        indexView.text = data.title
    }
}

class ListItemsAdapter(
    private val layoutInflater: LayoutInflater
) : RecyclerView.Adapter<MoodViewHolder>() {
    private val listData = mutableListOf<MoodUiModel>()

    fun setData(listData: List<MoodUiModel>) {
        this.listData.clear()
        this.listData.addAll(listData)
        notifyDataSetChanged()
    }

    fun removeItem(position: Int) {
        listData.removeAt(position)
        notifyItemRemoved(position)
    }

    fun addItem(position: Int, item: ListItemUiModel) {
        listData.add(position, item)
        notifyItemInserted(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MoodViewHolder {
        val view = layoutInflater.inflate(R.layout.item_mood, parent, false)
        return MoodViewHolder(view)
    }

    override fun getItemCount() = listData.size

    override fun onBindViewHolder(holder: ListItemViewHolder, position: Int) {
        holder.bindData(listData[position])
    }
}

val adapter = ListItemsAdapter(layoutInflater)

With SolidAdapter:

class MoodViewProvider(
    layoutInflater: LayoutInflater
) : InflatedViewProvider(layoutInflater, R.layout.item_mood)

class MoodViewHolder(
    override val containerView: View
) : RecyclerView.ViewHolder(containerView), LayoutContainer {
    val iconView: ImageView = layoutIconView
    val titleView: TextView = layoutTitleView
}

class MoodViewBinder(
    private val context: Context
) : SimpleViewBinder<MoodViewHolder, MoodUiModel>() {
    override fun bindView(viewHolder: MoodViewHolder, data: MoodUiModel) {
        viewHolder.iconView.setImageDrawable(
            AppCompatResources.getDrawable(context, data.iconResourceId)
        )
        viewHolder.indexView.text = data.title
    }
}

val adapter = SolidAdapter(
    MoodViewProvider(layoutInflater),
    { view, _ -> MoodViewHolder(view) },
    MoodViewBinder(this)
)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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].