Merge branch 'developToMapPravilnie' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-07 07:56:56 +00:00 committed by Gogs
commit 647b030b81
13 changed files with 100 additions and 65 deletions

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java" charset="UTF-8" />
</component>
</project>

View File

@ -57,6 +57,7 @@ dependencies {
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.auth0.android:jwtdecode:1.1.1' implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.annimon:stream:1.2.1' implementation 'com.annimon:stream:1.2.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
// FloatingBarMenu // FloatingBarMenu
implementation 'com.getbase:floatingactionbutton:1.10.1' implementation 'com.getbase:floatingactionbutton:1.10.1'

View File

@ -50,6 +50,10 @@
android:name=".activity.SettingsActivity" android:name=".activity.SettingsActivity"
android:label="@string/title_activity_settings" /> android:label="@string/title_activity_settings" />
<activity
android:name=".service.GoogleLocalizationActivity"
android:label="@string/title_activity_settings" />
<service <service
android:name=".service.BackgroundLocalizationService" android:name=".service.BackgroundLocalizationService"
android:exported="false" android:exported="false"

View File

@ -183,13 +183,14 @@ public abstract class BaseActivity
} }
} }
public void handleBackgroundTaskLifeCycle() { public void handleBackgroundTaskLifeCycle() {
if (PrefUtils.isEnableSharingLocalization(getApplicationContext()) Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext())
&& !PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) { && !PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext());
if (shouldServiceRun){
startBackgroundLocalizationTask(); startBackgroundLocalizationTask();
} else if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) { } else if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext()) &&
!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
stopBackgroundLocalizationTask(); stopBackgroundLocalizationTask();
} }
} }
@ -296,12 +297,6 @@ public abstract class BaseActivity
overridePendingTransition(0, 0); overridePendingTransition(0, 0);
} }
private void setFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.activity_content, fragment);
fragmentTransaction.commit();
}
private void removeFragment(Fragment fragment) { private void removeFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.hide(fragment); fragmentTransaction.hide(fragment);

View File

@ -5,31 +5,22 @@ import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.location.Location; import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.animation.LinearInterpolator; import android.view.animation.LinearInterpolator;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.annimon.stream.Stream;
import com.auth0.android.jwt.Claim;
import com.auth0.android.jwt.JWT;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.android.core.permissions.PermissionsListener; import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager; import com.mapbox.android.core.permissions.PermissionsManager;
@ -53,9 +44,6 @@ import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.sources.VectorSource; import com.mapbox.mapboxsdk.style.sources.VectorSource;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
import com.uam.wmi.findmytutor.model.JwtToken;
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.CoordinateService; import com.uam.wmi.findmytutor.service.CoordinateService;
@ -64,9 +52,10 @@ import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.mapUtils; import com.uam.wmi.findmytutor.utils.mapUtils;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -74,19 +63,19 @@ import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import timber.log.Timber; import timber.log.Timber;
import java.util.Set;
import static com.mapbox.mapboxsdk.style.layers.Property.NONE; import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
import static com.uam.wmi.findmytutor.R.id.activity_content;
public class MapActivity extends BaseActivity public class MapActivity extends BaseActivity
implements PermissionsListener, OnMapReadyCallback { implements PermissionsListener, OnMapReadyCallback {
String currentLanguage = "pl", currentLang;
private String tag = getClass().getName(); private String tag = getClass().getName();
private PermissionsManager permissionsManager; private PermissionsManager permissionsManager;
private LocationComponent locationComponent; private LocationComponent locationComponent;
@ -102,6 +91,9 @@ public class MapActivity extends BaseActivity
private Marker droppedMarker; private Marker droppedMarker;
private HashMap<String, Coordinate> coordsMap = new HashMap<>(); private HashMap<String, Coordinate> coordsMap = new HashMap<>();
private HashMap<String, Marker> markerHash = new HashMap<>(); private HashMap<String, Marker> markerHash = new HashMap<>();
private Set<String> previousCoordsIds = new HashSet<>();
private int zoomParam = 17; private int zoomParam = 17;
private int bearingParam = 180; private int bearingParam = 180;
private int tiltParam = 30; private int tiltParam = 30;
@ -109,7 +101,6 @@ public class MapActivity extends BaseActivity
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
@ -137,8 +128,6 @@ public class MapActivity extends BaseActivity
//start background task //start background task
handleBackgroundTaskLifeCycle(); handleBackgroundTaskLifeCycle();
currentLanguage = getIntent().getStringExtra(currentLang);
} }
@ -358,7 +347,38 @@ public class MapActivity extends BaseActivity
@Override @Override
public void onSuccess(List<Coordinate> coordsList) { public void onSuccess(List<Coordinate> coordsList) {
Log.e(tag, ""); if(coordsList.isEmpty()) {
Log.e(tag, "200 empty []");
mapboxMap.clear();
return;
}
ArrayList<String> tmp = new ArrayList<>();
for (Coordinate coordinate : coordsList) {
tmp.add(coordinate.getUserId());
}
Set<String> currentCoordsIds = new HashSet<>(tmp);
if (previousCoordsIds.isEmpty()){
previousCoordsIds.addAll(currentCoordsIds);
} else {
// here we clear + it returns bool if smthing was removed
if (previousCoordsIds.removeAll(currentCoordsIds)) {
for (String toRemoveId: previousCoordsIds) {
Log.e(tag+ "delete: " , "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
mapboxMap.removeMarker(markerHash.get(toRemoveId));
markerHash.remove(toRemoveId);
coordsMap.remove(toRemoveId);
}
} else {
// TODO double check when some markers api will change
Log.e(tag+ "delete: ","nothing to remove");
}
}
for (Coordinate element : coordsList) { for (Coordinate element : coordsList) {
String id = element.getUserId(); String id = element.getUserId();
@ -411,19 +431,9 @@ public class MapActivity extends BaseActivity
coordsMap.get(id).setLabel(newLabel); coordsMap.get(id).setLabel(newLabel);
} }
/* for (Coordinate coordinate : coordsMap.values()) { // For next fetch
// 300000 = 5mins previousCoordsIds.clear();
if ((System.currentTimeMillis() - coordinate.getTimeStamp()) > (long) 300000) { previousCoordsIds.addAll(currentCoordsIds);
String id = coordinate.getUserId();
Marker markerToRemove = markerHash.get(id);
markerHash.remove(id);
coordsMap.remove(id);
mapboxMap.removeMarker(markerToRemove);
}
}*/
} }
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")

View File

@ -52,6 +52,13 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
addPreferencesFromResource(R.layout.pref_main); addPreferencesFromResource(R.layout.pref_main);
Preference languagesList = findPreference(getResources().getString(R.string.key_language)); Preference languagesList = findPreference(getResources().getString(R.string.key_language));
languagesList.setDefaultValue(0);
if(PrefUtils.getLocale(getActivity()).equals("pl")){
languagesList.setDefaultValue(1);
}
languagesList.setOnPreferenceChangeListener((preference, newValue) -> { languagesList.setOnPreferenceChangeListener((preference, newValue) -> {

View File

@ -46,8 +46,4 @@ public class StartupActivity extends AppCompatActivity {
finish(); finish();
} }
} }

View File

@ -105,7 +105,6 @@ public class UsersListFragment extends Fragment {
} }
})); }));
} }
public void searchUser(String textToSearch) { public void searchUser(String textToSearch) {
@ -217,11 +216,13 @@ public class UsersListFragment extends Fragment {
} }
private void showError(Throwable e) { private void showError(Throwable e) {
String message = e.toString(); String message;
if (e instanceof HttpException) { if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody(); ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody); message = RestApiHelper.getErrorMessage(responseBody);
}else{
message = "Network Error !";
} }
Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG) Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG)

