feat: delete comment and subscription notification

This commit is contained in:
aayush262 2024-06-26 19:27:26 +05:30
parent c22fd6b66d
commit 46d16be835
9 changed files with 136 additions and 58 deletions

View file

@ -49,7 +49,10 @@ class StatusActivity : AppCompatActivity(), StoriesCallback {
if (activity.getOrNull(position) != null) {
val startFrom = findFirstNonMatch(watchedActivity, activity[position].activity )
val startIndex = if ( startFrom > 0) startFrom else 0
binding.stories.setStoriesList(activity[position].activity, this, startIndex + 1)
binding.stories.setStoriesList(
activityList = activity[position].activity,
startIndex = startIndex + 1
)
} else {
Logger.log("index out of bounds for position $position of size ${activity.size}")
finish()
@ -92,7 +95,7 @@ class StatusActivity : AppCompatActivity(), StoriesCallback {
val startFrom = findFirstNonMatch(watchedActivity, activity[position].activity )
val startIndex= if ( startFrom > 0) startFrom else 0
binding.stories.startAnimation(slideOutLeft)
binding.stories.setStoriesList(activity[position].activity, this, startIndex + 1)
binding.stories.setStoriesList(activity[position].activity, startIndex + 1)
binding.stories.startAnimation(slideInRight)
} else {
finish()
@ -107,7 +110,7 @@ class StatusActivity : AppCompatActivity(), StoriesCallback {
val startFrom = findFirstNonMatch(watchedActivity, activity[position].activity )
val startIndex = if ( startFrom > 0) startFrom else 0
binding.stories.startAnimation(slideOutRight)
binding.stories.setStoriesList(activity[position].activity, this, startIndex + 1)
binding.stories.setStoriesList(activity[position].activity,startIndex + 1)
binding.stories.startAnimation(slideInLeft)
} else {
finish()

View file

@ -49,7 +49,6 @@ import kotlin.math.abs
class Stories @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr), View.OnTouchListener {
private lateinit var activity: FragmentActivity
private lateinit var binding: FragmentStatusBinding
private lateinit var activityList: List<Activity>
private lateinit var storiesListener: StoriesCallback
@ -80,10 +79,9 @@ class Stories @JvmOverloads constructor(
fun setStoriesList(
activityList: List<Activity>, activity: FragmentActivity, startIndex: Int = 1
activityList: List<Activity>, startIndex: Int = 1
) {
this.activityList = activityList
this.activity = activity
this.storyIndex = startIndex
addLoadingViews(activityList)
}
@ -368,7 +366,9 @@ class Stories @JvmOverloads constructor(
if (
story.status?.contains("completed") == false &&
!story.status.contains("plans") &&
!story.status.contains("repeating")
!story.status.contains("repeating")&&
!story.status.contains("paused")&&
!story.status.contains("dropped")
) {
"of ${story.media?.title?.userPreferred}"
} else {
@ -389,7 +389,7 @@ class Stories @JvmOverloads constructor(
story.media?.id
),
ActivityOptionsCompat.makeSceneTransitionAnimation(
activity,
(it.context as FragmentActivity),
binding.coverImage,
ViewCompat.getTransitionName(binding.coverImage)!!
).toBundle()
@ -427,7 +427,7 @@ class Stories @JvmOverloads constructor(
binding.activityReplies.setColorFilter(ContextCompat.getColor(context, R.color.bg_opp))
binding.activityRepliesContainer.setOnClickListener {
RepliesBottomDialog.newInstance(story.id)
.show(activity.supportFragmentManager, "replies")
.show((it.context as FragmentActivity).supportFragmentManager, "replies")
}
binding.activityLike.setColorFilter(if (story.isLiked == true) likeColor else notLikeColor)
binding.activityLikeCount.text = story.likeCount.toString()
@ -435,10 +435,9 @@ class Stories @JvmOverloads constructor(
like()
}
binding.activityLikeContainer.setOnLongClickListener {
val context = activity
UsersDialogFragment().apply {
userList(userList)
show(context.supportFragmentManager, "dialog")
show((it.context as FragmentActivity).supportFragmentManager, "dialog")
}
true
}

View file

@ -60,7 +60,7 @@ class ActivityFragment : Fragment() {
binding.feedRefresh.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
}
binding.emptyTextView.text = getString(R.string.no_activities)
binding.emptyTextView.text = getString(R.string.nothing_here)
lifecycleScope.launch {
getList()
if (adapter.itemCount == 0) {

View file

@ -51,6 +51,7 @@ class FeedActivity : AppCompatActivity() {
binding.notificationBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
val getOne = intent.getIntExtra("activityId", -1)
if (getOne != -1) { navBar.visibility = View.GONE }
binding.notificationViewPager.isUserInputEnabled = false
binding.notificationViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, getOne)
binding.notificationViewPager.setOffscreenPageLimit(4)
binding.notificationViewPager.setCurrentItem(selected, false)
@ -63,13 +64,7 @@ class FeedActivity : AppCompatActivity() {
newTab: AnimatedBottomBar.Tab
) {
selected = newIndex
binding.notificationViewPager.setCurrentItem(selected, true)
}
})
binding.notificationViewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
navBar.selectTabAt(position)
binding.notificationViewPager.setCurrentItem(selected, false)
}
})
}

View file

@ -16,7 +16,8 @@ import ani.dantotsu.initActivity
import ani.dantotsu.navBarHeight
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.*
import ani.dantotsu.profile.notification.NotificationFragment.Companion.newInstance
import nl.joery.animatedbottombar.AnimatedBottomBar
class NotificationActivity : AppCompatActivity() {
@ -48,6 +49,7 @@ class NotificationActivity : AppCompatActivity() {
binding.notificationBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
val getOne = intent.getIntExtra("activityId", -1)
if (getOne != -1) navBar.isVisible = false
binding.notificationViewPager.isUserInputEnabled = false
binding.notificationViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, getOne)
binding.notificationViewPager.setCurrentItem(selected, false)
navBar.selectTabAt(selected)
@ -59,13 +61,7 @@ class NotificationActivity : AppCompatActivity() {
newTab: AnimatedBottomBar.Tab
) {
selected = newIndex
binding.notificationViewPager.setCurrentItem(selected, true)
}
})
binding.notificationViewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
navBar.selectTabAt(position)
binding.notificationViewPager.setCurrentItem(selected, false)
}
})
}
@ -83,11 +79,11 @@ class NotificationActivity : AppCompatActivity() {
override fun getItemCount(): Int = if (id != -1) 1 else 4
override fun createFragment(position: Int): Fragment = when (position) {
0 -> NotificationFragment.newInstance(NotificationType.USER)
1 -> NotificationFragment.newInstance(if (id != -1) NotificationType.ONE else NotificationType.MEDIA, id)
2 -> NotificationFragment.newInstance(NotificationType.SUBSCRIPTION)
3 -> NotificationFragment.newInstance(NotificationType.COMMENT)
else -> NotificationFragment.newInstance(NotificationType.MEDIA)
0 -> newInstance(USER)
1 -> newInstance(if (id != -1) ONE else MEDIA, id)
2 -> newInstance(SUBSCRIPTION)
3 -> newInstance(COMMENT)
else -> newInstance(MEDIA)
}
}
}

