Dantotsu/app/src/main/java/ani/dantotsu/media/CalendarActivity.kt
Wai What eee1242964
Added Saikou theme (#40)
* Update colors.xml

* Update themes.xml

* Update themes.xml

* Update ThemeManager.kt

* Update ThemeManager.kt

* Update ThemeManager.kt

* Update ThemeManager.kt

* Update DevelopersDialogFragment.kt

* Update activity_main.xml

* Update item_anime_page.xml

* Update item_manga_page.xml

* Update fragment_login.xml

* Update activity_media.xml

* Update activity_media.xml

* Update item_anime_page.xml

* Update item_manga_page.xml

* Update themes.xml

* Update themes.xml

* Update exo_player_control_view.xml

* Update activity_author.xml

* Update activity_studio.xml

* Update activity_manga_reader.xml

* Update activity_novel_reader.xml

* Update activity_media.xml

Fix

* Update tab_layout_icon.xml

* Update activity_media.xml

* Update activity_media.xml

* Update tab_layout_icon.xml

Changed selected layout icon from primary to secondary

* Update activity_list.xml

* Update ListActivity.kt

Unbound listTabLayout, listAppBar and listTitle because it stopped color reallocation

* Update CalendarActivity.kt

Unbound listTabLayout, listAppBar and listTitle because it stopped color reallocation

* Update button_switch_track.xml

* Update CalendarActivity.kt

Undo

* Update ListActivity.kt

Undo

* Update CalendarActivity.kt

* Update ListActivity.kt

* Update ListActivity.kt

* Update CalendarActivity.kt (Saikou theme complete!)

I'll just need to check for bugs and request to merge

* Update ThemeManager.kt

Took Sakiou theme out of beta

* Update tab_layout_icon.xml

Changes to media tabs (less accurate to Saikou but selected menu is more vibrant and supports other themes better)

* Update activity_media.xml

Changes to media tabs (less accurate to Saikou but selected menu is more vibrant and supports other themes better)

* Update activity_media.xml

Changes to media tabs (less accurate to Saikou but selected menu is more vibrant and supports other themes better)

* Update control_background_40dp.xml

* Update build.gradle

Changed version number
2023-11-12 12:55:16 -06:00

109 lines
4.5 KiB
Kotlin

package ani.dantotsu.media
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.TypedValue
import android.view.View
import android.view.Window
import android.view.WindowManager
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.loadData
import ani.dantotsu.media.user.ListViewPagerAdapter
import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.themes.ThemeManager
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)
ThemeManager(this).applyTheme()
binding = ActivityListBinding.inflate(layoutInflater)
val typedValue = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true)
val primaryColor = typedValue.data
val typedValue2 = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorOnBackground, typedValue2, true)
val titleTextColor = typedValue2.data
val typedValue3 = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorPrimary, typedValue3, true)
val primaryTextColor = typedValue3.data
val typedValue4 = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorOutline, typedValue4, true)
val secondaryTextColor = typedValue4.data
window.statusBarColor = primaryColor
window.navigationBarColor = primaryColor
binding.listTabLayout.setBackgroundColor(primaryColor)
binding.listAppBar.setBackgroundColor(primaryColor)
binding.listTitle.setTextColor(titleTextColor)
binding.listTabLayout.setTabTextColors(secondaryTextColor, primaryTextColor)
binding.listTabLayout.setSelectedTabIndicatorColor(primaryTextColor)
val uiSettings = loadData<UserInterfaceSettings>("ui_settings") ?: UserInterfaceSettings()
if (!uiSettings.immersiveMode) {
this.window.statusBarColor =
ContextCompat.getColor(this, R.color.nav_bg_inv)
binding.root.fitsSystemWindows = true
}else{
binding.root.fitsSystemWindows = false
requestWindowFeature(Window.FEATURE_NO_TITLE)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
setContentView(binding.root)
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)
}
}
}
}
}