Code Cleanup

main
Prathamesh More 2021-10-25 20:51:40 +05:30
parent aca697f6ff
commit db01ce6ee8
15 changed files with 32 additions and 115 deletions

View File

@ -20,10 +20,8 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
import code.name.monkey.retromusic.util.PreferenceUtil
import com.anjlab.android.iab.v3.BillingProcessor
import com.anjlab.android.iab.v3.TransactionDetails
import com.google.android.material.color.DynamicColors
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
@ -47,10 +45,6 @@ class App : Application() {
.commit()
}
if (PreferenceUtil.materialYou) {
DynamicColors.applyToActivitiesIfAvailable(this)
}
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(this).initDynamicShortcuts()

View File

@ -30,7 +30,6 @@ import androidx.annotation.StringDef
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.MaterialUtil
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
@ -89,8 +88,6 @@ open class BugReportActivity : AbsThemeActivity() {
private fun initViews() {
val accentColor = ThemeStore.accentColor(this)
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorSurface)
binding.toolbar.setBackgroundColor(primaryColor)
setSupportActionBar(binding.toolbar)
ToolbarContentTintHelper.colorBackButton(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)

View File

@ -21,7 +21,6 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.findFragment
import androidx.navigation.findNavController
@ -31,7 +30,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.*
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
@ -192,11 +190,7 @@ class HomeAdapter(
)
fun bindView(home: Home) {
val color = if (PreferenceUtil.materialYou && VersionUtils.hasS()) {
ContextCompat.getColor(App.getContext(), R.color.m3_accent_color)
} else {
ThemeStore.accentColor(activity)
}
val color = ThemeStore.accentColor(activity)
itemView.findViewById<TextView>(R.id.message).apply {
setTextColor(color)
setOnClickListener {

View File

@ -24,7 +24,6 @@ import android.view.ViewGroup.MarginLayoutParams
import android.view.ViewTreeObserver
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.FrameLayout
import androidx.annotation.LayoutRes
import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart
@ -34,7 +33,6 @@ import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.RetroUtil
import com.afollestad.materialdialogs.utils.MDUtil.updatePadding
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.imageview.ShapeableImageView
import com.google.android.material.shape.ShapeAppearanceModel

View File

@ -20,30 +20,27 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.MenuItem.SHOW_AS_ACTION_IF_ROOM
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.view.doOnPreDraw
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.*
import code.name.monkey.retromusic.adapter.HomeAdapter
import code.name.monkey.retromusic.databinding.FragmentBannerHomeBinding
import code.name.monkey.retromusic.databinding.FragmentHomeBinding
import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog
import code.name.monkey.retromusic.dialogs.ImportPlaylistDialog
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.drawNextToNavbar
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.glide.RetroGlideExtension
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.gms.cast.framework.CastButtonFactory
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.transition.MaterialSharedAxis
@ -144,12 +141,7 @@ class HomeFragment :
MaterialSharedAxis(MaterialSharedAxis.Z, false)
findNavController().navigate(R.id.searchFragment, null, navOptions)
}
val color = if (PreferenceUtil.materialYou && VersionUtils.hasS()) {
ContextCompat.getColor(App.getContext(), R.color.m3_accent_color)
} else {
ThemeStore.accentColor(requireContext())
}
val hexColor = String.format("#%06X", 0xFFFFFF and color)
val hexColor = String.format("#%06X", 0xFFFFFF and accentColor())
val appName = HtmlCompat.fromHtml(
"Retro <span style='color:$hexColor';>Music</span>",
HtmlCompat.FROM_HTML_MODE_COMPACT

View File

@ -23,7 +23,6 @@ import androidx.fragment.app.FragmentActivity
import androidx.navigation.fragment.findNavController
import androidx.transition.Fade
import androidx.viewpager2.adapter.FragmentStateAdapter
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.MainActivity
@ -118,7 +117,7 @@ class LyricsFragment : AbsMusicServiceFragment(R.layout.fragment_lyrics) {
}.attach()
// lyricsPager.isUserInputEnabled = false
binding.tabLyrics.setSelectedTabIndicatorColor(ThemeStore.accentColor(requireContext()))
binding.tabLyrics.setSelectedTabIndicatorColor(accentColor())
binding.tabLyrics.setTabTextColors(textColorSecondary(), accentColor())
}
@ -326,10 +325,10 @@ class LyricsFragment : AbsMusicServiceFragment(R.layout.fragment_lyrics) {
private fun setupLyricsView() {
binding.lyricsView.apply {
setCurrentColor(ThemeStore.accentColor(context))
setTimeTextColor(ThemeStore.accentColor(context))
setTimelineColor(ThemeStore.accentColor(context))
setTimelineTextColor(ThemeStore.accentColor(context))
setCurrentColor(accentColor())
setTimeTextColor(accentColor())
setTimelineColor(accentColor())
setTimelineTextColor(accentColor())
setDraggable(true, LrcView.OnPlayClickListener {
MusicPlayerRemote.seekTo(it.toInt())
return@OnPlayClickListener true

View File

@ -1,10 +1,8 @@
package code.name.monkey.retromusic.glide
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.App.Companion.getContext
import code.name.monkey.retromusic.Constants.USER_BANNER
import code.name.monkey.retromusic.Constants.USER_PROFILE
@ -19,7 +17,6 @@ import code.name.monkey.retromusic.util.CustomArtistImageUtil.Companion.getFile
import code.name.monkey.retromusic.util.CustomArtistImageUtil.Companion.getInstance
import code.name.monkey.retromusic.util.MusicUtil.getMediaStoreAlbumCoverUri
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.PreferenceUtil.materialYou
import com.bumptech.glide.GenericTransitionOptions
import com.bumptech.glide.Priority
import com.bumptech.glide.RequestBuilder
@ -185,11 +182,7 @@ object RetroGlideExtension {
return TintHelper.createTintedDrawable(
getContext(),
R.drawable.ic_account,
if (materialYou && VersionUtils.hasS()) {
ContextCompat.getColor(getContext(), R.color.m3_accent_color)
} else {
accentColor(getContext())
}
accentColor(getContext())
)
}

View File

@ -18,7 +18,6 @@ import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor
import code.name.monkey.appthemehelper.util.ColorUtil.isColorLight
import code.name.monkey.appthemehelper.util.MaterialValueHelper.getPrimaryTextColor
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.views.PopupBackground
import me.zhanghai.android.fastscroll.FastScroller
import me.zhanghai.android.fastscroll.FastScrollerBuilder
@ -28,11 +27,7 @@ import me.zhanghai.android.fastscroll.R
object ThemedFastScroller {
fun create(view: ViewGroup): FastScroller {
val context = view.context
val color = if (PreferenceUtil.materialYou && VersionUtils.hasS()) {
context.getColor(code.name.monkey.retromusic.R.color.m3_accent_color)
} else {
accentColor(context)
}
val color = accentColor(context)
val textColor = getPrimaryTextColor(context, isColorLight(color))
val fastScrollerBuilder = FastScrollerBuilder(view)
fastScrollerBuilder.useMd2Style()

View File

@ -4,13 +4,7 @@ import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.util.PreferenceUtil
class AccentIcon @JvmOverloads constructor(
context: Context,
@ -18,11 +12,6 @@ class AccentIcon @JvmOverloads constructor(
defStyleAttr: Int = -1
) : AppCompatImageView(context, attrs, defStyleAttr) {
init {
val color = if (PreferenceUtil.materialYou && VersionUtils.hasS()) {
ContextCompat.getColor(context, R.color.m3_accent_color)
} else {
ThemeStore.accentColor(context)
}
imageTintList = ColorStateList.valueOf(color)
imageTintList = ColorStateList.valueOf(ThemeStore.accentColor(context))
}
}

View File

@ -19,6 +19,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:fitsSystemWindows="true"
android:orientation="vertical">
<LinearLayout
@ -122,32 +123,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/mainContent" />
<LinearLayout
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:elevation="0dp"
app:elevation="0dp">
<code.name.monkey.retromusic.views.StatusBarView
android:id="@+id/status_bar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?attr/colorSurface"
tools:ignore="UnusedAttribute" />
<com.google.android.material.appbar.AppBarLayout
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:elevation="0dp"
app:elevation="0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_keyboard_backspace_black"
app:title="@string/social_stories"
app:titleTextAppearance="@style/ToolbarTextAppearanceNormal" />
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
app:navigationIcon="@drawable/ic_keyboard_backspace_black"
app:title="@string/social_stories"
app:titleTextAppearance="@style/ToolbarTextAppearanceNormal" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -10,6 +10,7 @@ import androidx.preference.PreferenceManager
import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark
import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.VersionUtils
/**
@ -205,6 +206,10 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
@CheckResult
@ColorInt
fun accentColor(context: Context): Int {
// Set MD3 accent if MD3 is enabled or in-app accent otherwise
if (isMD3Enabled(context) && VersionUtils.hasS()) {
return ContextCompat.getColor(context, R.color.m3_accent_color)
}
val desaturatedColor = prefs(context).getBoolean("desaturated_color", false)
val color = prefs(context).getInt(
ThemeStorePrefKeys.KEY_ACCENT_COLOR,
@ -301,7 +306,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
return true
}
fun isMD3Enabled(context: Context): Boolean {
private fun isMD3Enabled(context: Context): Boolean {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ThemeStorePrefKeys.KEY_MATERIAL_YOU, false)
}
}

View File

@ -17,12 +17,9 @@ package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.content.Context
import android.util.AttributeSet
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceViewHolder
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
class ATEPreferenceCategory @JvmOverloads constructor(
context: Context?,
@ -35,12 +32,7 @@ class ATEPreferenceCategory @JvmOverloads constructor(
super.onBindViewHolder(holder)
val title = holder.itemView.findViewById<TextView>(android.R.id.title)
title.setTextColor(
// Set MD3 accent if MD3 is enabled or in-app accent otherwise
if (ThemeStore.isMD3Enabled(context) && VersionUtils.hasS()) {
ContextCompat.getColor(context, R.color.m3_accent_color)
} else {
ThemeStore.accentColor(context)
}
ThemeStore.accentColor(context)
)
}
}

View File

@ -47,11 +47,7 @@ class ATESeekBarPreference @JvmOverloads constructor(
val seekBar = view.findViewById(R.id.seekbar) as SeekBar
TintHelper.setTintAuto(
seekBar, // Set MD3 accent if MD3 is enabled or in-app accent otherwise
if (ThemeStore.isMD3Enabled(context) && VersionUtils.hasS()) {
ContextCompat.getColor(context, R.color.m3_accent_color)
} else {
ThemeStore.accentColor(context)
}, false
ThemeStore.accentColor(context), false
)
(view.findViewById(R.id.seekbar_value) as TextView).apply {
appendUnit(editableText)

View File

@ -17,10 +17,7 @@ package code.name.monkey.appthemehelper.common.views
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
class ATEAccentTextView @JvmOverloads constructor(
context: Context,
@ -31,11 +28,7 @@ class ATEAccentTextView @JvmOverloads constructor(
init {
setTextColor(
// Set MD3 accent if MD3 is enabled or in-app accent otherwise
if (ThemeStore.isMD3Enabled(context) && VersionUtils.hasS()) {
ContextCompat.getColor(context, R.color.m3_accent_color)
} else {
ThemeStore.accentColor(context)
}
ThemeStore.accentColor(context)
)
}
}

View File

@ -3,12 +3,9 @@ package code.name.monkey.appthemehelper.common.views
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
/**
* @author Aidan Follestad (afollestad)
@ -32,11 +29,7 @@ class ATESwitch : SwitchCompat {
}
private fun init(context: Context) {
if (ThemeStore.isMD3Enabled(context) && VersionUtils.hasS()) {
ATH.setTint(this, ContextCompat.getColor(context, R.color.m3_accent_color))
} else {
ATH.setTint(this, ThemeStore.accentColor(context))
}
ATH.setTint(this, ThemeStore.accentColor(context))
}
override fun isShown(): Boolean {