fix: activity pagination
This commit is contained in:
parent
d04ced94ea
commit
92089067f1
6 changed files with 97 additions and 30 deletions
|
@ -1,8 +1,10 @@
|
|||
package ani.dantotsu.profile
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.PopupMenu
|
||||
|
@ -29,13 +31,15 @@ import ani.dantotsu.snackString
|
|||
import ani.dantotsu.statusBarHeight
|
||||
import ani.dantotsu.themes.ThemeManager
|
||||
import ani.dantotsu.toast
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import nl.joery.animatedbottombar.AnimatedBottomBar
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
class ProfileActivity : AppCompatActivity() {
|
||||
class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListener {
|
||||
lateinit var binding: ActivityProfileBinding
|
||||
private var selected: Int = 1
|
||||
private lateinit var navBar: AnimatedBottomBar
|
||||
|
@ -47,6 +51,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
initActivity(this)
|
||||
binding = ActivityProfileBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
screenWidth = resources.displayMetrics.widthPixels.toFloat()
|
||||
navBar = binding.profileNavBar
|
||||
navBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = navBarHeight }
|
||||
val feedTab = navBar.createTab(R.drawable.ic_round_filter_24, "Feed")
|
||||
|
@ -57,6 +62,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
navBar.addTab(statsTab)
|
||||
navBar.visibility = View.GONE
|
||||
binding.profileViewPager.isUserInputEnabled = false
|
||||
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val userid = intent.getIntExtra("userId", 0)
|
||||
val respond = Anilist.query.getUserProfile(userid)
|
||||
|
@ -72,6 +78,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
}
|
||||
binding.profileViewPager.adapter =
|
||||
ViewPagerAdapter(supportFragmentManager, lifecycle, user)
|
||||
binding.profileViewPager.setOffscreenPageLimit(3)
|
||||
binding.profileViewPager.setCurrentItem(selected, false)
|
||||
navBar.visibility = View.VISIBLE
|
||||
navBar.selectTabAt(selected)
|
||||
|
@ -163,10 +170,50 @@ class ProfileActivity : AppCompatActivity() {
|
|||
)
|
||||
}
|
||||
|
||||
mMaxScrollSize = binding.profileAppBar.totalScrollRange
|
||||
binding.profileAppBar.addOnOffsetChangedListener(this@ProfileActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Collapsing UI Stuff
|
||||
private var isCollapsed = false
|
||||
private val percent = 45
|
||||
private var mMaxScrollSize = 0
|
||||
private var screenWidth: Float = 0f
|
||||
|
||||
override fun onOffsetChanged(appBar: AppBarLayout, i: Int) {
|
||||
if (mMaxScrollSize == 0) mMaxScrollSize = appBar.totalScrollRange
|
||||
val percentage = abs(i) * 100 / mMaxScrollSize
|
||||
|
||||
binding.profileUserAvatarContainer.visibility =
|
||||
if (binding.profileUserAvatarContainer.scaleX == 0f) View.GONE else View.VISIBLE
|
||||
val duration = (200 * (PrefManager.getVal(PrefName.AnimationSpeed) as Float)).toLong()
|
||||
val typedValue = TypedValue()
|
||||
this@ProfileActivity.theme.resolveAttribute(
|
||||
com.google.android.material.R.attr.colorSecondary,
|
||||
typedValue,
|
||||
true
|
||||
)
|
||||
val color = typedValue.data
|
||||
if (percentage >= percent && !isCollapsed) {
|
||||
isCollapsed = true
|
||||
ObjectAnimator.ofFloat(binding.profileUserDataContainer, "translationX", screenWidth)
|
||||
.setDuration(duration).start()
|
||||
ObjectAnimator.ofFloat(binding.profileUserAvatarContainer, "translationX", screenWidth)
|
||||
.setDuration(duration).start()
|
||||
binding.profileBannerImage.pause()
|
||||
}
|
||||
if (percentage <= percent && isCollapsed) {
|
||||
isCollapsed = false
|
||||
ObjectAnimator.ofFloat(binding.profileUserDataContainer, "translationX", 0f)
|
||||
.setDuration(duration).start()
|
||||
ObjectAnimator.ofFloat(binding.profileUserAvatarContainer, "translationX", 0f).setDuration(duration)
|
||||
.start()
|
||||
if (PrefManager.getVal(PrefName.BannerAnimations)) binding.profileBannerImage.resume()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
if (this::navBar.isInitialized) {
|
||||
navBar.selectTabAt(selected)
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
|
@ -16,6 +17,7 @@ import ani.dantotsu.profile.ChartBuilder.Companion.ChartPacket
|
|||
import ani.dantotsu.profile.ChartBuilder.Companion.ChartType
|
||||
import ani.dantotsu.profile.ChartBuilder.Companion.MediaType
|
||||
import ani.dantotsu.profile.ChartBuilder.Companion.StatType
|
||||
import ani.dantotsu.statusBarHeight
|
||||
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartType
|
||||
import com.xwray.groupie.GroupieAdapter
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -49,10 +51,11 @@ class StatsFragment :
|
|||
|
||||
binding.statisticList.adapter = adapter
|
||||
binding.statisticList.setHasFixedSize(true)
|
||||
binding.statisticList.isNestedScrollingEnabled = false
|
||||
binding.statisticList.isNestedScrollingEnabled = true
|
||||
binding.statisticList.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.statisticProgressBar.visibility = View.VISIBLE
|
||||
binding.compare.visibility = if (user.id == Anilist.userid) View.GONE else View.VISIBLE
|
||||
binding.filterContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin = statusBarHeight }
|
||||
|
||||
binding.sourceType.setAdapter(
|
||||
ArrayAdapter(
|
||||
|
|
|
@ -58,14 +58,11 @@ class FeedFragment : Fragment() {
|
|||
adapter.update(activityList.map { ActivityItem(it) { _, _ -> } })
|
||||
}
|
||||
binding.listProgressBar.visibility = ViewGroup.GONE
|
||||
val scrollView = if (activity is ProfileActivity) {
|
||||
(activity as ProfileActivity).binding.profileScrollView
|
||||
} else {
|
||||
binding.listRecyclerView
|
||||
}
|
||||
val scrollView = binding.listRecyclerView
|
||||
|
||||
binding.listRecyclerView.setOnTouchListener { _, event ->
|
||||
if (event?.action == MotionEvent.ACTION_UP) {
|
||||
if (adapter.itemCount % AnilistQueries.ITEMS_PER_PAGE != 0) {
|
||||
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 &&
|
||||
|
|
|
@ -19,17 +19,18 @@
|
|||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/profileScrollView"
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/profileAppBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="72dp"
|
||||
android:scrollbars="none">
|
||||
android:translationZ="5dp">
|
||||
|
||||
<LinearLayout
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="false"
|
||||
app:contentScrim="?android:colorBackground"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/profileTopContainer"
|
||||
|
@ -129,16 +130,25 @@
|
|||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="72dp"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/profileViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:nestedScrollingEnabled="true"
|
||||
tools:ignore="SpeakableTextPresentCheck" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
|
||||
<nl.joery.animatedbottombar.AnimatedBottomBar
|
||||
android:id="@+id/profileNavBar"
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:nestedScrollingEnabled="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -144,8 +149,8 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:text="@string/stats"
|
||||
android:padding="8dp"
|
||||
android:text="@string/stats"
|
||||
android:textSize="18sp"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
|
@ -344,8 +349,8 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:text="@string/about_me"
|
||||
android:padding="8dp"
|
||||
android:text="@string/about_me"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<WebView
|
||||
|
@ -356,6 +361,7 @@
|
|||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:ellipsize="end"
|
||||
android:nestedScrollingEnabled="true"
|
||||
android:padding="16dp"
|
||||
android:textAlignment="textStart"
|
||||
tools:text="@string/slogan" />
|
||||
|
@ -464,8 +470,8 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:text="@string/fav_character"
|
||||
android:padding="8dp"
|
||||
android:text="@string/fav_character"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ani.dantotsu.FadingEdgeRecyclerView
|
||||
|
@ -497,8 +503,8 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:text="@string/fav_staff"
|
||||
android:padding="8dp"
|
||||
android:text="@string/fav_staff"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ani.dantotsu.FadingEdgeRecyclerView
|
||||
|
@ -516,3 +522,4 @@
|
|||
tools:orientation="horizontal" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -123,5 +125,6 @@
|
|||
android:id="@+id/statisticList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="true"
|
||||
tools:listitem="@layout/item_chart" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue