94 lines
3.9 KiB
Kotlin
94 lines
3.9 KiB
Kotlin
package ani.dantotsu.profile.notification
|
|
|
|
import android.os.Bundle
|
|
import android.view.ViewGroup
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.core.view.updateLayoutParams
|
|
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.ActivityNotificationBinding
|
|
import ani.dantotsu.initActivity
|
|
import ani.dantotsu.navBarHeight
|
|
import ani.dantotsu.statusBarHeight
|
|
import ani.dantotsu.themes.ThemeManager
|
|
import nl.joery.animatedbottombar.AnimatedBottomBar
|
|
|
|
class NotificationActivity : AppCompatActivity() {
|
|
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 = ActivityNotificationBinding.inflate(layoutInflater)
|
|
setContentView(binding.root)
|
|
binding.notificationTitle.text = getString(R.string.notifications)
|
|
binding.notificationToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
|
topMargin = statusBarHeight
|
|
}
|
|
navBar = binding.notificationNavBar
|
|
binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
|
bottomMargin = navBarHeight
|
|
}
|
|
val mediaTab = navBar.createTab(R.drawable.ic_round_movie_filter_24, "Media")
|
|
val userTab = navBar.createTab(R.drawable.ic_round_person_24, "User")
|
|
val subscriptionTab = navBar.createTab(R.drawable.ic_round_notifications_active_24, "Subscriptions")
|
|
val commentTab = navBar.createTab(R.drawable.ic_round_comment_24, "Comments")
|
|
navBar.addTab(mediaTab)
|
|
navBar.addTab(userTab)
|
|
navBar.addTab(subscriptionTab)
|
|
navBar.addTab(commentTab)
|
|
binding.notificationBack.setOnClickListener {
|
|
onBackPressedDispatcher.onBackPressed()
|
|
}
|
|
val getOne = intent.getIntExtra("activityId", -1)
|
|
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(
|
|
lastIndex: Int,
|
|
lastTab: AnimatedBottomBar.Tab?,
|
|
newIndex: Int,
|
|
newTab: AnimatedBottomBar.Tab
|
|
) {
|
|
selected = newIndex
|
|
binding.notificationViewPager.setCurrentItem(selected, true)
|
|
}
|
|
})
|
|
binding.notificationViewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
|
override fun onPageSelected(position: Int) {
|
|
super.onPageSelected(position)
|
|
navBar.selectTabAt(position)
|
|
}
|
|
})
|
|
}
|
|
override fun onResume() {
|
|
if (this::navBar.isInitialized) {
|
|
navBar.selectTabAt(selected)
|
|
}
|
|
super.onResume()
|
|
}
|
|
private class ViewPagerAdapter(
|
|
fragmentManager: FragmentManager,
|
|
lifecycle: Lifecycle,
|
|
val id: Int = -1
|
|
) : FragmentStateAdapter(fragmentManager, lifecycle) {
|
|
override fun getItemCount(): Int = 4
|
|
|
|
override fun createFragment(position: Int): Fragment = when (position) {
|
|
0 -> NotificationFragment(if (id != -1) "getOne" else "media", id)
|
|
1 -> NotificationFragment("user")
|
|
2 -> NotificationFragment("subscription")
|
|
3 -> NotificationFragment("comment")
|
|
else -> NotificationFragment("media")
|
|
}
|
|
}
|
|
}
|