summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/dialog/FeedPreferenceSkipDialog.java
blob: 77c9ff67ec5c5d393855b63ea77ee911886586da (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
package de.danoeh.antennapod.dialog;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.R;

/**
 * Displays a dialog with a username and password text field and an optional checkbox to save username and preferences.
 */
public abstract class FeedPreferenceSkipDialog extends MaterialAlertDialogBuilder {

    public FeedPreferenceSkipDialog(Context context, int skipIntroInitialValue,
                                    int skipEndInitialValue) {
        super(context);
        setTitle(R.string.pref_feed_skip);
        View rootView = View.inflate(context, R.layout.feed_pref_skip_dialog, null);
        setView(rootView);

        final EditText etxtSkipIntro = rootView.findViewById(R.id.etxtSkipIntro);
        final EditText etxtSkipEnd = rootView.findViewById(R.id.etxtSkipEnd);

        etxtSkipIntro.setText(String.valueOf(skipIntroInitialValue));
        etxtSkipEnd.setText(String.valueOf(skipEndInitialValue));

        setNegativeButton(R.string.cancel_label, null);
        setPositiveButton(R.string.confirm_label, (dialog, which)
                -> {
            int skipIntro;
            int skipEnding;
            try {
                skipIntro = Integer.parseInt(etxtSkipIntro.getText().toString());
            } catch (NumberFormatException e) {
                skipIntro = 0;
            }

            try {
                skipEnding = Integer.parseInt(etxtSkipEnd.getText().toString());
            } catch (NumberFormatException e) {
                skipEnding = 0;
            }
            onConfirmed(skipIntro, skipEnding);
        });
    }

    protected abstract void onConfirmed(int skipIntro, int skipEndig);
}