Skip to content

Commit

Permalink
feat: notification to activity click
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Mar 14, 2024
1 parent 9e37177 commit b69e466
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/ani/dantotsu/profile/activity/FeedActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/ani/dantotsu/profile/activity/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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) { _, _ -> } })
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -115,7 +121,7 @@ class NotificationActivity : AppCompatActivity() {

companion object {
enum class NotificationClickType {
USER, MEDIA, UNDEFINED
USER, MEDIA, ACTIVITY, UNDEFINED
}
}
}
Loading

0 comments on commit b69e466

Please sign in to comment.