Skip to content

Commit

Permalink
feat: delete comment and subscription notification
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed Jun 26, 2024
1 parent c22fd6b commit 46d16be
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 58 deletions.
9 changes: 6 additions & 3 deletions app/src/main/java/ani/dantotsu/home/status/StatusActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/ani/dantotsu/home/status/Stories.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -427,18 +427,17 @@ 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()
binding.activityLikeContainer.setOnClickListener {
like()
}
binding.activityLikeContainer.setOnLongClickListener {
val context = activity
UsersDialogFragment().apply {
userList(userList)
show(context.supportFragmentManager, "dialog")
show((it.context as FragmentActivity).supportFragmentManager, "dialog")
}
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
})
}
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
Expand All @@ -188,6 +208,7 @@ class NotificationFragment : Fragment() {
}
}


override fun onResume() {
super.onResume()
if (this::binding.isInitialized) {
Expand Down
Loading

0 comments on commit 46d16be

Please sign in to comment.