Fix manual pop up windows

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-27 19:52:36 +01:00
parent 66dba76ed4
commit ab74f0b7e1
8 changed files with 202 additions and 176 deletions

View File

@ -202,13 +202,11 @@ public abstract class BaseActivity
} }
public void handleBackgroundTaskLifeCycle() { public void handleBackgroundTaskLifeCycle() {
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()) Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext());
&& !PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext());
if (shouldServiceRun) { if (shouldServiceRun) {
startBackgroundLocalizationTask(); startBackgroundLocalizationTask();
} else if (PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext()) && } else {
!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
stopBackgroundLocalizationTask(); stopBackgroundLocalizationTask();
} }
} }

View File

@ -10,11 +10,13 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
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.text.TextUtils;
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.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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.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;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.FeedbackUtils; import com.uam.wmi.findmytutor.utils.FeedbackUtils;
import com.uam.wmi.findmytutor.utils.ManualLocationUtils; import com.uam.wmi.findmytutor.utils.ManualLocationUtils;
@ -115,7 +118,7 @@ public class MapActivity extends BaseActivity
} finally { } finally {
mHandler.postDelayed(mStatusChecker, mInterval); mHandler.postDelayed(mStatusChecker, mInterval);
} }
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
}; };
selectLocationButton = findViewById(R.id.select_location_button); selectLocationButton = findViewById(R.id.select_location_button);
@ -127,6 +130,7 @@ public class MapActivity extends BaseActivity
//start background task //start background task
handleBackgroundTaskLifeCycle(); handleBackgroundTaskLifeCycle();
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
} }
@Override @Override
@ -144,7 +148,6 @@ public class MapActivity extends BaseActivity
removeLocationButton.setVisibility(View.VISIBLE); removeLocationButton.setVisibility(View.VISIBLE);
removeLocationButton.setOnClickListener(view -> { removeLocationButton.setOnClickListener(view -> {
Log.e(tag + "Manual", "manual coords sending stopped");
stopBackgroundLocalizationTask(); stopBackgroundLocalizationTask();
removeLocationButton.setVisibility(View.GONE); removeLocationButton.setVisibility(View.GONE);
@ -159,6 +162,7 @@ public class MapActivity extends BaseActivity
}); });
setToggleMapBoundsArea(); setToggleMapBoundsArea();
if (isTutor) { if (isTutor) {
setOnMapLongClickListener(); setOnMapLongClickListener();
} }
@ -245,20 +249,26 @@ public class MapActivity extends BaseActivity
} }
private void setOnMapLongClickListener() { /* private void setOnMapLongClickListener() {
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> { mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
selectLocationButton.setVisibility(View.VISIBLE); selectLocationButton.setVisibility(View.VISIBLE);
removeLocationButton.setVisibility(View.GONE); removeLocationButton.setVisibility(View.GONE);
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.my_marker);
if (tmpLocalMarker == null) { if (tmpLocalMarker == null) {
tmpLocalMarker = mapboxMap.addMarker(new MarkerOptions() String sharingLevel = SharingLevel.MANUAL.toString();
.position(latLng) Icon defaultIcon = getMapIcon(sharingLevel, myId);
.icon(icon)
.title("My Loc") MarkerOptions markerOptions = new MarkerOptions()
.setSnippet("Snipecik")); .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 { } else {
ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position", ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position",
@ -269,36 +279,13 @@ public class MapActivity extends BaseActivity
selectLocationButton.setOnClickListener((View view) -> { selectLocationButton.setOnClickListener((View view) -> {
if (tmpLocalMarker != null) { if (tmpLocalMarker != null) {
// Toast instructing user to tap on the mapboxMap
// TODO PUT MANUAL CORD
try { 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); manualLocationUtils.showLocationDialog("Name the location", latLng);
handleBackgroundTaskLifeCycle(); startBackgroundLocalizationTask();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Timber.e(String.valueOf(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); selectLocationButton.setVisibility(View.GONE);
mapboxMap.removeMarker(tmpLocalMarker); mapboxMap.removeMarker(tmpLocalMarker);
tmpLocalMarker = null; 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() { private void fetchTopCoords() {

View File

@ -72,6 +72,7 @@ public class SharingFragment extends PreferenceFragment {
protected List<PredefinedCoordViewModel> predefinedCoordsList= new ArrayList<>(); protected List<PredefinedCoordViewModel> predefinedCoordsList= new ArrayList<>();
void getStatuses(CompositeDisposable disposable) { void getStatuses(CompositeDisposable disposable) {
disposable.add(statusesService.getUserPredefinedStatuses(PrefUtils.getUserId(getApplicationContext())) disposable.add(statusesService.getUserPredefinedStatuses(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -80,14 +81,11 @@ public class SharingFragment extends PreferenceFragment {
public void onSuccess(List<String> strings) { public void onSuccess(List<String> strings) {
String[] statusesArray = strings.toArray(new String[strings.size()]); String[] statusesArray = strings.toArray(new String[strings.size()]);
setListPreferenceData(statusList.getKey(), statusesArray); setListPreferenceData(statusList.getKey(), statusesArray);
Log.d("GETSTATUSES", Arrays.toString(statusesArray));
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
} }
})); }));
@ -101,15 +99,11 @@ public class SharingFragment extends PreferenceFragment {
@Override @Override
public void onSuccess(List<PredefinedCoordViewModel> coords) { public void onSuccess(List<PredefinedCoordViewModel> coords) {
PredefinedCoordViewModel [] statusesArray = (PredefinedCoordViewModel []) coords.toArray(new PredefinedCoordViewModel[0]); List<String> names = Stream.of(coords).map(PredefinedCoordViewModel::getName).collect(com.annimon.stream.Collectors.toList());
// setListPreferenceData(statusList.getKey(), statusesArray);
List<String> names = Stream.of(coords).map( p -> p.getName()).collect(com.annimon.stream.Collectors.toList());
predefinedCoordsList.addAll(coords); predefinedCoordsList.addAll(coords);
String [] stringnames = names.toArray(new String[0]); String [] stringnames = names.toArray(new String[0]);
Log.d("GETLOCATIONS", predefinedCoordsList.toString());
setListPreferenceData(manualLocationList.getKey(),stringnames); 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(); 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); statusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
disposable = new CompositeDisposable(); disposable = new CompositeDisposable();
getStatuses(disposable); getStatuses(disposable);
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) { if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) {
getLocations(disposable); getLocations(disposable);
} }
locationLevelMapping = new HashMap<Integer, String>(); locationLevelMapping = new HashMap<Integer, String>();
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString()); locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString()); locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
@ -156,11 +150,11 @@ public class SharingFragment extends PreferenceFragment {
/** Main sharing switch**/ /** Main sharing switch**/
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> { locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue); PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
return true; return true;
}); });
/** Sharing level list **/ /** Sharing level list **/
// locationMode.setSummary(PrefUtils.getLocationLevel(getApplicationContext()));
locationMode.setOnPreferenceChangeListener((preference, newValue) -> { locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) 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 **/ /** Custom manual location list change listener **/
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> { manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference; 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(); 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()); PrefUtils.putManualLocation(getApplicationContext(),temp.getGeoData());
// ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle(); // ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
return true; return true;
}); });
/** Button 'choose from map' button listener **/ /** Button 'choose from map' button listener **/
manualLocationButton.setOnPreferenceChangeListener((preference, o) -> { manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
//ToDO wywołanie wybierania lokalizacji z mapy
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.hide(SharingFragment.this); fragmentTransaction.hide(SharingFragment.this);
fragmentTransaction.commit(); fragmentTransaction.commit();
@ -209,25 +201,16 @@ public class SharingFragment extends PreferenceFragment {
ListPreference lp = (ListPreference) preference; ListPreference lp = (ListPreference) preference;
CharSequence [] entries = lp.getEntries(); CharSequence [] entries = lp.getEntries();
PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]); PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]);
// PrefUtils.storeStatus(getApplicationContext(),statusMapping.get(Integer.parseInt((String) newValue)));
return true; return true;
}); });
/** Custom status list change listener **/ /** Custom status list change listener **/
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { 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) disposable.add(statusesService.postUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), (String) newValue)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .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; return true;
@ -248,29 +231,6 @@ public class SharingFragment extends PreferenceFragment {
return view; 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 //todo bug z pustym statusem
ListPreference lp = (ListPreference) findPreference(lp_name); ListPreference lp = (ListPreference) findPreference(lp_name);
@ -281,23 +241,21 @@ public class SharingFragment extends PreferenceFragment {
entryValues[i] = Integer.toString(i); entryValues[i] = Integer.toString(i);
} }
lp.setDefaultValue("1"); lp.setDefaultValue("0");
lp.setEntryValues(entryValues); lp.setEntryValues(entryValues);
} }
private void handleResponse(List<String> resp) { 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()]); String[] statusesArray = resp.toArray(new String[resp.size()]);
setListPreferenceData(statusList.getKey(), statusesArray); setListPreferenceData(statusList.getKey(), statusesArray);
// Log.d("GETSTATUSES nowe lokalne", Arrays.toString(statusList.getEntries()));
// statusList.setValue(newStatus);
statusList.setValueIndex(resp.size() - 1); statusList.setValueIndex(resp.size() - 1);
PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() -1 ));
} }
private void handleError (Throwable error){ private void handleError (Throwable error){
if (error instanceof HttpException) { if (error instanceof HttpException) {
ResponseBody responseBody = ((HttpException) error).response().errorBody(); ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show(); RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();

View File

@ -1,16 +1,18 @@
package com.uam.wmi.findmytutor.utils; 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.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.preference.PreferenceFragment;
import android.os.Build;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils; import android.text.TextUtils;
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.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -19,22 +21,22 @@ import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.activity.BaseActivity; import com.uam.wmi.findmytutor.activity.BaseActivity;
import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.activity.MapActivity;
import com.uam.wmi.findmytutor.model.Feedback;
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel; import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.FeedbackService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService; import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import java.util.List; import java.util.List;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Response;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
import static java.security.AccessController.getContext;
@SuppressLint("ValidFragment")
public class ManualLocationUtils { public class ManualLocationUtils {
private Context activityContext; private Context activityContext;
@ -42,61 +44,7 @@ public class ManualLocationUtils {
activityContext = context; activityContext = context;
} }
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) { private void handleError(Throwable error) {
if (error instanceof HttpException) { if (error instanceof HttpException) {
@ -104,13 +52,10 @@ public class ManualLocationUtils {
ResponseBody responseBody = ((HttpException) error).response().errorBody(); ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(activityContext, Toast.makeText(activityContext,
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show(); RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
Log.d("POSTCOORDINATE", error.getMessage());
} else { } else {
Toast.makeText(activityContext, Toast.makeText(activityContext,
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show(); "Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("POSTCOORDINATE", error.getMessage());
} }
} }
} }

View File

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

View File

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

View File

@ -26,7 +26,7 @@
<string name="lang_eng">Angielski</string> <string name="lang_eng">Angielski</string>
<string name="lang_pol">Polski</string> <string name="lang_pol">Polski</string>
<string name="settings_language">Wybierz język</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="pref_header_about">O aplikacji</string>
<string name="summary_about"> <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> 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="nav_profile">User profile</string>
<string name="remove_manual_location">Remove Manual location</string> <string name="remove_manual_location">Remove Manual location</string>
<string name="title_activity_tutor_tab">TutorTab</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> </resources>