feat: notification to activity click
This commit is contained in:
parent
9e371778b7
commit
b69e466853
6 changed files with 199 additions and 62 deletions
|
@ -1351,8 +1351,9 @@ Page(page:$page,perPage:50) {
|
|||
return res
|
||||
}
|
||||
|
||||
suspend fun getFeed(userId: Int?, global: Boolean = false, page: Int = 1): FeedResponse? {
|
||||
val filter = if (userId != null) "userId:$userId,"
|
||||
suspend fun getFeed(userId: Int?, global: Boolean = false, page: Int = 1, activityId: Int? = null): FeedResponse? {
|
||||
val filter = if (activityId != null) "id:$activityId,"
|
||||
else if (userId != null) "userId:$userId,"
|
||||
else if (global) "isFollowing:false,type:TEXT,"
|
||||
else "isFollowing:true,type_not:MESSAGE,"
|
||||
return executeQuery<FeedResponse>(
|
||||
|
|
|
@ -236,7 +236,7 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
|
|||
|
||||
override fun getItemCount(): Int = 3
|
||||
override fun createFragment(position: Int): Fragment = when (position) {
|
||||
0 -> FeedFragment.newInstance(user.id, false)
|
||||
0 -> FeedFragment.newInstance(user.id, false, -1)
|
||||
1 -> ProfileFragment.newInstance(user)
|
||||
2 -> StatsFragment.newInstance(user)
|
||||
else -> ProfileFragment.newInstance(user)
|
||||
|
|
|
@ -39,7 +39,8 @@ class FeedActivity: AppCompatActivity() {
|
|||
topMargin += statusBarHeight
|
||||
}
|
||||
binding.listToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += statusBarHeight }
|
||||
binding.feedViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle)
|
||||
val activityId = intent.getIntExtra("activityId", -1)
|
||||
binding.feedViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, activityId)
|
||||
binding.feedViewPager.setCurrentItem(selected, false)
|
||||
binding.feedViewPager.isUserInputEnabled = false
|
||||
navBar.selectTabAt(selected)
|
||||
|
@ -67,14 +68,15 @@ class FeedActivity: AppCompatActivity() {
|
|||
|
||||
private class ViewPagerAdapter(
|
||||
fragmentManager: FragmentManager,
|
||||
lifecycle: Lifecycle
|
||||
lifecycle: Lifecycle,
|
||||
private val activityId: Int
|
||||
) : FragmentStateAdapter(fragmentManager, lifecycle) {
|
||||
override fun getItemCount(): Int = 2
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return when (position) {
|
||||
0 -> FeedFragment.newInstance(null, false)
|
||||
else -> FeedFragment.newInstance(null, true)
|
||||
0 -> FeedFragment.newInstance(null, false, activityId)
|
||||
else -> FeedFragment.newInstance(null, true, -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class FeedFragment : Fragment() {
|
|||
private var loadedFirstTime = false
|
||||
private var userId: Int? = null
|
||||
private var global: Boolean = false
|
||||
private var activityId: Int = -1
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
@ -49,6 +50,7 @@ class FeedFragment : Fragment() {
|
|||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
binding.listProgressBar.visibility = ViewGroup.VISIBLE
|
||||
userId = arguments?.getInt("userId", -1)
|
||||
activityId = arguments?.getInt("activityId", -1) ?: -1
|
||||
if (userId == -1) userId = null
|
||||
global = arguments?.getBoolean("global", false) ?: false
|
||||
}
|
||||
|
@ -60,11 +62,12 @@ class FeedFragment : Fragment() {
|
|||
binding.root.requestLayout()
|
||||
if (!loadedFirstTime) {
|
||||
activity.lifecycleScope.launch(Dispatchers.IO) {
|
||||
val res = Anilist.query.getFeed(userId, global)
|
||||
val nulledId = if (activityId == -1) null else activityId
|
||||
val res = Anilist.query.getFeed(userId, global, activityId = nulledId)
|
||||
withContext(Dispatchers.Main) {
|
||||
res?.data?.page?.activities?.let { activities ->
|
||||
activityList = activities
|
||||
val filtered = activities.filterNot { //filter out messages that are not directed to the user
|
||||
val filtered = activityList.filterNot { //filter out messages that are not directed to the user
|
||||
it.recipient?.id != null && it.recipient.id != Anilist.userid
|
||||
}
|
||||
adapter.update(filtered.map { ActivityItem(it) { _, _ -> } })
|
||||
|
@ -107,11 +110,12 @@ class FeedFragment : Fragment() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(userId: Int?, global: Boolean): FeedFragment {
|
||||
fun newInstance(userId: Int?, global: Boolean, activityId: Int): FeedFragment {
|
||||
val fragment = FeedFragment()
|
||||
val args = Bundle()
|
||||
args.putInt("userId", userId ?: -1)
|
||||
args.putBoolean("global", global)
|
||||
args.putInt("activityId", activityId)
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
}
|
||||
|
|
|
@ -107,6 +107,12 @@ class NotificationActivity : AppCompatActivity() {
|
|||
.putExtra("mediaId", id), null
|
||||
)
|
||||
}
|
||||
NotificationClickType.ACTIVITY -> {
|
||||
ContextCompat.startActivity(
|
||||
this, Intent(this, FeedActivity::class.java)
|
||||
.putExtra("activityId", id), null
|
||||
)
|
||||
}
|
||||
NotificationClickType.UNDEFINED -> {
|
||||
// Do nothing
|
||||
}
|
||||
|
@ -115,7 +121,7 @@ class NotificationActivity : AppCompatActivity() {
|
|||
|
||||
companion object {
|
||||
enum class NotificationClickType {
|
||||
USER, MEDIA, UNDEFINED
|
||||
USER, MEDIA, ACTIVITY, UNDEFINED
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package ani.dantotsu.profile.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import ani.dantotsu.R
|
||||
|
@ -10,20 +8,14 @@ import ani.dantotsu.connections.anilist.api.Notification
|
|||
import ani.dantotsu.connections.anilist.api.NotificationType
|
||||
import ani.dantotsu.databinding.ItemNotificationBinding
|
||||
import ani.dantotsu.loadImage
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import ani.dantotsu.profile.activity.NotificationActivity.Companion.NotificationClickType
|
||||
import com.xwray.groupie.viewbinding.BindableItem
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||
|
||||
class NotificationItem(
|
||||
private val notification: Notification,
|
||||
val clickCallback: (Int, NotificationActivity.Companion.NotificationClickType) -> Unit
|
||||
): BindableItem<ItemNotificationBinding>() {
|
||||
val clickCallback: (Int, NotificationClickType) -> Unit
|
||||
) : BindableItem<ItemNotificationBinding>() {
|
||||
private lateinit var binding: ItemNotificationBinding
|
||||
private lateinit var clickType: NotificationActivity.Companion.NotificationClickType
|
||||
private var id = 0
|
||||
override fun bind(viewBinding: ItemNotificationBinding, position: Int) {
|
||||
binding = viewBinding
|
||||
setBinding()
|
||||
|
@ -39,10 +31,20 @@ class NotificationItem(
|
|||
|
||||
private fun image(user: Boolean = false) {
|
||||
|
||||
val cover = if (user) notification.user?.bannerImage ?: notification.user?.avatar?.medium else notification.media?.bannerImage ?: notification.media?.coverImage?.large
|
||||
val cover = if (user) notification.user?.bannerImage
|
||||
?: notification.user?.avatar?.medium else notification.media?.bannerImage
|
||||
?: notification.media?.coverImage?.large
|
||||
blurImage(binding.notificationBannerImage, cover)
|
||||
val defaultHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 170f, binding.root.context.resources.displayMetrics).toInt()
|
||||
val userHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 90f, binding.root.context.resources.displayMetrics).toInt()
|
||||
val defaultHeight = TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
170f,
|
||||
binding.root.context.resources.displayMetrics
|
||||
).toInt()
|
||||
val userHeight = TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
90f,
|
||||
binding.root.context.resources.displayMetrics
|
||||
).toInt()
|
||||
|
||||
if (user) {
|
||||
binding.notificationCover.visibility = View.GONE
|
||||
|
@ -50,7 +52,7 @@ class NotificationItem(
|
|||
binding.notificationCoverUserContainer.visibility = View.VISIBLE
|
||||
binding.notificationCoverUser.loadImage(notification.user?.avatar?.large)
|
||||
binding.notificationBannerImage.layoutParams.height = userHeight
|
||||
} else{
|
||||
} else {
|
||||
binding.notificationCover.visibility = View.VISIBLE
|
||||
binding.notificationCoverUser.visibility = View.VISIBLE
|
||||
binding.notificationCoverUserContainer.visibility = View.GONE
|
||||
|
@ -64,108 +66,230 @@ class NotificationItem(
|
|||
NotificationType.valueOf(notification.notificationType)
|
||||
binding.notificationText.text = ActivityItemBuilder.getContent(notification)
|
||||
binding.notificationDate.text = ActivityItemBuilder.getDateTime(notification.createdAt)
|
||||
binding.root.setOnClickListener { clickCallback(id, clickType) }
|
||||
|
||||
|
||||
when (notificationType) {
|
||||
NotificationType.ACTIVITY_MESSAGE -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.ACTIVITY_REPLY -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.FOLLOWING -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.userId ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.ACTIVITY_MENTION -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.THREAD_COMMENT_MENTION -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.THREAD_SUBSCRIBED -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.THREAD_COMMENT_REPLY -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.AIRING -> {
|
||||
binding.notificationCover.loadImage(notification.media?.coverImage?.large)
|
||||
image()
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.MEDIA
|
||||
id = notification.media?.id ?: 0
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.ACTIVITY_LIKE -> {
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.ACTIVITY_REPLY_LIKE -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.THREAD_LIKE -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.THREAD_COMMENT_LIKE -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.ACTIVITY_REPLY_SUBSCRIBED -> {
|
||||
binding.notificationCover.loadImage(notification.user?.avatar?.large)
|
||||
image(true)
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.USER
|
||||
id = notification.user?.id ?: 0
|
||||
binding.notificationCoverUser.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.user?.id ?: 0, NotificationClickType.USER
|
||||
)
|
||||
}
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.activityId ?: 0, NotificationClickType.ACTIVITY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.RELATED_MEDIA_ADDITION -> {
|
||||
binding.notificationCover.loadImage(notification.media?.coverImage?.large)
|
||||
image()
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.MEDIA
|
||||
id = notification.media?.id ?: 0
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.MEDIA_DATA_CHANGE -> {
|
||||
binding.notificationCover.loadImage(notification.media?.coverImage?.large)
|
||||
image()
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.MEDIA
|
||||
id = notification.media?.id ?: 0
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.MEDIA_MERGE -> {
|
||||
binding.notificationCover.loadImage(notification.media?.coverImage?.large)
|
||||
image()
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.MEDIA
|
||||
id = notification.media?.id ?: 0
|
||||
binding.notificationBannerImage.setOnClickListener {
|
||||
clickCallback(
|
||||
notification.media?.id ?: 0, NotificationClickType.MEDIA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotificationType.MEDIA_DELETION -> {
|
||||
binding.notificationCover.visibility = View.GONE
|
||||
clickType = NotificationActivity.Companion.NotificationClickType.UNDEFINED
|
||||
id = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue