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
applicationId "code.name.monkey.retromusic"
versionCode 336
versionName '3.2.100'
versionCode 337
versionName '3.2.101'
multiDexEnabled true

View file

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

View file

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

View file

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

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_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)

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_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)

View file

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

View file

@ -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">
<LinearLayout
android:layout_width="match_parent"

View file

@ -47,7 +47,7 @@
<code.name.monkey.retromusic.views.IconImageView
android:layout_width="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
android:id="@+id/emptyText"

View file

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
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
android:defaultValue="true"
android:key="colored_notification"
android:summary="@string/pref_summary_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" />
</androidx.preference.PreferenceScreen>