View File

@ -23,6 +23,9 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
@ -31,6 +34,7 @@ import com.uam.wmi.findmytutor.utils.RestApiHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -58,6 +62,7 @@ public class BackgroundLocalizationService extends Service {
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private HandlerThread mHandlerThread = null; private HandlerThread mHandlerThread = null;
private Runnable mStatusChecker; private Runnable mStatusChecker;
private FusedLocationProviderClient mFusedLocationClient;
public BackgroundLocalizationService() { public BackgroundLocalizationService() {
providers.add(LocationManager.GPS_PROVIDER); providers.add(LocationManager.GPS_PROVIDER);
@ -107,6 +112,9 @@ public class BackgroundLocalizationService extends Service {
startForeground(1001, notification); startForeground(1001, notification);
} }
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
initializeLocationManager(); initializeLocationManager();
Integer providerIndex = 0; Integer providerIndex = 0;
@ -194,8 +202,21 @@ public class BackgroundLocalizationService extends Service {
Log.e("Best localization:", String.valueOf(bestLocation)); Log.e("Best localization:", String.valueOf(bestLocation));
if (bestLocation != null) /* if (bestLocation != null)
fn_update(bestLocation); fn_update(bestLocation);
*/
mFusedLocationClient.getLastLocation().addOnSuccessListener(
new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
mLastLocation = location;
fn_update(location);
}
}
});
} }
private void fn_update(Location location) { private void fn_update(Location location) {
@ -321,7 +342,5 @@ public class BackgroundLocalizationService extends Service {
return null; return null;
} }
} }
} }

