mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-16 03:01:59 +00:00
Implement dismiss notifications & mark notifications as seen
This commit is contained in:
parent
140f3eefea
commit
196f208533
7 changed files with 828 additions and 777 deletions
|
|
@ -348,6 +348,12 @@ public interface ApiService {
|
|||
@POST("notifications/{notificationId}/read")
|
||||
Flowable<HabitResponse<List>> readNotification(@Path("notificationId") String notificationId);
|
||||
|
||||
@POST("notifications/read")
|
||||
Flowable<HabitResponse<List>> readNotifications(@Body Map<String, List<String>> notificationIds);
|
||||
|
||||
@POST("notifications/see")
|
||||
Flowable<HabitResponse<List>> seeNotifications(@Body Map<String, List<String>> notificationIds);
|
||||
|
||||
@POST("user/open-mystery-item")
|
||||
Flowable<HabitResponse<Equipment>> openMysteryItem();
|
||||
|
||||
|
|
|
|||
|
|
@ -212,6 +212,8 @@ interface ApiClient {
|
|||
|
||||
// Notifications
|
||||
fun readNotification(notificationId: String): Flowable<List<*>>
|
||||
fun readNotifications(notificationIds: Map<String, List<String>>): Flowable<List<*>>
|
||||
fun seeNotifications(notificationIds: Map<String, List<String>>): Flowable<List<*>>
|
||||
|
||||
fun getErrorResponse(throwable: HttpException): ErrorResponse
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ interface UserRepository : BaseRepository {
|
|||
fun runCron()
|
||||
|
||||
fun readNotification(id: String): Flowable<List<*>>
|
||||
fun readNotifications(notificationIds: Map<String, List<String>>): Flowable<List<*>>
|
||||
fun seeNotifications(notificationIds: Map<String, List<String>>): Flowable<List<*>>
|
||||
|
||||
fun changeCustomDayStart(dayStartTime: Int): Flowable<User>
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -170,6 +170,12 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli
|
|||
|
||||
override fun readNotification(id: String): Flowable<List<*>> = apiClient.readNotification(id)
|
||||
|
||||
override fun readNotifications(notificationIds: Map<String, List<String>>): Flowable<List<*>> =
|
||||
apiClient.readNotifications(notificationIds)
|
||||
|
||||
override fun seeNotifications(notificationIds: Map<String, List<String>>): Flowable<List<*>> =
|
||||
apiClient.seeNotifications(notificationIds)
|
||||
|
||||
override fun changeCustomDayStart(dayStartTime: Int): Flowable<User> {
|
||||
val updateObject = HashMap<String, Any>()
|
||||
updateObject["dayStart"] = dayStartTime
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
|
||||
override fun getLayoutResId(): Int = R.layout.activity_notifications
|
||||
|
||||
private var notifications: List<GlobalNotification> = emptyList()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
@ -37,7 +39,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
|
||||
compositeSubscription.add(viewModel.getNotifications().subscribe(Consumer {
|
||||
this.setNotifications(it)
|
||||
viewModel.markNotificationsAsSeen()
|
||||
viewModel.markNotificationsAsSeen(it)
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
notifications_refresh_layout?.setOnRefreshListener(this)
|
||||
|
|
@ -64,6 +66,8 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
}
|
||||
|
||||
private fun setNotifications(notifications: List<GlobalNotification>) {
|
||||
this.notifications = notifications
|
||||
|
||||
if (notification_items == null) {
|
||||
return
|
||||
}
|
||||
|
|
@ -108,14 +112,14 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
badge?.text = notificationCount.toString()
|
||||
|
||||
val dismissAllButton = header?.findViewById(R.id.dismiss_all_button) as? Button
|
||||
dismissAllButton?.setOnClickListener({ viewModel.dismissAllNotifications() })
|
||||
dismissAllButton?.setOnClickListener { viewModel.dismissAllNotifications(notifications) }
|
||||
|
||||
return header
|
||||
}
|
||||
|
||||
private fun createNewChatMessageNotification(notification: GlobalNotification): View? {
|
||||
val data = notification.getData() as? NewChatMessageData
|
||||
val stringId = if (viewModel.isPartyMessage(data)) R.string.new_msg_party else R.string.new_msg_guild;
|
||||
val stringId = if (viewModel.isPartyMessage(data)) R.string.new_msg_party else R.string.new_msg_guild
|
||||
|
||||
return createNotificationItem(
|
||||
notification,
|
||||
|
|
@ -156,7 +160,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
val item = inflater.inflate(R.layout.notification_item, notification_items, false)
|
||||
|
||||
val dismissButton = item?.findViewById(R.id.dismiss_button) as? ImageView
|
||||
dismissButton?.setOnClickListener({ viewModel.dismissNotification(notification) })
|
||||
dismissButton?.setOnClickListener { viewModel.dismissNotification(notification) }
|
||||
|
||||
val messageTextView = item?.findViewById(R.id.message_text) as? TextView
|
||||
messageTextView?.text = messageText
|
||||
|
|
|
|||
|
|
@ -6,12 +6,11 @@ import com.habitrpg.android.habitica.models.notifications.GlobalNotification
|
|||
import com.habitrpg.android.habitica.models.notifications.NewChatMessageData
|
||||
import com.habitrpg.android.habitica.models.notifications.NotificationType
|
||||
import com.habitrpg.android.habitica.models.social.UserParty
|
||||
import com.playseeds.android.sdk.inappmessaging.Log
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.functions.Consumer
|
||||
import io.realm.RealmList
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
open class NotificationsViewModel : BaseViewModel() {
|
||||
var party: UserParty? = null
|
||||
|
|
@ -56,18 +55,42 @@ open class NotificationsViewModel : BaseViewModel() {
|
|||
}
|
||||
|
||||
fun dismissNotification(notification: GlobalNotification) {
|
||||
Log.d("NotificationsViewModel.dismissNotification " + notification.type + " " + notification.id)
|
||||
//TODO("not implemented")
|
||||
disposable.add(userRepository.readNotification(notification.id)
|
||||
.subscribe(Consumer {
|
||||
// TODO better way to handle updates than reload whole user ??
|
||||
refreshNotifications()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
fun dismissAllNotifications() {
|
||||
Log.d("NotificationsViewModel.dismissAllNotifications")
|
||||
//TODO("not implemented")
|
||||
fun dismissAllNotifications(notifications: List<GlobalNotification>) {
|
||||
if (notifications.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val notificationIds = HashMap<String, List<String>>()
|
||||
notificationIds["notificationIds"] = notifications.map { notification -> notification.id }
|
||||
|
||||
disposable.add(userRepository.readNotifications(notificationIds)
|
||||
.subscribe(Consumer {
|
||||
refreshNotifications()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
fun markNotificationsAsSeen() {
|
||||
Log.d("NotificationsViewModel.markNotificationsAsSeen")
|
||||
//TODO("not implemented")
|
||||
fun markNotificationsAsSeen(notifications: List<GlobalNotification>) {
|
||||
val unseenIds = notifications.filter { notification -> notification.seen != true }
|
||||
.map { notification -> notification.id }
|
||||
|
||||
if (unseenIds.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val notificationIds = HashMap<String, List<String>>()
|
||||
notificationIds["notificationIds"] = unseenIds
|
||||
|
||||
disposable.add(userRepository.seeNotifications(notificationIds)
|
||||
.subscribe(Consumer {
|
||||
refreshNotifications()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue