Skip to content

Commit

Permalink
Bug fixes and firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelMariages committed Nov 30, 2016
1 parent 4eddd43 commit 54aaedc
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 161 deletions.
16 changes: 12 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,36 @@ android {
applicationId "org.angelmariages.positionalertv2"
minSdkVersion 16
targetSdkVersion 25
versionCode 2
versionName "1.0.1"
versionCode 4
versionName "1.0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//compile 'com.google.firebase:firebase-database:10.0.1'
//compile 'com.google.maps.android:android-maps-utils:0.4'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.android.support:support-v4:25.0.1'
//compile 'com.google.maps.android:android-maps-utils:0.4'
testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.angelmariages.positionalertv2;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -46,38 +45,38 @@ public void disconnect() {
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
mConnected = false;
Utils.sendLog("LocationApiClient: Api disconnected");
U.sendLog("LocationApiClient: Api disconnected");
}
}

@Override
public void onConnected(@Nullable Bundle bundle) {
mConnected = true;
Utils.sendLog("GoogleApiClient connected!");
U.sendLog("GoogleApiClient connected!");
}

public Location getLocation() {
if(!Utils.checkPositionPermissions(mActivity)) {
Utils.askPositionPermissions(mActivity);
if(!U.checkPositionPermissions(mActivity)) {
U.askPositionPermissions(mActivity);
}
try {
return LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
} catch (SecurityException e) {
Utils.sendLog("LocationApiClient error: can't get permissions to ");
U.sendLog("LocationApiClient error: can't get permissions to ");
return null;
}
}

@Override
public void onConnectionSuspended(int i) {
Utils.sendLog("GoogleApiClient connection suspended");
U.sendLog("GoogleApiClient connection suspended");
mConnected = false;
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Utils.sendLog("GoogleApiClient connection failed: " + connectionResult.getErrorMessage());
U.sendLog("GoogleApiClient connection failed: " + connectionResult.getErrorMessage());
mConnected = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
/*import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;*/
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.iid.FirebaseInstanceId;

import org.angelmariages.positionalertv2.destination.Destination;
import org.angelmariages.positionalertv2.destination.DestinationDBHelper;
Expand All @@ -36,30 +36,28 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private MapFragmentManager mapFragmentManager;
private MapFragment mapFragment;

//private FirebaseAnalytics mFirebaseAnalytics;
//private DatabaseReference mDatabase;
private DatabaseReference firebaseRef;

private DestinationManager destinationManager;
private DestinationDBHelper dbHelper;
private NavigationView navigationView;
private DestinationToDBListener mToDBListener;
private String uniqueID = "non set";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

dbHelper = new DestinationDBHelper(this.getApplicationContext());
/*FirebaseApp.initializeApp(this);
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
mDatabase = firebaseDatabase.getReference();
mDatabase.child("destinations").setValue("Hola");*/
FirebaseDatabase firebaseDatabase = U.getFirebaseDatabase();
firebaseRef = firebaseDatabase.getReference();

uniqueID = FirebaseInstanceId.getInstance().getId();

Intent intent = getIntent();
if (intent.hasExtra(Utils.RINGTONE_TO_ACTIVITY)) {
String ringtone = intent.getStringExtra(Utils.RINGTONE_TO_ACTIVITY);
if (intent.hasExtra(U.RINGTONE_TO_ACTIVITY)) {
String ringtone = intent.getStringExtra(U.RINGTONE_TO_ACTIVITY);
loadStopAlarmFragment(ringtone);

} else {
Expand Down Expand Up @@ -118,14 +116,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for alarm:");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);

String ringtoneSaved = getSharedPreferences(Utils.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
.getString(Utils.RINGTONE_PREFERENCE, null);
String ringtoneSaved = getSharedPreferences(U.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
.getString(U.RINGTONE_PREFERENCE, null);
if(ringtoneSaved != null)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(ringtoneSaved));

intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
startActivityForResult(intent, Utils.RINGTONE_SELECT_RESULT);
startActivityForResult(intent, U.RINGTONE_SELECT_RESULT);
return true;
}

Expand All @@ -134,12 +132,12 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == Utils.RINGTONE_SELECT_RESULT && resultCode == RESULT_OK) {
if(requestCode == U.RINGTONE_SELECT_RESULT && resultCode == RESULT_OK) {
Uri ringtoneUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
Utils.showSToast("Ringtone selected: " + ringtone.getTitle(this), this);
getSharedPreferences(Utils.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE).edit()
.putString(Utils.RINGTONE_PREFERENCE, ringtoneUri.toString())
U.showSToast("Ringtone selected: " + ringtone.getTitle(this), this);
getSharedPreferences(U.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE).edit()
.putString(U.RINGTONE_PREFERENCE, ringtoneUri.toString())
.apply();
}
}
Expand Down Expand Up @@ -211,12 +209,9 @@ private void loadDestinationsListFragment() {
public void onAdded(Destination addedDestination) {
mToDBListener.onDestinationAdded((int) dbHelper.insertDestination(addedDestination));
destinationManager.addDestination(addedDestination);
/*Bundle args = new Bundle();
args.putString("name", addedDestination.getName());
args.putString("radius", String.valueOf(addedDestination.getRadius()));
args.putString("latitude", String.valueOf(addedDestination.getLatitude()));
args.putString("longitude", String.valueOf(addedDestination.getLongitude()));
mFirebaseAnalytics.logEvent("added_destination", args);*/

DatabaseReference push = firebaseRef.child("users").child(uniqueID).child("destinations").push();
push.setValue(addedDestination);
}

@Override
Expand Down Expand Up @@ -245,7 +240,7 @@ public void onDeleteOnReachChanged(int destinationID, boolean deleteOnReach) {
dbHelper.updateValue(destinationID, DestinationDBHelper.COLUMN_DELETEONREACH, deleteOnReach);
tmpDestination.setDeleteOnReach(deleteOnReach);
destinationManager.addDestination(tmpDestination);
Utils.showSToast(deleteOnReach ? "Destination will be deleted when reached" : "Destination will be kept when reached", this);
U.showSToast(deleteOnReach ? "Destination will be deleted when reached" : "Destination will be kept when reached", this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public void onInfoWindowClick(Marker marker) {
}

private void checkPermissions() {
if(!Utils.checkPositionPermissions(mapFragmentActivity)) {
Utils.askPositionPermissions(mapFragmentActivity);
if(!U.checkPositionPermissions(mapFragmentActivity)) {
U.askPositionPermissions(mapFragmentActivity);
} else {
setMapParameters();
}
Expand Down Expand Up @@ -189,7 +189,7 @@ private Marker setDestinationMarker(LatLng latLng) {

private void showMarkerDialog(Destination destination, final Marker marker) {
if(destination == null) {
destination = new Destination(Utils.NULL_ID,
destination = new Destination(U.NULL_ID,
null,
marker.getPosition(),
500,
Expand All @@ -209,13 +209,13 @@ public void onOkClicked(final Destination destination) {
marker.setTitle(destination.getName());
circlesByMarker.get(marker).setRadius(destination.getRadius());
marker.showInfoWindow();
if(destination.getDatabaseID() == Utils.NULL_ID) {
if(destination.getDatabaseID() == U.NULL_ID) {
mainActivity.setDestinationToDBListener(new DestinationToDBListener() {
@Override
public void onDestinationAdded(int destinationID) {
destination.setDatabaseID(destinationID);
marker.setTag(destination);
Utils.showLToast("Destination added succesfully!", mainActivity);
U.showLToast("Destination added succesfully!", mainActivity);
}
});

Expand All @@ -225,7 +225,7 @@ public void onDestinationAdded(int destinationID) {
if(destinationChangeListener != null)
destinationChangeListener.onChanged(destination);

Utils.showLToast("Destination changed succesfully!", mainActivity);
U.showLToast("Destination changed succesfully!", mainActivity);
}
}

Expand Down Expand Up @@ -257,7 +257,7 @@ public void addMarker(Destination destination) {

public void updateCamera(LatLng position, int radius) {
if(googleMap != null) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, Utils.getZoomByRadius(radius, position.latitude) - 0.5f));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, U.getZoomByRadius(radius, position.latitude) - 0.5f));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static StopAlarmFragment newInstance(String ringtone) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getArguments() != null) {
/*String ringtoneSaved = getSharedPreferences(Utils.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
.getString(Utils.RINGTONE_PREFERENCE, null);*/
/*String ringtoneSaved = getSharedPreferences(U.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
.getString(U.RINGTONE_PREFERENCE, null);*/
ringtoneSaved = getArguments().getString(ARG_RINGTONE);
startRingtone();
}
Expand All @@ -53,7 +53,7 @@ public void onViewCreated(final View view, Bundle savedInstanceState) {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(fromUser) {
if(progress > 95) {
Utils.showSToast("Stopped!", view.getContext());
U.showSToast("Stopped!", view.getContext());
stopRingtone();
getActivity().finish();
}
Expand All @@ -76,7 +76,7 @@ private void startRingtone() {
if(ringtoneSaved == null || ringtoneSaved.isEmpty()) {
ringtoneSaved = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString();
}
Utils.sendLog(ringtoneSaved);
U.sendLog(ringtoneSaved);
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(getActivity().getApplicationContext(), Uri.parse(ringtoneSaved));
Expand All @@ -88,19 +88,19 @@ private void startRingtone() {
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
Utils.sendLog("WHAT: " + i + ", EXTRA: " + i1);
U.sendLog("WHAT: " + i + ", EXTRA: " + i1);
return false;
}
});
Utils.sendLog("STARTED!!");
Utils.sendLog("URI: " + ringtoneSaved);
U.sendLog("STARTED!!");
U.sendLog("URI: " + ringtoneSaved);
} catch (IOException e) {
e.printStackTrace();
}
}

private void stopRingtone() {
Utils.sendLog("STOPPED!!");
U.sendLog("STOPPED!!");
mediaPlayer.stop();
}
}
Loading

0 comments on commit 54aaedc

Please sign in to comment.