Skip to content

Commit

Permalink
Release version 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Teester committed Feb 19, 2018
2 parents a2d8cf7 + a6845ca commit 5a1bcd6
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 75 deletions.
64 changes: 1 addition & 63 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 {
applicationId 'com.teester.whatsnearby'
minSdkVersion 21
targetSdkVersion 27
versionCode 10
versionName "0.10"
versionCode 11
versionName "0.11"
setProperty("archivesBaseName", "whatsnearby-$versionName")
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public void processLocation(Location location) {
lastQueryLocation = location;
}

preferences.setFloatPreference("location_accuracy", location.getAccuracy());
preferences.setFloatPreference("distance_to_last_query", location.distanceTo(lastQueryLocation));
preferences.setLongPreference("query_interval", System.currentTimeMillis() - lastQueryTime);
preferences.setFloatPreference("distance_to_last_location", location.distanceTo(lastLocation));

boolean query = true;

// Don't query Overpass if the location is less accurate than 100m
Expand All @@ -61,6 +66,10 @@ public void processLocation(Location location) {
query = false;
}

// if (BuildConfig.DEBUG) {
// query = true;
// }

if (query == true) {
lastQueryLocation = location;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;

import com.teester.whatsnearby.R;
import com.teester.whatsnearby.data.source.Preferences;
Expand All @@ -35,7 +33,7 @@ public static void createNotification(Context context, String name, int drawable
// Store the time the notification was made
SourceContract.Preferences preferences = new Preferences(context);
preferences.setLongPreference(OVERPASSLASTQUERYTIMEPREF, System.currentTimeMillis());

preferences.setLongPreference("last_notification_time", System.currentTimeMillis());
Intent resultIntent = new Intent(context, QuestionsActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

Expand Down Expand Up @@ -64,10 +62,6 @@ public static void createNotification(Context context, String name, int drawable
*/
private static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}

Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public long getLongPreference(String preference) {
public void setLongPreference(String preference, long value) {
prefs.edit().putLong(preference, value).apply();
}

@Override
public float getFloatPreference(String preference) {
return prefs.getFloat(preference, 0);
}

@Override
public void setFloatPreference(String preference, float value) {
prefs.edit().putFloat(preference, value).apply();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ public void processResult(String result) {

@Override
public void queryOverpass(double latitude, double longitude, float accuracy) {

SourceContract.Preferences preferences = new Preferences(context);
preferences.setLongPreference("last_query_time", System.currentTimeMillis());
queryLatitude = latitude;
queryLongitude = longitude;
queryAccuracy = accuracy;
String overpassUrl = getOverpassUri(latitude, longitude, accuracy);
String overpassQuery = queryOverpassApi(overpassUrl);
preferences.setStringPreference("last_query", overpassQuery);
processResult(overpassQuery);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ interface Preferences {
long getLongPreference(String preference);

void setLongPreference(String preference, long value);

float getFloatPreference(String preference);

void setFloatPreference(String preference, float value);
}

interface Overpass {
Expand Down
92 changes: 92 additions & 0 deletions app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.teester.whatsnearby.main;

import com.teester.whatsnearby.R;
import com.teester.whatsnearby.data.source.SourceContract;

public class DebugPresenter implements MainActivityContract.DebugPresenter {

private MainActivityContract.DebugView view;
private SourceContract.Preferences preferences;

public DebugPresenter(MainActivityContract.DebugView view, SourceContract.Preferences preferences) {
this.view = view;
this.preferences = preferences;
}

@Override
public void init() {

}

@Override
public void destroy() {

}

@Override
public void getDetails() {
getLastQuery();
getCheckDistance();
getLastNotificationTime();
getLastQueryTime();
getQueryDistance();
getAccuracy();
}

private void getQueryDistance() {
float preference = preferences.getFloatPreference("distance_to_last_location");
String querydistance = String.format("%.0fm", preference);
int color = R.color.green;
if (preference < 20) {
color = R.color.red;
}
view.setQuerydistance(querydistance, color);
}

private void getLastQueryTime() {
long lastQueryTime = preferences.getLongPreference("last_query_time");
long ago = (System.currentTimeMillis() - lastQueryTime) / 60000;
String lastQueryTime2 = String.format("%d mins ago", ago);
int color = R.color.green;
if (ago < 60) {
color = R.color.red;
}
view.setLastQueryTime(lastQueryTime2, color);
}

private void getLastNotificationTime() {
long lastNotificationTime = preferences.getLongPreference("last_notification_time");
long ago = (System.currentTimeMillis() - lastNotificationTime) / 60000;
int color = R.color.green;
if (ago < 60) {
color = R.color.red;
}
String lastNotificationTimeString = String.format("%d mins ago", ago);
view.setLastNotificationTime(lastNotificationTimeString, color);
}

private void getCheckDistance() {
float preference = preferences.getFloatPreference("distance_to_last_query");
String checkdistance = String.format("%.0fm", preference);
int color = R.color.green;
if (preference > 20) {
color = R.color.red;
}
view.setCheckdistance(checkdistance, color);
}

private void getLastQuery() {
String lastQuery = preferences.getStringPreference("last_query");
view.setLastQuery(lastQuery);
}

private void getAccuracy() {
float accuracy = preferences.getFloatPreference("location_accuracy");
String accuracyString = String.format("%.0fm", accuracy);
int accuracyColor = R.color.green;
if (accuracy > 50) {
accuracyColor = R.color.red;
}
view.setAccuracy(accuracyString, accuracyColor);
}
}
93 changes: 93 additions & 0 deletions app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.teester.whatsnearby.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.teester.whatsnearby.R;
import com.teester.whatsnearby.data.source.Preferences;
import com.teester.whatsnearby.data.source.SourceContract;

public class FragmentDebug extends Fragment implements MainActivityContract.DebugView {

private TextView lastQueryTime;
private TextView lastNotificationTime;
private TextView lastQuery;
private TextView accuracy;
private TextView querydistance;
private TextView checkdistance;
private MainActivityContract.DebugPresenter debugPresenter;
private SourceContract.Preferences preferences;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SourceContract.Preferences preferences = new Preferences(getContext());
debugPresenter = new DebugPresenter(this, preferences);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.fragment_debug, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.lastQueryTime = view.findViewById(R.id.textView6);
this.lastNotificationTime = view.findViewById(R.id.textView7);
this.lastQuery = view.findViewById(R.id.textView8);
this.accuracy = view.findViewById(R.id.textView16);
this.querydistance = view.findViewById(R.id.textView14);
this.checkdistance = view.findViewById(R.id.textView15);

debugPresenter.getDetails();
}

@Override
public void setLastQueryTime(String time, int color) {
this.lastQueryTime.setText(time);
this.lastQueryTime.setTextColor(getResources().getColor(color));
}

@Override
public void setLastNotificationTime(String notificationTime, int color) {
this.lastNotificationTime.setText(notificationTime);
this.lastNotificationTime.setTextColor(getResources().getColor(color));
}

@Override
public void setLastQuery(String queryTime) {
this.lastQuery.setText(queryTime);
}

@Override
public void setAccuracy(String accuracy, int color) {
this.accuracy.setText(accuracy);
this.accuracy.setTextColor(getResources().getColor(color));
}

@Override
public void setQuerydistance(String querydistance, int color) {
this.querydistance.setText(querydistance);
this.querydistance.setTextColor(getResources().getColor(color));
}

@Override
public void setCheckdistance(String queryTimeSince, int color) {
this.checkdistance.setText(queryTimeSince);
this.checkdistance.setTextColor(getResources().getColor(color));
}

@Override
public void setPresenter(MainActivityContract.DebugPresenter presenter) {

}
}
Loading

0 comments on commit 5a1bcd6

Please sign in to comment.