chore: cleanup pt 3

This commit is contained in:
aayush262 2024-04-30 00:26:30 +05:30
parent ea48809d07
commit 0a0da65f7c
26 changed files with 99 additions and 243 deletions

View file

@ -67,9 +67,12 @@ import android.widget.FrameLayout
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getSystemService import androidx.core.content.ContextCompat.getSystemService
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.core.math.MathUtils.clamp import androidx.core.math.MathUtils.clamp
@ -339,14 +342,7 @@ open class BottomSheetDialogFragment : BottomSheetDialogFragment() {
val behavior = BottomSheetBehavior.from(requireView().parent as View) val behavior = BottomSheetBehavior.from(requireView().parent as View)
behavior.state = BottomSheetBehavior.STATE_EXPANDED behavior.state = BottomSheetBehavior.STATE_EXPANDED
} }
val typedValue = TypedValue() window.navigationBarColor = requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface)
val theme = requireContext().theme
theme.resolveAttribute(
com.google.android.material.R.attr.colorSurface,
typedValue,
true
)
window.navigationBarColor = typedValue.data
} }
} }
@ -1383,7 +1379,11 @@ fun blurImage(imageView: ImageView, banner: String?) {
imageView.setImageResource(R.drawable.linear_gradient_bg) imageView.setImageResource(R.drawable.linear_gradient_bg)
} }
} }
fun Context.getThemeColor(@AttrRes attribute: Int): Int {
val typedValue = TypedValue()
theme.resolveAttribute(attribute, typedValue, true)
return typedValue.data
}
/** /**
* Builds the markwon instance with all the plugins * Builds the markwon instance with all the plugins
* @return the markwon instance * @return the markwon instance

View file

@ -6,7 +6,6 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -37,6 +36,7 @@ import ani.dantotsu.download.DownloadedType
import ani.dantotsu.download.DownloadsManager import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.download.DownloadsManager.Companion.compareName import ani.dantotsu.download.DownloadsManager.Companion.compareName
import ani.dantotsu.download.findValidName import ani.dantotsu.download.findValidName
import ani.dantotsu.getThemeColor
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
@ -91,9 +91,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
textInputLayout.boxBackgroundColor = semiTransparentColor textInputLayout.boxBackgroundColor = semiTransparentColor
val materialCardView = view.findViewById<MaterialCardView>(R.id.offlineMangaAvatarContainer) val materialCardView = view.findViewById<MaterialCardView>(R.id.offlineMangaAvatarContainer)
materialCardView.setCardBackgroundColor(semiTransparentColor) materialCardView.setCardBackgroundColor(semiTransparentColor)
val typedValue = TypedValue() val color = requireContext().getThemeColor(android.R.attr.windowBackground)
requireContext().theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data
val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar) val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar)
animeUserAvatar.setSafeOnClickListener { animeUserAvatar.setSafeOnClickListener {

View file

@ -5,7 +5,6 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -35,6 +34,7 @@ import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.download.DownloadsManager.Companion.compareName import ani.dantotsu.download.DownloadsManager.Companion.compareName
import ani.dantotsu.download.DownloadsManager.Companion.getSubDirectory import ani.dantotsu.download.DownloadsManager.Companion.getSubDirectory
import ani.dantotsu.download.findValidName import ani.dantotsu.download.findValidName
import ani.dantotsu.getThemeColor
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
@ -85,9 +85,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
textInputLayout.boxBackgroundColor = semiTransparentColor textInputLayout.boxBackgroundColor = semiTransparentColor
val materialCardView = view.findViewById<MaterialCardView>(R.id.offlineMangaAvatarContainer) val materialCardView = view.findViewById<MaterialCardView>(R.id.offlineMangaAvatarContainer)
materialCardView.setCardBackgroundColor(semiTransparentColor) materialCardView.setCardBackgroundColor(semiTransparentColor)
val typedValue = TypedValue() val color = requireContext().getThemeColor(android.R.attr.windowBackground)
requireContext().theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data
val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar) val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar)
animeUserAvatar.setSafeOnClickListener { animeUserAvatar.setSafeOnClickListener {

View file

@ -3,7 +3,6 @@ package ani.dantotsu.home
import android.content.Intent import android.content.Intent
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.util.TypedValue
import android.view.HapticFeedbackConstants import android.view.HapticFeedbackConstants
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -24,6 +23,7 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.currContext import ani.dantotsu.currContext
import ani.dantotsu.databinding.ItemAnimePageBinding import ani.dantotsu.databinding.ItemAnimePageBinding
import ani.dantotsu.databinding.LayoutTrendingBinding import ani.dantotsu.databinding.LayoutTrendingBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.media.CalendarActivity import ani.dantotsu.media.CalendarActivity
import ani.dantotsu.media.GenreActivity import ani.dantotsu.media.GenreActivity
@ -67,10 +67,7 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
val materialCardView = val materialCardView =
holder.itemView.findViewById<MaterialCardView>(R.id.userAvatarContainer) holder.itemView.findViewById<MaterialCardView>(R.id.userAvatarContainer)
materialCardView.setCardBackgroundColor(semiTransparentColor) materialCardView.setCardBackgroundColor(semiTransparentColor)
val typedValue = TypedValue() val color = binding.root.context.getThemeColor(android.R.attr.windowBackground)
currContext()?.theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000 textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000) materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000)

View file

@ -3,7 +3,6 @@ package ani.dantotsu.home
import android.content.Intent import android.content.Intent
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.util.TypedValue
import android.view.HapticFeedbackConstants import android.view.HapticFeedbackConstants
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -21,9 +20,9 @@ import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.MediaPageTransformer import ani.dantotsu.MediaPageTransformer
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.currContext
import ani.dantotsu.databinding.ItemMangaPageBinding import ani.dantotsu.databinding.ItemMangaPageBinding
import ani.dantotsu.databinding.LayoutTrendingBinding import ani.dantotsu.databinding.LayoutTrendingBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.media.GenreActivity import ani.dantotsu.media.GenreActivity
import ani.dantotsu.media.MediaAdaptor import ani.dantotsu.media.MediaAdaptor
@ -66,10 +65,7 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
val materialCardView = val materialCardView =
holder.itemView.findViewById<MaterialCardView>(R.id.userAvatarContainer) holder.itemView.findViewById<MaterialCardView>(R.id.userAvatarContainer)
materialCardView.setCardBackgroundColor(semiTransparentColor) materialCardView.setCardBackgroundColor(semiTransparentColor)
val typedValue = TypedValue() val color = binding.root.context.getThemeColor(android.R.attr.windowBackground)
currContext()?.theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000 textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000) materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000)

View file

@ -7,8 +7,8 @@ import android.graphics.Color
import android.graphics.Paint import android.graphics.Paint
import android.graphics.Path import android.graphics.Path
import android.util.AttributeSet import android.util.AttributeSet
import android.util.TypedValue
import android.view.View import android.view.View
import ani.dantotsu.getThemeColor
class CircleView(context: Context, attrs: AttributeSet?) : View(context, attrs) { class CircleView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
private var parts: Int = 3 private var parts: Int = 3
@ -30,12 +30,11 @@ class CircleView(context: Context, attrs: AttributeSet?) : View(context, attrs)
val totalGapAngle = gapAngle * (parts) val totalGapAngle = gapAngle * (parts)
val totalAngle = 360f - totalGapAngle val totalAngle = 360f - totalGapAngle
val typedValue = TypedValue()
context.theme.resolveAttribute(com.google.android.material.R.attr.colorPrimary, typedValue, true)
val primaryColor = typedValue.data val primaryColor = context.getThemeColor(com.google.android.material.R.attr.colorPrimary)
val typedValue1 = TypedValue() val secondColor = context.getThemeColor(com.google.android.material.R.attr.colorOnPrimary)
context.theme.resolveAttribute(com.google.android.material.R.attr.colorOnPrimary, typedValue1, true)
val secondColor = typedValue1.data
fun setColor(int: Int) { fun setColor(int: Int) {
paint.color = if (int < booleanList.size && booleanList[int]) { paint.color = if (int < booleanList.size && booleanList[int]) {
Color.GRAY Color.GRAY
@ -46,7 +45,6 @@ class CircleView(context: Context, attrs: AttributeSet?) : View(context, attrs)
} }
if (parts == 1) { if (parts == 1) {
// Draw a single arc covering the entire circle
path.addArc( path.addArc(
centerX - radius, centerX - radius,
centerY - radius, centerY - radius,

View file

@ -7,16 +7,11 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.util.AttributeSet import android.util.AttributeSet
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -27,6 +22,7 @@ import ani.dantotsu.buildMarkwon
import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.api.Activity import ani.dantotsu.connections.anilist.api.Activity
import ani.dantotsu.databinding.FragmentStatusBinding import ani.dantotsu.databinding.FragmentStatusBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.home.status.listener.StoriesCallback import ani.dantotsu.home.status.listener.StoriesCallback
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
@ -70,12 +66,9 @@ constructor(
val inflater: LayoutInflater = LayoutInflater.from(context) val inflater: LayoutInflater = LayoutInflater.from(context)
binding = FragmentStatusBinding.inflate(inflater, this, false) binding = FragmentStatusBinding.inflate(inflater, this, false)
addView(binding.root) addView(binding.root)
val typedValue = TypedValue()
val typedValue1 = TypedValue() primaryColor = context.getThemeColor(com.google.android.material.R.attr.colorPrimary)
context.theme.resolveAttribute(com.google.android.material.R.attr.colorPrimary, typedValue, true) onPrimaryColor = context.getThemeColor(com.google.android.material.R.attr.colorOnPrimary)
context.theme.resolveAttribute(com.google.android.material.R.attr.colorOnPrimary, typedValue1, true)
primaryColor = typedValue.data
onPrimaryColor = typedValue1.data
if (context is StoriesCallback) if (context is StoriesCallback)
storiesListener = context as StoriesCallback storiesListener = context as StoriesCallback

View file

@ -1,5 +1,6 @@
package ani.dantotsu.home.status package ani.dantotsu.home.status
import android.content.Context
import android.content.Intent import android.content.Intent
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup

View file

@ -1,7 +1,6 @@
package ani.dantotsu.media package ani.dantotsu.media
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.view.Window import android.view.Window
@ -14,6 +13,7 @@ import androidx.lifecycle.lifecycleScope
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.Refresh import ani.dantotsu.Refresh
import ani.dantotsu.databinding.ActivityListBinding import ani.dantotsu.databinding.ActivityListBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.hideSystemBarsExtendView import ani.dantotsu.hideSystemBarsExtendView
import ani.dantotsu.media.user.ListViewPagerAdapter import ani.dantotsu.media.user.ListViewPagerAdapter
import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.settings.saving.PrefManager
@ -39,15 +39,10 @@ class CalendarActivity : AppCompatActivity() {
binding = ActivityListBinding.inflate(layoutInflater) binding = ActivityListBinding.inflate(layoutInflater)
val typedValue = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true) val primaryColor = getThemeColor(com.google.android.material.R.attr.colorSurface)
val primaryColor = typedValue.data val primaryTextColor = getThemeColor(com.google.android.material.R.attr.colorPrimary)
val typedValue3 = TypedValue() val secondaryTextColor = getThemeColor(com.google.android.material.R.attr.colorOutline)
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.statusBarColor = primaryColor
window.navigationBarColor = primaryColor window.navigationBarColor = primaryColor

View file

@ -6,7 +6,6 @@ import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.util.TypedValue
import android.view.GestureDetector import android.view.GestureDetector
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
@ -38,6 +37,7 @@ import ani.dantotsu.blurImage
import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.copyToClipboard import ani.dantotsu.copyToClipboard
import ani.dantotsu.databinding.ActivityMediaBinding import ani.dantotsu.databinding.ActivityMediaBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.media.anime.AnimeWatchFragment import ani.dantotsu.media.anime.AnimeWatchFragment
@ -250,22 +250,12 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
@SuppressLint("ResourceType") @SuppressLint("ResourceType")
fun total() { fun total() {
val text = SpannableStringBuilder().apply { val text = SpannableStringBuilder().apply {
val mediaTypedValue = TypedValue()
this@MediaDetailsActivity.theme.resolveAttribute( val white = this@MediaDetailsActivity.getThemeColor(com.google.android.material.R.attr.colorOnBackground)
com.google.android.material.R.attr.colorOnBackground,
mediaTypedValue,
true
)
val white = mediaTypedValue.data
if (media.userStatus != null) { if (media.userStatus != null) {
append(if (media.anime != null) getString(R.string.watched_num) else getString(R.string.read_num)) append(if (media.anime != null) getString(R.string.watched_num) else getString(R.string.read_num))
val typedValue = TypedValue() val colorSecondary = getThemeColor(com.google.android.material.R.attr.colorSecondary)
theme.resolveAttribute( bold { color(colorSecondary) { append("${media.userProgress}") } }
com.google.android.material.R.attr.colorSecondary,
typedValue,
true
)
bold { color(typedValue.data) { append("${media.userProgress}") } }
append( append(
if (media.anime != null) getString(R.string.episodes_out_of) else getString( if (media.anime != null) getString(R.string.episodes_out_of) else getString(
R.string.chapters_out_of R.string.chapters_out_of

View file

@ -577,14 +577,14 @@ class MediaInfoFragment : Fragment() {
if (Anilist.token != null && media.userStatus != null) { if (Anilist.token != null && media.userStatus != null) {
users.add(0, users.add(0,
User( User(
Anilist.userid!!, id = Anilist.userid!!,
Anilist.username!!, name = getString(R.string.your_progress),
Anilist.avatar, pfp = Anilist.avatar,
Anilist.bg, banner = "",
status = media.userStatus, status = media.userStatus,
score = media.userScore.toFloat(), score = media.userScore.toFloat(),
progress = media.userProgress, progress = media.userProgress,
totalEpisodes = if (type == "ANIME") media.anime?.totalEpisodes else media.manga?.totalChapters, totalEpisodes = media.anime?.totalEpisodes ?: media.manga?.totalChapters,
nextAiringEpisode = media.anime?.nextAiringEpisode nextAiringEpisode = media.anime?.nextAiringEpisode
) )
) )

View file

@ -10,7 +10,6 @@ import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -34,6 +33,7 @@ import ani.dantotsu.databinding.ItemStreamBinding
import ani.dantotsu.databinding.ItemUrlBinding import ani.dantotsu.databinding.ItemUrlBinding
import ani.dantotsu.download.DownloadedType import ani.dantotsu.download.DownloadedType
import ani.dantotsu.download.video.Helper import ani.dantotsu.download.video.Helper
import ani.dantotsu.getThemeColor
import ani.dantotsu.hideSystemBars import ani.dantotsu.hideSystemBars
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaDetailsViewModel import ani.dantotsu.media.MediaDetailsViewModel
@ -95,10 +95,7 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
_binding = BottomSheetSelectorBinding.inflate(inflater, container, false) _binding = BottomSheetSelectorBinding.inflate(inflater, container, false)
val window = dialog?.window val window = dialog?.window
window?.statusBarColor = Color.TRANSPARENT window?.statusBarColor = Color.TRANSPARENT
val typedValue = TypedValue() window?.navigationBarColor = requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface)
val theme = requireContext().theme
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true)
window?.navigationBarColor = typedValue.data
return binding.root return binding.root
} }

View file

@ -1,7 +1,6 @@
package ani.dantotsu.media.manga package ani.dantotsu.media.manga
import android.app.AlertDialog import android.app.AlertDialog
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -145,8 +144,6 @@ class MangaChapterAdapter(
inner class ChapterListViewHolder(val binding: ItemChapterListBinding) : inner class ChapterListViewHolder(val binding: ItemChapterListBinding) :
RecyclerView.ViewHolder(binding.root) { RecyclerView.ViewHolder(binding.root) {
private val activeCoroutines = mutableSetOf<String>() private val activeCoroutines = mutableSetOf<String>()
private val typedValue1 = TypedValue()
private val typedValue2 = TypedValue()
fun bind(chapterNumber: String, progress: String?) { fun bind(chapterNumber: String, progress: String?) {
if (progress != null) { if (progress != null) {
binding.itemChapterTitle.visibility = View.VISIBLE binding.itemChapterTitle.visibility = View.VISIBLE
@ -201,17 +198,6 @@ class MangaChapterAdapter(
} }
init { init {
val theme = currContext()?.theme
theme?.resolveAttribute(
com.google.android.material.R.attr.colorError,
typedValue1,
true
)
theme?.resolveAttribute(
com.google.android.material.R.attr.colorPrimary,
typedValue2,
true
)
itemView.setOnClickListener { itemView.setOnClickListener {
if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size) if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size)
fragment.onMangaChapterClick(arr[bindingAdapterPosition].number) fragment.onMangaChapterClick(arr[bindingAdapterPosition].number)

View file

@ -3,7 +3,6 @@ package ani.dantotsu.media.manga.mangareader
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -14,6 +13,7 @@ import ani.dantotsu.BottomSheetDialogFragment
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.currActivity import ani.dantotsu.currActivity
import ani.dantotsu.databinding.BottomSheetSelectorBinding import ani.dantotsu.databinding.BottomSheetSelectorBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.media.MediaDetailsViewModel import ani.dantotsu.media.MediaDetailsViewModel
import ani.dantotsu.media.MediaSingleton import ani.dantotsu.media.MediaSingleton
import ani.dantotsu.media.manga.MangaChapter import ani.dantotsu.media.manga.MangaChapter
@ -78,10 +78,7 @@ class ChapterLoaderDialog : BottomSheetDialogFragment() {
_binding = BottomSheetSelectorBinding.inflate(inflater, container, false) _binding = BottomSheetSelectorBinding.inflate(inflater, container, false)
val window = dialog?.window val window = dialog?.window
window?.statusBarColor = Color.TRANSPARENT window?.statusBarColor = Color.TRANSPARENT
val typedValue = TypedValue() window?.navigationBarColor = requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface)
val theme = requireContext().theme
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true)
window?.navigationBarColor = typedValue.data
return binding.root return binding.root
} }

View file

@ -1,6 +1,5 @@
package ani.dantotsu.media.novel package ani.dantotsu.media.novel
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -8,6 +7,7 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.databinding.ItemNovelResponseBinding import ani.dantotsu.databinding.ItemNovelResponseBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.parsers.ShowResponse import ani.dantotsu.parsers.ShowResponse
import ani.dantotsu.setAnimation import ani.dantotsu.setAnimation
@ -40,14 +40,7 @@ class NovelResponseAdapter(
setAnimation(fragment.requireContext(), holder.binding.root) setAnimation(fragment.requireContext(), holder.binding.root)
binding.itemEpisodeImage.loadImage(novel.coverUrl, 400, 0) binding.itemEpisodeImage.loadImage(novel.coverUrl, 400, 0)
val typedValue = TypedValue() val color =fragment.requireContext().getThemeColor(com.google.android.material.R.attr.colorOnBackground)
fragment.requireContext().theme?.resolveAttribute(
com.google.android.material.R.attr.colorOnBackground,
typedValue,
true
)
val color = typedValue.data
binding.itemEpisodeTitle.text = novel.name binding.itemEpisodeTitle.text = novel.name
binding.itemEpisodeFiller.text = binding.itemEpisodeFiller.text =
if (downloadedCheckCallback.downloadedCheck(novel)) { if (downloadedCheckCallback.downloadedCheck(novel)) {

View file

@ -1,7 +1,6 @@
package ani.dantotsu.media.user package ani.dantotsu.media.user
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.view.Window import android.view.Window
@ -15,6 +14,7 @@ import androidx.lifecycle.lifecycleScope
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.Refresh import ani.dantotsu.Refresh
import ani.dantotsu.databinding.ActivityListBinding import ani.dantotsu.databinding.ActivityListBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.hideSystemBarsExtendView import ani.dantotsu.hideSystemBarsExtendView
import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.settings.saving.PrefName
@ -37,15 +37,9 @@ class ListActivity : AppCompatActivity() {
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityListBinding.inflate(layoutInflater) binding = ActivityListBinding.inflate(layoutInflater)
val typedValue = TypedValue() val primaryColor = getThemeColor(com.google.android.material.R.attr.colorSurface)
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true) val primaryTextColor = getThemeColor(com.google.android.material.R.attr.colorPrimary)
val primaryColor = typedValue.data val secondaryTextColor = getThemeColor(com.google.android.material.R.attr.colorOutline)
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.statusBarColor = primaryColor
window.navigationBarColor = primaryColor window.navigationBarColor = primaryColor

View file

@ -2,7 +2,7 @@ package ani.dantotsu.profile
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.util.TypedValue import ani.dantotsu.getThemeColor
import ani.dantotsu.util.ColorEditor import ani.dantotsu.util.ColorEditor
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartModel import com.github.aachartmodel.aainfographics.aachartcreator.AAChartModel
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartStackingType import com.github.aachartmodel.aainfographics.aachartcreator.AAChartStackingType
@ -53,13 +53,7 @@ class ChartBuilder {
scrollPos: Float? = null, scrollPos: Float? = null,
normalize: Boolean = false normalize: Boolean = false
): AAOptions { ): AAOptions {
val typedValue = TypedValue() val primaryColor = context.getThemeColor(com.google.android.material.R.attr.colorPrimary)
context.theme.resolveAttribute(
com.google.android.material.R.attr.colorPrimary,
typedValue,
true
)
val primaryColor = typedValue.data
var chartType = passedChartType var chartType = passedChartType
var aaChartType = passedAaChartType var aaChartType = passedAaChartType
var categories = passedCategories var categories = passedCategories
@ -309,31 +303,21 @@ class ChartBuilder {
} }
private fun setColors(aaOptions: AAOptions, context: Context) { private fun setColors(aaOptions: AAOptions, context: Context) {
val backgroundColor = TypedValue() val backgroundColor = context.getThemeColor(com.google.android.material.R.attr.colorSurfaceVariant)
context.theme.resolveAttribute(
com.google.android.material.R.attr.colorSurfaceVariant,
backgroundColor,
true
)
val backgroundStyle = AAStyle().color( val backgroundStyle = AAStyle().color(
AAColor.rgbaColor( AAColor.rgbaColor(
Color.red(backgroundColor.data), Color.red(backgroundColor),
Color.green(backgroundColor.data), Color.green(backgroundColor),
Color.blue(backgroundColor.data), Color.blue(backgroundColor),
1f 1f
) )
) )
val colorOnBackground = TypedValue() val colorOnBackground = context.getThemeColor(com.google.android.material.R.attr.colorOnSurface)
context.theme.resolveAttribute(
com.google.android.material.R.attr.colorOnSurface,
colorOnBackground,
true
)
val onBackgroundStyle = AAStyle().color( val onBackgroundStyle = AAStyle().color(
AAColor.rgbaColor( AAColor.rgbaColor(
Color.red(colorOnBackground.data), Color.red(colorOnBackground),
Color.green(colorOnBackground.data), Color.green(colorOnBackground),
Color.blue(colorOnBackground.data), Color.blue(colorOnBackground),
1.0f 1.0f
) )
) )
@ -342,9 +326,9 @@ class ChartBuilder {
aaOptions.chart?.backgroundColor(backgroundStyle.color) aaOptions.chart?.backgroundColor(backgroundStyle.color)
aaOptions.tooltip?.backgroundColor( aaOptions.tooltip?.backgroundColor(
AAColor.rgbaColor( AAColor.rgbaColor(
Color.red(backgroundColor.data), Color.red(backgroundColor),
Color.green(backgroundColor.data), Color.green(backgroundColor),
Color.blue(backgroundColor.data), Color.blue(backgroundColor),
1.0f 1.0f
) )
) )

View file

@ -2,9 +2,9 @@ package ani.dantotsu.profile
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import ani.dantotsu.databinding.ActivitySingleStatBinding import ani.dantotsu.databinding.ActivitySingleStatBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.toast import ani.dantotsu.toast
@ -20,9 +20,7 @@ class SingleStatActivity : AppCompatActivity() {
setContentView(binding.root) setContentView(binding.root)
val chartOptions = chartOptions val chartOptions = chartOptions
if (chartOptions != null) { if (chartOptions != null) {
val typedvalue = TypedValue() chartOptions.chart?.backgroundColor = getThemeColor(android.R.attr.windowBackground)
theme.resolveAttribute(android.R.attr.windowBackground, typedvalue, true)
chartOptions.chart?.backgroundColor = typedvalue.data
binding.chartView.aa_drawChartWithChartOptions(chartOptions) binding.chartView.aa_drawChartWithChartOptions(chartOptions)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
} else { } else {

View file

@ -203,6 +203,7 @@ class SettingsAddonActivity : AppCompatActivity() {
} }
} }
}, },
isVisible = torrentAddonManager.isAvailable()
) )
) )
) )

View file

@ -2,8 +2,13 @@ package ani.dantotsu.settings.extensionprefs
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.graphics.Typeface
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.preference.DialogPreference import androidx.preference.DialogPreference
@ -11,7 +16,10 @@ import androidx.preference.EditTextPreference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.forEach import androidx.preference.forEach
import androidx.preference.getOnBindEditTextListener import androidx.preference.getOnBindEditTextListener
import ani.dantotsu.R
import ani.dantotsu.getThemeColor
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.themes.ThemeManager
import eu.kanade.tachiyomi.PreferenceScreen import eu.kanade.tachiyomi.PreferenceScreen
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore
@ -29,25 +37,19 @@ class AnimeSourcePreferencesFragment : PreferenceFragmentCompat() {
snackString(e.message ?: "Unknown error") snackString(e.message ?: "Unknown error")
preferenceManager.createPreferenceScreen(requireContext()) preferenceManager.createPreferenceScreen(requireContext())
} }
//set background color
val color = TypedValue()
requireContext().theme.resolveAttribute(
com.google.android.material.R.attr.backgroundColor,
color,
true
)
view?.setBackgroundColor(color.data)
} }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ThemeManager(requireActivity()).applyTheme()
}
private var onCloseAction: (() -> Unit)? = null private var onCloseAction: (() -> Unit)? = null
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
onCloseAction?.invoke() onCloseAction?.invoke()
} }
fun populateAnimePreferenceScreen(): PreferenceScreen { private fun populateAnimePreferenceScreen(): PreferenceScreen {
val sourceId = requireArguments().getLong(SOURCE_ID) val sourceId = requireArguments().getLong(SOURCE_ID)
val source = Injekt.get<AnimeSourceManager>().get(sourceId) as? ConfigurableAnimeSource val source = Injekt.get<AnimeSourceManager>().get(sourceId) as? ConfigurableAnimeSource
?: error("Source with id: $sourceId not found!") ?: error("Source with id: $sourceId not found!")
@ -63,7 +65,6 @@ class AnimeSourcePreferencesFragment : PreferenceFragmentCompat() {
pref.dialogTitle = pref.title pref.dialogTitle = pref.title
} }
// Apply incognito IME for EditTextPreference
if (pref is EditTextPreference) { if (pref is EditTextPreference) {
val setListener = pref.getOnBindEditTextListener() val setListener = pref.getOnBindEditTextListener()
pref.setOnBindEditTextListener { pref.setOnBindEditTextListener {
@ -72,7 +73,6 @@ class AnimeSourcePreferencesFragment : PreferenceFragmentCompat() {
} }
} }
} }
return sourceScreen return sourceScreen
} }
@ -104,13 +104,8 @@ class InitialAnimeSourcePreferencesFragment(
preferenceManager.createPreferenceScreen(requireContext()) preferenceManager.createPreferenceScreen(requireContext())
} }
//set background color //set background color
val color = TypedValue() val color = requireContext().getThemeColor(com.google.android.material.R.attr.backgroundColor,)
requireContext().theme.resolveAttribute( view?.setBackgroundColor(color)
com.google.android.material.R.attr.backgroundColor,
color,
true
)
view?.setBackgroundColor(color.data)
} }

View file

@ -6,11 +6,11 @@ import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.databinding.StatisticsWidgetConfigureBinding import ani.dantotsu.databinding.StatisticsWidgetConfigureBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import eltos.simpledialogfragment.SimpleDialog import eltos.simpledialogfragment.SimpleDialog
@ -174,29 +174,10 @@ class ProfileStatsConfigure : AppCompatActivity(),
} }
private fun themeColors() { private fun themeColors() {
val typedValueSurface = TypedValue()
theme.resolveAttribute(
com.google.android.material.R.attr.colorSurface,
typedValueSurface,
true
)
val backgroundColor = typedValueSurface.data
val typedValuePrimary = TypedValue() val backgroundColor = getThemeColor(com.google.android.material.R.attr.colorSurface)
theme.resolveAttribute( val textColor = getThemeColor(com.google.android.material.R.attr.colorPrimary)
com.google.android.material.R.attr.colorPrimary, val subTextColor = getThemeColor(com.google.android.material.R.attr.colorOutline)
typedValuePrimary,
true
)
val textColor = typedValuePrimary.data
val typedValueOutline = TypedValue()
theme.resolveAttribute(
com.google.android.material.R.attr.colorOutline,
typedValueOutline,
true
)
val subTextColor = typedValueOutline.data
getSharedPreferences( getSharedPreferences(
ProfileStatsWidget.getPrefsName(appWidgetId), ProfileStatsWidget.getPrefsName(appWidgetId),

View file

@ -6,11 +6,11 @@ import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.databinding.UpcomingWidgetConfigureBinding import ani.dantotsu.databinding.UpcomingWidgetConfigureBinding
import ani.dantotsu.getThemeColor
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import eltos.simpledialogfragment.SimpleDialog import eltos.simpledialogfragment.SimpleDialog
@ -157,29 +157,9 @@ class UpcomingWidgetConfigure : AppCompatActivity(),
} }
private fun themeColors() { private fun themeColors() {
val typedValueSurface = TypedValue() val backgroundColor = getThemeColor(com.google.android.material.R.attr.colorSurface)
theme.resolveAttribute( val textColor = getThemeColor(com.google.android.material.R.attr.colorPrimary)
com.google.android.material.R.attr.colorSurface, val subTextColor = getThemeColor(com.google.android.material.R.attr.colorOutline)
typedValueSurface,
true
)
val backgroundColor = typedValueSurface.data
val typedValuePrimary = TypedValue()
theme.resolveAttribute(
com.google.android.material.R.attr.colorPrimary,
typedValuePrimary,
true
)
val textColor = typedValuePrimary.data
val typedValueOutline = TypedValue()
theme.resolveAttribute(
com.google.android.material.R.attr.colorOutline,
typedValueOutline,
true
)
val subTextColor = typedValueOutline.data
getSharedPreferences(UpcomingWidget.PREFS_NAME, Context.MODE_PRIVATE).edit().apply { getSharedPreferences(UpcomingWidget.PREFS_NAME, Context.MODE_PRIVATE).edit().apply {
putInt(UpcomingWidget.PREF_BACKGROUND_COLOR, backgroundColor) putInt(UpcomingWidget.PREF_BACKGROUND_COLOR, backgroundColor)

View file

@ -11,10 +11,8 @@ import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.PowerManager import android.os.PowerManager
import android.util.TypedValue
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.core.content.PermissionChecker import androidx.core.content.PermissionChecker
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.graphics.alpha import androidx.core.graphics.alpha
@ -81,19 +79,7 @@ fun Context.getResourceColor(@AttrRes resource: Int, alphaFactor: Float = 1f): I
return color return color
} }
@ColorInt
fun Context.getThemeColor(attr: Int): Int {
val tv = TypedValue()
return if (this.theme.resolveAttribute(attr, tv, true)) {
if (tv.resourceId != 0) {
ContextCompat.getColor(this, tv.resourceId)
} else {
tv.data
}
} else {
0
}
}
val Context.powerManager: PowerManager val Context.powerManager: PowerManager
get() = getSystemService()!! get() = getSystemService()!!

View file

@ -965,4 +965,6 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
<string name="cover">%1$s\ [Cover]</string> <string name="cover">%1$s\ [Cover]</string>
<string name="banner">%1$s\ [Banner]</string> <string name="banner">%1$s\ [Banner]</string>
<string name="your_story">Your Story</string> <string name="your_story">Your Story</string>
<string name="your_progress">Your Progress</string>
<string name="logout_confirm">Are you sure you want to logout?</string>
</resources> </resources>

View file

@ -80,12 +80,6 @@
<item name="android:textSize">18sp</item> <item name="android:textSize">18sp</item>
</style> </style>
<style name="PreferenceTheme" parent="PreferenceThemeOverlay.v14.Material">
<item name="android:fontFamily">@font/poppins_bold</item>
<item name="android:textColor">?attr/colorPrimary</item>
<item name="android:textSize">16sp</item>
</style>
<style name="BottomNavBar" parent=""> <style name="BottomNavBar" parent="">
<!-- set background color to transparent --> <!-- set background color to transparent -->
<item name="android:background">@android:color/transparent</item> <item name="android:background">@android:color/transparent</item>

View file

@ -11,7 +11,9 @@
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
<item name="android:windowContentTransitions">true</item> <item name="android:windowContentTransitions">true</item>
<item name="android:fontFamily">@font/poppins</item> <item name="android:fontFamily">@font/poppins</item>
<item name="preferenceTheme">@style/PreferenceTheme</item> <item name="android:dialogTheme">@style/MyPopup</item>
<item name="android:alertDialogTheme">@style/MyPopup</item>
<item name="android:alertDialogStyle">@style/MyPopup</item>
<item name="shapeAppearanceLargeComponent">@style/ShapeAppearanceOverlay.Demo</item> <item name="shapeAppearanceLargeComponent">@style/ShapeAppearanceOverlay.Demo</item>
<item name="android:ambientShadowAlpha">0.08</item> <item name="android:ambientShadowAlpha">0.08</item>
<item name="android:spotShadowAlpha">0.08</item> <item name="android:spotShadowAlpha">0.08</item>