Use a swipe to refresh layout
This commit is contained in:
@@ -57,6 +57,7 @@ dependencies {
|
||||
implementation "androidx.paging:paging-runtime:$paging_version"
|
||||
implementation "androidx.fragment:fragment-ktx:$fragment_version"
|
||||
implementation "androidx.preference:preference-ktx:$preference_version"
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||
|
||||
//implementation 'androidx.core:core-ktx:+'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
|
@@ -14,6 +14,7 @@ import androidx.paging.*
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import fr.uca.iut.clfreville2.teaiswarm.R
|
||||
import fr.uca.iut.clfreville2.teaiswarm.REPOSITORY_NAME
|
||||
import fr.uca.iut.clfreville2.teaiswarm.REPOSITORY_OWNER
|
||||
@@ -32,16 +33,20 @@ class ActivityListFragment : Fragment(R.layout.activity_list) {
|
||||
var repository: RepositoryIdentifier? = null
|
||||
var sha: String? = null
|
||||
|
||||
private lateinit var pagingAdapter: ActivityAdapter
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
if (view is SwipeRefreshLayout) {
|
||||
view.setOnRefreshListener {
|
||||
updateCommits()
|
||||
view.isRefreshing = false
|
||||
}
|
||||
}
|
||||
repository = RepositoryIdentifier(
|
||||
requireArguments().getString(REPOSITORY_OWNER)!!,
|
||||
requireArguments().getString(REPOSITORY_NAME)!!
|
||||
)
|
||||
updateCommits()
|
||||
}
|
||||
|
||||
private fun updateCommits() {
|
||||
val viewModel by viewModels<ActivityViewModel>(
|
||||
factoryProducer = {
|
||||
ActivityViewModelFactory(
|
||||
@@ -51,8 +56,8 @@ class ActivityListFragment : Fragment(R.layout.activity_list) {
|
||||
)
|
||||
}
|
||||
)
|
||||
val pagingAdapter = ActivityAdapter(ActivityComparator)
|
||||
val recyclerView = requireView().findViewById<RecyclerView>(R.id.activity_list_view)
|
||||
pagingAdapter = ActivityAdapter(ActivityComparator)
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.activity_list_view)
|
||||
recyclerView.adapter = pagingAdapter
|
||||
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
@@ -62,6 +67,10 @@ class ActivityListFragment : Fragment(R.layout.activity_list) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCommits() {
|
||||
pagingAdapter.refresh()
|
||||
}
|
||||
|
||||
class ActivitySource(
|
||||
private val service: RepositoryService,
|
||||
private val repository: RepositoryIdentifier,
|
||||
|
@@ -15,6 +15,7 @@ import androidx.lifecycle.viewModelScope
|
||||
import androidx.paging.*
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import fr.uca.iut.clfreville2.teaiswarm.R
|
||||
import fr.uca.iut.clfreville2.teaiswarm.TeaIsWarm
|
||||
import fr.uca.iut.clfreville2.teaiswarm.adapter.RepositoryListAdapter
|
||||
@@ -47,6 +48,12 @@ class RepositoryListFragment(
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
if (view is SwipeRefreshLayout) {
|
||||
view.setOnRefreshListener {
|
||||
updateRepositories()
|
||||
view.isRefreshing = false
|
||||
}
|
||||
}
|
||||
recyclerView = view.findViewById(R.id.repositories_view)
|
||||
val spinner: Spinner = view.findViewById(R.id.sort_by_spinner)
|
||||
ArrayAdapter.createFromResource(
|
||||
|
@@ -1,9 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/activity_list_view" />
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/activity_list_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</FrameLayout>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
@@ -1,26 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Spinner
|
||||
android:id="@+id/sort_by_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/desc_sort_toggle"
|
||||
android:textOff="@string/asc_sort"
|
||||
android:textOn="@string/desc_sort"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/sort_by_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/desc_sort_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textOff="@string/asc_sort"
|
||||
android:textOn="@string/desc_sort" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/repositories_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/repositories_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
Reference in New Issue
Block a user