Fix color notification toggle

This commit is contained in:
h4h13 2019-06-29 22:45:31 +05:30
parent 3d57688717
commit 425d7caddd
10 changed files with 78 additions and 66 deletions

View file

@ -31,8 +31,8 @@ android {
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
applicationId "code.name.monkey.retromusic" applicationId "code.name.monkey.retromusic"
versionCode 336 versionCode 337
versionName '3.2.100' versionName '3.2.101'
multiDexEnabled true multiDexEnabled true

View file

@ -33,7 +33,7 @@ import code.name.monkey.retromusic.mvp.presenter.HomePresenter
import code.name.monkey.retromusic.util.* import code.name.monkey.retromusic.util.*
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.abs_playlists.* import kotlinx.android.synthetic.main.abs_playlists.*
import kotlinx.android.synthetic.main.fragment_banner_home.* import kotlinx.android.synthetic.main.fragment_banner_home.*
@ -44,7 +44,7 @@ import kotlin.collections.ArrayList
class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeContract.HomeView { class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeContract.HomeView {
private var disposable: Disposable? = null private var disposable: CompositeDisposable = CompositeDisposable()
private lateinit var homePresenter: HomePresenter private lateinit var homePresenter: HomePresenter
private lateinit var toolbar: Toolbar private lateinit var toolbar: Toolbar
@ -53,10 +53,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
} }
private fun loadImageFromStorage() { private fun loadImageFromStorage() {
if (disposable != null) { disposable.add(Compressor(context!!)
disposable?.dispose()
}
disposable = Compressor(context!!)
.setMaxHeight(300) .setMaxHeight(300)
.setMaxWidth(300) .setMaxWidth(300)
.setQuality(75) .setQuality(75)
@ -72,7 +69,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
} }
}) { }) {
userImage.setImageDrawable(ContextCompat.getDrawable(context!!, R.drawable.ic_person_flat)) userImage.setImageDrawable(ContextCompat.getDrawable(context!!, R.drawable.ic_person_flat))
} })
} }
private val displayMetrics: DisplayMetrics private val displayMetrics: DisplayMetrics
@ -173,7 +170,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
disposable?.dispose() disposable.dispose()
homePresenter.unsubscribe() homePresenter.unsubscribe()
} }
@ -264,13 +261,13 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
.diskCacheStrategy(DiskCacheStrategy.ALL) .diskCacheStrategy(DiskCacheStrategy.ALL)
.into(bannerImage!!) .into(bannerImage!!)
} else { } else {
disposable = Compressor(context!!) disposable.add(Compressor(context!!)
.setQuality(100) .setQuality(100)
.setCompressFormat(Bitmap.CompressFormat.WEBP) .setCompressFormat(Bitmap.CompressFormat.WEBP)
.compressToBitmapAsFlowable(File(PreferenceUtil.getInstance().bannerImage, USER_BANNER)) .compressToBitmapAsFlowable(File(PreferenceUtil.getInstance().bannerImage, USER_BANNER))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { bannerImage?.setImageBitmap(it) } .subscribe { bitmap -> bannerImage.setImageBitmap(bitmap) })
} }
} }
loadImageFromStorage() loadImageFromStorage()

View file

