From 425d7caddddab660af3e874db21c4c3eaa06441f Mon Sep 17 00:00:00 2001 From: h4h13 Date: Sat, 29 Jun 2019 22:45:31 +0530 Subject: [PATCH] Fix color notification toggle --- app/build.gradle | 4 +- .../mainactivity/home/BannerHomeFragment.kt | 17 +++---- .../fragments/settings/AbsSettingsFragment.kt | 38 ++++++++-------- .../settings/NotificationSettingsFragment.kt | 44 ++++++++++++------- .../notification/PlayingNotificationImpl.kt | 5 +-- .../notification/PlayingNotificationOreo.kt | 5 +-- .../retromusic/util/PreferenceUtil.java | 4 ++ app/src/main/res/layout/activity_search.xml | 9 +++- app/src/main/res/layout/home_content.xml | 2 +- app/src/main/res/xml/pref_notification.xml | 16 +++---- 10 files changed, 78 insertions(+), 66 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c10da2f6..28a37f74 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { vectorDrawables.useSupportLibrary = true applicationId "code.name.monkey.retromusic" - versionCode 336 - versionName '3.2.100' + versionCode 337 + versionName '3.2.101' multiDexEnabled true diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt index 1622c9b5..024f2e01 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt @@ -33,7 +33,7 @@ import code.name.monkey.retromusic.mvp.presenter.HomePresenter import code.name.monkey.retromusic.util.* import com.bumptech.glide.load.engine.DiskCacheStrategy import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.Disposable +import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.abs_playlists.* import kotlinx.android.synthetic.main.fragment_banner_home.* @@ -44,7 +44,7 @@ import kotlin.collections.ArrayList class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeContract.HomeView { - private var disposable: Disposable? = null + private var disposable: CompositeDisposable = CompositeDisposable() private lateinit var homePresenter: HomePresenter private lateinit var toolbar: Toolbar @@ -53,10 +53,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba } private fun loadImageFromStorage() { - if (disposable != null) { - disposable?.dispose() - } - disposable = Compressor(context!!) + disposable.add(Compressor(context!!) .setMaxHeight(300) .setMaxWidth(300) .setQuality(75) @@ -72,7 +69,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba } }) { userImage.setImageDrawable(ContextCompat.getDrawable(context!!, R.drawable.ic_person_flat)) - } + }) } private val displayMetrics: DisplayMetrics @@ -173,7 +170,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba override fun onDestroyView() { super.onDestroyView() - disposable?.dispose() + disposable.dispose() homePresenter.unsubscribe() } @@ -264,13 +261,13 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba .diskCacheStrategy(DiskCacheStrategy.ALL) .into(bannerImage!!) } else { - disposable = Compressor(context!!) + disposable.add(Compressor(context!!) .setQuality(100) .setCompressFormat(Bitmap.CompressFormat.WEBP) .compressToBitmapAsFlowable(File(PreferenceUtil.getInstance().bannerImage, USER_BANNER)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe { bannerImage?.setImageBitmap(it) } + .subscribe { bitmap -> bannerImage.setImageBitmap(bitmap) }) } } loadImageFromStorage() 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 4e2c15ac..7a9eee1e 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 @@ -33,18 +33,12 @@ 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!!) } - protected fun setSummary(preference: Preference) { - setSummary(preference, PreferenceManager - .getDefaultSharedPreferences(preference.context) - .getString(preference.key, "")!!) - } - internal fun setSummary(preference: Preference, value: Any) { val stringValue = value.toString() if (preference is ListPreference) { @@ -57,6 +51,12 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() { abstract fun invalidateSettings() + protected fun setSummary(preference: Preference) { + setSummary(preference, PreferenceManager + .getDefaultSharedPreferences(preference.context) + .getString(preference.key, "")!!) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setDivider(ColorDrawable(Color.TRANSPARENT)) @@ -68,19 +68,18 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() { } override fun onDisplayPreferenceDialog(preference: Preference) { - var dialogFragment: DialogFragment? = null - if (preference is NowPlayingScreenPreference) { - dialogFragment = NowPlayingScreenPreferenceDialog.newInstance(preference.key); - } else if (preference is AlbumCoverStylePreference) { - dialogFragment = AlbumCoverStylePreferenceDialog.newInstance(preference.key); - } - if (preference is MaterialListPreference) { - preference.entries - dialogFragment = MaterialListPreferenceDialog.newInstance(preference) - } - if (preference is BlacklistPreference) { - dialogFragment = BlacklistPreferenceDialog.newInstance(preference.key) + var dialogFragment: DialogFragment? = null// Dialog creation could not be handled here. Try with the super method. + // The dialog was created (it was one of our custom Preferences), show the dialog for it + when (preference) { + is NowPlayingScreenPreference -> dialogFragment = NowPlayingScreenPreferenceDialog.newInstance(preference.key) + is AlbumCoverStylePreference -> dialogFragment = AlbumCoverStylePreferenceDialog.newInstance(preference.key) + is MaterialListPreference -> { + preference.entries + dialogFragment = MaterialListPreferenceDialog.newInstance(preference) + } + is BlacklistPreference -> dialogFragment = BlacklistPreferenceDialog.newInstance(preference.key) } + if (dialogFragment != null) { // The dialog was created (it was one of our custom Preferences), show the dialog for it dialogFragment.setTargetFragment(this, 0); @@ -89,6 +88,5 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() { // Dialog creation could not be handled here. Try with the super method. super.onDisplayPreferenceDialog(preference); } - } } 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 f2c6f065..aa99347c 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 @@ -14,40 +14,50 @@ package code.name.monkey.retromusic.fragments.settings -import android.os.Build +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.helper.MusicPlayerRemote import code.name.monkey.retromusic.util.PreferenceUtil + /** * @author Hemanth S (h4h13). */ class NotificationSettingsFragment : AbsSettingsFragment() { override fun invalidateSettings() { - val classicNotification: TwoStatePreference = findPreference("classic_notification")!! - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - classicNotification.isVisible = false + + val classicNotification: TwoStatePreference? = findPreference("classic_notification") + if (VERSION.SDK_INT < VERSION_CODES.N) { + classicNotification?.isVisible = false } else { - classicNotification.isChecked = PreferenceUtil.getInstance().classicNotification() - classicNotification.setOnPreferenceChangeListener { _, newValue -> - // Save preference - PreferenceUtil.getInstance().setClassicNotification(newValue as Boolean) - - val service = MusicPlayerRemote.musicService - if (service != null) { - service.initNotification() - service.updateNotification() + classicNotification?.apply { + isChecked = PreferenceUtil.getInstance().classicNotification() + setOnPreferenceChangeListener { _, newValue -> + // Save preference + PreferenceUtil.getInstance().setClassicNotification(newValue as Boolean) + invalidateSettings() + true } + } + } - true + val coloredNotification: TwoStatePreference? = findPreference("colored_notification") + if (VERSION.SDK_INT >= VERSION_CODES.O) { + coloredNotification?.isEnabled = PreferenceUtil.getInstance().classicNotification() + } else { + coloredNotification?.apply { + isChecked = PreferenceUtil.getInstance().coloredNotification() + setOnPreferenceChangeListener { _, newValue -> + PreferenceUtil.getInstance().setColoredNotification(newValue as Boolean) + true + } } } } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.pref_notification) + addPreferencesFromResource(code.name.monkey.retromusic.R.xml.pref_notification) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt index e6d612f8..764c255d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt @@ -33,13 +33,13 @@ import code.name.monkey.retromusic.Constants.ACTION_REWIND import code.name.monkey.retromusic.Constants.ACTION_SKIP import code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.activities.MainActivity import code.name.monkey.retromusic.appwidgets.base.BaseAppWidget.Companion.createBitmap import code.name.monkey.retromusic.glide.GlideApp import code.name.monkey.retromusic.glide.RetroGlideExtension import code.name.monkey.retromusic.glide.RetroSimpleTarget import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper import code.name.monkey.retromusic.service.MusicService -import code.name.monkey.retromusic.activities.MainActivity import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.RetroUtil @@ -89,8 +89,7 @@ class PlayingNotificationImpl : PlayingNotification() { .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT) val deleteIntent = buildPendingIntent(service, ACTION_QUIT, null) - val notification = NotificationCompat.Builder(service, - PlayingNotification.NOTIFICATION_CHANNEL_ID) + val notification = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID) .setSmallIcon(R.drawable.ic_notification) .setContentIntent(clickIntent) .setDeleteIntent(deleteIntent) diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.kt b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.kt index d57f5b44..15c24a5b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.kt @@ -30,13 +30,13 @@ import code.name.monkey.retromusic.Constants.ACTION_REWIND import code.name.monkey.retromusic.Constants.ACTION_SKIP import code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.activities.MainActivity import code.name.monkey.retromusic.glide.GlideApp import code.name.monkey.retromusic.glide.RetroGlideExtension import code.name.monkey.retromusic.glide.RetroSimpleTarget import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.service.MusicService -import code.name.monkey.retromusic.activities.MainActivity import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.RetroUtil.createBitmap @@ -87,8 +87,7 @@ class PlayingNotificationOreo : PlayingNotification() { .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT) val deleteIntent = buildPendingIntent(service, ACTION_QUIT, null) - val builder = NotificationCompat.Builder(service, - PlayingNotification.NOTIFICATION_CHANNEL_ID) + val builder = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID) .setSmallIcon(R.drawable.ic_notification) .setContentIntent(clickIntent) .setDeleteIntent(deleteIntent) diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java index a95e6042..591e0204 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java @@ -304,6 +304,10 @@ public final class PreferenceUtil { return mPreferences.getBoolean(COLORED_NOTIFICATION, true); } + public final void setColoredNotification(boolean b) { + mPreferences.edit().putBoolean(COLORED_NOTIFICATION, b).apply(); + } + public final boolean classicNotification() { return mPreferences.getBoolean(CLASSIC_NOTIFICATION, false); } diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index cb0e1a8a..e1eb1949 100755 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -19,9 +19,14 @@ android:id="@+id/searchContainer" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" app:cardCornerRadius="8dp" - app:cardElevation="6dp" - app:cardUseCompatPadding="true"> + app:cardElevation="0dp" + app:cardUseCompatPadding="true" + app:layout_scrollFlags="scroll|enterAlways" + app:strokeColor="?dividerColor" + app:strokeWidth="1dp"> + app:srcCompat="@drawable/ic_play_arrow_white_64dp" /> + - - + \ No newline at end of file