Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 5c234c5

Browse files
author
evtushenko-bogdan
committed
Fix sum bugs.
1 parent a15f785 commit 5c234c5

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

app/src/main/java/com/bogdan/codeforceswatcher/adapter/UserAdapter.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class UserAdapter(private var items: List<User>, private val ctx: Context) : Rec
2929
}
3030

3131
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
32-
return ViewHolder(LayoutInflater.from(ctx).inflate(R.layout.users_list_view, parent, false), ctx, items)
32+
return ViewHolder(LayoutInflater.from(ctx).inflate(R.layout.users_list_view, parent, false))
3333
}
3434

3535
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@@ -72,6 +72,10 @@ class UserAdapter(private var items: List<User>, private val ctx: Context) : Rec
7272
holder.ivDelta.setImageResource(0)
7373
holder.tvRatingChange.text = null
7474
}
75+
76+
holder.itemView.setOnClickListener {
77+
ctx.startActivity(TryActivity.newIntent(ctx, user.id))
78+
}
7579
}
7680

7781
private fun getDateTime(seconds: Long): String {
@@ -94,20 +98,14 @@ class UserAdapter(private var items: List<User>, private val ctx: Context) : Rec
9498
}
9599
}
96100

97-
class ViewHolder(view: View, ctx: Context, items: List<User>) : RecyclerView.ViewHolder(view) {
101+
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
98102

99103
val tvHandle: TextView = view.tvHandle
100104
val tvRating: TextView = view.tvRating
101105
val tvLastRatingUpdate: TextView = view.tvLastRatingUpdate
102106
val tvRatingChange: TextView = view.tvRatingChange
103107
val ivDelta: ImageView = view.ivDelta
104108

105-
init {
106-
view.setOnClickListener {
107-
ctx.startActivity(TryActivity.newIntent(ctx, items[adapterPosition].id))
108-
}
109-
}
110-
111109
}
112110

113111
}

app/src/main/java/com/bogdan/codeforceswatcher/fragment/UsersFragment.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class UsersFragment : android.support.v4.app.Fragment(), SwipeRefreshLayout.OnRe
2727
private var counterIcon: Int = 0
2828
private lateinit var spSort: AppCompatSpinner
2929
private var prefs = Prefs.get()
30+
private var itemsOnScreen = 0
3031

3132
override fun onRefresh() {
3233
UserLoader.loadUsers(shouldDisplayErrors = true) {
@@ -89,7 +90,18 @@ class UsersFragment : android.support.v4.app.Fragment(), SwipeRefreshLayout.OnRe
8990

9091
val liveData = CwApp.app.userDao.getAllLive()
9192
liveData.observe(this, Observer<List<User>> { userList ->
92-
userList?.let { usersList -> updateList(usersList) }
93+
userList?.let { usersList ->
94+
updateList(usersList)
95+
val firstVisiblePosition = (recyclerView.layoutManager as LinearLayoutManager)
96+
.findFirstVisibleItemPosition()
97+
val lastVisiblePosition = (recyclerView.layoutManager as LinearLayoutManager)
98+
.findLastVisibleItemPosition()
99+
if (lastVisiblePosition - firstVisiblePosition > itemsOnScreen) {
100+
itemsOnScreen = lastVisiblePosition - firstVisiblePosition
101+
} else {
102+
fab.show()
103+
}
104+
}
93105
})
94106
}
95107

0 commit comments

Comments
 (0)