blob: a87dccdf57b59193f0c8c2d4e2d99ac16bcc9dee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package de.danoeh.antennapod.dialog;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import androidx.fragment.app.DialogFragment;
import android.widget.Button;
import android.widget.CheckBox;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import java.util.List;
public class PlaybackControlsDialog extends DialogFragment {
private PlaybackController controller;
private AlertDialog dialog;
public static PlaybackControlsDialog newInstance() {
Bundle arguments = new Bundle();
PlaybackControlsDialog dialog = new PlaybackControlsDialog();
dialog.setArguments(arguments);
return dialog;
}
public PlaybackControlsDialog() {
// Empty constructor required for DialogFragment
}
@Override
public void onStart() {
super.onStart();
controller = new PlaybackController(getActivity()) {
@Override
public void loadMediaInfo() {
setupUi();
setupAudioTracks();
}
};
controller.init();
setupUi();
}
@Override
public void onStop() {
super.onStop();
controller.release();
controller = null;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
dialog = new MaterialAlertDialogBuilder(getContext())
.setTitle(R.string.audio_controls)
.setView(R.layout.audio_controls)
.setPositiveButton(R.string.close_label, null).create();
return dialog;
}
private void setupUi() {
final CheckBox skipSilence = dialog.findViewById(R.id.skipSilence);
skipSilence.setChecked(UserPreferences.isSkipSilence());
skipSilence.setOnCheckedChangeListener((buttonView, isChecked) -> {
UserPreferences.setSkipSilence(isChecked);
controller.setSkipSilence(isChecked);
});
}
private void setupAudioTracks() {
List<String> audioTracks = controller.getAudioTracks();
int selectedAudioTrack = controller.getSelectedAudioTrack();
final Button butAudioTracks = dialog.findViewById(R.id.audio_tracks);
if (audioTracks.size() < 2 || selectedAudioTrack < 0) {
butAudioTracks.setVisibility(View.GONE);
return;
}
butAudioTracks.setVisibility(View.VISIBLE);
butAudioTracks.setText(audioTracks.get(selectedAudioTrack));
butAudioTracks.setOnClickListener(v -> {
controller.setAudioTrack((selectedAudioTrack + 1) % audioTracks.size());
new Handler(Looper.getMainLooper()).postDelayed(this::setupAudioTracks, 500);
});
}
}
|