Commit 75f3858a authored by David Papazian's avatar David Papazian Committed by Geoffrey Métais

Use databinding in Equalizer

Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 7a66c734
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="680dp"
android:minHeight="448dp"
android:padding="@dimen/default_margin" >
<layout>
<data>
<variable
name="state"
type="org.videolan.vlc.gui.audio.EqualizerFragment.EqualizerState" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="680dp"
android:minHeight="448dp"
android:padding="@dimen/default_margin" >
<android.support.v7.widget.SwitchCompat
android:id="@+id/equalizer_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/equalizer_presets"
app:layout_constraintVertical_chainStyle="packed"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/equalizer_presets"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_button"
app:layout_constraintTop_toTopOf="@+id/equalizer_button"
app:layout_constraintLeft_toRightOf="@+id/equalizer_button"
app:layout_constraintRight_toLeftOf="@+id/equalizer_save"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/equalizer_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/equalizer_presets"
app:layout_constraintVertical_chainStyle="packed"/>
<ImageView
android:visibility="invisible"
android:id="@+id/equalizer_save"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_save"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_presets"
app:layout_constraintTop_toTopOf="@+id/equalizer_presets"
app:layout_constraintLeft_toRightOf="@+id/equalizer_presets"
app:layout_constraintRight_toLeftOf="@+id/equalizer_revert"/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/equalizer_presets"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_button"
app:layout_constraintTop_toTopOf="@+id/equalizer_button"
app:layout_constraintLeft_toRightOf="@+id/equalizer_button"
app:layout_constraintRight_toLeftOf="@+id/equalizer_save"/>
<ImageView
android:visibility="invisible"
android:id="@+id/equalizer_delete"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_trash"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toLeftOf="@+id/equalizer_save"
app:layout_constraintRight_toRightOf="@+id/equalizer_save" />
<ImageView
android:visibility="@{state.saveButtonVisibility}"
android:id="@+id/equalizer_save"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_save"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_presets"
app:layout_constraintTop_toTopOf="@+id/equalizer_presets"
app:layout_constraintLeft_toRightOf="@+id/equalizer_presets"
app:layout_constraintRight_toLeftOf="@+id/equalizer_revert"/>
<ImageView
android:visibility="invisible"
android:id="@+id/equalizer_revert"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_reset"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toRightOf="@+id/equalizer_save"
app:layout_constraintRight_toLeftOf="@+id/guideine" />
<ImageView
android:visibility="@{state.revertButtonVisibility}"
android:id="@+id/equalizer_revert"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_reset"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toRightOf="@+id/equalizer_save"
app:layout_constraintRight_toLeftOf="@+id/guideine" />
<android.support.constraint.Guideline
android:id="@+id/guideine"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintGuide_percent="0.5"
app:layout_constraintLeft_toRightOf="@+id/equalizer_revert"
app:layout_constraintRight_toLeftOf="@+id/equalizer_preamp" />
<ImageView
android:visibility="@{state.deleteButtonVisibility}"
android:id="@+id/equalizer_delete"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_trash"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toLeftOf="@+id/equalizer_save"
app:layout_constraintRight_toRightOf="@+id/equalizer_save" />
<SeekBar
android:id="@+id/equalizer_preamp"
android:layout_width="0dp"
android:layout_height="0dp"
android:maxHeight="4dip"
android:minHeight="4dip"
android:progressDrawable="@drawable/po_seekbar"
android:thumb="@drawable/seekbar_thumb"
android:splitTrack="false"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_revert"
app:layout_constraintTop_toTopOf="@+id/equalizer_revert"
app:layout_constraintLeft_toRightOf="@+id/guideine"
app:layout_constraintRight_toRightOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideine"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintGuide_percent="0.5"
app:layout_constraintLeft_toRightOf="@+id/equalizer_revert"
app:layout_constraintRight_toLeftOf="@+id/equalizer_preamp" />
<HorizontalScrollView
android:id="@+id/equalizer_scroll"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintHorizontal_bias="0.5"
android:fillViewport="true"
android:fadeScrollbars="false"
app:layout_constraintTop_toBottomOf="@+id/equalizer_preamp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<SeekBar
android:id="@+id/equalizer_preamp"
android:layout_width="0dp"
android:layout_height="0dp"
android:maxHeight="4dip"
android:minHeight="4dip"
android:progressDrawable="@drawable/po_seekbar"
android:thumb="@drawable/seekbar_thumb"
android:splitTrack="false"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_revert"
app:layout_constraintTop_toTopOf="@+id/equalizer_revert"
app:layout_constraintLeft_toRightOf="@+id/guideine"
app:layout_constraintRight_toRightOf="parent" />
<LinearLayout
android:id="@+id/equalizer_bands"
<HorizontalScrollView
android:id="@+id/equalizer_scroll"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</HorizontalScrollView>
android:layout_height="0dp"
app:layout_constraintHorizontal_bias="0.5"
android:fillViewport="true"
android:fadeScrollbars="false"
app:layout_constraintTop_toBottomOf="@+id/equalizer_preamp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<LinearLayout
android:id="@+id/equalizer_bands"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
\ No newline at end of file
</LinearLayout>
</layout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="680dp"
android:minHeight="448dp"
android:padding="@dimen/default_margin" >
<layout>
<data>
<variable
name="state"
type="org.videolan.vlc.gui.audio.EqualizerFragment.EqualizerState" />
</data>
<android.support.constraint.ConstraintLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:minWidth="680dp"
android:minHeight="448dp"
android:padding="@dimen/default_margin" >
<android.support.v7.widget.SwitchCompat
android:id="@+id/equalizer_button"
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintVertical_chainStyle="packed"/>
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/equalizer_presets"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_max="512dp"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_button"
app:layout_constraintTop_toTopOf="@+id/equalizer_button"
app:layout_constraintLeft_toRightOf="@+id/equalizer_button"
app:layout_constraintRight_toLeftOf="@+id/equalizer_save"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/equalizer_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintVertical_chainStyle="packed"/>
<ImageView
android:visibility="invisible"
android:id="@+id/equalizer_save"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_save"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_presets"
app:layout_constraintTop_toTopOf="@+id/equalizer_presets"
app:layout_constraintLeft_toRightOf="@+id/equalizer_presets"
app:layout_constraintRight_toLeftOf="@+id/equalizer_revert"/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/equalizer_presets"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_max="512dp"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_button"
app:layout_constraintTop_toTopOf="@+id/equalizer_button"
app:layout_constraintLeft_toRightOf="@+id/equalizer_button"
app:layout_constraintRight_toLeftOf="@+id/equalizer_save"/>
<ImageView
android:visibility="invisible"
android:id="@+id/equalizer_revert"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_reset"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toRightOf="@+id/equalizer_save"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:visibility="@{state.saveButtonVisibility}"
android:id="@+id/equalizer_save"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_save"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_presets"
app:layout_constraintTop_toTopOf="@+id/equalizer_presets"
app:layout_constraintLeft_toRightOf="@+id/equalizer_presets"
app:layout_constraintRight_toLeftOf="@+id/equalizer_revert"/>
<ImageView
android:visibility="invisible"
android:id="@+id/equalizer_delete"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_trash"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toLeftOf="@+id/equalizer_save"
app:layout_constraintRight_toRightOf="@+id/equalizer_save" />
<ImageView
android:visibility="@{state.revertButtonVisibility}"
android:id="@+id/equalizer_revert"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_reset"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toRightOf="@+id/equalizer_save"
app:layout_constraintRight_toRightOf="parent" />
<SeekBar
android:id="@+id/equalizer_preamp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxHeight="4dip"
android:minHeight="4dip"
android:progressDrawable="@drawable/po_seekbar"
android:thumb="@drawable/seekbar_thumb"
android:splitTrack="false"
app:layout_constraintTop_toBottomOf="@+id/equalizer_button"
app:layout_constraintBottom_toTopOf="@+id/equalizer_scroll"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:visibility="@{state.deleteButtonVisibility}"
android:id="@+id/equalizer_delete"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1"
android:src="?attr/ic_trash"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_save"
app:layout_constraintTop_toTopOf="@+id/equalizer_save"
app:layout_constraintLeft_toLeftOf="@+id/equalizer_save"
app:layout_constraintRight_toRightOf="@+id/equalizer_save" />
<HorizontalScrollView
android:id="@+id/equalizer_scroll"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintHorizontal_bias="0.5"
android:fillViewport="true"
android:fadeScrollbars="false"
app:layout_constraintTop_toBottomOf="@+id/equalizer_preamp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<SeekBar
android:id="@+id/equalizer_preamp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxHeight="4dip"
android:minHeight="4dip"
android:progressDrawable="@drawable/po_seekbar"
android:thumb="@drawable/seekbar_thumb"
android:splitTrack="false"
app:layout_constraintTop_toBottomOf="@+id/equalizer_button"
app:layout_constraintBottom_toTopOf="@+id/equalizer_scroll"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<LinearLayout
android:id="@+id/equalizer_bands"
<HorizontalScrollView
android:id="@+id/equalizer_scroll"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</HorizontalScrollView>
android:layout_height="0dp"
app:layout_constraintHorizontal_bias="0.5"
android:fillViewport="true"
android:fadeScrollbars="false"
app:layout_constraintTop_toBottomOf="@+id/equalizer_preamp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<LinearLayout
android:id="@+id/equalizer_bands"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
\ No newline at end of file
</LinearLayout>
</layout>
\ No newline at end of file
......@@ -21,12 +21,12 @@ package org.videolan.vlc.gui.audio;
import android.content.Context;
import android.content.DialogInterface;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableInt;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.SwitchCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
......@@ -40,7 +40,6 @@ import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
......@@ -50,6 +49,7 @@ import org.videolan.libvlc.MediaPlayer;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.databinding.EqualizerBinding;
import org.videolan.vlc.gui.PlaybackServiceFragment;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.EqualizerBar;
......@@ -65,14 +65,7 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
private PlaybackService mService;
public final static String TAG = "VLC/EqualizerFragment";
private SwitchCompat button;
private ImageView save;
private ImageView delete;
private ImageView revert;
private AppCompatSpinner equalizer_sets;
private SeekBar preamp;
private LinearLayout bands_layout;
private MediaPlayer.Equalizer mEqualizer = null;
private static final int BAND_COUNT = MediaPlayer.Equalizer.getBandCount();
private int customCount = 0;
......@@ -80,11 +73,12 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
private List<String> allSets = new ArrayList<>();
private ArrayAdapter<String> adapter;
private Context context;
private View dialogView;
private int revertPos = 0;
private int savePos = 0;
private boolean saved = true;
private boolean updateAlreadyHandled = false;
private EqualizerBinding binding;
final private EqualizerState mState = new EqualizerState();
private final static int TYPE_PRESET = 0;
private final static int TYPE_CUSTOM = 1;
private final static int TYPE_NEW = 2;
......@@ -92,10 +86,9 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.equalizer, container, false);
saveViewChildren(v);
return v;
binding = DataBindingUtil.inflate(inflater, R.layout.equalizer, container, false);
binding.setState(mState);
return binding.getRoot();
}
@Override
......@@ -110,17 +103,6 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
PlaybackServiceFragment.unregisterPlaybackService(this, this);
}
private void saveViewChildren(View v) {
dialogView = v;
button = v.findViewById(R.id.equalizer_button);
equalizer_sets = v.findViewById(R.id.equalizer_presets);
preamp = v.findViewById(R.id.equalizer_preamp);
bands_layout = v.findViewById(R.id.equalizer_bands);
save = v.findViewById(R.id.equalizer_save);
delete = v.findViewById(R.id.equalizer_delete);
revert = v.findViewById(R.id.equalizer_revert);
}
@Override
public void onConnected(PlaybackService service) {
mService = service;
......@@ -152,8 +134,8 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
mEqualizer = VLCOptions.getEqualizerSetFromSettings(context);
// on/off
button.setChecked(VLCOptions.getEqualizerEnabledState(context));
button.setOnCheckedChangeListener(new OnCheckedChangeListener() {
binding.equalizerButton.setChecked(VLCOptions.getEqualizerEnabledState(context));
binding.equalizerButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (mService != null)
......@@ -163,19 +145,19 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
mService.setEqualizer(null);
}
});
save.setOnClickListener(new View.OnClickListener() {
binding.equalizerSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
createSaveCustomSetDialog(equalizer_sets.getSelectedItemPosition(), true, false);
createSaveCustomSetDialog(binding.equalizerPresets.getSelectedItemPosition(), true, false);
}
});
delete.setOnClickListener(new View.OnClickListener() {
binding.equalizerDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
createDeleteCustomSetSnacker();
}
});
revert.setOnClickListener(new View.OnClickListener() {
binding.equalizerRevert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
revertCustomSetChanges();
......@@ -184,20 +166,20 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
// presets
adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, allSets);
equalizer_sets.setAdapter(adapter);
binding.equalizerPresets.setAdapter(adapter);
// Set the default selection asynchronously to prevent a layout initialization bug.
equalizer_sets.post(new Runnable() {
binding.equalizerPresets.post(new Runnable() {
@Override
public void run() {
equalizer_sets.setOnItemSelectedListener(mSetListener);
saved = VLCOptions.getEqualizerSavedState(context);
binding.equalizerPresets.setOnItemSelectedListener(mSetListener);
final int pos = allSets.indexOf(VLCOptions.getEqualizerNameFromSettings(context));
mState.update(pos, VLCOptions.getEqualizerSavedState(context));
updateAlreadyHandled = true;
if (button.isChecked() || !saved) {
final int pos = allSets.indexOf(VLCOptions.getEqualizerNameFromSettings(context));
if (binding.equalizerButton.isChecked() || !mState.saved) {
savePos = pos;
revertPos = getEqualizerType(pos) == TYPE_CUSTOM ? pos : 0;
equalizer_sets.setSelection(pos);
binding.equalizerPresets.setSelection(pos);
} else {
updateEqualizer(0);
}
......@@ -206,9 +188,9 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
});
// preamp
preamp.setMax(40);
preamp.setProgress((int) mEqualizer.getPreAmp() + 20);
preamp.setOnSeekBarChangeListener(mPreampListener);
binding.equalizerPreamp.setMax(40);
binding.equalizerPreamp.setProgress((int) mEqualizer.getPreAmp() + 20);
binding.equalizerPreamp.setOnSeekBarChangeListener(mPreampListener);
// bands
for (int i = 0; i < BAND_COUNT; i++) {
......@@ -218,7 +200,7 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
bar.setValue(mEqualizer.getAmp(i));
bar.setListener(new BandListener(i));
bands_layout.addView(bar);
binding.equalizerBands.addView(bar);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT, 1);
......@@ -229,18 +211,18 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
@Override
public void onPause() {
super.onPause();
button.setOnCheckedChangeListener(null);
equalizer_sets.setOnItemSelectedListener(null);
preamp.setOnSeekBarChangeListener(null);
bands_layout.removeAllViews();
if (button.isChecked()) {
int pos = equalizer_sets.getSelectedItemPosition();
VLCOptions.saveEqualizerInSettings(context, mEqualizer, allSets.get(pos), true, saved);
binding.equalizerButton.setOnCheckedChangeListener(null);
binding.equalizerPresets.setOnItemSelectedListener(null);
binding.equalizerPreamp.setOnSeekBarChangeListener(null);
binding.equalizerBands.removeAllViews();
if (binding.equalizerButton.isChecked()) {
int pos = binding.equalizerPresets.getSelectedItemPosition();
VLCOptions.saveEqualizerInSettings(context, mEqualizer, allSets.get(pos), true, mState.saved);
} else {
VLCOptions.saveEqualizerInSettings(context, MediaPlayer.Equalizer.createFromPreset(0), allSets.get(0), false, true);
}
if (!saved)
createSaveCustomSetDialog(equalizer_sets.getSelectedItemPosition(), false, true);
if (!mState.saved)
createSaveCustomSetDialog(binding.equalizerPresets.getSelectedItemPosition(), false, true);
}
@Override
......@@ -254,11 +236,11 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (mService == null)
return;
if (!button.isChecked() && !updateAlreadyHandled)
button.setChecked(true);
if (!binding.equalizerButton.isChecked() && !updateAlreadyHandled)
binding.equalizerButton.setChecked(true);
//save set if changes made (needs old currentPosition)
if (!saved && !updateAlreadyHandled)
if (!mState.saved && !updateAlreadyHandled)
createSaveCustomSetDialog(savePos, false, false);
updateEqualizer(pos);
......@@ -283,24 +265,23 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
if (!fromUser || mService == null)
return;
mEqualizer.setPreAmp(progress - 20);
if (!button.isChecked())
button.setChecked(true);
if (!binding.equalizerButton.isChecked())
binding.equalizerButton.setChecked(true);
int pos = equalizer_sets.getSelectedItemPosition();
int pos = binding.equalizerPresets.getSelectedItemPosition();
if (getEqualizerType(pos) == TYPE_PRESET) {
revertPos = pos;
savePos = presetCount + customCount;
saved = false;
mState.update(presetCount + customCount, false);
updateAlreadyHandled = true;
equalizer_sets.setSelection(presetCount + customCount);
binding.equalizerPresets.setSelection(presetCount + customCount);
} else if (getEqualizerType(pos) == TYPE_CUSTOM) {
revertPos = pos;
savePos = pos;
saved = false;
updateButtonVisibility(pos);
mState.update(pos, false);
}
if (button.isChecked())
if (binding.equalizerButton.isChecked())
mService.setEqualizer(mEqualizer);
}
};
......@@ -317,24 +298,23 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
if (!fromUser)
return;
mEqualizer.setAmp(index, value);
if (!button.isChecked())
button.setChecked(true);
if (!binding.equalizerButton.isChecked())
binding.equalizerButton.setChecked(true);
int pos = equalizer_sets.getSelectedItemPosition();
int pos = binding.equalizerPresets.getSelectedItemPosition();
if (getEqualizerType(pos) == TYPE_PRESET) {
revertPos = pos;
savePos = presetCount + customCount;
saved = false;
mState.update(presetCount + customCount, false);