View file

@ -20,7 +20,11 @@ import ani.dantotsu.notifications.comment.CommentStore
import ani.dantotsu.notifications.subscription.SubscriptionStore
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.profile.activity.FeedActivity
import ani.dantotsu.setBaseline
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.COMMENT
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.MEDIA
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.ONE
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.SUBSCRIPTION
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.USER
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import com.xwray.groupie.GroupieAdapter
@ -29,8 +33,8 @@ import kotlinx.coroutines.launch
class NotificationFragment : Fragment() {
private lateinit var type : NotificationType
private var getID : Int = -1
private lateinit var type: NotificationType
private var getID: Int = -1
private lateinit var binding: FragmentNotificationsBinding
private var adapter: GroupieAdapter = GroupieAdapter()
private var currentPage = 1
@ -53,12 +57,10 @@ class NotificationFragment : Fragment() {
binding.notificationRecyclerView.adapter = adapter
binding.notificationRecyclerView.layoutManager = LinearLayoutManager(context)
binding.notificationProgressBar.isVisible = true
binding.emptyTextView.text = getString(R.string.no_notifications)
binding.emptyTextView.text = getString(R.string.nothing_here)
lifecycleScope.launch {
getList()
if (adapter.itemCount == 0) {
binding.emptyTextView.isVisible = true
}
binding.notificationProgressBar.isVisible = false
}
binding.notificationSwipeRefresh.setOnRefreshListener {
@ -87,13 +89,16 @@ class NotificationFragment : Fragment() {
private suspend fun getList() {
val list = when (type) {
NotificationType.ONE -> getNotificationsFiltered(false) { it.id == getID }
NotificationType.MEDIA -> getNotificationsFiltered(type = true) { it.media != null }
NotificationType.USER -> getNotificationsFiltered { it.media == null }
NotificationType.SUBSCRIPTION -> getSubscriptions()
NotificationType.COMMENT -> getComments()
ONE -> getNotificationsFiltered(false) { it.id == getID }
MEDIA -> getNotificationsFiltered(type = true) { it.media != null }
USER -> getNotificationsFiltered { it.media == null }
SUBSCRIPTION -> getSubscriptions()
COMMENT -> getComments()
}
adapter.addAll(list.map { NotificationItem(it, type, adapter, ::onClick) })
if (adapter.itemCount == 0) {
binding.emptyTextView.isVisible = true
}
adapter.addAll(list.map { NotificationItem(it, ::onClick) })
}
private suspend fun getNotificationsFiltered(
@ -114,8 +119,11 @@ class NotificationFragment : Fragment() {
PrefName.SubscriptionNotificationStore,
null
) ?: listOf()
return list.sortedByDescending { (it.time / 1000L).toInt() }
.filter { it.image != null }.map {
return list
.sortedByDescending { (it.time / 1000L).toInt() }
.filter { it.image != null } // to remove old data
.map {
Notification(
it.type,
System.currentTimeMillis().toInt(),
@ -162,19 +170,31 @@ class NotificationFragment : Fragment() {
fun onClick(id: Int, optional: Int?, type: NotificationClickType) {
val intent = when (type) {
NotificationClickType.USER -> Intent(requireContext(), ProfileActivity::class.java).apply {
NotificationClickType.USER -> Intent(
requireContext(),
ProfileActivity::class.java
).apply {
putExtra("userId", id)
}
NotificationClickType.MEDIA -> Intent(requireContext(), MediaDetailsActivity::class.java).apply {
NotificationClickType.MEDIA -> Intent(
requireContext(),
MediaDetailsActivity::class.java
).apply {
putExtra("mediaId", id)
}
NotificationClickType.ACTIVITY -> Intent(requireContext(), FeedActivity::class.java).apply {
NotificationClickType.ACTIVITY -> Intent(
requireContext(),
FeedActivity::class.java
).apply {
putExtra("activityId", id)
}
NotificationClickType.COMMENT -> Intent(requireContext(), MediaDetailsActivity::class.java).apply {
NotificationClickType.COMMENT -> Intent(
requireContext(),
MediaDetailsActivity::class.java
).apply {
putExtra("FRAGMENT_TO_LOAD", "COMMENTS")
putExtra("mediaId", id)
putExtra("commentId", optional ?: -1)
@ -188,6 +208,7 @@ class NotificationFragment : Fragment() {
}
}
override fun onResume() {
super.onResume()
if (this::binding.isInitialized) {

View file

@ -8,16 +8,27 @@ import ani.dantotsu.connections.anilist.api.Notification
import ani.dantotsu.connections.anilist.api.NotificationType
import ani.dantotsu.databinding.ItemNotificationBinding
import ani.dantotsu.loadImage
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationClickType
import ani.dantotsu.notifications.comment.CommentStore
import ani.dantotsu.notifications.subscription.SubscriptionStore
import ani.dantotsu.profile.activity.ActivityItemBuilder
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationClickType
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.COMMENT
import ani.dantotsu.profile.notification.NotificationFragment.Companion.NotificationType.SUBSCRIPTION
import ani.dantotsu.setAnimation
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.toPx
import ani.dantotsu.util.customAlertDialog
import com.xwray.groupie.GroupieAdapter
import com.xwray.groupie.viewbinding.BindableItem
class NotificationItem(
private val notification: Notification,
val clickCallback: (Int, Int?, NotificationClickType) -> Unit
) : BindableItem<ItemNotificationBinding>() {
val type: NotificationFragment.Companion.NotificationType,
val parentAdapter: GroupieAdapter,
val clickCallback: (Int, Int?, NotificationClickType) -> Unit,
) : BindableItem<ItemNotificationBinding>() {
private lateinit var binding: ItemNotificationBinding
override fun bind(viewBinding: ItemNotificationBinding, position: Int) {
binding = viewBinding
@ -25,6 +36,48 @@ class NotificationItem(
setBinding()
}
fun dialog() {
when (type) {
COMMENT, SUBSCRIPTION -> {
binding.root.context.customAlertDialog().apply {
setTitle(R.string.delete)
setMessage(ActivityItemBuilder.getContent(notification))
setPosButton(R.string.yes) {
when (type) {
COMMENT -> {
val list = PrefManager.getNullableVal<List<CommentStore>>(
PrefName.CommentNotificationStore,
null
) ?: listOf()
val newList = list.filter { it.commentId != notification.commentId }
PrefManager.setVal(PrefName.CommentNotificationStore, newList)
parentAdapter.remove(this@NotificationItem)
}
SUBSCRIPTION -> {
val list = PrefManager.getNullableVal<List<SubscriptionStore>>(
PrefName.SubscriptionNotificationStore,
null
) ?: listOf()
val newList = list.filter { (it.time / 1000L).toInt() != notification.createdAt}
PrefManager.setVal(PrefName.SubscriptionNotificationStore, newList)
parentAdapter.remove(this@NotificationItem)
}
else -> {}
}
}
setNegButton(R.string.no)
show()
}
}
else -> {}
}
}
override fun getLayout(): Int {
return R.layout.item_notification
}
@ -33,7 +86,11 @@ class NotificationItem(
return ItemNotificationBinding.bind(view)
}
private fun image(user: Boolean = false, commentNotification: Boolean = false, newRelease: Boolean = false) {
private fun image(
user: Boolean = false,
commentNotification: Boolean = false,
newRelease: Boolean = false
) {
val cover = if (user) notification.user?.bannerImage
?: notification.user?.avatar?.medium else notification.media?.bannerImage
@ -348,6 +405,14 @@ class NotificationItem(
}
}
}
binding.notificationCoverUser.setOnLongClickListener {
dialog()
true
}
binding.notificationBannerImage.setOnLongClickListener {
dialog()
true
}
}
}

View file

@ -177,7 +177,7 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="32dp"
android:layout_marginVertical="6dp"
android:orientation="horizontal">
<TextView

View file

@ -83,8 +83,7 @@
<item>All</item>
</string-array>
<string name="no_notifications">No more notifications</string>
<string name="no_activities">No more activities</string>
<string name="nothing_here">Nothing here</string>
<string name="followers">Followers</string>
<string name="write_a_message">Write a Message</string>
<string name="status">STATUS</string>