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
|
package ani.dantotsu.profile
|
||||||
|
|
||||||
|
import android.animation.ObjectAnimator
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.PopupMenu
|
import android.widget.PopupMenu
|
||||||
|
@ -29,13 +31,15 @@ import ani.dantotsu.snackString
|
||||||
import ani.dantotsu.statusBarHeight
|
import ani.dantotsu.statusBarHeight
|
||||||
import ani.dantotsu.themes.ThemeManager
|
import ani.dantotsu.themes.ThemeManager
|
||||||
import ani.dantotsu.toast
|
import ani.dantotsu.toast
|
||||||
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import nl.joery.animatedbottombar.AnimatedBottomBar
|
import nl.joery.animatedbottombar.AnimatedBottomBar
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
|
||||||
class ProfileActivity : AppCompatActivity() {
|
class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListener {
|
||||||
lateinit var binding: ActivityProfileBinding
|
lateinit var binding: ActivityProfileBinding
|
||||||
private var selected: Int = 1
|
private var selected: Int = 1
|
||||||
private lateinit var navBar: AnimatedBottomBar
|
private lateinit var navBar: AnimatedBottomBar
|
||||||
|
@ -47,6 +51,7 @@ class ProfileActivity : AppCompatActivity() {
|
||||||
initActivity(this)
|
initActivity(this)
|
||||||
binding = ActivityProfileBinding.inflate(layoutInflater)
|
binding = ActivityProfileBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
screenWidth = resources.displayMetrics.widthPixels.toFloat()
|
||||||
navBar = binding.profileNavBar
|
navBar = binding.profileNavBar
|
||||||
navBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = navBarHeight }
|
navBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = navBarHeight }
|
||||||
val feedTab = navBar.createTab(R.drawable.ic_round_filter_24, "Feed")
|
val feedTab = navBar.createTab(R.drawable.ic_round_filter_24, "Feed")
|
||||||
|
@ -57,6 +62,7 @@ class ProfileActivity : AppCompatActivity() {
|
||||||
navBar.addTab(statsTab)
|
navBar.addTab(statsTab)
|
||||||
navBar.visibility = View.GONE
|
navBar.visibility = View.GONE
|
||||||
binding.profileViewPager.isUserInputEnabled = false
|
binding.profileViewPager.isUserInputEnabled = false
|
||||||
|
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val userid = intent.getIntExtra("userId", 0)
|
val userid = intent.getIntExtra("userId", 0)
|
||||||
val respond = Anilist.query.getUserProfile(userid)
|
val respond = Anilist.query.getUserProfile(userid)
|
||||||
|
@ -72,6 +78,7 @@ class ProfileActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
binding.profileViewPager.adapter =
|
binding.profileViewPager.adapter =
|
||||||
ViewPagerAdapter(supportFragmentManager, lifecycle, user)
|
ViewPagerAdapter(supportFragmentManager, lifecycle, user)
|
||||||
|
binding.profileViewPager.setOffscreenPageLimit(3)
|
||||||
binding.profileViewPager.setCurrentItem(selected, false)
|
binding.profileViewPager.setCurrentItem(selected, false)
|
||||||
navBar.visibility = View.VISIBLE
|
navBar.visibility = View.VISIBLE
|
||||||
navBar.selectTabAt(selected)
|
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() {
|
override fun onResume() {
|
||||||
if (this::navBar.isInitialized) {
|
if (this::navBar.isInitialized) {
|
||||||
navBar.selectTabAt(selected)
|
navBar.selectTabAt(selected)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
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.ChartType
|
||||||
import ani.dantotsu.profile.ChartBuilder.Companion.MediaType
|
import ani.dantotsu.profile.ChartBuilder.Companion.MediaType
|
||||||
import ani.dantotsu.profile.ChartBuilder.Companion.StatType
|
import ani.dantotsu.profile.ChartBuilder.Companion.StatType
|
||||||
|
import ani.dantotsu.statusBarHeight
|
||||||
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartType
|
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartType
|
||||||
import com.xwray.groupie.GroupieAdapter
|
import com.xwray.groupie.GroupieAdapter
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -49,10 +51,11 @@ class StatsFragment :
|
||||||
|
|
||||||
binding.statisticList.adapter = adapter
|
binding.statisticList.adapter = adapter
|
||||||
binding.statisticList.setHasFixedSize(true)
|
binding.statisticList.setHasFixedSize(true)
|
||||||
binding.statisticList.isNestedScrollingEnabled = false
|
binding.statisticList.isNestedScrollingEnabled = true
|
||||||
binding.statisticList.layoutManager = LinearLayoutManager(requireContext())
|
binding.statisticList.layoutManager = LinearLayoutManager(requireContext())
|
||||||
binding.statisticProgressBar.visibility = View.VISIBLE
|
binding.statisticProgressBar.visibility = View.VISIBLE
|
||||||
binding.compare.visibility = if (user.id == Anilist.userid) View.GONE else 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(
|
binding.sourceType.setAdapter(
|
||||||
ArrayAdapter(
|
ArrayAdapter(
|
||||||
|
|
|
@ -58,14 +58,11 @@ class FeedFragment : Fragment() {
|
||||||
adapter.update(activityList.map { ActivityItem(it) { _, _ -> } })
|
adapter.update(activityList.map { ActivityItem(it) { _, _ -> } })
|
||||||
}
|
}
|
||||||
binding.listProgressBar.visibility = ViewGroup.GONE
|
binding.listProgressBar.visibility = ViewGroup.GONE
|
||||||
val scrollView = if (activity is ProfileActivity) {
|
val scrollView = binding.listRecyclerView
|
||||||
(activity as ProfileActivity).binding.profileScrollView
|
|
||||||
} else {
|
|
||||||
binding.listRecyclerView
|
|
||||||
}
|
|
||||||
binding.listRecyclerView.setOnTouchListener { _, event ->
|
binding.listRecyclerView.setOnTouchListener { _, event ->
|
||||||
if (event?.action == MotionEvent.ACTION_UP) {
|
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")
|
snackString("No more activities")
|
||||||
} else if (!scrollView.canScrollVertically(1) && !binding.feedRefresh.isVisible
|
} else if (!scrollView.canScrollVertically(1) && !binding.feedRefresh.isVisible
|
||||||
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
|
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
|
||||||
|
|
|
@ -19,17 +19,18 @@
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.core.widget.NestedScrollView
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/profileScrollView"
|
android:id="@+id/profileAppBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="72dp"
|
android:translationZ="5dp">
|
||||||
android:scrollbars="none">
|
|
||||||
|
|
||||||
<LinearLayout
|
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:fitsSystemWindows="false"
|
||||||
|
app:contentScrim="?android:colorBackground"
|
||||||
|
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/profileTopContainer"
|
android:id="@+id/profileTopContainer"
|
||||||
|
@ -129,15 +130,24 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||||
android:id="@+id/profileViewPager"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:ignore="SpeakableTextPresentCheck" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
<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>
|
||||||
|
|
||||||
|
|
||||||
<nl.joery.animatedbottombar.AnimatedBottomBar
|
<nl.joery.animatedbottombar.AnimatedBottomBar
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -144,8 +149,8 @@
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:fontFamily="@font/poppins_bold"
|
android:fontFamily="@font/poppins_bold"
|
||||||
android:text="@string/stats"
|
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
|
android:text="@string/stats"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
@ -344,9 +349,9 @@
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:fontFamily="@font/poppins_bold"
|
android:fontFamily="@font/poppins_bold"
|
||||||
android:text="@string/about_me"
|
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:textSize="18sp"/>
|
android:text="@string/about_me"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
|
||||||
<WebView
|
<WebView
|
||||||
android:id="@+id/profileUserBio"
|
android:id="@+id/profileUserBio"
|
||||||
|
@ -356,6 +361,7 @@
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:textAlignment="textStart"
|
android:textAlignment="textStart"
|
||||||
tools:text="@string/slogan" />
|
tools:text="@string/slogan" />
|
||||||
|
@ -464,8 +470,8 @@
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:fontFamily="@font/poppins_bold"
|
android:fontFamily="@font/poppins_bold"
|
||||||
android:text="@string/fav_character"
|
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
|
android:text="@string/fav_character"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
<ani.dantotsu.FadingEdgeRecyclerView
|
<ani.dantotsu.FadingEdgeRecyclerView
|
||||||
|
@ -497,8 +503,8 @@
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:fontFamily="@font/poppins_bold"
|
android:fontFamily="@font/poppins_bold"
|
||||||
android:text="@string/fav_staff"
|
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
|
android:text="@string/fav_staff"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
<ani.dantotsu.FadingEdgeRecyclerView
|
<ani.dantotsu.FadingEdgeRecyclerView
|
||||||
|
@ -515,4 +521,5 @@
|
||||||
tools:listitem="@layout/item_media_compact"
|
tools:listitem="@layout/item_media_compact"
|
||||||
tools:orientation="horizontal" />
|
tools:orientation="horizontal" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp">
|
android:paddingBottom="16dp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -123,5 +125,6 @@
|
||||||
android:id="@+id/statisticList"
|
android:id="@+id/statisticList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
tools:listitem="@layout/item_chart" />
|
tools:listitem="@layout/item_chart" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue