Send Intent when Media Store changes. Removed possible memory leak from PreferenceUtil.

This commit is contained in:
Karim Abou Zeid 2015-07-13 04:58:55 +02:00
commit e0a6535f9f
9 changed files with 104 additions and 153 deletions

View file

@ -7,11 +7,9 @@ package com.kabouzeid.gramophone.helper;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
@ -42,17 +40,12 @@ import com.nostra13.universalimageloader.core.process.BitmapProcessor;
public class PlayingNotificationHelper {
public static final String TAG = PlayingNotificationHelper.class.getSimpleName();
public static final int NOTIFICATION_ID = 1337;
public static final String ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED = "com.kabouzeid.gramophone.NOTIFICATION_COLOR_PREFERENCE_CHANGED";
public static final String EXTRA_NOTIFICATION_COLORED = "com.kabouzeid.gramophone.EXTRA_NOTIFICATION_COLORED";
@NonNull
private final MusicService service;
@NonNull
private final NotificationManager notificationManager;
@Nullable
private Notification notification;
private int notificationId = hashCode();
private RemoteViews notificationLayout;
private RemoteViews notificationLayoutExpanded;
@ -62,44 +55,23 @@ public class PlayingNotificationHelper {
private boolean isDark;
private boolean isColored;
private boolean isReceiverRegistered;
private boolean isNotificationShown;
private ImageAware notificationImageAware;
@NonNull
final IntentFilter intentFilter;
public PlayingNotificationHelper(@NonNull final MusicService service) {
this.service = service;
notificationManager = (NotificationManager) service
.getSystemService(Context.NOTIFICATION_SERVICE);
intentFilter = new IntentFilter();
intentFilter.addAction(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED);
int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size);
notificationImageAware = new NonViewAware(new ImageSize(bigNotificationImageSize, bigNotificationImageSize), ViewScaleType.CROP);
}
@NonNull
private BroadcastReceiver notificationColorPreferenceChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, @NonNull Intent intent) {
if (intent.getAction().equals(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED)) {
boolean isColored = intent.getBooleanExtra(EXTRA_NOTIFICATION_COLORED, false);
if (isNotificationShown && PlayingNotificationHelper.this.isColored != isColored) {
updateNotification(isColored);
}
}
}
};
public void updateNotification() {
updateNotification(PreferenceUtil.getInstance(service).coloredNotification());
}
private void updateNotification(final boolean isColored) {
public void updateNotification(final boolean isColored) {
Song song = service.getCurrentSong();
if (song.id == -1) {
service.stopForeground(true);
@ -108,10 +80,6 @@ public class PlayingNotificationHelper {
this.isColored = isColored;
currentSong = song;
this.isPlaying = service.isPlaying();
if (!isReceiverRegistered)
service.registerReceiver(notificationColorPreferenceChangedReceiver, intentFilter);
isReceiverRegistered = true;
isNotificationShown = true;
notificationLayout = new RemoteViews(service.getPackageName(), R.layout.notification);
notificationLayoutExpanded = new RemoteViews(service.getPackageName(), R.layout.notification_big);
@ -133,7 +101,7 @@ public class PlayingNotificationHelper {
setUpPlaybackActions();
setUpExpandedPlaybackActions();
service.startForeground(NOTIFICATION_ID, notification);
service.startForeground(notificationId, notification);
}
private PendingIntent getOpenMusicControllerPendingIntent() {
@ -269,7 +237,7 @@ public class PlayingNotificationHelper {
}
if (notification != null) {
notificationManager.notify(NOTIFICATION_ID, notification);
notificationManager.notify(notificationId, notification);
}
}
@ -279,12 +247,8 @@ public class PlayingNotificationHelper {
}
public void killNotification() {
if (isReceiverRegistered)
service.unregisterReceiver(notificationColorPreferenceChangedReceiver);
isReceiverRegistered = false;
service.stopForeground(true);
notification = null;
isNotificationShown = false;
}
public void updatePlayState(final boolean setPlaying) {
@ -300,7 +264,7 @@ public class PlayingNotificationHelper {
if (notificationLayoutExpanded != null) {
notificationLayoutExpanded.setImageViewResource(R.id.action_play_pause, playPauseRes);
}
notificationManager.notify(NOTIFICATION_ID, notification);
notificationManager.notify(notificationId, notification);
}
private void setNotificationTextDark(boolean setDark) {

View file

@ -8,6 +8,8 @@ import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaMetadataRetriever;
@ -23,6 +25,7 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.Process;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
@ -54,7 +57,8 @@ import java.util.List;
/**
* @author Karim Abou Zeid (kabouzeid), Andrew Neal
*/
public class MusicService extends Service {
@SuppressWarnings("deprecation")
public class MusicService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String TAG = MusicService.class.getSimpleName();
public static final String PHONOGRAPH_PACKAGE_NAME = "com.kabouzeid.gramophone";
@ -68,14 +72,12 @@ public class MusicService extends Service {
public static final String ACTION_REWIND = "com.kabouzeid.gramophone.action.REWIND";
public static final String ACTION_QUIT = "com.kabouzeid.gramophone.action.QUIT";
public static final String META_CHANGED = "com.kabouzeid.gramophone.metachanged";
public static final String PLAY_STATE_CHANGED = "com.kabouzeid.gramophone.playstatechanged";
public static final String REPEAT_MODE_CHANGED = "com.kabouzeid.gramophone.repeatmodechanged";
public static final String SHUFFLE_MODE_CHANGED = "com.kabouzeid.gramophone.shufflemodechanged";
public static final String META_CHANGED = "com.kabouzeid.gramophone.meta_changed";
public static final String PLAY_STATE_CHANGED = "com.kabouzeid.gramophone.playstate_changed";
public static final String REPEAT_MODE_CHANGED = "com.kabouzeid.gramophone.repeat_mode_changed";
public static final String SHUFFLE_MODE_CHANGED = "com.kabouzeid.gramophone.shuffle_mode_changed";
public static final String SETTING_GAPLESS_PLAYBACK_CHANGED = "com.kabouzeid.gramophone.SETTING_GAPLESS_PLAYBACK_CHANGED";
public static final String SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED = "com.kabouzeid.gramophone.SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED";
public static final String SETTING_BOOLEAN_EXTRA = "com.kabouzeid.gramophone.SETTING_BOOLEAN_EXTRA";
public static final String MEDIA_STORE_CHANGED = "com.kabouzeid.gramophone.media_store_changed";
public static final String SAVED_POSITION = "POSITION";
public static final String SAVED_POSITION_IN_TRACK = "POSITION_IN_TRACK";
@ -110,7 +112,6 @@ public class MusicService extends Service {
private boolean receiversAndRemoteControlClientRegistered;
private PlayingNotificationHelper playingNotificationHelper;
private AudioManager audioManager;
@SuppressWarnings("deprecation")
private RemoteControlClient remoteControlClient;
private PowerManager.WakeLock wakeLock;
private MusicPlayerHandler playerHandler;
@ -119,39 +120,10 @@ public class MusicService extends Service {
private HandlerThread queueSaveHandlerThread;
private RecentlyPlayedStore recentlyPlayedStore;
private SongPlayCountStore songPlayCountStore;
private ContentObserver mediaStoreObserver;
private boolean notNotifiedMetaChangedForCurrentTrack;
private boolean isServiceInUse;
private final BroadcastReceiver becomingNoisyReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, @NonNull Intent intent) {
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
pause();
}
}
};
private final BroadcastReceiver preferencesChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, @NonNull Intent intent) {
switch (intent.getAction()) {
case SETTING_GAPLESS_PLAYBACK_CHANGED:
setGaplessPlaybackEnabled(intent.getBooleanExtra(SETTING_BOOLEAN_EXTRA, false));
break;
case SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED:
updateRemoteControlClientImpl(intent.getBooleanExtra(SETTING_BOOLEAN_EXTRA, true));
break;
}
}
};
private final AudioManager.OnAudioFocusChangeListener audioFocusListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(final int focusChange) {
playerHandler.obtainMessage(FOCUS_CHANGE, focusChange, 0).sendToTarget();
}
};
@Override
public void onCreate() {
super.onCreate();
@ -175,6 +147,7 @@ public class MusicService extends Service {
musicPlayerHandlerThread.start();
playerHandler = new MusicPlayerHandler(this, musicPlayerHandlerThread.getLooper());
// queue saving needs to run on a separate thread so that it doesn't block the player handler events
queueSaveHandlerThread = new HandlerThread("QueueSaveHandler",
Process.THREAD_PRIORITY_BACKGROUND);
queueSaveHandlerThread.start();
@ -186,18 +159,35 @@ public class MusicService extends Service {
registerReceiversAndRemoteControlClient();
restoreQueueAndPosition();
mediaStoreObserver = new MediaStoreObserver(playerHandler);
getContentResolver().registerContentObserver(
MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
getContentResolver().registerContentObserver(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this);
}
private final BroadcastReceiver becomingNoisyReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, @NonNull Intent intent) {
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
pause();
}
}
};
private final AudioManager.OnAudioFocusChangeListener audioFocusListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(final int focusChange) {
playerHandler.obtainMessage(FOCUS_CHANGE, focusChange, 0).sendToTarget();
}
};
private void registerReceiversAndRemoteControlClient() {
if (!receiversAndRemoteControlClientRegistered) {
registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
IntentFilter preferenceIntentFilter = new IntentFilter();
preferenceIntentFilter.addAction(SETTING_GAPLESS_PLAYBACK_CHANGED);
preferenceIntentFilter.addAction(SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED);
registerReceiver(preferencesChangedReceiver, preferenceIntentFilter);
//noinspection deprecation
getAudioManager().registerMediaButtonEventReceiver(new ComponentName(getApplicationContext(), MediaButtonIntentReceiver.class));
initRemoteControlClient();
receiversAndRemoteControlClientRegistered = true;
@ -268,6 +258,8 @@ public class MusicService extends Service {
public void onDestroy() {
quit();
releaseResources();
getContentResolver().unregisterContentObserver(mediaStoreObserver);
PreferenceUtil.getInstance(this).unregisterOnSharedPreferenceChangedListener(this);
wakeLock.release();
}
@ -294,10 +286,7 @@ public class MusicService extends Service {
private void unregisterReceiversAndRemoteControlClient() {
if (receiversAndRemoteControlClientRegistered) {
unregisterReceiver(becomingNoisyReceiver);
unregisterReceiver(preferencesChangedReceiver);
//noinspection deprecation
getAudioManager().unregisterRemoteControlClient(remoteControlClient);
//noinspection deprecation
getAudioManager().unregisterMediaButtonEventReceiver(new ComponentName(getApplicationContext(), MediaButtonIntentReceiver.class));
receiversAndRemoteControlClientRegistered = false;
}
@ -866,6 +855,21 @@ public class MusicService extends Service {
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) {
case PreferenceUtil.GAPLESS_PLAYBACK:
setGaplessPlaybackEnabled(sharedPreferences.getBoolean(key, false));
break;
case PreferenceUtil.ALBUM_ART_ON_LOCKSCREEN:
updateRemoteControlClientImpl(sharedPreferences.getBoolean(key, true));
break;
case PreferenceUtil.COLORED_NOTIFICATION:
playingNotificationHelper.updateNotification(sharedPreferences.getBoolean(key, false));
break;
}
}
public class MusicBinder extends Binder {
@NonNull
public MusicService getService() {
@ -893,6 +897,32 @@ public class MusicService extends Service {
}
}
private class MediaStoreObserver extends ContentObserver implements Runnable {
// milliseconds to delay before calling refresh to aggregate events
private static final long REFRESH_DELAY = 500;
private Handler mHandler;
public MediaStoreObserver(Handler handler) {
super(handler);
mHandler = handler;
}
@Override
public void onChange(boolean selfChange) {
// if a change is detected, remove any scheduled callback
// then post a new one. This is intended to prevent closely
// spaced events from generating multiple refresh calls
mHandler.removeCallbacks(this);
mHandler.postDelayed(this, REFRESH_DELAY);
}
@Override
public void run() {
// actually call refresh when the delayed callback fires
notifyChange(MEDIA_STORE_CHANGED);
}
}
private static final class MusicPlayerHandler extends Handler {
@NonNull
private final WeakReference<MusicService> mService;

View file

@ -257,7 +257,7 @@ public class MainActivity extends AbsFabActivity
}
private void setUpDrawerLayout() {
drawerLayout.setStatusBarBackgroundColor(PreferenceUtil.getInstance(this).getThemeColorPrimaryDarker());
drawerLayout.setStatusBarBackgroundColor(getThemeColorPrimaryDarker());
setUpNavigationView();
}
@ -600,7 +600,7 @@ public class MainActivity extends AbsFabActivity
cab = new MaterialCab(this, R.id.cab_stub)
.setMenu(menu)
.setCloseDrawableRes(R.drawable.ic_close_white_24dp)
.setBackgroundColor(PreferenceUtil.getInstance(this).getThemeColorPrimary())
.setBackgroundColor(getThemeColorPrimary())
.start(callback);
return cab;
}

View file

@ -156,7 +156,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
cab = new MaterialCab(this, R.id.cab_stub)
.setMenu(menu)
.setCloseDrawableRes(R.drawable.ic_close_white_24dp)
.setBackgroundColor(PreferenceUtil.getInstance(this).getThemeColorPrimary())
.setBackgroundColor(getThemeColorPrimary())
.start(callback);
return cab;
}

View file

@ -22,7 +22,6 @@ import android.widget.TextView;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.SearchAdapter;
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
import com.kabouzeid.gramophone.util.PreferenceUtil;
import com.kabouzeid.gramophone.util.Util;
import butterknife.ButterKnife;
@ -66,7 +65,7 @@ public class SearchActivity extends AbsBaseActivity {
}
});
toolbar.setBackgroundColor(PreferenceUtil.getInstance(this).getThemeColorPrimary());
toolbar.setBackgroundColor(getThemeColorPrimary());
setSupportActionBar(toolbar);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

View file

@ -18,9 +18,7 @@ import android.view.MenuItem;
import com.afollestad.materialdialogs.util.DialogUtils;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.dialogs.ColorChooserDialog;
import com.kabouzeid.gramophone.helper.PlayingNotificationHelper;
import com.kabouzeid.gramophone.prefs.ColorChooserPreference;
import com.kabouzeid.gramophone.service.MusicService;
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
import com.kabouzeid.gramophone.util.NavigationUtil;
import com.kabouzeid.gramophone.util.PreferenceUtil;
@ -35,7 +33,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
setContentView(R.layout.activity_preferences);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(PreferenceUtil.getInstance(this).getThemeColorPrimary());
toolbar.setBackgroundColor(getThemeColorPrimary());
setSupportActionBar(toolbar);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -92,25 +90,25 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
});
ColorChooserPreference primaryColor = (ColorChooserPreference) findPreference("primary_color");
primaryColor.setColor(PreferenceUtil.getInstance(getActivity()).getThemeColorPrimary(),
primaryColor.setColor(((SettingsActivity) getActivity()).getThemeColorPrimary(),
DialogUtils.resolveColor(getActivity(), android.R.attr.textColorPrimary));
primaryColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
new ColorChooserDialog().show(getActivity(), preference.getTitleRes(),
PreferenceUtil.getInstance(getActivity()).getThemeColorPrimary());
((SettingsActivity) getActivity()).getThemeColorPrimary());
return true;
}
});
ColorChooserPreference accentColor = (ColorChooserPreference) findPreference("accent_color");
accentColor.setColor(PreferenceUtil.getInstance(getActivity()).getThemeColorAccent(),
accentColor.setColor(((SettingsActivity) getActivity()).getThemeColorAccent(),
DialogUtils.resolveColor(getActivity(), android.R.attr.textColorPrimary));
accentColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
new ColorChooserDialog().show(getActivity(), preference.getTitleRes(),
PreferenceUtil.getInstance(getActivity()).getThemeColorAccent());
((SettingsActivity) getActivity()).getThemeColorAccent());
return true;
}
});
@ -121,33 +119,6 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
colorNavBar.setSummary(R.string.pref_only_lollipop);
}
Preference coloredNotification = findPreference("colored_notification");
coloredNotification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
getActivity().sendBroadcast(new Intent(PlayingNotificationHelper.ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED).putExtra(PlayingNotificationHelper.EXTRA_NOTIFICATION_COLORED, (boolean) newValue));
return true;
}
});
Preference albumArtOnLockscreen = findPreference("album_art_on_lockscreen");
albumArtOnLockscreen.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
getActivity().sendBroadcast(new Intent(MusicService.SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED).putExtra(MusicService.SETTING_BOOLEAN_EXTRA, (boolean) newValue));
return true;
}
});
Preference gaplessPlayback = findPreference("gapless_playback");
gaplessPlayback.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
getActivity().sendBroadcast(new Intent(MusicService.SETTING_GAPLESS_PLAYBACK_CHANGED).putExtra(MusicService.SETTING_BOOLEAN_EXTRA, (boolean) newValue));
return true;
}
});
Preference ignoreMediaStoreArtwork = findPreference("ignore_media_store_artwork");
ignoreMediaStoreArtwork.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override

