Create notification item view and implement few notification types
BIN
Habitica/res/drawable-hdpi/notification_close.webp
Normal file
|
After Width: | Height: | Size: 154 B |
BIN
Habitica/res/drawable-hdpi/notification_stat_sparkles.webp
Normal file
|
After Width: | Height: | Size: 712 B |
BIN
Habitica/res/drawable-hdpi/notifications_bailey.webp
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
Habitica/res/drawable-mdpi/notification_close.webp
Normal file
|
After Width: | Height: | Size: 138 B |
BIN
Habitica/res/drawable-mdpi/notification_stat_sparkles.webp
Normal file
|
After Width: | Height: | Size: 522 B |
BIN
Habitica/res/drawable-mdpi/notifications_bailey.webp
Normal file
|
After Width: | Height: | Size: 432 B |
BIN
Habitica/res/drawable-xhdpi/notification_close.webp
Normal file
|
After Width: | Height: | Size: 190 B |
BIN
Habitica/res/drawable-xhdpi/notification_stat_sparkles.webp
Normal file
|
After Width: | Height: | Size: 960 B |
BIN
Habitica/res/drawable-xhdpi/notifications_bailey.webp
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
Habitica/res/drawable-xxhdpi/notification_close.webp
Normal file
|
After Width: | Height: | Size: 224 B |
BIN
Habitica/res/drawable-xxhdpi/notification_stat_sparkles.webp
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
Habitica/res/drawable-xxhdpi/notifications_bailey.webp
Normal file
|
After Width: | Height: | Size: 5.1 KiB |
40
Habitica/res/layout/notification_item.xml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingRight="20dp"
|
||||
android:paddingBottom="10dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/notification_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="20dp"
|
||||
android:background="@color/transparent"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:layout_weight="1"
|
||||
android:lineSpacingExtra="5dp"
|
||||
android:text="Message" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dismiss_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@color/transparent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:src="@drawable/notification_close" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -863,6 +863,9 @@
|
|||
<string name="no_notifications_title">You’re all caught up!</string>
|
||||
<string name="no_notifications_text">The notification fairies give you a raucous round of applause! Well done!</string>
|
||||
<string name="dismiss_all">Dismiss All</string>
|
||||
<string name="new_bailey_update">New Bailey Update!</string>
|
||||
<string name="new_msg_guild"><![CDATA[<b>%1$s</b> has new posts]]></string>
|
||||
<string name="unallocated_stats_points"><![CDATA[You have <b>%1$s unallocated Stat Points</b>]]></string>
|
||||
<string name="create">Create</string>
|
||||
<string name="only_leader_create_challenge">Only leader can create Challenges</string>
|
||||
<string name="create_party">Create Party</string>
|
||||
|
|
|
|||
|
|
@ -2,15 +2,17 @@ package com.habitrpg.android.habitica.ui.activities
|
|||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.AppComponent
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.notifications.GlobalNotification
|
||||
import com.habitrpg.android.habitica.models.notifications.*
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.NotificationsViewModel
|
||||
import io.reactivex.functions.Consumer
|
||||
import kotlinx.android.synthetic.main.activity_notifications.*
|
||||
|
|
@ -87,7 +89,10 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
|
||||
notifications.map {
|
||||
val item: View? = when (it.type) {
|
||||
//TODO("not implemented")
|
||||
NotificationType.NEW_CHAT_MESSAGE.type -> createNewChatMessageNotification(it)
|
||||
NotificationType.NEW_STUFF.type -> createNewStuffNotification(it)
|
||||
NotificationType.UNALLOCATED_STATS_POINTS.type -> createUnallocatedStatsNotification(it)
|
||||
//TODO rest of the notification types
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
|
@ -106,4 +111,61 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
|
|||
|
||||
return header
|
||||
}
|
||||
|
||||
private fun createNewChatMessageNotification(notification: GlobalNotification): View? {
|
||||
val data = notification.getData() as? NewChatMessageData
|
||||
|
||||
return createNotificationItem(
|
||||
notification,
|
||||
fromHtml(getString(R.string.new_msg_guild, data?.group?.name))
|
||||
)
|
||||
}
|
||||
|
||||
private fun createNewStuffNotification(notification: GlobalNotification): View? {
|
||||
val data = notification.getData() as? NewStuffData
|
||||
val text = fromHtml("<b>" + getString(R.string.new_bailey_update) + "</b><br>" + data?.title)
|
||||
|
||||
return createNotificationItem(
|
||||
notification,
|
||||
text,
|
||||
R.drawable.notifications_bailey
|
||||
)
|
||||
}
|
||||
|
||||
private fun createUnallocatedStatsNotification(notification: GlobalNotification): View? {
|
||||
val data = notification.getData() as? UnallocatedPointsData
|
||||
|
||||
return createNotificationItem(
|
||||
notification,
|
||||
fromHtml(getString(R.string.unallocated_stats_points, data?.points.toString())),
|
||||
R.drawable.notification_stat_sparkles
|
||||
)
|
||||
}
|
||||
|
||||
private fun createNotificationItem(notification: GlobalNotification, messageText: CharSequence, imageResourceId: Int? = null): View? {
|
||||
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) })
|
||||
|
||||
val messageTextView = item?.findViewById(R.id.message_text) as? TextView
|
||||
messageTextView?.text = messageText
|
||||
|
||||
if (imageResourceId != null) {
|
||||
val notificationImage = item?.findViewById(R.id.notification_image) as? ImageView
|
||||
notificationImage?.setImageResource(imageResourceId)
|
||||
notificationImage?.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
private fun fromHtml(text: String): CharSequence {
|
||||
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
||||
Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
Html.fromHtml(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||