Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.support.v4.util.LruCache;
import android.util.Log;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.android.gms.maps.GoogleMap;

import java.util.ArrayList;
Expand All @@ -21,7 +20,6 @@
import cc.softwarefactory.lokki.android.models.Contact;
import cc.softwarefactory.lokki.android.models.MainUser;
import cc.softwarefactory.lokki.android.models.Place;
import cc.softwarefactory.lokki.android.models.User;
import cc.softwarefactory.lokki.android.utilities.AnalyticsUtils;
import cc.softwarefactory.lokki.android.utilities.PreferenceUtils;

Expand All @@ -41,103 +39,19 @@ public class MainApplication extends Application {
* Int array enumerating the codes used for different Google Maps map view types
*/
public static final int[] mapTypes = {GoogleMap.MAP_TYPE_NORMAL, GoogleMap.MAP_TYPE_SATELLITE, GoogleMap.MAP_TYPE_HYBRID};

/**
* Currently selected Google Maps map view type.
* TODO: make private with proper accessor methods to disallow values not in mapTypes
*/
public static int mapType = 0;
public static String emailBeingTracked;
/**
* User dashboard JSON object. Format:
* {
* "battery":"",
* "canseeme":["c429003ba3a3c508cba1460607ab7f8cd4a0d450"],
* "icansee":{
* "c429003ba3a3c508cba1460607ab7f8cd4a0d450":{
* "battery":"",
* "location":{},
* "visibility":true
* }
* },
* "idmapping":{
* "a1b2c3d4e5f6g7h8i9j10k11l12m13n14o15p16q":"test@test.com",
* "c429003ba3a3c508cba1460607ab7f8cd4a0d450":"family.member@example.com"
* },
* "location":{},
* "visibility":true
* }
*/
public static class Dashboard extends User {
/**
* List of user ids that can see me
*/
@JsonProperty("canseeme")
private List<String> canSeeMe;

/**
* Map where key is user id and value is the user object. Users that I can see.
*/
@JsonProperty("icansee")
private Map<String, User> iCanSee;

/**
* Map between user ids and email addresses.
*/
@JsonProperty("idmapping")
private Map<String, String> idMapping;

public List<String> getUserIdsICanSee() {
return new ArrayList<String>(iCanSee.keySet());
}

public List<String> getUserIds() {
return new ArrayList<String>(idMapping.keySet());
}

public String getEmailByUserId(String userId) {
return idMapping.get(userId);
}

public boolean containsEmail(String email) {
for (String containedEmail : idMapping.values()) {
if (email.equals(containedEmail)) return true;
}
return false;
}

public User getUserICanSeeByUserId(String userId) {
return iCanSee.get(userId);
}

public List<String> getCanSeeMe() {
return canSeeMe;
}

public void setCanSeeMe(List<String> canSeeMe) {
this.canSeeMe = canSeeMe;
}

public Map<String, User> getiCanSee() {
return iCanSee;
}

public void setiCanSee(Map<String, User> iCanSee) {
this.iCanSee = iCanSee;
}

public Map<String, String> getIdMapping() {
return idMapping;
}

public void setIdMapping(Map<String, String> idMapping) {
this.idMapping = idMapping;
}
}
public static Dashboard dashboard = null;
public static String emailBeingTracked;

public static MainUser user;

public static List<Contact> contacts;

/**
* Is the user visible to others?
*/
Expand Down Expand Up @@ -187,8 +101,6 @@ protected int sizeOf(String key, Bitmap bitmap) {
.build());
}

user = new MainUser(this);

super.onCreate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import android.support.v7.widget.SearchView;
import android.widget.Toast;

import cc.softwarefactory.lokki.android.models.MainUser;
import cc.softwarefactory.lokki.android.services.UserService;
import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
Expand Down Expand Up @@ -89,6 +91,8 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF

private PlaceService placeService;

private UserService userService;

//Is this activity currently paused?
private boolean paused = true;

Expand Down Expand Up @@ -219,9 +223,9 @@ protected void onResume() {
LocalBroadcastManager.getInstance(this).registerReceiver(serverErrorReceiver, new IntentFilter("SERVER-ERROR"));

Log.i(TAG, "onResume - check if dashboard is null");
if (MainApplication.dashboard == null) {
if (MainApplication.user == null) {
Log.w(TAG, "onResume - dashboard was null, get dashboard from server");
ServerApi.getDashboard(getApplicationContext());
userService.getDashBoard();
}
if (MainApplication.contacts == null) {
Log.w(TAG, "onResume - dashboard was null, get contacts from server");
Expand Down Expand Up @@ -378,6 +382,7 @@ private void signUserIn() {
finish();
}
} else { // User already logged-in
if (MainApplication.user == null) MainApplication.user = new MainUser(this);
MainApplication.user.setEmail(PreferenceUtils.getString(this, PreferenceUtils.KEY_USER_ACCOUNT));
((NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer)).setUserInfo();
GcmHelper.start(getApplicationContext()); // Register to GCM
Expand Down Expand Up @@ -729,7 +734,6 @@ public void onClick(DialogInterface dialog, int which){
PreferenceUtils.setString(main, PreferenceUtils.KEY_LOCAL_CONTACTS, null);
PreferenceUtils.setString(main, PreferenceUtils.KEY_PLACES, null);
MainApplication.user = null;
MainApplication.dashboard = null;
MainApplication.contacts = null;
MainApplication.places = null;
MainApplication.firstTimeZoom = true;
Expand All @@ -751,7 +755,6 @@ public void logoutSilent(){
PreferenceUtils.setString(main, PreferenceUtils.KEY_LOCAL_CONTACTS, null);
PreferenceUtils.setString(main, PreferenceUtils.KEY_PLACES, null);
MainApplication.user = null;
MainApplication.dashboard = null;
MainApplication.contacts = null;
MainApplication.places = null;
MainApplication.firstTimeZoom = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ private void doSignUp() {
aq.id(R.id.email).getEditText().setError(errorMessage);
return;
}
if (MainApplication.user == null) MainApplication.user = new MainUser(getApplicationContext());
if (MainApplication.user == null) MainApplication.user = new MainUser(this);
MainApplication.user.setEmail(accountName);

PreferenceUtils.setString(this, PreferenceUtils.KEY_DEVICE_ID, Utils.getDeviceId());

ServerApi.signUp(this, new SignUpCallback());
Expand Down Expand Up @@ -155,6 +156,7 @@ public void callback(String url, JSONObject json, AjaxStatus status) {
String id = json.optString("id");
String authorizationToken = json.optString("authorizationtoken");
String userType = json.optString("userType");
if (MainApplication.user == null) MainApplication.user = new MainUser(SignUpActivity.this);
MainApplication.user.setUserId(id);
PreferenceUtils.setString(SignUpActivity.this, PreferenceUtils.KEY_AUTH_TOKEN, authorizationToken);
Log.d(TAG, "User id: " + id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
import android.util.Log;


import java.io.IOException;

import cc.softwarefactory.lokki.android.MainApplication;
import cc.softwarefactory.lokki.android.services.ContactService;
import cc.softwarefactory.lokki.android.services.PlaceService;
import cc.softwarefactory.lokki.android.utilities.JsonUtils;
import cc.softwarefactory.lokki.android.utilities.PreferenceUtils;
import cc.softwarefactory.lokki.android.services.UserService;
import cc.softwarefactory.lokki.android.utilities.ServerApi;


Expand All @@ -39,6 +35,7 @@ public class DataService extends Service {

private static PlaceService placeService;
private static ContactService contactService;
private static UserService userService;

public static void start(Context context) {
Log.d(TAG, "start Service called");
Expand Down Expand Up @@ -76,15 +73,12 @@ public void onCreate() {
super.onCreate();
setTimer();
serviceRunning = true;
try {
MainApplication.dashboard = JsonUtils.createFromJson(PreferenceUtils.getString(this.getApplicationContext(), PreferenceUtils.KEY_DASHBOARD), MainApplication.Dashboard.class);
} catch (IOException e) {
MainApplication.dashboard = null;
}

userService = new UserService(getApplicationContext());
placeService = new PlaceService(getApplicationContext());
contactService = new ContactService(getApplicationContext());

getDashboard();
getPlaces();
getContacts();
}
Expand Down Expand Up @@ -115,7 +109,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}

if (extras.containsKey(ALARM_TIMER)) {
fetchDashboard();
getDashboard();
} if (extras.containsKey(GET_PLACES)) {
getPlaces();
} if (extras.containsKey(GET_CONTACTS)) {
Expand All @@ -134,10 +128,9 @@ private void getContacts() {
contactService.getContacts();
}

private void fetchDashboard() {

private void getDashboard() {
Log.d(TAG, "alarmCallback");
ServerApi.getDashboard(this);
userService.getDashBoard();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ protected void onPostExecute(Bitmap bitmapResult) {
if (bitmapResult == null || cancelAsyncTasks || !isAdded() || map == null) {
return;
}
Person marker = null;
Person marker;
try{
marker = (Person) person.clone();
}
Expand Down

This file was deleted.

Loading