From e26310dbc78204899b51ed1836800d5ecbc3ebb3 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Wed, 20 May 2020 15:44:49 +0530 Subject: [PATCH] Code refactor --- .../retromusic/activities/AboutActivity.kt | 8 ++----- .../activities/GenreDetailsActivity.kt | 4 ++-- .../activities/LockScreenActivity.kt | 2 +- .../retromusic/extensions/ActivityEx.kt | 10 +++++++++ .../monkey/retromusic/extensions/ColorExt.kt | 21 ++++++++++++------- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/AboutActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/AboutActivity.kt index 6f51e696..045597d9 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/AboutActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/AboutActivity.kt @@ -9,8 +9,6 @@ import android.view.View import androidx.core.app.ShareCompat import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager -import code.name.monkey.appthemehelper.util.ATHUtil -import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.App import code.name.monkey.retromusic.Constants.APP_INSTAGRAM_LINK import code.name.monkey.retromusic.Constants.APP_TELEGRAM_LINK @@ -24,6 +22,7 @@ import code.name.monkey.retromusic.Constants.TRANSLATE import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsBaseActivity import code.name.monkey.retromusic.adapter.ContributorAdapter +import code.name.monkey.retromusic.extensions.applyToolbar import code.name.monkey.retromusic.model.Contributor import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil @@ -67,10 +66,7 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener { setNavigationbarColorAuto() setLightNavigationBar(true) - val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface) - toolbar.setBackgroundColor(toolbarColor) - ToolbarContentTintHelper.colorBackButton(toolbar) - setSupportActionBar(toolbar) + applyToolbar(toolbar) version.setSummary(getAppVersion()) setUpView() loadContributors() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt index 97ecbcc9..809fbaae 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt @@ -12,6 +12,7 @@ import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter +import code.name.monkey.retromusic.extensions.applyToolbar import code.name.monkey.retromusic.helper.menu.GenreMenuHelper import code.name.monkey.retromusic.interfaces.CabHolder import code.name.monkey.retromusic.model.Genre @@ -75,8 +76,7 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), CabHolder, GenreDet } private fun setUpToolBar() { - toolbar.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorSurface)) - setSupportActionBar(toolbar) + applyToolbar(toolbar) title = genre.name } diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt index 0d4dd018..8520f8c1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt @@ -25,6 +25,7 @@ class LockScreenActivity : AbsMusicServiceActivity() { private var fragment: LockScreenPlayerControlsFragment? = null override fun onCreate(savedInstanceState: Bundle?) { + setDrawUnderStatusBar() super.onCreate(savedInstanceState) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { setShowWhenLocked(true) @@ -36,7 +37,6 @@ class LockScreenActivity : AbsMusicServiceActivity() { WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON ) } - setDrawUnderStatusBar() setContentView(R.layout.activity_lock_screen) hideStatusBar() setStatusbarColorAuto() diff --git a/app/src/main/java/code/name/monkey/retromusic/extensions/ActivityEx.kt b/app/src/main/java/code/name/monkey/retromusic/extensions/ActivityEx.kt index 81265b42..e896bddb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/extensions/ActivityEx.kt +++ b/app/src/main/java/code/name/monkey/retromusic/extensions/ActivityEx.kt @@ -14,3 +14,13 @@ package code.name.monkey.retromusic.extensions +import androidx.appcompat.app.AppCompatActivity +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import com.google.android.material.appbar.MaterialToolbar + +fun AppCompatActivity.applyToolbar(toolbar: MaterialToolbar) { + toolbar.setBackgroundColor(surfaceColor()) + ToolbarContentTintHelper.colorBackButton(toolbar) + setSupportActionBar(toolbar) +} + diff --git a/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt b/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt index 29fb16cc..b22359c3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt +++ b/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt @@ -18,6 +18,7 @@ import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import androidx.appcompat.widget.Toolbar +import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.retromusic.R @@ -26,8 +27,12 @@ fun Int.ripAlpha(): Int { return ColorUtil.stripAlpha(this) } -fun Any.surfaceColor(context: Context): Int { - return ATHUtil.resolveColor(context, R.attr.colorSurface, Color.WHITE) +fun Context.accentColor(): Int { + return ThemeStore.accentColor(this) +} + +fun Context.surfaceColor(): Int { + return ATHUtil.resolveColor(this, R.attr.colorSurface, Color.WHITE) } fun Toolbar.backgroundTintList() { @@ -36,14 +41,14 @@ fun Toolbar.backgroundTintList() { backgroundTintList = colorStateList } -fun textColorSecondary(context: Context): Int { - return ATHUtil.resolveColor(context, android.R.attr.textColorSecondary) +fun Context.textColorSecondary(): Int { + return ATHUtil.resolveColor(this, android.R.attr.textColorSecondary) } -fun colorControlNormal(context: Context): Int { - return ATHUtil.resolveColor(context, android.R.attr.colorControlNormal) +fun Context.colorControlNormal(): Int { + return ATHUtil.resolveColor(this, android.R.attr.colorControlNormal) } -fun textColorPrimary(context: Context): Int { - return ATHUtil.resolveColor(context, android.R.attr.textColorPrimary) +fun Context.textColorPrimary(): Int { + return ATHUtil.resolveColor(this, android.R.attr.textColorPrimary) } \ No newline at end of file