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.EditText;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import net.somethingdreadful.MAL.PrefManager;
import net.somethingdreadful.MAL.R;

public class UpdateImageDialogFragment extends DialogFragment {
    EditText input;

    private View createView() {
        View result = getActivity().getLayoutInflater().inflate(R.layout.dialog_update_nav_image, null);
        input = (EditText) result.findViewById(R.id.editText);
        return result;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getTheme());
        builder.setTitle(R.string.dialog_title_update_navigation);
        builder.setView(createView());

        builder.setPositiveButton(R.string.dialog_label_update, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                input.clearFocus();
                Picasso.with(getActivity())
                        .load(input.getText().toString())
                        .into((ImageView) getActivity().findViewById(R.id.NDimage));
                PrefManager pref = new PrefManager(getActivity());
                pref.setNavigationBackground(input.getText().toString());
                pref.commitChanges();
                dismiss();
            }
        });
        builder.setNeutralButton(R.string.dialog_label_remove, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                Picasso.with(getActivity())
                        .load(R.drawable.atarashii_background)
                        .into((ImageView) getActivity().findViewById(R.id.NDimage));
                PrefManager pref = new PrefManager(getActivity());
                pref.setNavigationBackground(null);
                pref.commitChanges();
                dismiss();
            }
        });
        builder.setNegativeButton(R.string.dialog_label_cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                dismiss();
            }
        });

        return builder.create();
    }
}

@@ -1230,24 +1230,90 @@
 earFocus();%0A
+                if (!input.getText().toString().equals(%22%22)) %7B%0A    
             
@@ -1336,32 +1336,36 @@
 (getActivity())%0A
+    
                 
@@ -1422,32 +1422,36 @@
                 
+  
+  
 .into((ImageView
@@ -1487,32 +1487,36 @@
 R.id.NDimage));%0A
+    
                 
@@ -1574,32 +1574,36 @@
                 
+    
 pref.setNavigati
@@ -1652,32 +1652,36 @@
                 
+    
 pref.commitChang
@@ -1678,32 +1678,50 @@
 ommitChanges();%0A
+                %7D%0A
                 

Fix picasso crash when an user tries to update the image with an empty url (Dialog)