mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-23 22:27:15 +00:00
Load notifications on activity create + add swipe refresh
This commit is contained in:
parent
15a352982b
commit
6c09f32e63
2 changed files with 54 additions and 1 deletions
|
|
@ -27,7 +27,28 @@
|
|||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:layout_gravity="top|center" >
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/notifications_refresh_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="?attr/actionBarSize">
|
||||
<com.habitrpg.android.habitica.ui.views.PaddedLinearLayout
|
||||
android:id="@+id/notification_items"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:divider="?android:listDivider"
|
||||
android:showDividers="middle">
|
||||
</com.habitrpg.android.habitica.ui.views.PaddedLinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -3,9 +3,18 @@ package com.habitrpg.android.habitica.ui.activities
|
|||
import android.os.Bundle
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.AppComponent
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.notifications.GlobalNotification
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import io.reactivex.functions.Consumer
|
||||
import io.realm.RealmList
|
||||
import kotlinx.android.synthetic.main.activity_notifications.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class NotificationsActivity : BaseActivity() {
|
||||
class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener {
|
||||
@Inject
|
||||
lateinit var userRepository: UserRepository
|
||||
|
||||
override fun getLayoutResId(): Int = R.layout.activity_notifications
|
||||
|
||||
|
|
@ -13,6 +22,17 @@ class NotificationsActivity : BaseActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
|
||||
setupToolbar(toolbar)
|
||||
|
||||
compositeSubscription.add(userRepository.getUser().subscribe(Consumer<User> {
|
||||
this.setNotifications(it.notifications)
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
notifications_refresh_layout?.setOnRefreshListener(this)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
userRepository.close()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun injectActivity(component: AppComponent?) {
|
||||
|
|
@ -26,4 +46,16 @@ class NotificationsActivity : BaseActivity() {
|
|||
}
|
||||
return super.onSupportNavigateUp()
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
notifications_refresh_layout.isRefreshing = true
|
||||
|
||||
compositeSubscription.add(userRepository.retrieveUser(false, true).subscribe(Consumer<User> {
|
||||
notifications_refresh_layout.isRefreshing = false
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
private fun setNotifications(notifications: RealmList<GlobalNotification>) {
|
||||
//TODO("not implemented")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue