bullheadandplato/AndroidEqualizer

adding enable and disable equalizer.

Opened this issue · 2 comments

Am trying to add enable and disable in my app so i tried below but unable to save setting in shared preference. So kindly help me to add this function. below is what i tried.

private void loadEqualizerSettings(){
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

        Gson gson = new Gson();
        EqualizerSettings settings = gson.fromJson(preferences.getString(PREF_KEY, "{}"), EqualizerSettings.class);
        EqualizerModel model = new EqualizerModel();
        model.setEqualizerEnabled(settings.isEqualizerEnabled);
        model.setBassStrength(settings.bassStrength);
        model.setPresetPos(settings.presetPos);
        model.setReverbPreset(settings.reverbPreset);
        model.setSeekbarpos(settings.seekbarpos);

        Settings.isEqualizerEnabled = settings.isEqualizerEnabled;
        Settings.isEqualizerReloaded = true;
        Settings.bassStrength = settings.bassStrength;
        Settings.presetPos = settings.presetPos;
        Settings.reverbPreset = settings.reverbPreset;
        Settings.seekbarpos = settings.seekbarpos;
        Settings.equalizerModel = model;
    }

    private void saveEqualizerSettings(){
        if (Settings.equalizerModel != null){
            EqualizerSettings settings = new EqualizerSettings();
            settings.isEqualizerEnabled = Settings.equalizerModel.isEqualizerEnabled();
            settings.bassStrength = Settings.equalizerModel.getBassStrength();
            settings.presetPos = Settings.equalizerModel.getPresetPos();
            settings.reverbPreset = Settings.equalizerModel.getReverbPreset();
            settings.seekbarpos = Settings.equalizerModel.getSeekbarpos();

            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

            Gson gson = new Gson();
            preferences.edit()
                    .putString(PREF_KEY, gson.toJson(settings))
                    .apply();
        }
    }

from above code you could notice i have added this line settings.isEqualizerEnabled = Settings.equalizerModel.isEqualizerEnabled(); instead of settings.isEqualizerEnabled = true; so that we have a extra function of enable and disable.

settings.java

public class EqualizerSettings {
    public boolean isEqualizerEnabled;
    public int[] seekbarpos = new int[5];
    public int presetPos;
    public short reverbPreset;
    public short bassStrength;
}

Screenshot_1569785199

Hi, currently Settings does not work for Equalizer in Dialog.
You can look at https://github.com/bullheadandplato/AndroidEqualizer/blob/master/equalizer/src/main/java/com/bullhead/equalizer/EqualizerFragment.java and do same changes in DialogEqualizerFragment and create pull request. I will check and merge it.
If you do not have the time to create pull request then wait some and I will find time to do changes by myself.
Thanks

@bullheadandplato Great looking forward for your changes. Hope will arrive soon with enabling and disable to be saved in shared preference.