Skip to content

Commit

Permalink
chore: optimized feed activity
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed May 26, 2024
1 parent 46c17dc commit b256f02
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 48 deletions.
68 changes: 30 additions & 38 deletions app/src/main/java/ani/dantotsu/profile/activity/FeedActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,48 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.R
import ani.dantotsu.databinding.ActivityFeedBinding
import ani.dantotsu.databinding.ActivityNotificationBinding
import ani.dantotsu.initActivity
import ani.dantotsu.navBarHeight
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.profile.activity.ActivityFragment.Companion.ActivityType
import ani.dantotsu.profile.notification.NotificationActivity
import nl.joery.animatedbottombar.AnimatedBottomBar

class FeedActivity : AppCompatActivity() {
private lateinit var binding: ActivityFeedBinding
private lateinit var binding: ActivityNotificationBinding
private var selected: Int = 0
lateinit var navBar: AnimatedBottomBar

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ThemeManager(this).applyTheme()
initActivity(this)
binding = ActivityFeedBinding.inflate(layoutInflater)
binding = ActivityNotificationBinding.inflate(layoutInflater)
setContentView(binding.root)
navBar = binding.feedNavBar
val navBarMargin = if (resources.configuration.orientation ==
Configuration.ORIENTATION_LANDSCAPE
) 0 else navBarHeight
navBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = navBarMargin }
val personalTab = navBar.createTab(R.drawable.ic_round_person_24, "Following")
val globalTab = navBar.createTab(R.drawable.ic_globe_24, "Global")
navBar.addTab(personalTab)
navBar.addTab(globalTab)
binding.listTitle.text = getString(R.string.activities)
binding.feedViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarMargin
topMargin += statusBarHeight
binding.notificationTitle.text = getString(R.string.activities)
binding.notificationToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = statusBarHeight
}
binding.listToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += statusBarHeight }
val activityId = intent.getIntExtra("activityId", -1)
if (activityId != -1) { navBar.visibility = View.GONE }
binding.feedViewPager.adapter =
ViewPagerAdapter(supportFragmentManager, lifecycle, activityId)
binding.feedViewPager.setCurrentItem(selected, false)
binding.feedViewPager.isUserInputEnabled = false
navBar = binding.notificationNavBar
binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
}
val tabs = listOf(
Pair(R.drawable.ic_round_person_24, "Following"),
Pair(R.drawable.ic_globe_24, "Global"),
)
tabs.forEach { (icon, title) -> navBar.addTab(navBar.createTab(icon, title)) }
binding.notificationBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
val getOne = intent.getIntExtra("activityId", -1)
if (getOne != -1) { navBar.visibility = View.GONE }
binding.notificationViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, getOne)
binding.notificationViewPager.setOffscreenPageLimit(4)
binding.notificationViewPager.setCurrentItem(selected, false)
navBar.selectTabAt(selected)
navBar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
override fun onTabSelected(
Expand All @@ -61,24 +62,15 @@ class FeedActivity : AppCompatActivity() {
newTab: AnimatedBottomBar.Tab
) {
selected = newIndex
binding.feedViewPager.setCurrentItem(selected, true)
binding.notificationViewPager.setCurrentItem(selected, true)
}
})
binding.notificationViewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
navBar.selectTabAt(position)
}
})
binding.listBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
val margin =
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) 0 else navBarHeight
val params: ViewGroup.MarginLayoutParams =
binding.feedViewPager.layoutParams as ViewGroup.MarginLayoutParams
val paramsNav: ViewGroup.MarginLayoutParams =
navBar.layoutParams as ViewGroup.MarginLayoutParams
params.updateMargins(bottom = margin)
paramsNav.updateMargins(bottom = margin)
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class NotificationActivity : AppCompatActivity() {
binding.notificationViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, getOne)
binding.notificationViewPager.setOffscreenPageLimit(4)
binding.notificationViewPager.setCurrentItem(selected, false)
binding.notificationViewPager
navBar.selectTabAt(selected)
navBar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
override fun onTabSelected(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class NotificationFragment(
binding.notificationRecyclerView.setBaseline(navbar)
binding.notificationRecyclerView.adapter = adapter
binding.notificationRecyclerView.layoutManager = LinearLayoutManager(context)
binding.notificationProgressBar.isVisible = true
binding.notificationRefresh.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
}
Expand All @@ -78,6 +79,7 @@ class NotificationFragment(
super.onScrolled(recyclerView, dx, dy)
if (shouldLoadMore()) {
lifecycleScope.launch {
binding.notificationRefresh.isVisible = true
getList()
binding.notificationRefresh.isVisible = false
}
Expand All @@ -94,7 +96,6 @@ class NotificationFragment(
NotificationType.USER -> getNotificationsFiltered { it.media == null }
NotificationType.SUBSCRIPTION -> getSubscriptions()
NotificationType.COMMENT -> getComments()
else -> listOf()
}
adapter.addAll(list.map { NotificationItem(it, ::onClick) })
}
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/res/layout/fragment_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
android:layout_height="match_parent"
android:orientation="vertical">

<ProgressBar
<LinearLayout
android:id="@+id/listProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:visibility="gone">

<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">

<TextView
android:id="@+id/emptyTextView"
android:layout_width="match_parent"
Expand Down Expand Up @@ -45,7 +51,6 @@

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>


<ProgressBar
android:id="@+id/feedRefresh"
style="?android:attr/progressBarStyle"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_notifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</LinearLayout>

<LinearLayout
android:id="@+id/listFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
Expand Down

0 comments on commit b256f02

Please sign in to comment.