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

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-27 19:54:41 +00:00 committed by Gogs
commit 72f2ac798a
12 changed files with 294 additions and 298 deletions

View File

@ -100,7 +100,6 @@ public abstract class BaseActivity
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask();
}
@ -194,7 +193,7 @@ public abstract class BaseActivity
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
startForegroundService(startIntent);
} else {
startService(startIntent);
@ -202,13 +201,11 @@ public abstract class BaseActivity
}
public void handleBackgroundTaskLifeCycle() {
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext())
&& !PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext());
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext());
if (shouldServiceRun) {
startBackgroundLocalizationTask();
} else if (PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext()) &&
!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
} else {
stopBackgroundLocalizationTask();
}
}

View File

@ -154,7 +154,7 @@ public class LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) {
ValidateUser user = new ValidateUser(email, password);
LdapUser fuser = new LdapUser(email,password,"wmi","tutor","marek","nocny","szmare@wmi.pl");
LdapUser fuser = new LdapUser(email,password,"tutor","tutor","mieszko","nocny","szmsdsdsdsdare@wmi.pl");
// disposable.add(ldapService.validate(user)
disposable.add(ldapService.fakeValidate(fuser)
.subscribeOn(Schedulers.io())

View File

@ -10,11 +10,13 @@ import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@ -42,6 +44,7 @@ import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.CoordinateService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
import com.uam.wmi.findmytutor.utils.ManualLocationUtils;
@ -95,11 +98,12 @@ public class MapActivity extends BaseActivity
private int bearingParam = 180;
private int tiltParam = 30;
private String myId;
private boolean isTutor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isTutor = PrefUtils.getIsTutor(this);
myId = PrefUtils.getUserId(getApplicationContext());
coordinateService = ApiClient.getClient(getApplicationContext())
@ -114,7 +118,7 @@ public class MapActivity extends BaseActivity
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
};
selectLocationButton = findViewById(R.id.select_location_button);
@ -126,6 +130,7 @@ public class MapActivity extends BaseActivity
//start background task
handleBackgroundTaskLifeCycle();
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
}
@Override
@ -136,13 +141,13 @@ public class MapActivity extends BaseActivity
mapboxMap.setOnMarkerClickListener(marker -> {
String id = markerUserHash.get(marker.getId());
String locationLevel = PrefUtils.getLocationLevel(getApplicationContext());
if (id.equals(myId)) {
if (id.equals(myId) && (locationLevel.equals(SharingLevel.MANUAL.toString()) || locationLevel.equals(SharingLevel.PREDEFINED.toString()))) {
selectLocationButton.setVisibility(View.GONE);
removeLocationButton.setVisibility(View.VISIBLE);
removeLocationButton.setOnClickListener(view -> {
Log.e(tag + "Manual", "manual coords sending stopped");
stopBackgroundLocalizationTask();
removeLocationButton.setVisibility(View.GONE);
@ -158,7 +163,7 @@ public class MapActivity extends BaseActivity
setToggleMapBoundsArea();
if (PrefUtils.getIsTutor(this)) {
if (isTutor) {
setOnMapLongClickListener();
}
}
@ -244,20 +249,26 @@ public class MapActivity extends BaseActivity
}
private void setOnMapLongClickListener() {
/* private void setOnMapLongClickListener() {
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
selectLocationButton.setVisibility(View.VISIBLE);
removeLocationButton.setVisibility(View.GONE);
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.my_marker);
if (tmpLocalMarker == null) {
tmpLocalMarker = mapboxMap.addMarker(new MarkerOptions()
.position(latLng)
.icon(icon)
.title("My Loc")
.setSnippet("Snipecik"));
String sharingLevel = SharingLevel.MANUAL.toString();
Icon defaultIcon = getMapIcon(sharingLevel, myId);
MarkerOptions markerOptions = new MarkerOptions()
.setIcon(defaultIcon)
.position(latLng);
tmpLocalMarker = mapboxMap.addMarker(markerOptions);
MapMarker marker = new MapMarker(tmpLocalMarker, markerOptions, defaultIcon, sharingLevel);
markerHash.put(myId, marker);
updateUserHashMap(myId, marker.getMarker().getId());
} else {
ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position",
@ -268,36 +279,13 @@ public class MapActivity extends BaseActivity
selectLocationButton.setOnClickListener((View view) -> {
if (tmpLocalMarker != null) {
// Toast instructing user to tap on the mapboxMap
// TODO PUT MANUAL CORD
try {
// droppedMarkercoordinate = new Coordinate(
// latLng.getLatitude(),
// latLng.getLongitude(),
// latLng.getAltitude(),
// "approx",
// PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
// PrefUtils.getUserId(getApplicationContext()),
// PrefUtils.getLocationLevel(getApplicationContext())
// );
manualLocationUtils.showLocationDialog("Name the location",latLng);
handleBackgroundTaskLifeCycle();
manualLocationUtils.showLocationDialog("Name the location", latLng);
startBackgroundLocalizationTask();
} catch (IllegalArgumentException e) {
Timber.e(String.valueOf(e));
}
// Toast.makeText(
// MapActivity.this,
// "Manual Locations selected!" + latLng,
// Toast.LENGTH_LONG
// ).show();
// LayoutInflater layoutInflaterAndroid = LayoutInflater.from(MapActivity.this);
// View dialogView = layoutInflaterAndroid.inflate(R.layout.feedback_modal, null);
// AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(MapActivity.this );
// alertDialogBuilderUserInput.setView(dialogView).setPositiveButton("dupa", null);
// final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
// alertDialog.show();
selectLocationButton.setVisibility(View.GONE);
mapboxMap.removeMarker(tmpLocalMarker);
tmpLocalMarker = null;
@ -305,6 +293,141 @@ public class MapActivity extends BaseActivity
});
});
}*/
private void setOnMapLongClickListener() {
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
selectLocationButton.setVisibility(View.VISIBLE);
removeLocationButton.setVisibility(View.GONE);
if (tmpLocalMarker == null) {
String sharingLevel = SharingLevel.MANUAL.toString();
Icon defaultIcon = getMapIcon(sharingLevel, myId);
MarkerOptions markerOptions = new MarkerOptions()
.setIcon(defaultIcon)
.position(latLng);
tmpLocalMarker = mapboxMap.addMarker(markerOptions);
MapMarker marker = new MapMarker(tmpLocalMarker, markerOptions, defaultIcon, sharingLevel);
updateUserHashMap(myId, marker.getMarker().getId());
} else {
ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position",
new mapUtils.LatLngEvaluator(), tmpLocalMarker.getPosition(), latLng);
markerAnimator.setDuration(2000);
markerAnimator.start();
}
selectLocationButton.setOnClickListener((View view) -> {
if (tmpLocalMarker != null) {
try {
droppedMarkercoordinate = new Coordinate(
latLng.getLatitude(),
latLng.getLongitude(),
latLng.getAltitude(),
"approx",
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
PrefUtils.getUserId(getApplicationContext()),
PrefUtils.getLocationLevel(getApplicationContext())
);
PrefUtils.putManualLocation(this, latLng);
handleBackgroundTaskLifeCycle();
} catch (IllegalArgumentException e) {
Timber.e(String.valueOf(e));
}
Toast.makeText(
MapActivity.this,
"Manual Locations selected!" + latLng,
Toast.LENGTH_LONG
).show();
selectLocationButton.setVisibility(View.GONE);
mapboxMap.removeMarker(tmpLocalMarker);
tmpLocalMarker = null;
showLocationDialog(latLng);
}
});
});
}
public void showLocationDialog(LatLng latLng) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.location_modal, null);
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this);
alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null);
alertDialogBuilderUserInput
.setPositiveButton(R.string.lbl_ok, null)
.setNegativeButton(R.string.lbl_cancel, null);
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
EditText modalUserInput = view.findViewById(R.id.feedback_input);
alertDialog.setOnShowListener(dialogInterface -> {
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
dismissButton.setOnClickListener(view1 -> alertDialog.dismiss());
sendButton.setOnClickListener(view1 -> {
String body = modalUserInput.getText().toString();
if (TextUtils.isEmpty(body)) {
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.modal_location_hint), Toast.LENGTH_SHORT).show();
modalUserInput.requestFocus();
} else {
PrefUtils.putManualLocation(getApplicationContext(), latLng);
sendLocation(body,latLng);
alertDialog.dismiss();
}
});
});
alertDialog.show();
}
private void sendLocation(String body, LatLng latLng) {
PredefinedCoordViewModel droppedMarkercoordinate = new PredefinedCoordViewModel(
latLng.getLatitude(),
latLng.getLongitude(),
latLng.getAltitude(),
PrefUtils.getUserId(getApplicationContext()),
"string",
"predefined",
body
);
PredefinedStatusesService predefinedStatusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
CompositeDisposable disposable = new CompositeDisposable();
disposable.add(predefinedStatusesService.postUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), droppedMarkercoordinate)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError));
}
private void handleResponse(List<PredefinedCoordViewModel> resp) {
Toast.makeText(getApplicationContext(), "Location saved!", Toast.LENGTH_SHORT).show();
}
private void fetchTopCoords() {
@ -364,7 +487,7 @@ public class MapActivity extends BaseActivity
Marker marker = markerHash.get(id).getMarker();
Boolean showModalAfterAnimation = false;
if(marker.isInfoWindowShown()){
if (marker.isInfoWindowShown()) {
marker.hideInfoWindow();
showModalAfterAnimation = true;
}
@ -380,12 +503,11 @@ public class MapActivity extends BaseActivity
markerAnimator.start();
coordsMap.put(id, element);
marker.setPosition(toDestination);
if(showModalAfterAnimation){
if (showModalAfterAnimation) {
mapboxMap.selectMarker(marker);
}
@ -393,8 +515,6 @@ public class MapActivity extends BaseActivity
}
} else {
//Add new marker
coordsMap.put(id, element);
@ -435,18 +555,6 @@ public class MapActivity extends BaseActivity
// For next fetch
previousCoordsIds.clear();
previousCoordsIds.addAll(currentCoordsIds);
for (Coordinate coordinate : coordsMap.values()) {
// 300000 = 5mins
if ((System.currentTimeMillis() - coordinate.getTimeStamp()) > (long) 300000) {
String id = coordinate.getUserId();
Marker markerToRemove = markerHash.get(id).getMarker();
markerHash.remove(id);
coordsMap.remove(id);
mapboxMap.removeMarker(markerToRemove);
}
}
}
@Override
@ -463,7 +571,7 @@ public class MapActivity extends BaseActivity
if (sharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.approximate_localization_marker);
} else if (sharingLevel.equals(SharingLevel.MANUAL.toString()) ||
sharingLevel.equals(SharingLevel.PREDEFINED.toString()) ) {
sharingLevel.equals(SharingLevel.PREDEFINED.toString())) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.manual_localization_marker);
} else if (id.equals(myId)) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.my_marker);
@ -649,7 +757,7 @@ public class MapActivity extends BaseActivity
for (MapMarker marker : markersToSet) {
marker.getMarker().setIcon(markedMarker);
if(markersToSet.size() == 1)
if (markersToSet.size() == 1)
mapboxMap.selectMarker(marker.getMarker());
}