View file

@ -35,9 +35,9 @@ public abstract class AbsThemeActivity extends AppCompatActivity implements KabV
private void setupTheme() {
colorPrimary = PreferenceUtil.getInstance(this).getThemeColorPrimary();
colorPrimary = PreferenceUtil.getInstance(this).getThemeColorPrimary(this);
colorPrimaryDarker = ColorUtil.shiftColorDown(colorPrimary);
colorAccent = PreferenceUtil.getInstance(this).getThemeColorAccent();
colorAccent = PreferenceUtil.getInstance(this).getThemeColorAccent(this);
ThemeSingleton.get().positiveColor = colorAccent;
ThemeSingleton.get().negativeColor = ThemeSingleton.get().positiveColor;
@ -46,7 +46,7 @@ public abstract class AbsThemeActivity extends AppCompatActivity implements KabV
ThemeSingleton.get().darkTheme = PreferenceUtil.getInstance(this).getGeneralTheme() == R.style.Theme_MaterialMusic;
if (!overridesTaskColor()) {
notifyTaskColorChange(PreferenceUtil.getInstance(this).getThemeColorPrimary());
notifyTaskColorChange(getThemeColorPrimary());
}
}

View file

@ -200,7 +200,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
private void resetColors() {
paletteColorPrimary = PreferenceUtil.getInstance(this).getThemeColorPrimary();
paletteColorPrimary = getThemeColorPrimary();
observableScrollViewCallbacks.onScrollChanged(observableScrollView.getCurrentScrollY(), false, false);
setStatusBarColor(paletteColorPrimary);
if (PreferenceUtil.getInstance(this).coloredNavigationBarTagEditor())
@ -252,7 +252,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
observableScrollViewCallbacks.onScrollChanged(observableScrollView.getCurrentScrollY(), false, false);
paletteColorPrimary = getIntent().getIntExtra(EXTRA_PALETTE,
PreferenceUtil.getInstance(this).getThemeColorPrimary());
getThemeColorPrimary());
toolbar.setBackgroundColor(paletteColorPrimary);
header.setBackgroundColor(paletteColorPrimary);

