Skip to content

Commit

Permalink
Cannot call this method in a scroll callback. 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethSS committed Oct 21, 2020
1 parent ae43342 commit 8d35044
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ import com.solar.recyclerview.SolarRecyclerView

class FoodRecyclerView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : SolarRecyclerView<Food>(context, attrs, defStyleAttr) {

override val viewModel: FoodViewModel = FoodViewModel()
}
) : SolarRecyclerView<Food>(context, attrs, defStyleAttr)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class MainActivity : AppCompatActivity() {
}*/

main_recycler_view.run {
addMore(FoodFactory.getFoodSample(), false)
addMore(FoodFactory.getFoodSample())

listener = object: SolarRecyclerView.RecyclerViewListener {
override fun isEnd() {
postDelayed({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class SolarRecyclerView<T: ItemType> @JvmOverloads constructor(
loadStateAdapter.loadState = value
}

abstract val viewModel: ViewModel
var viewModel: ViewModel? = null

var isReverse: Boolean = true

Expand Down Expand Up @@ -172,7 +172,10 @@ abstract class SolarRecyclerView<T: ItemType> @JvmOverloads constructor(
if (visibleItemCount + lastVisibleItemPosition + threshold > totalItemCount) {
if (loadStateAdapter.loadState != LoadState.Loading) {
listener?.isEnd()
loadStateAdapter.loadState = LoadState.Loading

post {
loadStateAdapter.loadState = LoadState.Loading
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.solar.recyclerview.ItemListener
import com.solar.recyclerview.holder.BindingHolder
import com.solar.recyclerview.ItemType

class DataBindingAdapter<T : ItemType>(private val viewModel: ViewModel)
class DataBindingAdapter<T : ItemType>(private val viewModel: ViewModel?)
: BaseAdapter<T, BindingHolder<T>>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindingHolder<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BindingHolder<T>(
val binding: ViewDataBinding
) : RecyclerView.ViewHolder(binding.root){

fun bind(item: T, position: Int, viewModel: ViewModel) {
fun bind(item: T, position: Int, viewModel: ViewModel?) {
binding.setVariable(BR.item, item)
binding.setVariable(BR.position, position)
binding.setVariable(BR.vm, viewModel)
Expand Down

0 comments on commit 8d35044

Please sign in to comment.