Fixed errors on infinite scroll

This commit is contained in:
ivan agosto 2019-02-12 11:45:24 -06:00
parent 130ece5982
commit c1b746da80
3 changed files with 5 additions and 5 deletions

View File

@ -111,6 +111,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
(viewAdapter as VideosAdapter).clearData() (viewAdapter as VideosAdapter).clearData()
recyclerView.scrollToPosition(0) recyclerView.scrollToPosition(0)
} }
(viewAdapter as VideosAdapter).addData(videos) (viewAdapter as VideosAdapter).addData(videos)
}catch (err: Exception){ }catch (err: Exception){
err.printStackTrace() err.printStackTrace()
@ -281,8 +282,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
// lastItem.isChecked = false // lastItem.isChecked = false
// } // }
lastItem = item lastItem = item
pagination = 0
// item.isChecked = true // item.isChecked = true
when (item.itemId) { when (item.itemId) {
@ -350,7 +350,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private fun loadMore(){ private fun loadMore(){
swipeContainer.isRefreshing = true swipeContainer.isRefreshing = true
this.pagination += 30 this.pagination += ManagerSingleton.videos_count
when(section){ when(section){
"local" -> this.getLocalVideos() "local" -> this.getLocalVideos()

View File

@ -100,7 +100,7 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
} }
fun addData(newItems: ArrayList<VideoModel>){ fun addData(newItems: ArrayList<VideoModel>){
val lastPos = myDataset.size - 1 val lastPos = myDataset.size
myDataset.addAll(newItems) myDataset.addAll(newItems)
notifyItemRangeInserted(lastPos, newItems.size) notifyItemRangeInserted(lastPos, newItems.size)
} }

View File

@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.3.0' classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong