Skip to content

Swipe down refresh animation #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.dinuscxj.refresh.RecyclerRefreshLayout
import kotlinx.android.synthetic.main.fragment_leaderboard.view.*
import org.hackillinois.android.R
import org.hackillinois.android.database.entity.Leaderboard
Expand All @@ -31,6 +32,7 @@ class LeaderboardFragment : Fragment() {
private lateinit var recyclerView: RecyclerView
private lateinit var mLayoutManager: LinearLayoutManager
private lateinit var mAdapter: LeaderboardAdapter
private lateinit var refreshLayout: RecyclerRefreshLayout

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -45,6 +47,8 @@ class LeaderboardFragment : Fragment() {
): View? {
val view = inflater.inflate(R.layout.fragment_leaderboard, container, false)

refreshLayout = view.findViewById(R.id.refresh_layout)

mAdapter = LeaderboardAdapter(leaderboard)

recyclerView = view.recyclerview_leaderboard.apply {
Expand All @@ -54,6 +58,12 @@ class LeaderboardFragment : Fragment() {
addItemDecorationWithoutLastItem()
}

refreshLayout.setOnRefreshListener {
// code to refresh list
viewModel.leaderboardRepository.fetchLeaderboard()
refreshLayout.setRefreshing(false)
}

viewModel.leaderboardLiveData.observe(
viewLifecycleOwner,
Observer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.hackillinois.android.database.entity.Leaderboard
import org.hackillinois.android.repository.LeaderboardRepository

class LeaderboardViewModel : ViewModel() {
private val leaderboardRepository = LeaderboardRepository.instance
val leaderboardRepository = LeaderboardRepository.instance

lateinit var leaderboardLiveData: LiveData<List<Leaderboard>>

Expand Down
33 changes: 18 additions & 15 deletions app/src/main/res/layout/fragment_leaderboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@
android:textColor="@color/white"
android:text="@string/leaderboard"
/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_leaderboard"
<com.dinuscxj.refresh.RecyclerRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="50dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_textview_leaderboard"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingEnd="31dp"
android:paddingStart="31dp"
android:paddingBottom="30dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_leaderboard"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="50dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_textview_leaderboard"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingEnd="31dp"
android:paddingStart="31dp"
android:paddingBottom="30dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</com.dinuscxj.refresh.RecyclerRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>