All Projects → ssseasonnn → Yasha

ssseasonnn / Yasha

Licence: apache-2.0
Kotlin-based modern RecyclerView rendering weapon

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Yasha

Klaster
Declare RecyclerView adapters in a functional way, without boilerplate and subclassing. No compromises on flexibility. If it's possible to do something by subclassing, it's possible to do it with this library.
Stars: ✭ 373 (-24.49%)
Mutual labels:  recyclerview
Recyclerviewtemplate
One Template which solves all frequently used RecyclerViews Code Snippets
Stars: ✭ 404 (-18.22%)
Mutual labels:  recyclerview
Tvrecyclerview
TvRecyclerView--针对TV端特性进行的适配与开发
Stars: ✭ 453 (-8.3%)
Mutual labels:  recyclerview
Stackcardlayoutmanager
Stars: ✭ 376 (-23.89%)
Mutual labels:  recyclerview
Popupbubble
🅿️ Easily add and customise "New Post" popup button with the feeds (RecyclerView) of your app.
Stars: ✭ 385 (-22.06%)
Mutual labels:  recyclerview
Recyclerview Gallery
Recyclerview-Gallery:This library shows you a gallery using RecyclerView.
Stars: ✭ 420 (-14.98%)
Mutual labels:  recyclerview
Dragselectrecyclerview
TouchListener that can be attached to any RecyclerView and handles multi selection for you
Stars: ✭ 371 (-24.9%)
Mutual labels:  recyclerview
Indicatordialog
a dialog with arrow indicator in the location where you want
Stars: ✭ 485 (-1.82%)
Mutual labels:  recyclerview
Brvah kotlin
This is kotlin BRVAH Demo
Stars: ✭ 402 (-18.62%)
Mutual labels:  recyclerview
Androidwithkotlin
🚀 These are android sample projects which are written in Kotlin. It covers video streaming, mp3 player, sqlite, location services, custom camera, o-notifications, simple compass etc.
Stars: ✭ 447 (-9.51%)
Mutual labels:  recyclerview
Adapter
A quick adapter library for RecyclerView, GridView, ListView, ViewPager, Spinner
Stars: ✭ 376 (-23.89%)
Mutual labels:  recyclerview
Delegationadapter
一种优雅的方式来使用RecyclerView
Stars: ✭ 382 (-22.67%)
Mutual labels:  recyclerview
Alphabetindex Fast Scroll Recyclerview
A Powerful AlphabetIndex FastScroller Library for Android's RecyclerView!
Stars: ✭ 444 (-10.12%)
Mutual labels:  recyclerview
Y divideritemdecoration
A common RecyclerView divider , supports the LinearLayoutManager and the GridLayoutManager.
Stars: ✭ 373 (-24.49%)
Mutual labels:  recyclerview
Dragdropswiperecyclerview
Kotlin Android library that extends RecyclerView to support gestures like drag & drop and swipe, among others. It works with vertical, horizontal and grid lists.
Stars: ✭ 469 (-5.06%)
Mutual labels:  recyclerview
Familiarrecyclerview
一个如你熟悉ListView、GridView一样熟悉的RecyclerView
Stars: ✭ 372 (-24.7%)
Mutual labels:  recyclerview
Scrollingpagerindicator
Pager indicator inspired by Instagram. Lightweight and easy to set up.
Stars: ✭ 419 (-15.18%)
Mutual labels:  recyclerview
Spannedgridlayoutmanager
Android RecyclerView.LayoutManager that resizes and reorders views based on SpanSize
Stars: ✭ 492 (-0.4%)
Mutual labels:  recyclerview
Nestedrecyclerview
🔥Copied the homepage of taobao and jd.com, and realized the TAB ceiling effect through two-layer nesting RecyclerView .
Stars: ✭ 479 (-3.04%)
Mutual labels:  recyclerview
Recycler Fast Scroll
Provides fast scroll and section idexer for recycler view
Stars: ✭ 445 (-9.92%)
Mutual labels:  recyclerview

Read this in other languages: 中文, English, Changelog

Yasha

Item introduction:

Kotlin-based modern RecyclerView rendering weapon

Item Features:

  • No Adapter required
  • No ViewHolder required
  • Support Coroutine
  • Support page loading
  • Support for MultiViewType
  • Support for Header and Footer
  • Support DiffUtil
  • Support Loading State
  • Support CleanUp, free resources to avoid memory leaks

Prepare

  1. Add jitpack to build.gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add dependency
dependencies {
	implementation 'com.github.ssseasonnn:Yasha:1.1.0'
}

First Blood

