From 147b8b5292ab46a6debf5969974b7bf75bda1c00 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Mon, 5 Aug 2019 21:43:44 +0530 Subject: [PATCH] Tiny player update --- .../activities/AlbumDetailsActivity.kt | 27 ++++++++++--------- .../fragments/base/AbsPlayerFragment.kt | 2 +- .../blur/BlurPlaybackControlsFragment.kt | 15 +++-------- .../tiny/TinyPlaybackControlsFragment.kt | 27 ++++++++++++------- .../player/tiny/TinyPlayerFragment.kt | 10 ++++--- .../fragments/settings/AbsSettingsFragment.kt | 6 ++--- .../fragments/settings/AudioSettings.kt | 4 +-- .../settings/ImageSettingFragment.kt | 4 +-- .../settings/MainSettingsFragment.kt | 12 +++------ .../settings/NotificationSettingsFragment.kt | 3 ++- .../settings/ThemeSettingsFragment.kt | 10 +++---- .../retromusic/helper/MusicPlayerRemote.kt | 14 ++++++---- .../drawable/progress_drawable_vertical.xml | 6 ++--- app/src/main/res/layout/fragment_library.xml | 9 ++++--- .../main/res/layout/fragment_tiny_player.xml | 3 ++- .../util/ToolbarContentTintHelper.java | 9 ++++--- 16 files changed, 84 insertions(+), 77 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt index 6b276273..191ca116 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt @@ -14,7 +14,10 @@ import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import code.name.monkey.appthemehelper.ThemeStore -import code.name.monkey.appthemehelper.util.* +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.appthemehelper.util.MaterialUtil +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity import code.name.monkey.retromusic.activities.tageditor.AbsTagEditorActivity @@ -38,9 +41,7 @@ import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.RetroUtil import com.google.android.material.appbar.AppBarLayout -import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.activity_album.* import kotlinx.android.synthetic.main.activity_album_content.* import java.util.* @@ -71,12 +72,12 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac setupWindowTransition() super.onCreate(savedInstanceState) toggleBottomNavigationView(true) - contentContainer?.setCardBackgroundColor( ColorStateList.valueOf(ThemeStore.primaryColor(this))) setLightNavigationBar(true) setNavigationbarColorAuto() - ActivityCompat.postponeEnterTransition(this) + contentContainer?.setCardBackgroundColor(ColorStateList.valueOf(ThemeStore.primaryColor(this))) + ActivityCompat.postponeEnterTransition(this) artistImage = findViewById(R.id.artistImage) @@ -116,19 +117,19 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac val primaryColor = ThemeStore.primaryColor(this) //TintHelper.setTintAuto(contentContainer!!, primaryColor, true) - if (collapsingToolbarLayout != null) { - collapsingToolbarLayout!!.apply { - setContentScrimColor(primaryColor) - setStatusBarScrimColor(ColorUtil.darkenColor(primaryColor)) - } + + collapsingToolbarLayout?.let { + it.setContentScrimColor(primaryColor) + it.setStatusBarScrimColor(ColorUtil.darkenColor(primaryColor)) } + toolbar.setNavigationIcon(R.drawable.ic_keyboard_backspace_black_24dp) if (toolbar != null && !PreferenceUtil.getInstance().fullScreenMode) { - val params = toolbar!!.layoutParams as ViewGroup.MarginLayoutParams + val params = toolbar.layoutParams as ViewGroup.MarginLayoutParams params.topMargin = RetroUtil.getStatusBarHeight() - toolbar!!.layoutParams = params + toolbar.layoutParams = params } appBarLayout?.apply { @@ -253,6 +254,8 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac MaterialUtil.setTint(button = shuffleAction, color = buttonColor) MaterialUtil.setTint(button = playAction, color = buttonColor) + + ToolbarContentTintHelper.setToolbarContentColorBasedOnToolbarColor(this@AlbumDetailsActivity, toolbar, color) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt index 8c272d01..90d2a7f4 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt @@ -256,7 +256,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(), playerAlbumCoverFragment?.setCallbacks(this) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - statusBarShadow.hide() + statusBarShadow?.hide() } interface Callbacks { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt index 0e7d36c7..62c9a411 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt @@ -25,7 +25,6 @@ import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil -import code.name.monkey.retromusic.util.PreferenceUtil import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.* class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { @@ -113,17 +112,11 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { updateShuffleState() updatePrevNextColor() + text.setTextColor(lastDisabledPlaybackControlsColor) - val colorFinal = if (PreferenceUtil.getInstance().adaptiveColor) { - color - } else { - ThemeStore.textColorSecondary(requireContext()) - } - - text.setTextColor(colorFinal) - TintHelper.setTintAuto(progressSlider, colorFinal.ripAlpha(), false) - volumeFragment?.setTintableColor(Color.WHITE) - setFabColor(colorFinal.ripAlpha()) + TintHelper.setTintAuto(progressSlider, lastPlaybackControlsColor , false) + volumeFragment?.setTintableColor(lastPlaybackControlsColor) + setFabColor(lastPlaybackControlsColor) } private fun setFabColor(i: Int) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt index 09043a6e..f8cf8e0e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt @@ -5,12 +5,11 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import code.name.monkey.appthemehelper.util.ColorUtil -import code.name.monkey.appthemehelper.util.MaterialValueHelper +import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.service.MusicService -import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import kotlinx.android.synthetic.main.fragment_tiny_controls_fragment.* class TinyPlaybackControlsFragment : AbsPlayerControlsFragment() { @@ -28,13 +27,9 @@ class TinyPlaybackControlsFragment : AbsPlayerControlsFragment() { } override fun setDark(color: Int) { - if (ColorUtil.isColorLight(color)) { - lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(getActivity(), true); - lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(getActivity(), true); - } else { - lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(getActivity(), false); - lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(getActivity(), false); - } + + lastPlaybackControlsColor = ThemeStore.textColorPrimary(requireContext()) + lastDisabledPlaybackControlsColor = ThemeStore.textColorSecondary(requireContext()) updateRepeatState(); updateShuffleState(); @@ -94,4 +89,16 @@ class TinyPlaybackControlsFragment : AbsPlayerControlsFragment() { } } + override fun onServiceConnected() { + updateRepeatState() + updateShuffleState() + } + + override fun onRepeatModeChanged() { + updateRepeatState() + } + + override fun onShuffleModeChanged() { + updateShuffleState() + } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt index 170abcb4..41de5162 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt @@ -59,7 +59,7 @@ class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca } override fun toolbarIconColor(): Int { - return MaterialValueHelper.getSecondaryTextColor(context, ColorUtil.isColorLight(lastColor)) + return ThemeStore.textColorSecondary(requireContext()) } private var lastColor: Int = 0 @@ -67,18 +67,20 @@ class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca get() = lastColor override fun onColorChanged(color: Int) { + val lastColor = if (PreferenceUtil.getInstance().adaptiveColor) { color } else { - ThemeStore.accentColor(context!!) + ThemeStore.accentColor(requireContext()) } callbacks?.onPaletteColorChanged() + tinyPlaybackControlsFragment.setDark(lastColor) TintHelper.setTintAuto(progressBar, lastColor, false) - val iconColor = MaterialValueHelper.getSecondaryTextColor(context, ColorUtil.isColorLight(lastColor)) - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, iconColor, activity) + val iconColor = ThemeStore.textColorSecondary(requireContext()) + ToolbarContentTintHelper.colorizeToolbar(playerToolbar, iconColor, requireActivity()) } override fun onFavoriteToggled() { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AbsSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AbsSettingsFragment.kt index bd74ae9c..8af78efb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AbsSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AbsSettingsFragment.kt @@ -35,8 +35,8 @@ import code.name.monkey.retromusic.util.NavigationUtil abstract class AbsSettingsFragment : PreferenceFragmentCompat() { internal fun showProToastAndNavigate(message: String) { - Toast.makeText(context, "$message is Pro version feature.", Toast.LENGTH_SHORT).show() - NavigationUtil.goToProVersion(activity!!) + Toast.makeText(requireContext(), "$message is Pro version feature.", Toast.LENGTH_SHORT).show() + NavigationUtil.goToProVersion(requireActivity()) } internal fun setSummary(preference: Preference, value: Any) { @@ -60,7 +60,7 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setDivider(ColorDrawable(Color.TRANSPARENT)) - listView.setBackgroundColor(ThemeStore.primaryColor(context!!)) + listView.setBackgroundColor(ThemeStore.primaryColor(requireContext())) listView.overScrollMode = View.OVER_SCROLL_NEVER listView.setPadding(0, 0, 0, 0) listView.setPaddingRelative(0, 0, 0, 0) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AudioSettings.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AudioSettings.kt index 50ed5ede..a947409c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AudioSettings.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/AudioSettings.kt @@ -36,7 +36,7 @@ class AudioSettings : AbsSettingsFragment() { findPreference.isEnabled = true } findPreference.setOnPreferenceClickListener { - NavigationUtil.openEqualizer(activity!!) + NavigationUtil.openEqualizer(requireActivity()) true } } @@ -44,7 +44,7 @@ class AudioSettings : AbsSettingsFragment() { private fun hasEqualizer(): Boolean { val effects = Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL) - val pm = activity!!.packageManager + val pm = requireActivity().packageManager val ri = pm.resolveActivity(effects, 0) return ri != null } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ImageSettingFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ImageSettingFragment.kt index de616d86..2f60f1ba 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ImageSettingFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ImageSettingFragment.kt @@ -40,7 +40,7 @@ class ImageSettingFragment : AbsSettingsFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val preference: Preference = findPreference("auto_download_images_policy")!! - setSummary(preference) + val preference: Preference? = findPreference("auto_download_images_policy") + preference?.let { setSummary(it) } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/MainSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/MainSettingsFragment.kt index bb61c777..890a8681 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/MainSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/MainSettingsFragment.kt @@ -48,8 +48,6 @@ class MainSettingsFragment : Fragment(), View.OnClickListener { } } - private val settingsIcons = arrayOf(R.id.general_settings_icon, R.id.audio_settings_icon, R.id.now_playing_settings_icon, R.id.personalize_settings_icon, R.id.image_settings_icon, R.id.notification_settings_icon, R.id.other_settings_icon) - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_main_settings, container, false) @@ -74,20 +72,16 @@ class MainSettingsFragment : Fragment(), View.OnClickListener { } } buyPremium.setOnClickListener { - NavigationUtil.goToProVersion(context!!) + NavigationUtil.goToProVersion(requireContext()) } MaterialUtil.setTint(buyPremium) - val primaryColor = MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(ThemeStore.primaryColor(context!!))) + val primaryColor = MaterialValueHelper.getPrimaryTextColor(requireContext(), ColorUtil.isColorLight(ThemeStore.primaryColor(requireContext()))) text.setTextColor(ColorUtil.withAlpha(primaryColor, 0.75f)) - //title.setTextColor(primaryColor) text2.setTextColor(primaryColor) text3.imageTintList = ColorStateList.valueOf(primaryColor) - } private fun inflateFragment(fragment: Fragment, @StringRes title: Int) { - if (activity != null) { - (activity as SettingsActivity).setupFragment(fragment, title) - } + (requireActivity() as SettingsActivity).setupFragment(fragment, title) } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/NotificationSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/NotificationSettingsFragment.kt index aa99347c..866b26f0 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/NotificationSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/NotificationSettingsFragment.kt @@ -18,6 +18,7 @@ import android.os.Build.VERSION import android.os.Build.VERSION_CODES import android.os.Bundle import androidx.preference.TwoStatePreference +import code.name.monkey.retromusic.R import code.name.monkey.retromusic.util.PreferenceUtil @@ -58,6 +59,6 @@ class NotificationSettingsFragment : AbsSettingsFragment() { } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(code.name.monkey.retromusic.R.xml.pref_notification) + addPreferencesFromResource(R.xml.pref_notification) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ThemeSettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ThemeSettingsFragment.kt index f2a63ea4..5ca12af8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ThemeSettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/ThemeSettingsFragment.kt @@ -70,7 +70,7 @@ class ThemeSettingsFragment : AbsSettingsFragment() { else PreferenceUtil.getThemeResFromPrefValue("dark") - ThemeStore.editTheme(context).activityTheme(theme).primaryColor(color).commit() + ThemeStore.editTheme(requireContext()).activityTheme(theme).primaryColor(color).commit() if (VersionUtils.hasNougatMR()) DynamicShortcutManager(context).updateDynamicShortcuts() @@ -107,10 +107,10 @@ class ThemeSettingsFragment : AbsSettingsFragment() { .commit() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { - activity?.setTheme(PreferenceUtil.getThemeResFromPrefValue(theme)) + requireActivity().setTheme(PreferenceUtil.getThemeResFromPrefValue(theme)) DynamicShortcutManager(requireContext()).updateDynamicShortcuts() } - activity?.recreate() + requireActivity().recreate() true } } @@ -128,9 +128,9 @@ class ThemeSettingsFragment : AbsSettingsFragment() { if (!ColorUtil.isColorSaturated(color)) { colorFinal = color }*/ - ThemeStore.editTheme(context).accentColor(color).commit() + ThemeStore.editTheme(requireContext()).accentColor(color).commit() if (VersionUtils.hasNougatMR()) - DynamicShortcutManager(context).updateDynamicShortcuts() + DynamicShortcutManager(requireContext()).updateDynamicShortcuts() requireActivity().recreate() } } diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt b/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt index b0c0a51b..a2ea4e1c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt @@ -26,6 +26,7 @@ import android.provider.DocumentsContract import android.provider.MediaStore import android.util.Log import android.widget.Toast +import androidx.core.content.ContextCompat import code.name.monkey.retromusic.loaders.SongLoader import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.service.MusicService @@ -108,9 +109,12 @@ object MusicPlayerRemote { } val contextWrapper = ContextWrapper(realActivity) - - contextWrapper.startService(Intent(contextWrapper, MusicService::class.java)) - + val intent = Intent(contextWrapper, MusicService::class.java) + try { + contextWrapper.startService(intent) + } catch (ignored: IllegalStateException) { + ContextCompat.startForegroundService(context, intent) + } val binder = ServiceBinder(callback) if (contextWrapper.bindService(Intent().setClass(contextWrapper, MusicService::class.java), binder, Context.BIND_AUTO_CREATE)) { @@ -140,8 +144,8 @@ object MusicPlayerRemote { try { cursor = context.contentResolver.query(uri, projection, null, null, null) if (cursor != null && cursor.moveToFirst()) { - val column_index = cursor.getColumnIndexOrThrow(column) - return cursor.getString(column_index) + val columnIndex = cursor.getColumnIndexOrThrow(column) + return cursor.getString(columnIndex) } } catch (e: Exception) { Log.e(TAG, e.message) diff --git a/app/src/main/res/drawable/progress_drawable_vertical.xml b/app/src/main/res/drawable/progress_drawable_vertical.xml index 7416c591..8898220f 100644 --- a/app/src/main/res/drawable/progress_drawable_vertical.xml +++ b/app/src/main/res/drawable/progress_drawable_vertical.xml @@ -10,10 +10,8 @@ android:clipOrientation="vertical" android:gravity="bottom"> - + diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index 7fc5b06d..9fe96532 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -33,13 +33,13 @@ android:id="@+id/toolbarContainer" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" app:cardCornerRadius="8dp" app:cardElevation="0dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - app:strokeColor="?dividerColor" app:cardUseCompatPadding="true" app:layout_scrollFlags="scroll|enterAlways" + app:strokeColor="?dividerColor" app:strokeWidth="1dp"> + android:background="?colorPrimary" />