Code refactor

This commit is contained in:
Hemanth S 2020-05-20 15:44:49 +05:30
parent 0b16b1f5c4
commit e26310dbc7
5 changed files with 28 additions and 17 deletions

View file

@ -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()

View file

@ -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
}

View file

@ -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()

View file

@ -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)
}

View file

@ -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)
}