package net.somethingdreadful.MAL.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.NumberPicker;

import net.somethingdreadful.MAL.DetailView;
import net.somethingdreadful.MAL.R;

public class EpisodesPickerDialogFragment extends DialogFragment {

    NumberPicker numberPicker;

    private View makeNumberPicker() {
        View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_episode_picker, null);
        int totalEpisodes = ((DetailView) getActivity()).animeRecord.getEpisodes();
        int watchedEpisodes = ((DetailView) getActivity()).animeRecord.getWatchedEpisodes();

        numberPicker = (NumberPicker) view.findViewById(R.id.numberPicker);
        if (totalEpisodes != 0) {
            numberPicker.setMaxValue(totalEpisodes);
        } else {
            numberPicker.setMaxValue(999);
        }
        numberPicker.setMinValue(0);
        numberPicker.setValue(watchedEpisodes);
        return view;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getTheme());
        builder.setView(makeNumberPicker());
        builder.setTitle(R.string.dialog_title_watched_update);
        builder.setPositiveButton(R.string.dialog_label_update, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                numberPicker.clearFocus();
                ((DetailView) getActivity()).onDialogDismissed(numberPicker.getValue());
                dismiss();
            }
        });
        builder.setNegativeButton(R.string.dialog_label_cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                dismiss();
            }
        });

        return builder.create();
    }
}
@@ -196,16 +196,41 @@
 Bundle;%0A
+import android.util.Log;%0A
 import a
@@ -284,16 +284,61 @@
 icker;%0A%0A
+import com.crashlytics.android.Crashlytics;%0A%0A
 import n
@@ -669,32 +669,77 @@
  totalEpisodes =
+ 0;%0A        try %7B%0A            totalEpisodes =
  ((DetailView) g
@@ -775,24 +775,184 @@
 Episodes();%0A
+        %7D catch (Exception e) %7B%0A            Crashlytics.log(Log.ERROR, %22MALX%22, %22EpisodesPickerDialogFragment.makeNumberPicker(): %22 + e.getMessage());%0A        %7D%0A
         int 

Fix crashes on some android versions when the episode amount was null (Dialog)