View File

@ -20,7 +20,6 @@ public class PrefUtils {
return context.getSharedPreferences("com.uam.wmi.findmytutor_preferences", Context.MODE_PRIVATE); return context.getSharedPreferences("com.uam.wmi.findmytutor_preferences", Context.MODE_PRIVATE);
} }
public static void getAllKeys(Context context){ public static void getAllKeys(Context context){
Map<String,?> keys = getSharedPreferences(context).getAll(); Map<String,?> keys = getSharedPreferences(context).getAll();
@ -35,9 +34,6 @@ public class PrefUtils {
editor.clear().apply(); editor.clear().apply();
} }
public static void storeApiKey(Context context, String apiKey) { public static void storeApiKey(Context context, String apiKey) {
SharedPreferences.Editor editor = getSharedPreferences(context).edit(); SharedPreferences.Editor editor = getSharedPreferences(context).edit();
editor.putString("API_KEY", apiKey); editor.putString("API_KEY", apiKey);
@ -150,5 +146,4 @@ public class PrefUtils {
editor.putBoolean("BACKGROUND_SERVICE_STATUS", status); editor.putBoolean("BACKGROUND_SERVICE_STATUS", status);
editor.apply(); editor.apply();
} }
} }

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
</selector>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
</selector>

View File

@ -168,9 +168,9 @@
<string name="title_activity_main2">Main2Activity</string> <string name="title_activity_main2">Main2Activity</string>
<!--PulsingLayerOpacityColorActivity activity--> <!--PulsingLayerOpacityColorActivity activity-->
<string name="fab_title_hotels">Hotels</string> <string name="fab_title_hotels">TODO</string>
<string name="fab_title_parks">Parks</string> <string name="fab_title_parks">THIS</string>
<string name="fab_title_attractions">Attractions</string> <string name="fab_title_attractions">TOO</string>
<string name="select_a_location">Select a location</string> <string name="select_a_location">Select a location</string>
<string name="user_location_permission_explanation">This app needs location permissions in order to show its functionality.</string> <string name="user_location_permission_explanation">This app needs location permissions in order to show its functionality.</string>
<string name="user_location_permission_not_granted">You didn\'t grant location permissions.</string> <string name="user_location_permission_not_granted">You didn\'t grant location permissions.</string>
@ -189,5 +189,10 @@
<string name="action_log_in">Log in </string> <string name="action_log_in">Log in </string>
<string name="user_list_nav">Users list</string> <string name="user_list_nav">Users list</string>
<string name="error_invalid_login_name">Invalid login format.</string> <string name="error_invalid_login_name">Invalid login format.</string>
<string name="title_locale_utils">Locale utils</string>
<string name="permission_denied_explanation">Permission denied</string>
<string name="permission_rationale">permission should be granted</string>
<string name="launch_activity" />
<string name="remove_location_updates" />
</resources> </resources>