mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-14 02:01:56 +00:00
Show new stuff status in menu and notifications
This commit is contained in:
parent
8afe1f05f8
commit
01ea0f6841
8 changed files with 61 additions and 13 deletions
|
|
@ -37,4 +37,12 @@
|
|||
tools:visibility="visible"
|
||||
tools:text="Test"
|
||||
android:visibility="gone"/>
|
||||
<View
|
||||
android:id="@+id/bubble_view"
|
||||
style="@style/Pill.Selected"
|
||||
android:background="@drawable/pill_bg_purple_200"
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="12dp"
|
||||
tools:visibility="visible"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -42,4 +42,17 @@ class Notification {
|
|||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val priority: Int
|
||||
get() {
|
||||
return when (type) {
|
||||
Type.NEW_STUFF.type -> 1
|
||||
Type.GUILD_INVITATION.type -> 2
|
||||
Type.PARTY_INVITATION.type -> 3
|
||||
Type.UNALLOCATED_STATS_POINTS.type -> 4
|
||||
Type.NEW_MYSTERY_ITEMS.type -> 5
|
||||
Type.NEW_CHAT_MESSAGE.type -> 6
|
||||
else -> 100
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,11 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
|
||||
private fun createNewStuffNotification(notification: Notification): View? {
|
||||
val data = notification.data as? NewStuffData
|
||||
val text = fromHtml("<b>" + getString(R.string.new_bailey_update) + "</b><br>" + data?.title)
|
||||
val text = if (data?.title != null) {
|
||||
fromHtml("<b>" + getString(R.string.new_bailey_update) + "</b><br>" + data.title)
|
||||
} else {
|
||||
fromHtml("<b>" + getString(R.string.new_bailey_update) + "</b>")
|
||||
}
|
||||
|
||||
return createDismissableNotificationItem(
|
||||
notification,
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ class NavigationDrawerAdapter(tintColor: Int, backgroundTintColor: Int): Recycle
|
|||
|
||||
private val titleTextView: TextView? by bindOptionalView(itemView, R.id.titleTextView)
|
||||
private val pillView: TextView? by bindOptionalView(itemView, R.id.pillView)
|
||||
private val bubbleView: View? by bindOptionalView(itemView, R.id.bubble_view)
|
||||
private val additionalInfoView: TextView? by bindOptionalView(itemView, R.id.additionalInfoView)
|
||||
|
||||
fun bind(drawerItem: HabiticaDrawerItem, isSelected: Boolean) {
|
||||
|
|
@ -141,6 +142,7 @@ class NavigationDrawerAdapter(tintColor: Int, backgroundTintColor: Int): Recycle
|
|||
}
|
||||
}
|
||||
}
|
||||
bubbleView?.visibility = if (drawerItem.showBubble) View.VISIBLE else View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -228,6 +228,9 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
}
|
||||
updateItem(statsItem)
|
||||
}
|
||||
getItemWithIdentifier(SIDEBAR_NEWS)?.let {
|
||||
it.showBubble = user.flags?.newStuff ?: false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
@ -315,11 +318,7 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
}))
|
||||
subscriptions?.add(viewModel.getHasPartyNotification().subscribeWithErrorHandler(Consumer {
|
||||
val partyMenuItem = getItemWithIdentifier(SIDEBAR_PARTY)
|
||||
if (it) {
|
||||
partyMenuItem?.additionalInfo = ""
|
||||
} else {
|
||||
partyMenuItem?.additionalInfo = null
|
||||
}
|
||||
partyMenuItem?.showBubble = it
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.ConsoleMessage
|
||||
import android.webkit.WebChromeClient
|
||||
import com.habitrpg.android.habitica.BuildConfig
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.extensions.subscribeWithErrorHandler
|
||||
import io.reactivex.functions.Consumer
|
||||
import kotlinx.android.synthetic.main.fragment_news.*
|
||||
|
||||
|
||||
|
|
@ -21,6 +23,7 @@ class NewsFragment : BaseMainFragment() {
|
|||
return container?.inflate(R.layout.fragment_news)
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val address = if (BuildConfig.DEBUG) BuildConfig.BASE_URL else context?.getString(R.string.base_url)
|
||||
|
|
@ -36,5 +39,8 @@ class NewsFragment : BaseMainFragment() {
|
|||
component.inject(this)
|
||||
}
|
||||
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
compositeSubscription.add(userRepository.updateUser(user, "flags.newStuff", false).subscribeWithErrorHandler(Consumer {}))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.menu
|
|||
class HabiticaDrawerItem(val transitionId: Int,val identifier: String, val text: String, val isHeader: Boolean = false, var additionalInfoAsPill: Boolean = true) {
|
||||
|
||||
var additionalInfo: String? = null
|
||||
var showBubble: Boolean = false
|
||||
var isVisible: Boolean = true
|
||||
var isEnabled: Boolean = true
|
||||
}
|
||||
|
|
@ -72,7 +72,16 @@ open class NotificationsViewModel : BaseViewModel() {
|
|||
disposable.add(userRepository.getUser()
|
||||
.subscribe(Consumer {
|
||||
party = it.party
|
||||
customNotifications.onNext(convertInvitationsToNotifications(it))
|
||||
var notifications = convertInvitationsToNotifications(it)
|
||||
if (it.flags?.newStuff == true) {
|
||||
val notification = Notification()
|
||||
notification.id = "new-stuff-notification"
|
||||
notification.type = Notification.Type.NEW_STUFF.type
|
||||
val data = NewStuffData()
|
||||
notification.data = data
|
||||
notifications.add(notification)
|
||||
}
|
||||
customNotifications.onNext(notifications)
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
|
|
@ -85,9 +94,15 @@ open class NotificationsViewModel : BaseViewModel() {
|
|||
serverNotifications,
|
||||
customNotifications.toFlowable(BackpressureStrategy.LATEST),
|
||||
BiFunction<List<Notification>, List<Notification>, List<Notification>> {
|
||||
serverNotificationsList, customNotificationsList -> serverNotificationsList + customNotificationsList
|
||||
serverNotificationsList, customNotificationsList ->
|
||||
if (serverNotificationsList.firstOrNull { notification -> notification.type == Notification.Type.NEW_STUFF.type } != null) {
|
||||
return@BiFunction serverNotificationsList + customNotificationsList.filter { notification -> notification.type != Notification.Type.NEW_STUFF.type }
|
||||
}
|
||||
return@BiFunction serverNotificationsList + customNotificationsList
|
||||
}
|
||||
).observeOn(AndroidSchedulers.mainThread())
|
||||
)
|
||||
.map { it.sortedBy { notification -> notification.priority } }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun getNotificationCount(): Flowable<Int> {
|
||||
|
|
@ -121,8 +136,8 @@ open class NotificationsViewModel : BaseViewModel() {
|
|||
return notifications.filter { supportedNotificationTypes.contains(it.type) }
|
||||
}
|
||||
|
||||
private fun convertInvitationsToNotifications(user: User): List<Notification> {
|
||||
val notifications = arrayListOf<Notification>()
|
||||
private fun convertInvitationsToNotifications(user: User): MutableList<Notification> {
|
||||
val notifications = mutableListOf<Notification>()
|
||||
|
||||
notifications.addAll(user.invitations?.parties?.map {
|
||||
val notification = Notification()
|
||||
|
|
|
|||
Loading…
Reference in a new issue