@ -33,18 +33,12 @@ import code.name.monkey.retromusic.util.NavigationUtil
*/ */
abstract class AbsSettingsFragment : PreferenceFragmentCompat() { abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
internal fun showProToastAndNavigate(message: String) { internal fun showProToastAndNavigate(message: String) {
Toast.makeText(context, "$message is Pro version feature.", Toast.LENGTH_SHORT).show() Toast.makeText(context, "$message is Pro version feature.", Toast.LENGTH_SHORT).show()
NavigationUtil.goToProVersion(activity!!) NavigationUtil.goToProVersion(activity!!)
} }
protected fun setSummary(preference: Preference) {
setSummary(preference, PreferenceManager
.getDefaultSharedPreferences(preference.context)
.getString(preference.key, "")!!)
}
internal fun setSummary(preference: Preference, value: Any) { internal fun setSummary(preference: Preference, value: Any) {
val stringValue = value.toString() val stringValue = value.toString()
if (preference is ListPreference) { if (preference is ListPreference) {
@ -57,6 +51,12 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
abstract fun invalidateSettings() abstract fun invalidateSettings()
protected fun setSummary(preference: Preference) {
setSummary(preference, PreferenceManager
.getDefaultSharedPreferences(preference.context)
.getString(preference.key, "")!!)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
setDivider(ColorDrawable(Color.TRANSPARENT)) setDivider(ColorDrawable(Color.TRANSPARENT))
@ -68,19 +68,18 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
} }
override fun onDisplayPreferenceDialog(preference: Preference) { override fun onDisplayPreferenceDialog(preference: Preference) {
var dialogFragment: DialogFragment? = null var dialogFragment: DialogFragment? = null// Dialog creation could not be handled here. Try with the super method.
if (preference is NowPlayingScreenPreference) { // The dialog was created (it was one of our custom Preferences), show the dialog for it
dialogFragment = NowPlayingScreenPreferenceDialog.newInstance(preference.key); when (preference) {
} else if (preference is AlbumCoverStylePreference) { is NowPlayingScreenPreference -> dialogFragment = NowPlayingScreenPreferenceDialog.newInstance(preference.key)
dialogFragment = AlbumCoverStylePreferenceDialog.newInstance(preference.key); is AlbumCoverStylePreference -> dialogFragment = AlbumCoverStylePreferenceDialog.newInstance(preference.key)
} is MaterialListPreference -> {
if (preference is MaterialListPreference) {
preference.entries preference.entries
dialogFragment = MaterialListPreferenceDialog.newInstance(preference) dialogFragment = MaterialListPreferenceDialog.newInstance(preference)
} }
if (preference is BlacklistPreference) { is BlacklistPreference -> dialogFragment = BlacklistPreferenceDialog.newInstance(preference.key)
dialogFragment = BlacklistPreferenceDialog.newInstance(preference.key)
} }
if (dialogFragment != null) { if (dialogFragment != null) {
// The dialog was created (it was one of our custom Preferences), show the dialog for it // The dialog was created (it was one of our custom Preferences), show the dialog for it
dialogFragment.setTargetFragment(this, 0); dialogFragment.setTargetFragment(this, 0);
@ -89,6 +88,5 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
// Dialog creation could not be handled here. Try with the super method. // Dialog creation could not be handled here. Try with the super method.
super.onDisplayPreferenceDialog(preference); super.onDisplayPreferenceDialog(preference);
} }
} }
} }

View file

@ -14,40 +14,50 @@
package code.name.monkey.retromusic.fragments.settings 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 android.os.Bundle
import androidx.preference.TwoStatePreference import androidx.preference.TwoStatePreference
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
/** /**
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
*/ */
class NotificationSettingsFragment : AbsSettingsFragment() { class NotificationSettingsFragment : AbsSettingsFragment() {
override fun invalidateSettings() { override fun invalidateSettings() {
val classicNotification: TwoStatePreference = findPreference("classic_notification")!!
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { val classicNotification: TwoStatePreference? = findPreference("classic_notification")
classicNotification.isVisible = false if (VERSION.SDK_INT < VERSION_CODES.N) {
classicNotification?.isVisible = false
} else { } else {
classicNotification.isChecked = PreferenceUtil.getInstance().classicNotification() classicNotification?.apply {
classicNotification.setOnPreferenceChangeListener { _, newValue -> isChecked = PreferenceUtil.getInstance().classicNotification()
setOnPreferenceChangeListener { _, newValue ->
// Save preference // Save preference
PreferenceUtil.getInstance().setClassicNotification(newValue as Boolean) PreferenceUtil.getInstance().setClassicNotification(newValue as Boolean)
invalidateSettings()
val service = MusicPlayerRemote.musicService
if (service != null) {
service.initNotification()
service.updateNotification()
}
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?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_notification) addPreferencesFromResource(code.name.monkey.retromusic.R.xml.pref_notification)
} }
} }

View file

@ -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_SKIP
import code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE import code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE
import code.name.monkey.retromusic.R 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.appwidgets.base.BaseAppWidget.Companion.createBitmap
import code.name.monkey.retromusic.glide.GlideApp import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.glide.RetroGlideExtension import code.name.monkey.retromusic.glide.RetroGlideExtension
import code.name.monkey.retromusic.glide.RetroSimpleTarget import code.name.monkey.retromusic.glide.RetroSimpleTarget
import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper
import code.name.monkey.retromusic.service.MusicService 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.PreferenceUtil
import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.RetroColorUtil
import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.RetroUtil
@ -89,8 +89,7 @@ class PlayingNotificationImpl : PlayingNotification() {
.getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT) .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT)
val deleteIntent = buildPendingIntent(service, ACTION_QUIT, null) val deleteIntent = buildPendingIntent(service, ACTION_QUIT, null)
val notification = NotificationCompat.Builder(service, val notification = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID)
PlayingNotification.NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification)
.setContentIntent(clickIntent) .setContentIntent(clickIntent)
.setDeleteIntent(deleteIntent) .setDeleteIntent(deleteIntent)

View file

@ -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_SKIP
import code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE import code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE
import code.name.monkey.retromusic.R 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.GlideApp
import code.name.monkey.retromusic.glide.RetroGlideExtension import code.name.monkey.retromusic.glide.RetroGlideExtension
import code.name.monkey.retromusic.glide.RetroSimpleTarget import code.name.monkey.retromusic.glide.RetroSimpleTarget
import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.service.MusicService 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.PreferenceUtil
import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.RetroUtil
import code.name.monkey.retromusic.util.RetroUtil.createBitmap import code.name.monkey.retromusic.util.RetroUtil.createBitmap
@ -87,8 +87,7 @@ class PlayingNotificationOreo : PlayingNotification() {
.getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT) .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT)
val deleteIntent = buildPendingIntent(service, ACTION_QUIT, null) val deleteIntent = buildPendingIntent(service, ACTION_QUIT, null)
val builder = NotificationCompat.Builder(service, val builder = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID)
PlayingNotification.NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification)
.setContentIntent(clickIntent) .setContentIntent(clickIntent)
.setDeleteIntent(deleteIntent) .setDeleteIntent(deleteIntent)

View file

@ -304,6 +304,10 @@ public final class PreferenceUtil {
return mPreferences.getBoolean(COLORED_NOTIFICATION, true); return mPreferences.getBoolean(COLORED_NOTIFICATION, true);
} }
public final void setColoredNotification(boolean b) {
mPreferences.edit().putBoolean(COLORED_NOTIFICATION, b).apply();
}
public final boolean classicNotification() { public final boolean classicNotification() {
return mPreferences.getBoolean(CLASSIC_NOTIFICATION, false); return mPreferences.getBoolean(CLASSIC_NOTIFICATION, false);
} }

View file

@ -19,9 +19,14 @@
android:id="@+id/searchContainer" android:id="@+id/searchContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="6dp" app:cardElevation="0dp"
app:cardUseCompatPadding="true"> app:cardUseCompatPadding="true"
app:layout_scrollFlags="scroll|enterAlways"
app:strokeColor="?dividerColor"
app:strokeWidth="1dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -47,7 +47,7 @@
<code.name.monkey.retromusic.views.IconImageView <code.name.monkey.retromusic.views.IconImageView
android:layout_width="96dp" android:layout_width="96dp"
android:layout_height="96dp" android:layout_height="96dp"
app:srcCompat="@drawable/ic_music_note_off_white_24dp" /> app:srcCompat="@drawable/ic_play_arrow_white_64dp" />
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/emptyText" android:id="@+id/emptyText"

View file

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="false"
android:key="classic_notification"
android:summary="@string/pref_summary_classic_notification"
android:title="@string/pref_title_classic_notification"
app:enableCopying="true"
app:icon="@drawable/ic_cellphone_lock_white_24dp" />
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="colored_notification" android:key="colored_notification"
android:summary="@string/pref_summary_colored_notification" android:summary="@string/pref_summary_colored_notification"
android:title="@string/pref_title_colored_notification" android:title="@string/pref_title_colored_notification"
app:enableCopying="true"
app:icon="@drawable/ic_cellphone_lock_white_24dp" />
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="false"
android:key="classic_notification"
android:summary="@string/pref_summary_classic_notification"
android:title="@string/pref_title_classic_notification"
app:enableCopying="true" /> app:enableCopying="true" />
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>