Fix manual pop up windows
This commit is contained in:
parent
66dba76ed4
commit
ab74f0b7e1
@ -202,13 +202,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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -115,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);
|
||||
@ -127,6 +130,7 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
//start background task
|
||||
handleBackgroundTaskLifeCycle();
|
||||
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -144,7 +148,6 @@ public class MapActivity extends BaseActivity
|
||||
removeLocationButton.setVisibility(View.VISIBLE);
|
||||
|
||||
removeLocationButton.setOnClickListener(view -> {
|
||||
Log.e(tag + "Manual", "manual coords sending stopped");
|
||||
stopBackgroundLocalizationTask();
|
||||
|
||||
removeLocationButton.setVisibility(View.GONE);
|
||||
@ -159,6 +162,7 @@ public class MapActivity extends BaseActivity
|
||||
});
|
||||
|
||||
setToggleMapBoundsArea();
|
||||
|
||||
if (isTutor) {
|
||||
setOnMapLongClickListener();
|
||||
}
|
||||
@ -245,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",
|
||||
@ -269,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();
|
||||
|
||||
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;
|
||||
@ -306,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() {
|
||||
|
@ -72,6 +72,7 @@ public class SharingFragment extends PreferenceFragment {
|
||||
protected List<PredefinedCoordViewModel> predefinedCoordsList= new ArrayList<>();
|
||||
|
||||
void getStatuses(CompositeDisposable disposable) {
|
||||
|
||||
disposable.add(statusesService.getUserPredefinedStatuses(PrefUtils.getUserId(getApplicationContext()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -80,14 +81,11 @@ 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();
|
||||
|
||||
}
|
||||
|
||||
}));
|
||||
@ -101,15 +99,11 @@ public class SharingFragment extends PreferenceFragment {
|
||||
|
||||
@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());
|
||||
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]);
|
||||
Log.d("GETLOCATIONS", predefinedCoordsList.toString());
|
||||
|
||||
setListPreferenceData(manualLocationList.getKey(),stringnames);
|
||||
Log.d("GETLOCATIONS", Arrays.toString(stringnames));
|
||||
|
||||
}
|
||||
|
||||
@ -118,7 +112,6 @@ public class SharingFragment extends PreferenceFragment {
|
||||
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
@ -138,10 +131,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);
|
||||
|
||||
}
|
||||
|
||||
locationLevelMapping = new HashMap<Integer, String>();
|
||||
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
|
||||
locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
|
||||
@ -156,11 +150,11 @@ 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)));
|
||||
@ -185,19 +179,17 @@ 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();
|
||||
|
||||
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();
|
||||
@ -209,25 +201,16 @@ public class SharingFragment extends PreferenceFragment {
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
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;
|
||||
@ -248,29 +231,6 @@ 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) {
|
||||
//todo bug z pustym statusem
|
||||
ListPreference lp = (ListPreference) findPreference(lp_name);
|
||||
@ -281,23 +241,21 @@ 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) {
|
||||
|
||||
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
||||
Toast.makeText(getApplicationContext(),
|
||||
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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" />
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user