feat(social): filter activity only with in 3days
This commit is contained in:
parent
133354a22d
commit
90b9b7bef3
7 changed files with 40 additions and 30 deletions
|
@ -6,7 +6,6 @@ import ani.dantotsu.checkGenreTime
|
|||
import ani.dantotsu.checkId
|
||||
import ani.dantotsu.connections.anilist.Anilist.authorRoles
|
||||
import ani.dantotsu.connections.anilist.Anilist.executeQuery
|
||||
import ani.dantotsu.connections.anilist.api.Activity
|
||||
import ani.dantotsu.connections.anilist.api.FeedResponse
|
||||
import ani.dantotsu.connections.anilist.api.FuzzyDate
|
||||
import ani.dantotsu.connections.anilist.api.NotificationResponse
|
||||
|
@ -1651,14 +1650,12 @@ Page(page:$page,perPage:50) {
|
|||
}""".trimIndent()
|
||||
val list = mutableListOf<User>()
|
||||
val threeDaysAgo = Calendar.getInstance().apply {
|
||||
add(Calendar.DAY_OF_MONTH, -10)
|
||||
add(Calendar.DAY_OF_MONTH, -3)
|
||||
}.timeInMillis
|
||||
executeQuery<Social>(query(), force = true)?.data?.let { data ->
|
||||
val activities = listOf(data.page1.activities, data.page2.activities).flatten()
|
||||
|
||||
.sortedByDescending { it.createdAt }
|
||||
.filter { it.createdAt < threeDaysAgo }
|
||||
|
||||
.filter { it.createdAt * 1000L > threeDaysAgo }
|
||||
val anilistActivities = mutableListOf<User>()
|
||||
val groupedActivities = activities.groupBy { it.userId }
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import ani.dantotsu.setSlideIn
|
|||
import ani.dantotsu.setSlideUp
|
||||
import ani.dantotsu.settings.SettingsDialogFragment
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefManager.asLiveBool
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.snackString
|
||||
import ani.dantotsu.statusBarHeight
|
||||
|
@ -56,7 +57,6 @@ import kotlin.math.min
|
|||
class HomeFragment : Fragment() {
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
@ -322,7 +322,12 @@ class HomeFragment : Fragment() {
|
|||
binding.homeUserStatusRecyclerView.visibility = View.GONE
|
||||
if (it != null) {
|
||||
if (it.isNotEmpty()) {
|
||||
binding.homeUserStatusRecyclerView.adapter = UserStatusAdapter(it)
|
||||
PrefManager.getLiveVal(PrefName.RefreshStatus, false).apply {
|
||||
asLiveBool()
|
||||
observe(viewLifecycleOwner) { _ ->
|
||||
binding.homeUserStatusRecyclerView.adapter = UserStatusAdapter(it)
|
||||
}
|
||||
}
|
||||
binding.homeUserStatusRecyclerView.layoutManager = LinearLayoutManager(
|
||||
requireContext(),
|
||||
LinearLayoutManager.HORIZONTAL,
|
||||
|
|
|
@ -58,9 +58,8 @@ class CircleView(context: Context, attrs: AttributeSet?) : View(context, attrs)
|
|||
setColor(0)
|
||||
} else {
|
||||
val effectiveAngle = totalAngle / parts
|
||||
|
||||
for (i in 0 until parts) {
|
||||
val startAngle = i * (effectiveAngle + gapAngle)
|
||||
val startAngle = i * (effectiveAngle + gapAngle) -90f
|
||||
path.reset()
|
||||
path.addArc(
|
||||
centerX - radius,
|
||||
|
|
|
@ -106,7 +106,6 @@ constructor(
|
|||
|
||||
leftTouchPanel.setOnTouchListener(this)
|
||||
rightTouchPanel.setOnTouchListener(this)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -469,25 +468,7 @@ constructor(
|
|||
activityLikeCount.text = story.likeCount.toString()
|
||||
activityLike.setColorFilter(if (story.isLiked == true) likeColor else notLikeColor)
|
||||
activityLikeContainer.setOnClickListener {
|
||||
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
scope.launch {
|
||||
val res = Anilist.query.toggleLike(story.id, "ACTIVITY")
|
||||
withContext(Dispatchers.Main) {
|
||||
if (res != null) {
|
||||
if (story.isLiked == true) {
|
||||
story.likeCount = story.likeCount?.minus(1)
|
||||
} else {
|
||||
story.likeCount = story.likeCount?.plus(1)
|
||||
}
|
||||
activityLikeCount.text = (story.likeCount ?: 0).toString()
|
||||
story.isLiked = !story.isLiked!!
|
||||
activityLike.setColorFilter(if (story.isLiked == true) likeColor else notLikeColor)
|
||||
|
||||
} else {
|
||||
snackString("Failed to like activity")
|
||||
}
|
||||
}
|
||||
}
|
||||
like()
|
||||
}
|
||||
activityLikeContainer.setOnLongClickListener {
|
||||
UsersDialogFragment().apply {
|
||||
|
@ -497,4 +478,28 @@ constructor(
|
|||
true
|
||||
}
|
||||
}
|
||||
fun like(){
|
||||
val story = activityList[storyIndex - 1]
|
||||
val likeColor = ContextCompat.getColor(context, R.color.yt_red)
|
||||
val notLikeColor = ContextCompat.getColor(context, R.color.bg_opp)
|
||||
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
scope.launch {
|
||||
val res = Anilist.query.toggleLike(story.id, "ACTIVITY")
|
||||
withContext(Dispatchers.Main) {
|
||||
if (res != null) {
|
||||
if (story.isLiked == true) {
|
||||
story.likeCount = story.likeCount?.minus(1)
|
||||
} else {
|
||||
story.likeCount = story.likeCount?.plus(1)
|
||||
}
|
||||
activityLikeCount.text = (story.likeCount ?: 0).toString()
|
||||
story.isLiked = !story.isLiked!!
|
||||
activityLike.setColorFilter(if (story.isLiked == true) likeColor else notLikeColor)
|
||||
|
||||
} else {
|
||||
snackString("Failed to like activity")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,8 +5,10 @@ import android.view.LayoutInflater
|
|||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.connections.anilist.Anilist
|
||||
import ani.dantotsu.databinding.ItemUserStatusBinding
|
||||
import ani.dantotsu.getAppString
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.profile.ProfileActivity
|
||||
import ani.dantotsu.profile.User
|
||||
|
@ -59,7 +61,7 @@ class UserStatusAdapter(private val user: ArrayList<User>) :
|
|||
setAnimation(b.root.context, b.root)
|
||||
val user = user[position]
|
||||
b.profileUserAvatar.loadImage(user.pfp)
|
||||
b.profileUserName.text = if (Anilist.userid == user.id) "You" else user.name
|
||||
b.profileUserName.text = if (Anilist.userid == user.id) getAppString(R.string.your_story) else user.name
|
||||
|
||||
val watchedActivity =
|
||||
PrefManager.getCustomVal<Set<Int>>("${user.id}_activities", setOf())
|
||||
|
|
|
@ -187,6 +187,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
|
|||
CommentNotificationStore(Pref(Location.Irrelevant, List::class, listOf<CommentStore>())),
|
||||
UnreadCommentNotifications(Pref(Location.Irrelevant, Int::class, 0)),
|
||||
DownloadsDir(Pref(Location.Irrelevant, String::class, "")),
|
||||
RefreshStatus(Pref(Location.Irrelevant, Boolean::class, false)),
|
||||
|
||||
//Protected
|
||||
DiscordToken(Pref(Location.Protected, String::class, "")),
|
||||
|
|
|
@ -964,4 +964,5 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
|
|||
<string name="avatar">%1$s\ [Avatar]</string>
|
||||
<string name="cover">%1$s\ [Cover]</string>
|
||||
<string name="banner">%1$s\ [Banner]</string>
|
||||
<string name="your_story">Your Story</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue