// Path: app/src/main/java/hr/foi/rsc/lifeline/LifeLineApplication.java
// public class LifeLineApplication extends Application {
// 
//     private static LifeLineApplication instance;
// 
//     @Override
//     public void onCreate() {
//         instance = this;
// 
//         Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
// 
//         Parse.enableLocalDatastore(getApplicationContext());
//         Parse.initialize(this, "Qz1N1B4aBwzmiszChrGKU37QalVXzZ8iew6hV2oH",
//             "kWAfX9HmPe1HRXojqj8kuPEufx0r9yXFcoCzVdAq");
//         ParseTwitterUtils.initialize("GtQtnF894a6USOPRIVZx2HWfv",
//             "yiG7Sn6ZTlVQbKSCtylH9LRmNCGA4Ir6jdNyKXdQMSGu9oQmwx");
//         ParseFacebookUtils.initialize("830133423676900");
// 
//         ParsePush.subscribeInBackground("all", new SaveCallback() {
//             @Override
//             public void done(ParseException e) {
//                 if (e == null) {
//                     Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
//                 } else {
//                     Log.e("com.parse.push", "failed to subscribe for push", e);
//                 }
//             }
//         });
//     }
// 
//     public static LifeLineApplication getInstance() {
//         return instance;
//     }
// }
// 
// 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/LoginPresenter.java
// public interface LoginPresenter extends BasePresenter {
// 
//     public void authenticateUser(String username, String password);
// 
//     public void authenticateUserFb(Activity activity);
// 
//     public void authenticateUserTwitter(Activity activity);
// 
//     public void resetPassword(String email);
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/views/LoginView.java
// public interface LoginView extends BaseView {
// 
//     public void navigateToHome();
// 
//     public void onPasswordReset();
// }


import android.app.Activity;
import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseFacebookUtils;
import com.parse.ParseTwitterUtils;
import com.parse.ParseUser;
import com.parse.RequestPasswordResetCallback;
import hr.foi.rsc.lifeline.LifeLineApplication;
import hr.foi.rsc.lifeline.R;
import hr.foi.rsc.lifeline.models.User;
import hr.foi.rsc.lifeline.mvp.presenters.LoginPresenter;
import hr.foi.rsc.lifeline.mvp.views.LoginView;
package hr.foi.rsc.lifeline.mvp.presenters.impl;




/**
 * Created by dino on 22/11/14.
 */
public class LoginPresenterImpl implements LoginPresenter {

    private boolean canceled;

    private LoginView loginView;

    public LoginPresenterImpl(LoginView loginView) {
        this.loginView = loginView;
    }

    @Override
    public void authenticateUser(String username, String password) {
        canceled = false;
        loginView.showProgress();
        ParseUser.logInInBackground(username, password, logInCallback);
    }

    @Override
    public void authenticateUserFb(Activity activity) {
        canceled = false;
        ParseFacebookUtils.logIn(activity, logInCallback);
    }

    @Override
    public void authenticateUserTwitter(Activity activity) {
        canceled = false;
        ParseTwitterUtils.logIn(activity, logInCallback);
    }

    @Override
    public void resetPassword(String email) {
// Path: app/src/main/java/hr/foi/rsc/lifeline/LifeLineApplication.java
// public class LifeLineApplication extends Application {
// 
//     private static LifeLineApplication instance;
// 
//     @Override
//     public void onCreate() {
//         instance = this;
// 
//         Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
// 
//         Parse.enableLocalDatastore(getApplicationContext());
//         Parse.initialize(this, "Qz1N1B4aBwzmiszChrGKU37QalVXzZ8iew6hV2oH",
//             "kWAfX9HmPe1HRXojqj8kuPEufx0r9yXFcoCzVdAq");
//         ParseTwitterUtils.initialize("GtQtnF894a6USOPRIVZx2HWfv",
//             "yiG7Sn6ZTlVQbKSCtylH9LRmNCGA4Ir6jdNyKXdQMSGu9oQmwx");
//         ParseFacebookUtils.initialize("830133423676900");
// 
//         ParsePush.subscribeInBackground("all", new SaveCallback() {
//             @Override
//             public void done(ParseException e) {
//                 if (e == null) {
//                     Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
//                 } else {
//                     Log.e("com.parse.push", "failed to subscribe for push", e);
//                 }
//             }
//         });
//     }
// 
//     public static LifeLineApplication getInstance() {
//         return instance;
//     }
// }
// 
// 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/LoginPresenter.java
// public interface LoginPresenter extends BasePresenter {
// 
//     public void authenticateUser(String username, String password);
// 
//     public void authenticateUserFb(Activity activity);
// 
//     public void authenticateUserTwitter(Activity activity);
// 
//     public void resetPassword(String email);
// }
// 
// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/views/LoginView.java
// public interface LoginView extends BaseView {
// 
//     public void navigateToHome();
// 
//     public void onPasswordReset();
// }


// Path: app/src/main/java/hr/foi/rsc/lifeline/mvp/presenters/impl/LoginPresenterImpl.java
import android.app.Activity;
import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseFacebookUtils;
import com.parse.ParseTwitterUtils;
import com.parse.ParseUser;
import com.parse.RequestPasswordResetCallback;
import hr.foi.rsc.lifeline.LifeLineApplication;
import hr.foi.rsc.lifeline.R;
import hr.foi.rsc.lifeline.models.User;
import hr.foi.rsc.lifeline.mvp.presenters.LoginPresenter;
import hr.foi.rsc.lifeline.mvp.views.LoginView;

package hr.foi.rsc.lifeline.mvp.presenters.impl;




/**
 * Created by dino on 22/11/14.
 */
public class LoginPresenterImpl implements LoginPresenter {

    private boolean canceled;

    private LoginView loginView;

    public LoginPresenterImpl(LoginView loginView) {
        this.loginView = loginView;
    }

    @Override
    public void authenticateUser(String username, String password) {
        canceled = false;
        loginView.showProgress();
        ParseUser.logInInBackground(username, password, logInCallback);
    }

    @Override
    public void authenticateUserFb(Activity activity) {
        canceled = false;
        ParseFacebookUtils.logIn(activity, logInCallback);
    }

    @Override
    public void authenticateUserTwitter(Activity activity) {
        canceled = false;
        ParseTwitterUtils.logIn(activity, logInCallback);
    }

    @Override
    public void resetPassword(String email) {
        ParseUser.requestPasswordResetInBackground(email, requestPasswordResetCallback);