Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 422
versionName "4.2.2"
versionCode 423
versionName "4.2.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,18 @@
import android.support.v4.util.LruCache;
import android.util.Log;

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

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cc.softwarefactory.lokki.android.models.BuzzPlace;
import cc.softwarefactory.lokki.android.models.Contact;
import cc.softwarefactory.lokki.android.models.JSONMap;
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.JsonUtils;
import cc.softwarefactory.lokki.android.utilities.PreferenceUtils;

public class MainApplication extends Application {
Expand Down Expand Up @@ -156,8 +149,6 @@ public void setIdMapping(Map<String, String> idMapping) {

public static boolean locationDisabledPromptShown;

public static List<BuzzPlace> buzzPlaces;

public static boolean firstTimeZoom = true;

@Override
Expand Down Expand Up @@ -196,8 +187,6 @@ protected int sizeOf(String key, Bitmap bitmap) {
.build());
}

buzzPlaces = new ArrayList<>();

user = new MainUser(this);

super.onCreate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,39 @@
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;

import cc.softwarefactory.lokki.android.MainApplication;
import cc.softwarefactory.lokki.android.R;
import cc.softwarefactory.lokki.android.fragments.PlacesFragment;
import cc.softwarefactory.lokki.android.models.BuzzPlace;
import cc.softwarefactory.lokki.android.utilities.Utils;
import cc.softwarefactory.lokki.android.models.Place;
import cc.softwarefactory.lokki.android.services.PlaceService;

public class BuzzActivity extends AppCompatActivity {
private static final String TAG = "BuzzActivity";

private PlaceService placeService;

@Override
protected void onStart() {
super.onStart();
placeService = new PlaceService(this);
try {
checkForActiveBuzzes();
} catch (JSONException e) {
e.printStackTrace();
}
}

public static void removeBuzz(String id) {
for (Iterator<BuzzPlace> it = MainApplication.buzzPlaces.iterator(); it.hasNext();) {
BuzzPlace buzzPlace = it.next();
if (buzzPlace.getPlaceId().equals(id))
MainApplication.buzzPlaces.remove(buzzPlace);
}
}

public static void setBuzz(String id, int buzzCount) {
removeBuzz(id);
BuzzPlace buzzPlace = new BuzzPlace();
buzzPlace.setPlaceId(id);
buzzPlace.setBuzzCount(buzzCount);
MainApplication.buzzPlaces.add(buzzPlace);
}

public static BuzzPlace getBuzz(String id) {
for (BuzzPlace buzzPlace : MainApplication.buzzPlaces) {
if (buzzPlace.getPlaceId().equals(id))
return buzzPlace;
}
return null;
}

private void checkForActiveBuzzes() throws JSONException {
Log.d(TAG, "Checking for active buzzes...");
for (BuzzPlace buzzPlace : MainApplication.buzzPlaces) {
if (buzzPlace.isActivated())
openBuzzTerminationDialog(buzzPlace);
for (Place place : placeService.getPlacesWithBuzz()) {
if (place.getBuzzObject().isActivated()) {
openBuzzTerminationDialog(place);
return;
}
}
this.finish();
}

public void openBuzzTerminationDialog(final BuzzPlace placeBuzz) {
public void openBuzzTerminationDialog(final Place place) {
Log.d(TAG, "Opening termination dialog");
final Activity thisActivity = this;
Dialog buzzTerminationDialog = new android.app.AlertDialog.Builder(this)
Expand All @@ -74,7 +49,8 @@ public void openBuzzTerminationDialog(final BuzzPlace placeBuzz) {
public void onClick(DialogInterface dialogInterface, int which) {
try {
Log.d(TAG, "Removed buzz");
setBuzz(placeBuzz.getPlaceId(), 0);
Place.Buzz buzz = place.getBuzzObject();
buzz.setBuzzCount(0);
thisActivity.finish();
} catch (Exception e) {
Log.e(TAG, "Unable to terminate buzzing.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import cc.softwarefactory.lokki.android.androidServices.LocationService;
import cc.softwarefactory.lokki.android.models.Contact;
import cc.softwarefactory.lokki.android.services.ContactService;
import cc.softwarefactory.lokki.android.services.PlaceService;
import cc.softwarefactory.lokki.android.utilities.AnalyticsUtils;
import cc.softwarefactory.lokki.android.utilities.PreferenceUtils;
import cc.softwarefactory.lokki.android.utilities.ServerApi;
Expand Down Expand Up @@ -86,6 +87,8 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
private ContactService contactService;
private List<Contact> phoneContacts;

private PlaceService placeService;

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

Expand Down Expand Up @@ -123,6 +126,8 @@ public void onClick(View v) {

contactService = new ContactService(this);
phoneContacts = contactService.getPhoneContacts();

placeService = new PlaceService(this);
}

/**
Expand Down Expand Up @@ -288,7 +293,7 @@ private void unbindLocationService(){
* Call setLocationServiceAccuracyLevel() afterwards to send it to the service.
*/
private void setBackgroundLocationAccuracy(){
if (MainApplication.buzzPlaces.size() > 0){
if (placeService.getPlacesWithBuzz().size() > 0){
currentAccuracy = LocationService.LocationAccuracy.BGACCURATE;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import cc.softwarefactory.lokki.android.R;
import cc.softwarefactory.lokki.android.activities.BuzzActivity;
import cc.softwarefactory.lokki.android.activities.MainActivity;
import cc.softwarefactory.lokki.android.models.BuzzPlace;
import cc.softwarefactory.lokki.android.models.Place;
import cc.softwarefactory.lokki.android.services.PlaceService;
import cc.softwarefactory.lokki.android.utilities.PreferenceUtils;
Expand Down Expand Up @@ -336,63 +335,52 @@ private void showArrivalNotification() {
}

class VibrationThread implements Runnable {
private String id;
private Place place;

VibrationThread(String id) {
this.id = id;
VibrationThread(Place place) {
this.place = place;
}

@Override
public void run() {
BuzzPlace buzzPlace = BuzzActivity.getBuzz(id);
Place.Buzz buzz = place.getBuzzObject();
try {
while (buzzPlace != null && buzzPlace.getBuzzCount() > 0) {
while (buzz != null && buzz.getBuzzCount() > 0) {
Log.d(TAG, "Vibrating...");
Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(1000);
Thread.sleep(2500);
buzzPlace.decBuzzCount();
buzz.decBuzzCount();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

private void triggerBuzzing(final BuzzPlace buzzPlace) throws JSONException {
if (buzzPlace.getBuzzCount() <= 0 || buzzPlace.isActivated()) return;
private void triggerBuzzing(Place place) {
Place.Buzz buzz = place.getBuzzObject();
if (buzz.isActivated() || buzz.getBuzzCount() <= 0) return;

buzz.setActivated(true);

buzzPlace.setActivated(false);
Intent i = new Intent();
i.setClass(this, BuzzActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
showArrivalNotification();

Log.d(TAG, "Starting vibration...");
new Thread(new VibrationThread(buzzPlace.getPlaceId())).start();
new Thread(new VibrationThread(place)).start();
}

private void checkBuzzPlaces() {
for (BuzzPlace buzzPlace : MainApplication.buzzPlaces) {
try {
String placeId = buzzPlace.getPlaceId();
Place place = placeService.getPlaceById(placeId);
//create android location from Place location information
Location placeLocation = new Location(placeId);
placeLocation.setLatitude(place.getLocation().getLat());
placeLocation.setLongitude((place.getLocation().getLon()));
if (placeLocation.distanceTo(lastLocation) < place.getLocation().getAcc())
triggerBuzzing(buzzPlace);
else {
buzzPlace.setBuzzCount(5);
buzzPlace.setActivated(false);
}
} catch (JSONException e) {
Log.e(TAG,"Error in checking buzz places" + e);
for (Place place : placeService.getPlacesWithBuzz()) {
if (place.getLocation().convertToAndroidLocation().distanceTo(lastLocation) < place.getLocation().getAcc()) {
triggerBuzzing(place);
} else {
place.setBuzzObject(PlaceService.createBuzz());
}
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@

import cc.softwarefactory.lokki.android.MainApplication;
import cc.softwarefactory.lokki.android.R;
import cc.softwarefactory.lokki.android.activities.BuzzActivity;
import cc.softwarefactory.lokki.android.androidServices.DataService;
import cc.softwarefactory.lokki.android.models.BuzzPlace;
import cc.softwarefactory.lokki.android.models.Contact;
import cc.softwarefactory.lokki.android.models.Place;
import cc.softwarefactory.lokki.android.models.Person;
Expand Down Expand Up @@ -135,17 +133,14 @@ public void onClick(View v) {
}
});
Log.d(TAG, "Setting up checkbox callback");
final String placeId = place.getId();

aq.id(R.id.buzz_checkBox).checked(place.isBuzz());

aq.id(R.id.buzz_checkBox).clicked(new View.OnClickListener() {
@Override
public void onClick(final View view) {

if (((CheckBox) view).isChecked()) {
// This ensures that automatic UI refresh won't uncheck the checkbox
// while the the dialog is still open.
BuzzActivity.setBuzz(placeId, 0);

Dialog dialog = new AlertDialog.Builder(getActivity())
.setMessage(R.string.confirm_buzz)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
Expand All @@ -154,13 +149,13 @@ public void onClick(DialogInterface dialogInterface, int which) {
AnalyticsUtils.eventHit(getString(R.string.analytics_category_ux),
getString(R.string.analytics_action_click),
getString(R.string.analytics_label_buzz_turn_on));
BuzzActivity.setBuzz(placeId, 5);
placeService.setBuzz(place, true);
((CheckBox) view).setChecked(true);
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
BuzzActivity.removeBuzz(placeId);
((CheckBox) view).setChecked(false);
placesFragment.showPlaces(); // Update UI for tests
AnalyticsUtils.eventHit(getString(R.string.analytics_category_ux),
Expand All @@ -171,17 +166,12 @@ public void onClick(DialogInterface dialogInterface, int which) {
dialog.setCanceledOnTouchOutside(false);
dialog.show();
} else {
BuzzActivity.removeBuzz(placeId);
placeService.setBuzz(place, false);
}

}
});

for (BuzzPlace buzzPlace : MainApplication.buzzPlaces) {
if (buzzPlace.getPlaceId().equals(placeId))
aq.id(R.id.buzz_checkBox).checked(true);
}

Log.d(TAG, "Place name: " + place.getName());
Log.d(TAG, "peopleInsidePlace? " + peopleInsidePlace.containsKey(place));

Expand Down Expand Up @@ -420,7 +410,6 @@ private void calculatePeopleInside(Place place) {
// Compare location
float distance = placeLocation.distanceTo(contactLocation);
if (distance < placeLocation.getAccuracy()) {
//Log.d(TAG, email + " is in place: " + placeLocation.getProvider());
peopleInThisPlace.add(contact);
}
}
Expand Down

This file was deleted.

Loading