// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java
// public class LocalDb {
// 
//     private static LocalDb instance;
// 
//     public static LocalDb getInstance() {
//         if (instance == null) {
//             instance = new LocalDb();
//         }
// 
//         return instance;
//     }
// 
//     private User currentUser;
//     private Room selectedRoom;
//     private boolean isTrackingOn;
// 
//     private LocalDb() {
//         currentUser = (User) User.getCurrentUser();
//         isTrackingOn = false;
//     }
// 
//     public User getCurrentUser() {
//         return currentUser;
//     }
// 
//     public void setCurrentUser(User currentUser) {
//         this.currentUser = currentUser;
//     }
// 
//     public Room getSelectedRoom() {
//         return selectedRoom;
//     }
// 
//     public void setSelectedRoom(Room selectedRoom) {
//         this.selectedRoom = selectedRoom;
//     }
// 
//     public boolean isTrackingOn() {
//         return isTrackingOn;
//     }
// 
//     public void setTrackingOn(boolean isTrackingOn) {
//         this.isTrackingOn = isTrackingOn;
//     }
// }
// 
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java
// @ParseClassName(Constants.USER_DETAIL_TABLE)
// public class UserDetail extends ParseObject {
// 
//     public ParseGeoPoint getLocation() {
//         return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION);
//     }
// 
//     public void setLocation(ParseGeoPoint location) {
//         put(Constants.USER_DETAIL_COL_LOCATION, location);
//     }
// 
//     public String getProvider() {
//         return getString(Constants.USER_DETAIL_COL_PROVIDER);
//     }
// 
//     public void setProvider(String provider) {
//         put(Constants.USER_DETAIL_COL_PROVIDER, provider);
//     }
// 
//     public boolean getActive() {
//         return getBoolean(Constants.USER_DETAIL_COL_ACTIVE);
//     }
// 
//     public void setActive(boolean active) {
//         put(Constants.USER_DETAIL_COL_ACTIVE, active);
//     }
// 
//     public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); }
// 
//     public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); }
// }
// 
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java
// @ParseClassName(Constants.USER_TABLE)
// public class User extends ParseUser{
// 
//     public UserDetail getUserDetail() {
//         return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL);
//     }
// 
//     public void setUserDetail(UserDetail userDetail) {
//         put(Constants.USER_COL_USER_DETAIL, userDetail);
//     }
// 
//     public Room getRoom() {
//         return (Room) getParseObject(Constants.USER_COL_ROOM);
//     }
// 
//     public void setRoom(Room room) {
//         put(Constants.USER_COL_ROOM, room);
//     }
// 
//     public ParseFile getAvatar() {
//         return getParseFile(Constants.USER_COL_AVATAR);
//     }
// 
//     public void setAvatar(ParseFile avatar) {
//         put(Constants.USER_COL_AVATAR, avatar);
//     }
// 
//     public Follow getFollow() {
//         return (Follow) getParseObject(Constants.USER_COL_FOLLOW);
//     }
// 
//     public void setFollow(Follow follow) {
//         put(Constants.USER_COL_FOLLOW, follow);
//     }
// }


import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import com.parse.ParseException;
import com.parse.ParseGeoPoint;
import bg.mentormate.academy.radarapp.data.LocalDb;
import bg.mentormate.academy.radarapp.models.UserDetail;
import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.services;




/**
 * Created by tl on 13.02.15.
 */
public class ServiceLocationListener implements LocationListener {
    private User mCurrentUser;

    public ServiceLocationListener() {
    }