View file

@ -25,8 +25,6 @@ public final class PreferenceUtil {
public static final String ALBUM_SORT_ORDER = "album_sort_order";
public static final String ALBUM_SONG_SORT_ORDER = "album_song_sort_order";
public static final String SONG_SORT_ORDER = "song_sort_order";
public static final String AUTO_DOWNLOAD_ARTIST_IMAGES_ONLY_ON_WIFI = "auto_download_artist_images_only_on_wifi";
public static final String COLORED_ALBUM_FOOTERS = "colored_album_footers";
public static final String COLORED_NAVIGATION_BAR = "colored_navigation_bar";
public static final String COLORED_NAVIGATION_BAR_ALBUM = "colored_navigation_bar_album";
public static final String COLORED_NAVIGATION_BAR_ARTIST = "colored_navigation_bar_artist";
@ -52,12 +50,9 @@ public final class PreferenceUtil {
private static PreferenceUtil sInstance;
@NonNull
private final Context mContext;
private final SharedPreferences mPreferences;
public PreferenceUtil(@NonNull final Context context) {
mContext = context;
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}
@ -87,12 +82,12 @@ public final class PreferenceUtil {
return R.style.Theme_MaterialMusic_Light;
}
public int getThemeColorPrimary() {
return mPreferences.getInt("primary_color", mContext.getResources().getColor(R.color.indigo_500));
public int getThemeColorPrimary(Context context) {
return mPreferences.getInt("primary_color", context.getResources().getColor(R.color.indigo_500));
}
public int getThemeColorPrimaryDarker() {
return ColorUtil.shiftColorDown(getThemeColorPrimary());
public int getThemeColorPrimaryDarker(Context context) {
return ColorUtil.shiftColorDown(getThemeColorPrimary(context));
}
@SuppressLint("CommitPrefEdits")
@ -100,8 +95,8 @@ public final class PreferenceUtil {
mPreferences.edit().putInt("primary_color", color).commit();
}
public int getThemeColorAccent() {
return mPreferences.getInt("accent_color", mContext.getResources().getColor(R.color.pink_A200));
public int getThemeColorAccent(Context context) {
return mPreferences.getInt("accent_color", context.getResources().getColor(R.color.pink_A200));
}
@SuppressLint("CommitPrefEdits")
@ -123,14 +118,6 @@ public final class PreferenceUtil {
return mPreferences.getInt(LAST_START_PAGE, DEFAULT_PAGE);
}
public final boolean autoDownloadArtistImagesOnlyOnWifi() {
return mPreferences.getBoolean(AUTO_DOWNLOAD_ARTIST_IMAGES_ONLY_ON_WIFI, false);
}
public final boolean coloredAlbumFooters() {
return mPreferences.getBoolean(COLORED_ALBUM_FOOTERS, true);
}
public final boolean coloredNotification() {
return mPreferences.getBoolean(COLORED_NOTIFICATION, false);
}