View File

@ -1,12 +1,7 @@
package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
@ -16,52 +11,34 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.annimon.stream.Collector;
import com.annimon.stream.Stream;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.Feedback;
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.service.FeedbackService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.RightButtonPreference;
import com.uam.wmi.findmytutor.utils.SharingLevel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Response;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
public class SharingFragment extends PreferenceFragment {
private HashMap<Integer, String> locationLevelMapping;
private HashMap<Integer, String> statusMapping;
private PredefinedStatusesService statusesService;
private CompositeDisposable disposable;
protected Preference locationSharing;
protected Preference locationMode;
protected Preference manualLocationList;
@ -69,9 +46,18 @@ public class SharingFragment extends PreferenceFragment {
protected RightButtonPreference manualLocationButton;
protected Preference manualStatus;
protected ListPreference statusList;
protected List<PredefinedCoordViewModel> predefinedCoordsList= new ArrayList<>();
protected List<PredefinedCoordViewModel> predefinedCoordsList = new ArrayList<>();
private HashMap<Integer, String> locationLevelMapping;
private HashMap<Integer, String> statusMapping;
private PredefinedStatusesService statusesService;
private CompositeDisposable disposable;
public static SharingFragment newInstance() {
return new SharingFragment();
}
void getStatuses(CompositeDisposable disposable) {
disposable.add(statusesService.getUserPredefinedStatuses(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -80,7 +66,29 @@ public class SharingFragment extends PreferenceFragment {
public void onSuccess(List<String> strings) {
String[] statusesArray = strings.toArray(new String[strings.size()]);
setListPreferenceData(statusList.getKey(), statusesArray);
Log.d("GETSTATUSES", Arrays.toString(statusesArray));
}
@Override
public void onError(Throwable e) {
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
}
}));
}
void getLocations(CompositeDisposable disposable) {
disposable.add(statusesService.getUserPredefinedCoords(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<PredefinedCoordViewModel>>() {
@Override
public void onSuccess(List<PredefinedCoordViewModel> coords) {
List<String> names = Stream.of(coords).map(PredefinedCoordViewModel::getName).collect(com.annimon.stream.Collectors.toList());
predefinedCoordsList.addAll(coords);
String[] stringnames = names.toArray(new String[0]);
setListPreferenceData(manualLocationList.getKey(), stringnames);
}
@ -89,39 +97,9 @@ public class SharingFragment extends PreferenceFragment {
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
}
}));
}
void getLocations(CompositeDisposable disposable) {
disposable.add(statusesService.getUserPredefinedCoords(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<PredefinedCoordViewModel>>() {
@Override
public void onSuccess(List<PredefinedCoordViewModel> coords) {
PredefinedCoordViewModel [] statusesArray = (PredefinedCoordViewModel []) coords.toArray(new PredefinedCoordViewModel[0]);
// setListPreferenceData(statusList.getKey(), statusesArray);
List<String> names = Stream.of(coords).map( p -> p.getName()).collect(com.annimon.stream.Collectors.toList());
predefinedCoordsList.addAll(coords);
String [] stringnames = names.toArray(new String[0]);
Log.d("GETLOCATIONS", predefinedCoordsList.toString());
setListPreferenceData(manualLocationList.getKey(),stringnames);
Log.d("GETLOCATIONS", Arrays.toString(stringnames));
}
@Override
public void onError(Throwable e) {
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
}
}));
}
@SuppressLint("ResourceType")
@Override
public void onCreate(final Bundle savedInstanceState) {
@ -138,10 +116,11 @@ public class SharingFragment extends PreferenceFragment {
statusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
disposable = new CompositeDisposable();
getStatuses(disposable);
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) {
getLocations(disposable);
}
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
getLocations(disposable);
}
locationLevelMapping = new HashMap<Integer, String>();
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
@ -156,19 +135,19 @@ public class SharingFragment extends PreferenceFragment {
/** Main sharing switch**/
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
return true;
});
/** Sharing level list **/
// locationMode.setSummary(PrefUtils.getLocationLevel(getApplicationContext()));
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) {
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
preferenceCategory.addPreference(manualLocationList);
getLocations(disposable);
preferenceCategory.addPreference(manualLocationButton);
getLocations(disposable);
preferenceCategory.addPreference(manualLocationButton);
} else {
preferenceCategory.removePreference(manualLocationList);
@ -185,19 +164,16 @@ public class SharingFragment extends PreferenceFragment {
/** Custom manual location list change listener **/
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference;
Log.d("SELECTEDLOCATION",(lp.getEntries()[Integer.parseInt((String) newValue)].toString()));
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter( p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).single();
Log.d("SELECTEDLOCATION",temp.toString());
// LatLng latLng = new LatLng(latitude, longitude, altitude);
PrefUtils.putManualLocation(getApplicationContext(),temp.getGeoData());
// ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).single();
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData());
return true;
});
/** Button 'choose from map' button listener **/
manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
//ToDO wywołanie wybierania lokalizacji z mapy
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.hide(SharingFragment.this);
fragmentTransaction.commit();
@ -207,27 +183,18 @@ public class SharingFragment extends PreferenceFragment {
/** Status list change listener **/
statusList.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference;
CharSequence [] entries = lp.getEntries();
CharSequence[] entries = lp.getEntries();
PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]);
// PrefUtils.storeStatus(getApplicationContext(),statusMapping.get(Integer.parseInt((String) newValue)));
return true;
});
/** Custom status list change listener **/
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
// ListPreference lp = (ListPreference) findPreference("key_status_value");
// updateListPreference(lp, newValue, "manual_statuses");
// PrefUtils.storeStatus(getApplicationContext(),(String) newValue);
// statusList.setValue((String) newValue);
disposable.add(statusesService.postUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), (String) newValue)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError));
// Log.d("GETSTATUSES", "statusy po dodaniu nowego");
// getStatuses(disposable);
// CharSequence[] entriesIndexes = statusList.getEntries();
//// Log.d("GETENTRIES", Arrays.toString(entriesIndexes));
// Log.d("GETENTRIES ostatni w handle response", (String) entriesIndexes[entriesIndexes.length - 1]);
return true;
@ -235,11 +202,6 @@ public class SharingFragment extends PreferenceFragment {
}
public static SharingFragment newInstance() {
return new SharingFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
@ -248,30 +210,7 @@ public class SharingFragment extends PreferenceFragment {
return view;
}
public String getListPreferenceValue(String key) {
ListPreference lp = (ListPreference) findPreference(key);
return (String) lp.getEntry();
}
protected void updateListPreference(ListPreference lp, Object newValue, String storageKey) {
CharSequence[] entries = lp.getEntries();
Set<String> defaultEntries = new HashSet(Arrays.asList(entries));
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
Set<String> manualStatusSet = sharedPref.getStringSet(storageKey, defaultEntries);
manualStatusSet.add((String) newValue);
String[] manualStatusArr = manualStatusSet.toArray(new String[0]);
//Arrays.sort(manualStatusArr);
setListPreferenceData(lp.getKey(), manualStatusArr);
// lp.setValue((String) newValue);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putStringSet(storageKey, manualStatusSet);
editor.apply();
}
protected void setListPreferenceData(String lp_name, String [] entries) {
protected void setListPreferenceData(String lp_name, String[] entries) {
//todo bug z pustym statusem
ListPreference lp = (ListPreference) findPreference(lp_name);
lp.setEntries(entries);
@ -281,32 +220,29 @@ public class SharingFragment extends PreferenceFragment {
entryValues[i] = Integer.toString(i);
}
lp.setDefaultValue("1");
lp.setDefaultValue("0");
lp.setEntryValues(entryValues);
}
private void handleResponse(List<String> resp) {
String newStatus = resp.toArray(new String[resp.size()])[resp.size() - 1];
Log.d("GETSTATUSES new status", newStatus);
String[] statusesArray = resp.toArray(new String[resp.size()]);
setListPreferenceData(statusList.getKey(), statusesArray);
// Log.d("GETSTATUSES nowe lokalne", Arrays.toString(statusList.getEntries()));
// statusList.setValue(newStatus);
statusList.setValueIndex(resp.size() - 1);
PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() - 1));
}
private void handleError (Throwable error){
if (error instanceof HttpException) {
private void handleError(Throwable error) {
if (error instanceof HttpException) {
ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(getApplicationContext(),
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(getApplicationContext(),
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("FEEDBACK", error.getMessage());
}
} else {
Toast.makeText(getApplicationContext(),
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -25,14 +25,12 @@ 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.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
import com.uam.wmi.findmytutor.utils.Consts;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.SharingLevel;
@ -40,6 +38,8 @@ import com.uam.wmi.findmytutor.utils.mapUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -61,7 +61,8 @@ public class BackgroundLocalizationService extends Service {
private static long notify_interval = 10000;
Location mLastLocation;
Boolean stopService = false;
Intent intent;
public static String str_receiver = "background.location.broadcast";
ArrayList<String> providers = new ArrayList<String>();
LocationListener[] mLocationListeners;
@ -146,17 +147,22 @@ public class BackgroundLocalizationService extends Service {
}
if (!stopService) {
mStatusChecker = () -> {
try {
fn_getlocation();
} finally {
mHandler.postDelayed(mStatusChecker, notify_interval);
}
};
AsyncTask.execute(mStatusChecker);
Timer mTimer = new Timer();
mTimer.schedule(new TimerTaskToGetLocation(), 20, notify_interval);
intent = new Intent(str_receiver);
fn_getlocation();
}
}
private class TimerTaskToGetLocation extends TimerTask {
@Override
public void run() {
mHandler.post(BackgroundLocalizationService.this::fn_getlocation);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)

View File

@ -1,16 +1,18 @@
package com.uam.wmi.findmytutor.utils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceFragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@ -19,98 +21,41 @@ import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.activity.BaseActivity;
import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.model.Feedback;
import com.uam.wmi.findmytutor.activity.MapActivity;
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.FeedbackService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import java.util.List;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Response;
public class ManualLocationUtils {
private Context activityContext;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
import static java.security.AccessController.getContext;
public ManualLocationUtils(Context context) {
activityContext = context;
}
@SuppressLint("ValidFragment")
public class ManualLocationUtils {
private Context activityContext;
public void showLocationDialog(String subject, LatLng latLng) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(activityContext);
View view = layoutInflaterAndroid.inflate(R.layout.location_modal, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(activityContext);
alertDialogBuilderUserInput.setView(view).setPositiveButton(activityContext.getString(R.string.modal_location_send), null);
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
EditText modalUserInput = view.findViewById(R.id.feedback_input);
TextView modalTitle = view.findViewById(R.id.feedback_modal_title);
modalTitle.setText(subject);
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String body = modalUserInput.getText().toString();
if (TextUtils.isEmpty(body)) {
Toast.makeText(activityContext, activityContext.getString(R.string.modal_location_hint), Toast.LENGTH_SHORT).show();
modalUserInput.requestFocus();
} else {
PrefUtils.putManualLocation(activityContext, latLng);
sendLocation(body,latLng);
alertDialog.dismiss();
}
}
});
}
});
alertDialog.show();
}
private void sendLocation(String body, LatLng latLng) {
PredefinedCoordViewModel droppedMarkercoordinate = new PredefinedCoordViewModel(
latLng.getLatitude(),
latLng.getLongitude(),
latLng.getAltitude(),
PrefUtils.getUserId(activityContext),
"string",
"predefined",
body
);
PredefinedStatusesService predefinedStatusesService = ApiClient.getClient(activityContext).create(PredefinedStatusesService.class);
CompositeDisposable disposable = new CompositeDisposable();
disposable.add(predefinedStatusesService.postUserPredefinedCoord(PrefUtils.getUserId(activityContext),droppedMarkercoordinate)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError));
}
private void handleResponse(List<PredefinedCoordViewModel> resp) {
Toast.makeText(activityContext, "Location saved", Toast.LENGTH_SHORT).show();
}
private void handleError(Throwable error) {
if (error instanceof HttpException) {
ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(activityContext,
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
Log.d("POSTCOORDINATE", error.getMessage());
public ManualLocationUtils(Context context) {
activityContext = context;
}
} else {
Toast.makeText(activityContext,
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("POSTCOORDINATE", error.getMessage());
}
}
private void handleError(Throwable error) {
if (error instanceof HttpException) {
ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(activityContext,
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activityContext,
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -15,21 +15,30 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/feedback_input"
android:layout_marginBottom="@dimen/dimen_10"
android:layout_marginBottom="15dp"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:lineSpacingExtra="10sp"
android:text="placeholder"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<TextView
android:id="@+id/feedback_modal_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="placeholder"
android:textColor="@color/note_list_text"
android:textSize="14sp" />
<EditText
android:id="@+id/feedback_input"
android:layout_width="315dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:layout_marginTop="70dp"
android:ems="10"
android:hint="@string/modal_feedback_hint"
android:inputType="textMultiLine"
@ -55,13 +64,5 @@
android:layout_alignEnd="@+id/feedback_input"
android:textSize="14sp" />
<TextView
android:id="@+id/feedback_modal_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/feedback_input"
android:layout_alignEnd="@+id/feedback_input"
android:layout_marginEnd="0dp"
android:layout_marginBottom="-50dp"
android:textSize="14sp" />
</RelativeLayout>

View File

@ -18,7 +18,7 @@ android:paddingTop="@dimen/activity_vertical_margin">
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:text="placeholder"
android:text="@string/manual_modal_title"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
@ -34,6 +34,7 @@ android:paddingTop="@dimen/activity_vertical_margin">
android:hint="@string/modal_feedback_hint"
android:maxLength="30"
android:maxLines="1"
android:textColor="@color/note_list_text"
android:requiresFadingEdge="vertical"
android:scrollbars="vertical" />

View File

@ -24,7 +24,6 @@
android:summary="%s"
android:title="@string/title_location_level" />
<ListPreference
android:defaultValue="1"
android:key="key_manual_location_value"
android:entries="@array/manual_location_entries"
android:entryValues="@array/manual_location_values"

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/drawer_group_tutor">
<item
<!-- <item
android:id="@+id/nav_item_one"
android:icon="@drawable/ic_people_white"
android:title="@string/navigation_item_whitelist" />
<item
android:id="@+id/nav_item_two"
android:icon="@drawable/ic_people_black"
android:title="@string/navigation_item_blacklist" />
android:title="@string/navigation_item_blacklist" />-->
<item
android:id="@+id/nav_item_three"
android:icon="@drawable/outline_person_white_24dp"

View File

@ -26,7 +26,7 @@
<string name="lang_eng">Angielski</string>
<string name="lang_pol">Polski</string>
<string name="settings_language">Wybierz język</string>
<string name="mockup_location_string">\"\"</string>
<string name="pref_header_about">O aplikacji</string>
<string name="summary_about">
Jesteśmy grupą studentów, która chce pomoć w rozwoju naszego wydziału.\nDziękujemy za używanie naszej aplikacji.\nZespół FMT.!</string>

View File

@ -219,6 +219,9 @@
<string name="nav_profile">User profile</string>
<string name="remove_manual_location">Remove Manual location</string>
<string name="title_activity_tutor_tab">TutorTab</string>
<string name="manual_modal_title">Do you want to save this localization?</string>
<string name="lbl_ok">Save!</string>
<string name="lbl_cancel">Cancel!</string>
</resources>