feat: swipe refresh activity/notifications
This commit is contained in:
parent
e00bbb2d8e
commit
91bcacc978
5 changed files with 84 additions and 39 deletions
|
@ -79,6 +79,9 @@ class FollowActivity : AppCompatActivity(){
|
||||||
PrefManager.setVal(PrefName.FollowerLayout, 1)
|
PrefManager.setVal(PrefName.FollowerLayout, 1)
|
||||||
fillList()
|
fillList()
|
||||||
}
|
}
|
||||||
|
binding.followSwipeRefresh.setOnRefreshListener {
|
||||||
|
binding.followSwipeRefresh.isRefreshing = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillList() {
|
private fun fillList() {
|
||||||
|
|
|
@ -87,23 +87,20 @@ class FeedFragment : Fragment() {
|
||||||
) {
|
) {
|
||||||
page++
|
page++
|
||||||
binding.feedRefresh.visibility = ViewGroup.VISIBLE
|
binding.feedRefresh.visibility = ViewGroup.VISIBLE
|
||||||
activity.lifecycleScope.launch(Dispatchers.IO) {
|
loadPage {
|
||||||
val newRes = Anilist.query.getFeed(userId, global, page)
|
binding.feedRefresh.visibility = ViewGroup.GONE
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
newRes?.data?.page?.activities?.let { activities ->
|
|
||||||
activityList += activities
|
|
||||||
val filtered = activities.filterNot {
|
|
||||||
it.recipient?.id != null && it.recipient.id != Anilist.userid
|
|
||||||
}
|
|
||||||
adapter.addAll(filtered.map { ActivityItem(it, ::onActivityClick,requireActivity()) })
|
|
||||||
}
|
|
||||||
binding.feedRefresh.visibility = ViewGroup.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.feedSwipeRefresh.setOnRefreshListener {
|
||||||
|
page = 1
|
||||||
|
adapter.clear()
|
||||||
|
activityList = emptyList()
|
||||||
|
loadPage()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadedFirstTime = true
|
loadedFirstTime = true
|
||||||
|
@ -111,6 +108,23 @@ class FeedFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadPage(onFinish: () -> Unit = {}) {
|
||||||
|
activity.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val newRes = Anilist.query.getFeed(userId, global, page)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
newRes?.data?.page?.activities?.let { activities ->
|
||||||
|
activityList += activities
|
||||||
|
val filtered = activities.filterNot {
|
||||||
|
it.recipient?.id != null && it.recipient.id != Anilist.userid
|
||||||
|
}
|
||||||
|
adapter.addAll(filtered.map { ActivityItem(it, ::onActivityClick,requireActivity()) })
|
||||||
|
}
|
||||||
|
binding.feedSwipeRefresh.isRefreshing = false
|
||||||
|
onFinish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun onActivityClick(id: Int, type: String) {
|
private fun onActivityClick(id: Int, type: String) {
|
||||||
when (type) {
|
when (type) {
|
||||||
"USER" -> {
|
"USER" -> {
|
||||||
|
|
|
@ -88,25 +88,34 @@ class NotificationActivity : AppCompatActivity() {
|
||||||
) {
|
) {
|
||||||
page++
|
page++
|
||||||
binding.followRefresh.visibility = ViewGroup.VISIBLE
|
binding.followRefresh.visibility = ViewGroup.VISIBLE
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
loadPage {
|
||||||
val res = Anilist.query.getNotifications(Anilist.userid ?: 0, page)
|
binding.followRefresh.visibility = ViewGroup.GONE
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
res?.data?.page?.notifications?.let { notifications ->
|
|
||||||
notificationList += notifications
|
|
||||||
adapter.addAll(notifications.map {
|
|
||||||
NotificationItem(
|
|
||||||
it,
|
|
||||||
::onNotificationClick
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
binding.followRefresh.visibility = ViewGroup.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.followSwipeRefresh.setOnRefreshListener {
|
||||||
|
page = 1
|
||||||
|
adapter.clear()
|
||||||
|
notificationList = emptyList()
|
||||||
|
loadPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadPage(onFinish: () -> Unit = {}) {
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val res = Anilist.query.getNotifications(Anilist.userid ?: 0, page)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
res?.data?.page?.notifications?.let { notifications ->
|
||||||
|
notificationList += notifications
|
||||||
|
adapter.addAll(notifications.map { NotificationItem(it, ::onNotificationClick) })
|
||||||
|
}
|
||||||
|
binding.followSwipeRefresh.isRefreshing = false
|
||||||
|
onFinish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,13 +98,23 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/listRecyclerView"
|
android:id="@+id/followSwipeRefresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:clipChildren="false"
|
||||||
android:layout_marginEnd="8dp"
|
android:clipToPadding="false">
|
||||||
android:nestedScrollingEnabled="true" />
|
|
||||||
|
<ani.dantotsu.FadingEdgeRecyclerView
|
||||||
|
android:id="@+id/listRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
|
android:requiresFadingEdge="vertical" />
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/followRefresh"
|
android:id="@+id/followRefresh"
|
||||||
|
|
|
@ -16,16 +16,25 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
android:id="@+id/feedSwipeRefresh"
|
||||||
android:id="@+id/listRecyclerView"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:clipChildren="false"
|
||||||
android:layout_marginEnd="8dp"
|
android:clipToPadding="false">
|
||||||
android:nestedScrollingEnabled="true"
|
|
||||||
android:visibility="visible"
|
<ani.dantotsu.FadingEdgeRecyclerView
|
||||||
tools:listitem="@layout/item_activity" />
|
android:id="@+id/listRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
|
android:requiresFadingEdge="vertical"
|
||||||
|
android:visibility="visible"
|
||||||
|
tools:listitem="@layout/item_activity" />
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue