From 9c580ad5255baada337735f1386fe902741c2038 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Mon, 16 Dec 2019 10:36:08 +0530 Subject: [PATCH] Fix color backgrounds --- .../retromusic/activities/AboutActivity.kt | 12 +++--- .../activities/LicenseActivity.java | 2 +- .../retromusic/activities/LyricsActivity.kt | 43 ++++++++----------- .../monkey/retromusic/extensions/ColorExt.kt | 8 ++++ app/src/main/res/layout/fragment_lyrics.xml | 1 + app/src/main/res/layout/fragment_synced.xml | 1 + 6 files changed, 34 insertions(+), 33 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 7fa5f979..48ffc3fb 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,6 +9,7 @@ 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.Constants.APP_INSTAGRAM_LINK import code.name.monkey.retromusic.Constants.APP_TELEGRAM_LINK @@ -22,7 +23,6 @@ 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.surfaceColor import code.name.monkey.retromusic.model.Contributor import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil @@ -69,15 +69,13 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener { setLightNavigationBar(true) - loadContributors() + val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface) + toolbar.setBackgroundColor(toolbarColor) + ToolbarContentTintHelper.colorBackButton(toolbar) setSupportActionBar(toolbar) - toolbar.apply { - setBackgroundColor(surfaceColor(context)) - setNavigationOnClickListener { onBackPressed() } - ToolbarContentTintHelper.colorBackButton(toolbar) - } version.setSummary(getAppVersion()) setUpView() + loadContributors() } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java index 00e742ac..d0edccdb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java @@ -79,7 +79,7 @@ public class LicenseActivity extends AbsBaseActivity { // Inject color values for WebView body background and links final boolean isDark = INSTANCE.isWindowBackgroundDark(this); - final String backgroundColor = colorToCSS(INSTANCE.resolveColor(this, android.R.attr.windowBackground, Color.parseColor(isDark ? "#424242" : "#ffffff"))); + final String backgroundColor = colorToCSS(INSTANCE.resolveColor(this, R.attr.colorSurface, Color.parseColor(isDark ? "#424242" : "#ffffff"))); final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000")); final String changeLog = buf.toString() .replace("{style-placeholder}", diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt index 70551114..16ddd66f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt @@ -15,15 +15,11 @@ import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter import androidx.viewpager.widget.ViewPager import code.name.monkey.appthemehelper.ThemeStore -import code.name.monkey.appthemehelper.util.ColorUtil -import code.name.monkey.appthemehelper.util.MaterialUtil -import code.name.monkey.appthemehelper.util.MaterialValueHelper -import code.name.monkey.appthemehelper.util.TintHelper +import code.name.monkey.appthemehelper.util.* import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity import code.name.monkey.retromusic.activities.tageditor.WriteTagsAsyncTask -import code.name.monkey.retromusic.extensions.applyToolbar import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper @@ -52,7 +48,8 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage override fun onPageScrollStateChanged(state: Int) { when (state) { ViewPager.SCROLL_STATE_IDLE -> fab.show() - ViewPager.SCROLL_STATE_DRAGGING, ViewPager.SCROLL_STATE_SETTLING -> fab.hide() + ViewPager.SCROLL_STATE_DRAGGING, + ViewPager.SCROLL_STATE_SETTLING -> fab.hide() } } @@ -91,7 +88,6 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage setTaskDescriptionColorAuto() setNavigationbarColorAuto() - applyToolbar(toolbar) fab.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this)) ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(this, ColorUtil.isColorLight(ThemeStore.accentColor(this)))) .apply { @@ -106,33 +102,30 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage addOnPageChangeListener(this@LyricsActivity) } - tabs.apply { - setupWithViewPager(viewPager) - setSelectedTabIndicator( - TintHelper.createTintedDrawable( - ContextCompat.getDrawable( - this@LyricsActivity, R.drawable.tab_indicator - ), ThemeStore.accentColor(this@LyricsActivity) - ) - ) - setTabTextColors( - ThemeStore.textColorSecondary(this@LyricsActivity), - ThemeStore.accentColor(this@LyricsActivity) - ) - setSelectedTabIndicatorColor(ThemeStore.accentColor(context)) - } + val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface) + toolbar.setBackgroundColor(toolbarColor) + tabs.setBackgroundColor(toolbarColor) + ToolbarContentTintHelper.colorBackButton(toolbar) + + tabs.setupWithViewPager(viewPager) + tabs.setSelectedTabIndicator(TintHelper.createTintedDrawable(ContextCompat.getDrawable(this, R.drawable.tab_indicator), ThemeStore.accentColor(this))) + tabs.setTabTextColors(ATHUtil.resolveColor(this, android.R.attr.textColorSecondary), ThemeStore.accentColor(this)) + tabs.setSelectedTabIndicatorColor(ThemeStore.accentColor(this)) + fab.setOnClickListener(this) } override fun onPlayingMetaChanged() { super.onPlayingMetaChanged() - song = MusicPlayerRemote.currentSong - toolbar.title = song.title - toolbar.subtitle = song.artistName + updateTitleSong() } override fun onServiceConnected() { super.onServiceConnected() + updateTitleSong() + } + + private fun updateTitleSong() { song = MusicPlayerRemote.currentSong toolbar.title = song.title toolbar.subtitle = song.artistName 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 4966d991..87a21374 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 @@ -15,7 +15,9 @@ package code.name.monkey.retromusic.extensions import android.content.Context +import android.content.res.ColorStateList import android.graphics.Color +import androidx.appcompat.widget.Toolbar import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.retromusic.R @@ -26,4 +28,10 @@ fun Int.ripAlpha(): Int { fun Any.surfaceColor(context: Context): Int { return ATHUtil.resolveColor(context, R.attr.colorSurface, Color.WHITE) +} + +fun Toolbar.backgroundTintList() { + val surfaceColor = ATHUtil.resolveColor(context, R.attr.colorSurface, Color.BLACK) + val colorStateList = ColorStateList.valueOf(surfaceColor) + backgroundTintList = colorStateList } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_lyrics.xml b/app/src/main/res/layout/fragment_lyrics.xml index 403ed542..ed10ec1d 100644 --- a/app/src/main/res/layout/fragment_lyrics.xml +++ b/app/src/main/res/layout/fragment_lyrics.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/colorSurface" android:fadingEdge="vertical" app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> diff --git a/app/src/main/res/layout/fragment_synced.xml b/app/src/main/res/layout/fragment_synced.xml index 01637ca0..8ef770ed 100644 --- a/app/src/main/res/layout/fragment_synced.xml +++ b/app/src/main/res/layout/fragment_synced.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/colorSurface" android:orientation="vertical" app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">