// Path: app/src/main/java/hr/foi/rsc/lifeline/models/User.java
// public class User {
// 
//     public static final String NAME = "name";
// 
//     public static final String SURNAME = "surname";
// 
//     public static final String ADDRESS = "address";
// 
//     public static final String BLOOD_TYPE = "bloodType";
// 
//     public static final String SEX = "sex";
// 
//     public static final String ADDITIONAL = "additional";
// 
//     public static final String USER_DATA = "UserData";
// 
//     public static final String USER_OBJECT_ID = "userObjectId";
// 
//     public static final String USER_DONATION = "UserDonation";
// 
//     public static final String DONOR = "donor";
// 
//     public static final String TYPE = "type";
// 
//     public static final float BLOOD_PER_DONATION_LITERS = 0.5f;
// 
//     public static final float BLOOD_FOR_TICKET_LITERS = 2f;
// 
//     private ParseUser parseUser;
// 
//     public static User getInstance() {
//         return new User(ParseUser.getCurrentUser());
//     }
// 
//     public User(ParseUser parseUser) {
//         this.parseUser = parseUser;
//     }
// 
//     public void getUserData(final GetCallback<ParseObject> getCallback) {
//         ParseQuery<ParseObject> query = ParseQuery.getQuery(USER_DATA);
//         query.whereEqualTo(USER_OBJECT_ID, parseUser.getObjectId());
//         query.getFirstInBackground(new GetCallback<ParseObject>() {
//             @Override
//             public void done(ParseObject parseObject, ParseException e) {
//                 if (parseObject == null) {
//                     parseObject = new ParseObject(USER_DATA);
//                     parseObject.put(USER_OBJECT_ID, parseUser.getObjectId());
//                     getCallback.done(parseObject, e);
//                 }
//                 getCallback.done(parseObject, e);
//             }
//         });
//     }
// 
//     public void getUserDonations(final FindCallback<ParseObject> findCallback) {
//         ParseQuery<ParseObject> query = ParseQuery.getQuery(USER_DONATION);
//         query.whereEqualTo(USER_OBJECT_ID, parseUser.getObjectId());
//         query.findInBackground(new FindCallback<ParseObject>() {
//             public void done(List<ParseObject> donationList, ParseException e) {
//                 findCallback.done(donationList, e);
//             }
//         });
//     }
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/presenters/ProfilePresenter.java
// public interface ProfilePresenter extends BasePresenter {
// 
//     public void saveData(String name, String surname, String address, String bloodType, String sex,
//                          String additional, String rhType);
// 
//     public void saveData(String address, String additional);
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/presenters/impl/ProfilePresenterImpl.java
// public class ProfilePresenterImpl implements ProfilePresenter {
// 
//     private boolean canceled;
// 
//     private ProfileView profileView;
// 
//     private Handler mainHandler = new Handler(Looper.getMainLooper());
// 
//     public ProfilePresenterImpl(ProfileView profileView) {
//         this.profileView = profileView;
//     }
// 
//     @Override
//     public void saveData(final String name, final String surname, final String address,
//                          final String bloodType, final String sex,
//                          final String additional, final String rhType) {
//         profileView.showProgress();
//         User.getInstance().getUserData(new GetCallback<ParseObject>() {
//             @Override
//             public void done(ParseObject parseObject, ParseException e) {
//                 parseObject.put(User.NAME, name);
//                 parseObject.put(User.SURNAME, surname);
//                 parseObject.put(User.ADDRESS, address);
//                 parseObject.put(User.BLOOD_TYPE, bloodType + rhType);
//                 parseObject.put(User.SEX, sex);
//                 parseObject.put(User.ADDITIONAL, additional);
//                 parseObject.saveInBackground();
//                 profileView.hideProgress();
//             }
//         });
//     }
// 
//     @Override
//     public void saveData(final String address, final String additional) {
//         profileView.showProgress();
//         User.getInstance().getUserData(new GetCallback<ParseObject>() {
//             @Override
//             public void done(ParseObject parseObject, ParseException e) {
//                 parseObject.put(User.ADDRESS, address);
//                 parseObject.put(User.ADDITIONAL, additional);
//                 parseObject.saveInBackground();
//                 profileView.hideProgress();
//             }
//         });
//     }
// 
//     @Override
//     public void cancel() {
//         canceled = true;
//     }
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/views/ProfileView.java
// public interface ProfileView extends BaseView {
// 
//     public void onSuccess();
// }


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseUser;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import hr.foi.rsc.lifeline.R;
import hr.foi.rsc.lifeline.models.User;
import hr.foi.rsc.lifeline.mvp.presenters.ProfilePresenter;
import hr.foi.rsc.lifeline.mvp.presenters.impl.ProfilePresenterImpl;
import hr.foi.rsc.lifeline.mvp.views.ProfileView;

    @InjectView(R.id.layout_rh)
    View layoutRh;

    private ProfilePresenter profilePresenter;

    private boolean isEdit;

    public ProfileFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_profile, container, false);
        ButterKnife.inject(this, view);

        if (!ParseUser.getCurrentUser().isNew()) {
            isEdit = true;
        }

        if (isEdit) {
            inputName.setVisibility(View.GONE);
            inputSurname.setVisibility(View.GONE);
            layoutSex.setVisibility(View.GONE);
            layoutBloodType.setVisibility(View.GONE);
            layoutRh.setVisibility(View.GONE);

            showProgress();
// Path: app/src/main/java/hr/foi/rsc/lifeline/models/User.java
// public class User {
// 
//     public static final String NAME = "name";
// 
//     public static final String SURNAME = "surname";
// 
//     public static final String ADDRESS = "address";
// 
//     public static final String BLOOD_TYPE = "bloodType";
// 
//     public static final String SEX = "sex";
// 
//     public static final String ADDITIONAL = "additional";
// 
//     public static final String USER_DATA = "UserData";
// 
//     public static final String USER_OBJECT_ID = "userObjectId";
// 
//     public static final String USER_DONATION = "UserDonation";
// 
//     public static final String DONOR = "donor";
// 
//     public static final String TYPE = "type";
// 
//     public static final float BLOOD_PER_DONATION_LITERS = 0.5f;
// 
//     public static final float BLOOD_FOR_TICKET_LITERS = 2f;
// 
//     private ParseUser parseUser;
// 
//     public static User getInstance() {
//         return new User(ParseUser.getCurrentUser());
//     }
// 
//     public User(ParseUser parseUser) {
//         this.parseUser = parseUser;
//     }
// 
//     public void getUserData(final GetCallback<ParseObject> getCallback) {
//         ParseQuery<ParseObject> query = ParseQuery.getQuery(USER_DATA);
//         query.whereEqualTo(USER_OBJECT_ID, parseUser.getObjectId());
//         query.getFirstInBackground(new GetCallback<ParseObject>() {
//             @Override
//             public void done(ParseObject parseObject, ParseException e) {
//                 if (parseObject == null) {
//                     parseObject = new ParseObject(USER_DATA);
//                     parseObject.put(USER_OBJECT_ID, parseUser.getObjectId());
//                     getCallback.done(parseObject, e);
//                 }
//                 getCallback.done(parseObject, e);
//             }
//         });
//     }
// 
//     public void getUserDonations(final FindCallback<ParseObject> findCallback) {
//         ParseQuery<ParseObject> query = ParseQuery.getQuery(USER_DONATION);
//         query.whereEqualTo(USER_OBJECT_ID, parseUser.getObjectId());
//         query.findInBackground(new FindCallback<ParseObject>() {
//             public void done(List<ParseObject> donationList, ParseException e) {
//                 findCallback.done(donationList, e);
//             }
//         });
//     }
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/presenters/ProfilePresenter.java
// public interface ProfilePresenter extends BasePresenter {
// 
//     public void saveData(String name, String surname, String address, String bloodType, String sex,
//                          String additional, String rhType);
// 
//     public void saveData(String address, String additional);
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/presenters/impl/ProfilePresenterImpl.java
// public class ProfilePresenterImpl implements ProfilePresenter {
// 
//     private boolean canceled;
// 
//     private ProfileView profileView;
// 
//     private Handler mainHandler = new Handler(Looper.getMainLooper());
// 
//     public ProfilePresenterImpl(ProfileView profileView) {
//         this.profileView = profileView;
//     }
// 
//     @Override
//     public void saveData(final String name, final String surname, final String address,
//                          final String bloodType, final String sex,
//                          final String additional, final String rhType) {
//         profileView.showProgress();
//         User.getInstance().getUserData(new GetCallback<ParseObject>() {
//             @Override
//             public void done(ParseObject parseObject, ParseException e) {
//                 parseObject.put(User.NAME, name);
//                 parseObject.put(User.SURNAME, surname);
//                 parseObject.put(User.ADDRESS, address);
//                 parseObject.put(User.BLOOD_TYPE, bloodType + rhType);
//                 parseObject.put(User.SEX, sex);
//                 parseObject.put(User.ADDITIONAL, additional);
//                 parseObject.saveInBackground();
//                 profileView.hideProgress();
//             }
//         });
//     }
// 
//     @Override
//     public void saveData(final String address, final String additional) {
//         profileView.showProgress();
//         User.getInstance().getUserData(new GetCallback<ParseObject>() {
//             @Override
//             public void done(ParseObject parseObject, ParseException e) {
//                 parseObject.put(User.ADDRESS, address);
//                 parseObject.put(User.ADDITIONAL, additional);
//                 parseObject.saveInBackground();
//                 profileView.hideProgress();
//             }
//         });
//     }
// 
//     @Override
//     public void cancel() {
//         canceled = true;
//     }
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/views/ProfileView.java
// public interface ProfileView extends BaseView {
// 
//     public void onSuccess();
// }


// Path: app/src/main/java/hr/foi/rsc/lifeline/fragments/ProfileFragment.java
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseUser;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import hr.foi.rsc.lifeline.R;
import hr.foi.rsc.lifeline.models.User;
import hr.foi.rsc.lifeline.mvp.presenters.ProfilePresenter;
import hr.foi.rsc.lifeline.mvp.presenters.impl.ProfilePresenterImpl;
import hr.foi.rsc.lifeline.mvp.views.ProfileView;


    @InjectView(R.id.layout_rh)
    View layoutRh;

    private ProfilePresenter profilePresenter;

    private boolean isEdit;

    public ProfileFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_profile, container, false);
        ButterKnife.inject(this, view);

        if (!ParseUser.getCurrentUser().isNew()) {
            isEdit = true;
        }

        if (isEdit) {
            inputName.setVisibility(View.GONE);
            inputSurname.setVisibility(View.GONE);
            layoutSex.setVisibility(View.GONE);
            layoutBloodType.setVisibility(View.GONE);
            layoutRh.setVisibility(View.GONE);

            showProgress();
            User.getInstance().getUserData(new GetCallback<ParseObject>() {