Fix disable color notificaitons

This commit is contained in:
h4h13 2019-09-29 15:03:41 +05:30
parent 0c5909a05b
commit c64880a0c9
2 changed files with 21 additions and 24 deletions

View file

@ -67,29 +67,6 @@ abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
invalidateSettings() invalidateSettings()
} }
/*override fun onDisplayPreferenceDialog(preference: Preference) {
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 LibraryPreference -> dialogFragment = LibraryPreferenceDialog.newInstance(preference.key)
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()
}
if (dialogFragment != null) {
// The dialog was created (it was one of our custom Preferences), show the dialog for it
dialogFragment.setTargetFragment(this, 0);
dialogFragment.show(this.fragmentManager!!, "android.support.v7.preference.PreferenceFragment.DIALOG");
} else {
// Dialog creation could not be handled here. Try with the super method.
super.onDisplayPreferenceDialog(preference);
}
}*/
override fun onCreatePreferenceDialog(preference: Preference): DialogFragment? { override fun onCreatePreferenceDialog(preference: Preference): DialogFragment? {
return when (preference) { return when (preference) {
is LibraryPreference -> LibraryPreferenceDialog.newInstance(preference.key) is LibraryPreference -> LibraryPreferenceDialog.newInstance(preference.key)

View file

@ -14,9 +14,11 @@
package code.name.monkey.retromusic.fragments.settings package code.name.monkey.retromusic.fragments.settings
import android.content.SharedPreferences
import android.os.Build.VERSION import android.os.Build.VERSION
import android.os.Build.VERSION_CODES import android.os.Build.VERSION_CODES
import android.os.Bundle import android.os.Bundle
import androidx.preference.Preference
import androidx.preference.TwoStatePreference import androidx.preference.TwoStatePreference
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
@ -26,7 +28,15 @@ import code.name.monkey.retromusic.util.PreferenceUtil
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
*/ */
class NotificationSettingsFragment : AbsSettingsFragment() { class NotificationSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
if (key == PreferenceUtil.CLASSIC_NOTIFICATION) {
if (VERSION.SDK_INT >= VERSION_CODES.O) {
findPreference<Preference>("colored_notification")?.isEnabled = sharedPreferences?.getBoolean(key, false)!!
}
}
}
override fun invalidateSettings() { override fun invalidateSettings() {
val classicNotification: TwoStatePreference? = findPreference("classic_notification") val classicNotification: TwoStatePreference? = findPreference("classic_notification")
@ -58,6 +68,16 @@ class NotificationSettingsFragment : AbsSettingsFragment() {
} }
} }
override fun onResume() {
super.onResume()
PreferenceUtil.getInstance(requireContext()).registerOnSharedPreferenceChangedListener(this)
}
override fun onDestroyView() {
super.onDestroyView()
PreferenceUtil.getInstance(requireContext()).unregisterOnSharedPreferenceChangedListener(this)
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_notification) addPreferencesFromResource(R.xml.pref_notification)
} }