mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-23 03:11:03 +00:00
70 lines
2.7 KiB
Kotlin
70 lines
2.7 KiB
Kotlin
package ani.dantotsu.media
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.os.Bundle
|
|
import android.view.View
|
|
import androidx.activity.viewModels
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.lifecycleScope
|
|
import ani.dantotsu.R
|
|
import ani.dantotsu.Refresh
|
|
import ani.dantotsu.databinding.ActivityListBinding
|
|
import ani.dantotsu.media.user.ListViewPagerAdapter
|
|
import com.google.android.material.tabs.TabLayout
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.withContext
|
|
|
|
class CalendarActivity : AppCompatActivity() {
|
|
private lateinit var binding: ActivityListBinding
|
|
private val scope = lifecycleScope
|
|
private var selectedTabIdx = 1
|
|
private val model: OtherDetailsViewModel by viewModels()
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
binding = ActivityListBinding.inflate(layoutInflater)
|
|
setContentView(binding.root)
|
|
|
|
window.statusBarColor = ContextCompat.getColor(this, R.color.nav_bg)
|
|
binding.listTitle.setText(R.string.release_calendar)
|
|
binding.listSort.visibility = View.GONE
|
|
|
|
binding.listTabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
|
override fun onTabSelected(tab: TabLayout.Tab?) {
|
|
this@CalendarActivity.selectedTabIdx = tab?.position ?: 1
|
|
}
|
|
override fun onTabUnselected(tab: TabLayout.Tab?) { }
|
|
override fun onTabReselected(tab: TabLayout.Tab?) { }
|
|
})
|
|
|
|
model.getCalendar().observe(this) {
|
|
if (it != null) {
|
|
binding.listProgressBar.visibility = View.GONE
|
|
binding.listViewPager.adapter = ListViewPagerAdapter(it.size, true,this)
|
|
val keys = it.keys.toList()
|
|
val values = it.values.toList()
|
|
val savedTab = this.selectedTabIdx
|
|
TabLayoutMediator(binding.listTabLayout, binding.listViewPager) { tab, position ->
|
|
tab.text = "${keys[position]} (${values[position].size})"
|
|
}.attach()
|
|
binding.listViewPager.setCurrentItem(savedTab, false)
|
|
}
|
|
}
|
|
|
|
val live = Refresh.activity.getOrPut(this.hashCode()) { MutableLiveData(true) }
|
|
live.observe(this) {
|
|
if (it) {
|
|
scope.launch {
|
|
withContext(Dispatchers.IO) { model.loadCalendar() }
|
|
live.postValue(false)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |