feat: combine profile queries
This commit is contained in:
parent
867a4f36b3
commit
eb5e2623a0
5 changed files with 165 additions and 116 deletions
|
@ -34,6 +34,7 @@ class StatsFragment :
|
|||
private var statType: StatType = StatType.COUNT
|
||||
private lateinit var user: Query.UserProfile
|
||||
private lateinit var activity: ProfileActivity
|
||||
private var loadedFirstTime = false
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
@ -101,29 +102,32 @@ class StatsFragment :
|
|||
}
|
||||
|
||||
binding.filterContainer.visibility = View.GONE
|
||||
activity.lifecycleScope.launch {
|
||||
stats.clear()
|
||||
stats.add(Anilist.query.getUserStatistics(user.id)?.data?.user)
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.filterContainer.visibility = View.VISIBLE
|
||||
binding.sourceType.setOnItemClickListener { _, _, i, _ ->
|
||||
type = MediaType.entries.toTypedArray()[i]
|
||||
loadStats(type == MediaType.ANIME)
|
||||
}
|
||||
binding.sourceFilter.setOnItemClickListener { _, _, i, _ ->
|
||||
statType = StatType.entries.toTypedArray()[i]
|
||||
loadStats(type == MediaType.ANIME)
|
||||
}
|
||||
loadStats(type == MediaType.ANIME)
|
||||
binding.statisticProgressBar.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (this::binding.isInitialized) {
|
||||
binding.root.requestLayout()
|
||||
if (!loadedFirstTime) {
|
||||
activity.lifecycleScope.launch {
|
||||
stats.clear()
|
||||
stats.add(Anilist.query.getUserStatistics(user.id)?.data?.user)
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.filterContainer.visibility = View.VISIBLE
|
||||
binding.sourceType.setOnItemClickListener { _, _, i, _ ->
|
||||
type = MediaType.entries.toTypedArray()[i]
|
||||
loadStats(type == MediaType.ANIME)
|
||||
}
|
||||
binding.sourceFilter.setOnItemClickListener { _, _, i, _ ->
|
||||
statType = StatType.entries.toTypedArray()[i]
|
||||
loadStats(type == MediaType.ANIME)
|
||||
}
|
||||
loadStats(type == MediaType.ANIME)
|
||||
binding.statisticProgressBar.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
loadedFirstTime = true
|
||||
}
|
||||
}
|
||||
loadStats(type == MediaType.ANIME)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ class FeedFragment : Fragment() {
|
|||
private var activityList: List<Activity> = emptyList()
|
||||
private lateinit var activity: androidx.activity.ComponentActivity
|
||||
private var page: Int = 1
|
||||
private var loadedFirstTime = false
|
||||
private var userId: Int? = null
|
||||
private var global: Boolean = false
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
@ -38,7 +41,6 @@ class FeedFragment : Fragment() {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
activity = requireActivity()
|
||||
|
@ -46,52 +48,55 @@ class FeedFragment : Fragment() {
|
|||
binding.listRecyclerView.layoutManager =
|
||||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
binding.listProgressBar.visibility = ViewGroup.VISIBLE
|
||||
var userId: Int? = arguments?.getInt("userId", -1)
|
||||
userId = arguments?.getInt("userId", -1)
|
||||
if (userId == -1) userId = null
|
||||
val global = arguments?.getBoolean("global", false) ?: false
|
||||
|
||||
activity.lifecycleScope.launch(Dispatchers.IO) {
|
||||
val res = Anilist.query.getFeed(userId, global)
|
||||
withContext(Dispatchers.Main) {
|
||||
res?.data?.page?.activities?.let { activities ->
|
||||
activityList = activities
|
||||
adapter.update(activityList.map { ActivityItem(it) { _, _ -> } })
|
||||
}
|
||||
binding.listProgressBar.visibility = ViewGroup.GONE
|
||||
val scrollView = binding.listRecyclerView
|
||||
|
||||
binding.listRecyclerView.setOnTouchListener { _, event ->
|
||||
if (event?.action == MotionEvent.ACTION_UP) {
|
||||
if (adapter.itemCount % AnilistQueries.ITEMS_PER_PAGE != 0 && !global) {
|
||||
snackString("No more activities")
|
||||
} else if (!scrollView.canScrollVertically(1) && !binding.feedRefresh.isVisible
|
||||
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
|
||||
(binding.listRecyclerView.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() == (binding.listRecyclerView.adapter!!.itemCount - 1)
|
||||
) {
|
||||
page++
|
||||
binding.feedRefresh.visibility = ViewGroup.VISIBLE
|
||||
activity.lifecycleScope.launch(Dispatchers.IO) {
|
||||
val res = Anilist.query.getFeed(userId, global, page)
|
||||
withContext(Dispatchers.Main) {
|
||||
res?.data?.page?.activities?.let { activities ->
|
||||
activityList += activities
|
||||
adapter.addAll(activities.map { ActivityItem(it) { _, _ -> } })
|
||||
}
|
||||
binding.feedRefresh.visibility = ViewGroup.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
global = arguments?.getBoolean("global", false) ?: false
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (this::binding.isInitialized) {
|
||||
binding.root.requestLayout()
|
||||
if (!loadedFirstTime) {
|
||||
activity.lifecycleScope.launch(Dispatchers.IO) {
|
||||
val res = Anilist.query.getFeed(userId, global)
|
||||
withContext(Dispatchers.Main) {
|
||||
res?.data?.page?.activities?.let { activities ->
|
||||
activityList = activities
|
||||
adapter.update(activityList.map { ActivityItem(it) { _, _ -> } })
|
||||
}
|
||||
binding.listProgressBar.visibility = ViewGroup.GONE
|
||||
val scrollView = binding.listRecyclerView
|
||||
|
||||
binding.listRecyclerView.setOnTouchListener { _, event ->
|
||||
if (event?.action == MotionEvent.ACTION_UP) {
|
||||
if (adapter.itemCount % AnilistQueries.ITEMS_PER_PAGE != 0 && !global) {
|
||||
snackString("No more activities")
|
||||
} else if (!scrollView.canScrollVertically(1) && !binding.feedRefresh.isVisible
|
||||
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
|
||||
(binding.listRecyclerView.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() == (binding.listRecyclerView.adapter!!.itemCount - 1)
|
||||
) {
|
||||
page++
|
||||
binding.feedRefresh.visibility = ViewGroup.VISIBLE
|
||||
activity.lifecycleScope.launch(Dispatchers.IO) {
|
||||
val res = Anilist.query.getFeed(userId, global, page)
|
||||
withContext(Dispatchers.Main) {
|
||||
res?.data?.page?.activities?.let { activities ->
|
||||
activityList += activities
|
||||
adapter.addAll(activities.map { ActivityItem(it) { _, _ -> } })
|
||||
}
|
||||
binding.feedRefresh.visibility = ViewGroup.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
loadedFirstTime = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue