huaxunhuang
10/22/2017 - 9:30 AM

AntennaPod #01

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <CheckBox
        android:id="@+id/chkAutoFlattr"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:text="@string/auto_flattr_enable"
        android:textColor="?android:attr/textColorPrimary"
        android:textSize="@dimen/text_size_small" />

    <SeekBar
        android:id="@+id/skbPercent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:max="100" />

    <TextView
        android:id="@+id/txtvStatus"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:ellipsize="end"
        android:lines="2"
        android:text="@string/auto_flattr_after_percent"
        android:textColor="?android:attr/textColorPrimary"
        android:textSize="@dimen/text_size_small" />

</LinearLayout>
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();
    }