Search in sources :

Example 1 with Validate.notNull

use of org.apache.commons.lang3.Validate.notNull in project AntennaPod by AntennaPod.

the class AutoFlattrPreferenceDialog method newAutoFlattrPreferenceDialog.

public static void newAutoFlattrPreferenceDialog(final Activity activity, final AutoFlattrPreferenceDialogInterface callback) {
    Validate.notNull(activity);
    Validate.notNull(callback);
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    @SuppressLint("InflateParams") View view = activity.getLayoutInflater().inflate(R.layout.autoflattr_preference_dialog, null);
    final CheckBox chkAutoFlattr = (CheckBox) view.findViewById(R.id.chkAutoFlattr);
    final SeekBar skbPercent = (SeekBar) view.findViewById(R.id.skbPercent);
    final TextView txtvStatus = (TextView) view.findViewById(R.id.txtvStatus);
    chkAutoFlattr.setChecked(UserPreferences.isAutoFlattr());
    skbPercent.setEnabled(chkAutoFlattr.isChecked());
    txtvStatus.setEnabled(chkAutoFlattr.isChecked());
    final int initialValue = (int) (UserPreferences.getAutoFlattrPlayedDurationThreshold() * 100.0f);
    setStatusMsgText(activity, txtvStatus, initialValue);
    skbPercent.setProgress(initialValue);
    chkAutoFlattr.setOnClickListener(v -> {
        skbPercent.setEnabled(chkAutoFlattr.isChecked());
        txtvStatus.setEnabled(chkAutoFlattr.isChecked());
    });
    skbPercent.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            setStatusMsgText(activity, txtvStatus, progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    builder.setTitle(R.string.pref_auto_flattr_title).setView(view).setPositiveButton(R.string.confirm_label, (dialog, which) -> {
        float progDouble = ((float) skbPercent.getProgress()) / 100.0f;
        callback.onConfirmed(chkAutoFlattr.isChecked(), progDouble);
        dialog.dismiss();
    }).setNegativeButton(R.string.cancel_label, (dialog, which) -> {
        callback.onCancelled();
        dialog.dismiss();
    }).setCancelable(false).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) Context(android.content.Context) SeekBar(android.widget.SeekBar) SuppressLint(android.annotation.SuppressLint) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Validate(org.apache.commons.lang3.Validate) CheckBox(android.widget.CheckBox) R(de.danoeh.antennapod.R) View(android.view.View) Activity(android.app.Activity) SeekBar(android.widget.SeekBar) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) CheckBox(android.widget.CheckBox) SuppressLint(android.annotation.SuppressLint) TextView(android.widget.TextView)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Context (android.content.Context)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 R (de.danoeh.antennapod.R)1 UserPreferences (de.danoeh.antennapod.core.preferences.UserPreferences)1 Validate (org.apache.commons.lang3.Validate)1