How to quickly render a RecyclerView? Still tirelessly writing Adapter, ViewHolder? Let Yasha come to save you:

  //Render a list with ** dataSource ** as the data source
  recycler_view.linear(dataSource) {

      //Render an Item of type NormalItem
      renderItem<NormalItem> {
          //layout res
          res(R.layout.view_holder_normal)

          //bind data 
          onBind {
              tv_normal_content.text = data.toString()
          }
      }

      //Render an Header of type HeaderItem
      renderItem<HeaderItem> {
          //layout res
          res(R.layout.view_holder_header)

          //bind data 
          onBind {
              tv_header_content.text = data.toString()
          }
      }

      //Render an Footer of type FooterItem
      renderItem<FooterItem> {

          //layout res
          res(R.layout.view_holder_footer)

          //bind data 
          onBind {
              tv_footer_content.text = data.toString()
          }
      }
  }

As you can see, it's very simple and intuitive, and you don't see any Adapter or ViewHolder. Equipped with Yasha, go to Gank!

Double Kill

Rendering is done. Where does the data source come from? Yasha thoughtfully prepared a good partner for you:Sange

Sange is another powerful weapon. It can provide any data that Yasha needs. With it, Yasha can be like a fish. As in Dota, they are also inseparable. Friends who are familiar with Dota know that Yasha + Sange = Dark Night The sword is the same here. With both of them, why fear any headwinds?

//Create a DataSource
class DemoDataSource : YashaDataSource() {
   
    //loadInitial is responsible for loading list initialization data
    override fun loadInitial(loadCallback: LoadCallback<YashaItem>) {
        
        //Simulate the delay, don't worry, this method will be executed in an asynchronous thread, so you can rest assured to make network requests or database loading, etc.
        Thread.sleep(1500)

        val allDataList = mutableListOf<YashaItem>()

        //Add Headers data
        for (i in 0 until 2) {
            allDataList.add(HeaderItem(i))
        }
        //Add Items data
        for (i in 0 until 10) {
            allDataList.add(NormalItem(i))
        }
        //Add Footers data
        for (i in 0 until 2) {
            allDataList.add(FooterItem(i))
        }

        //Notify data loading is complete
        loadCallback.setResult(allDataList)
    }

    //loadAfter is responsible for loading the next page of data. Yasha will decide whether to trigger pagination loading by itself. You only need to do the logic to load the next page. Leave the rest to Yasha
    override fun loadAfter(loadCallback: LoadCallback<YashaItem>) {
       
        //when loading failed:
        if (page % 3 == 0) {

            //When data loading fails, you only need to simply tell Yasha a NULL value, and Yasha will automatically stop loading and display a status of loading failure.
            loadCallback.setResult(null)
            return
        }

        //when loading finished:
        if(page == 5) {
            //After the data is loaded, you only need to tell Yasha an empty list, and Yasha will automatically stop loading and display a loading status.            loadCallback.setResult(emptyList())
            return
        }

        //Load the next page of data:
        val items = mutableListOf<YashaItem>()
        for (i in page * 10 until (page + 1) * 10) {
            items.add(NormalItem(i))
        }

        loadCallback.setResult(items)
    }
}

Is it easy? That's right, the API provided by Yasha and Sange is simple and easy to understand. It can be quickly used without any threshold. It is an essential weapon for traveling at home and killing more goods!

In addition, Sange also provides many APIs for directly operating data sources, such as

//Headers
fun addHeader(t: T, position: Int = -1, delay: Boolean = false)
fun addHeaders(list: List<T>, position: Int = -1, delay: Boolean = false) 
fun removeHeader(t: T, delay: Boolean = false) 
fun setHeader(old: T, new: T, delay: Boolean = false)
fun getHeader(position: Int): T
fun clearHeader(delay: Boolean = false)

//Footers
fun addFooter(t: T, position: Int = -1, delay: Boolean = false)
fun addFooters(list: List<T>, position: Int = -1, delay: Boolean = false) 
fun removeFooter(t: T, delay: Boolean = false) 
fun setFooter(old: T, new: T, delay: Boolean = false)
fun getFooter(position: Int): T
fun clearFooter(delay: Boolean = false)

//Items
fun addItem(t: T, position: Int = -1, delay: Boolean = false)
fun addItems(list: List<T>, position: Int = -1, delay: Boolean = false) 
fun removeItem(t: T, delay: Boolean = false) 
fun setItem(old: T, new: T, delay: Boolean = false)
fun getItem(position: Int): T
fun clearItem(delay: Boolean = false)

//...

Triple Kill

In addition, Yasha also prepared the status display for the younger friends, such as commonly used ** Loading **, ** Loading failed **, ** Loading completed **

If there is any dissatisfaction with the state that comes with it, it is very simple. The first method is to kill it. The second method is to replace it.

//kill it:
class DemoDataSource : YashaDataSource() {

    override fun onStateChanged(newState: Int) {
        //super.onStateChanged(newState)
        //You just need to redo this method and comment out the call to super, so there is no status display!
    }
}

//replace it:
recycler_view.linear(dataSource) {

    //Replace with your own state rendering
    renderItem<YashaStateItem> {
        //new state layout res
        res(R.layout.your_state_view)

        //new state bind
        onBind {
            
        }
        gridSpanSize(spanCount)
        staggerFullSpan(true)
    }
}

Radiant wins, GG

License

Copyright 2019 Season.Zlc

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