    @Override
    public void onLocationChanged(Location location) {
        Log.d(ServiceLocationListener.class.getSimpleName(),
                "Provider: " +location.getProvider() + "|" +
                "Lat/Lng: " + location.getLatitude() + "/" + location.getLongitude());

        if (LocalDb.getInstance() != null) {
            mCurrentUser = LocalDb.getInstance().getCurrentUser();

            UserDetail userDetail = mCurrentUser.getUserDetail();

            userDetail.setLocation(
                    new ParseGeoPoint(
                            location.getLatitude(),
                            location.getLongitude()));

            userDetail.setProvider(location.getProvider());

            userDetail.setActive(true);
            try {
                userDetail.save();
            } catch (ParseException e) {
                Log.d(ServiceLocationListener.class.getSimpleName(),
                                e.getMessage());
            }
        }

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java
// public class LocalDb {
// 
//     private static LocalDb instance;
// 
//     public static LocalDb getInstance() {
//         if (instance == null) {
//             instance = new LocalDb();
//         }
// 
//         return instance;
//     }
// 
//     private User currentUser;
//     private Room selectedRoom;
//     private boolean isTrackingOn;
// 
//     private LocalDb() {
//         currentUser = (User) User.getCurrentUser();
//         isTrackingOn = false;
//     }
// 
//     public User getCurrentUser() {
//         return currentUser;
//     }
// 
//     public void setCurrentUser(User currentUser) {
//         this.currentUser = currentUser;
//     }
// 
//     public Room getSelectedRoom() {
//         return selectedRoom;
//     }
// 
//     public void setSelectedRoom(Room selectedRoom) {
//         this.selectedRoom = selectedRoom;
//     }
// 
//     public boolean isTrackingOn() {
//         return isTrackingOn;
//     }
// 
//     public void setTrackingOn(boolean isTrackingOn) {
//         this.isTrackingOn = isTrackingOn;
//     }
// }
// 
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java
// @ParseClassName(Constants.USER_DETAIL_TABLE)
// public class UserDetail extends ParseObject {
// 
//     public ParseGeoPoint getLocation() {
//         return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION);
//     }
// 
//     public void setLocation(ParseGeoPoint location) {
//         put(Constants.USER_DETAIL_COL_LOCATION, location);
//     }
// 
//     public String getProvider() {
//         return getString(Constants.USER_DETAIL_COL_PROVIDER);
//     }
// 
//     public void setProvider(String provider) {
//         put(Constants.USER_DETAIL_COL_PROVIDER, provider);
//     }
// 
//     public boolean getActive() {
//         return getBoolean(Constants.USER_DETAIL_COL_ACTIVE);
//     }
// 
//     public void setActive(boolean active) {
//         put(Constants.USER_DETAIL_COL_ACTIVE, active);
//     }
// 
//     public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); }
// 
//     public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); }
// }
// 
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java
// @ParseClassName(Constants.USER_TABLE)
// public class User extends ParseUser{
// 
//     public UserDetail getUserDetail() {
//         return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL);
//     }
// 
//     public void setUserDetail(UserDetail userDetail) {
//         put(Constants.USER_COL_USER_DETAIL, userDetail);
//     }
// 
//     public Room getRoom() {
//         return (Room) getParseObject(Constants.USER_COL_ROOM);
//     }
// 
//     public void setRoom(Room room) {
//         put(Constants.USER_COL_ROOM, room);
//     }
// 
//     public ParseFile getAvatar() {
//         return getParseFile(Constants.USER_COL_AVATAR);
//     }
// 
//     public void setAvatar(ParseFile avatar) {
//         put(Constants.USER_COL_AVATAR, avatar);
//     }
// 
//     public Follow getFollow() {
//         return (Follow) getParseObject(Constants.USER_COL_FOLLOW);
//     }
// 
//     public void setFollow(Follow follow) {
//         put(Constants.USER_COL_FOLLOW, follow);
//     }
// }


// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/ServiceLocationListener.java
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import com.parse.ParseException;
import com.parse.ParseGeoPoint;
import bg.mentormate.academy.radarapp.data.LocalDb;
import bg.mentormate.academy.radarapp.models.UserDetail;
import bg.mentormate.academy.radarapp.models.User;

package bg.mentormate.academy.radarapp.services;




/**
 * Created by tl on 13.02.15.
 */
public class ServiceLocationListener implements LocationListener {
    private User mCurrentUser;

    public ServiceLocationListener() {
    }

    @Override
    public void onLocationChanged(Location location) {
        Log.d(ServiceLocationListener.class.getSimpleName(),
                "Provider: " +location.getProvider() + "|" +
                "Lat/Lng: " + location.getLatitude() + "/" + location.getLongitude());

        if (LocalDb.getInstance() != null) {
            mCurrentUser = LocalDb.getInstance().getCurrentUser();

            UserDetail userDetail = mCurrentUser.getUserDetail();

            userDetail.setLocation(
                    new ParseGeoPoint(
                            location.getLatitude(),
                            location.getLongitude()));

            userDetail.setProvider(location.getProvider());

            userDetail.setActive(true);
            try {
                userDetail.save();
            } catch (ParseException e) {
                Log.d(ServiceLocationListener.class.getSimpleName(),
                                e.getMessage());
            }
        }

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    @Override