-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nested RecyclerViews and eased diffing (#10)
Improvements: * added `onHolderCreated` to be able to perform also one-shot bindings when creating a new view holder * eased diffing implementation * improved diffing algorithm * added documentation for carousels * minor code improvements
- Loading branch information
Showing
42 changed files
with
862 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 0 additions & 92 deletions
92
app/demo/src/main/java/net/gotev/recycleradapterdemo/activities/APIIntegration.kt
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
app/demo/src/main/java/net/gotev/recycleradapterdemo/activities/Carousels.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package net.gotev.recycleradapterdemo.activities | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlinx.android.synthetic.main.activity_recycler_view.* | ||
import net.gotev.recycleradapter.RecyclerAdapter | ||
import net.gotev.recycleradapter.ext.NestedRecyclerAdapterItem | ||
import net.gotev.recycleradapterdemo.R | ||
import net.gotev.recycleradapterdemo.adapteritems.LabelItem | ||
import net.gotev.recycleradapterdemo.adapteritems.TitledCarousel | ||
|
||
|
||
class Carousels : AppCompatActivity() { | ||
|
||
companion object { | ||
private const val PARAM_POOL = "withPool" | ||
fun show(activity: AppCompatActivity, withPool: Boolean) { | ||
activity.startActivity(Intent(activity, Carousels::class.java).apply { | ||
putExtra(PARAM_POOL, withPool) | ||
}) | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_recycler_view) | ||
|
||
val withPool = intent.getBooleanExtra(PARAM_POOL, false) | ||
|
||
title = getString(if (withPool) { | ||
R.string.carousels_pool | ||
} else { | ||
R.string.carousels_plain | ||
}) | ||
|
||
supportActionBar?.apply { | ||
setHomeButtonEnabled(true) | ||
setDisplayHomeAsUpEnabled(true) | ||
} | ||
|
||
val recyclerAdapter = RecyclerAdapter() | ||
|
||
recycler_view.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) | ||
recycler_view.adapter = recyclerAdapter | ||
|
||
val recycledViewPool = if (withPool) { | ||
RecyclerAdapter.createRecycledViewPool( | ||
parent = recycler_view, | ||
items = listOf(LabelItem("")), | ||
maxViewsPerItem = 50 | ||
) | ||
} else { | ||
null | ||
} | ||
|
||
recyclerAdapter.add(createCarousels(recycledViewPool)) | ||
|
||
swipeRefresh.setOnRefreshListener { | ||
swipeRefresh.isRefreshing = false | ||
} | ||
|
||
} | ||
|
||
private fun createCarouselItems(): List<LabelItem> { | ||
return (0..40).map { | ||
LabelItem("Text $it") | ||
} | ||
} | ||
|
||
private fun createCarousels(recycledViewPool: RecyclerView.RecycledViewPool?) | ||
: List<NestedRecyclerAdapterItem<*>> { | ||
return (0..60).map { | ||
val adapter = RecyclerAdapter().apply { | ||
add(createCarouselItems()) | ||
} | ||
|
||
TitledCarousel("Carousel $it", adapter, recycledViewPool) | ||
} | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
app/demo/src/main/java/net/gotev/recycleradapterdemo/activities/InfiniteScroll.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.gotev.recycleradapterdemo.activities | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.paging.PagedList | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlinx.android.synthetic.main.activity_recycler_view.* | ||
import net.gotev.recycleradapterdemo.App | ||
import net.gotev.recycleradapterdemo.R | ||
import net.gotev.recycleradapterdemo.network.api.StarWarsPeopleDataSource | ||
import net.gotev.recycleradapterdemo.paging.PagingHelper | ||
|
||
|
||
class InfiniteScroll : AppCompatActivity() { | ||
|
||
companion object { | ||
fun show(activity: AppCompatActivity) { | ||
activity.startActivity(Intent(activity, InfiniteScroll::class.java)) | ||
} | ||
} | ||
|
||
private lateinit var pagingHelper: PagingHelper<*> | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_recycler_view) | ||
|
||
title = getString(R.string.infinite_scrolling) | ||
|
||
supportActionBar?.apply { | ||
setHomeButtonEnabled(true) | ||
setDisplayHomeAsUpEnabled(true) | ||
} | ||
|
||
pagingHelper = PagingHelper( | ||
dataSource = { StarWarsPeopleDataSource(App.starWarsClient) }, | ||
config = PagedList.Config.Builder() | ||
.setPageSize(20) | ||
.setEnablePlaceholders(false) | ||
.setPrefetchDistance(10) | ||
.setMaxSize(50) | ||
.build() | ||
) | ||
|
||
recycler_view.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) | ||
pagingHelper.setupRecyclerView(recycler_view) | ||
|
||
swipeRefresh.isRefreshing = true | ||
pagingHelper.start(this) { | ||
swipeRefresh.isRefreshing = false | ||
} | ||
|
||
swipeRefresh.setOnRefreshListener { | ||
pagingHelper.reload() | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.