Fix handle BG
This commit is contained in:
parent
c8145323c5
commit
f7edee0c56
@ -20,6 +20,7 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -46,6 +47,7 @@ import io.reactivex.functions.Function;
|
|||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
|
|
||||||
|
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||||
import static com.uam.wmi.findmytutor.utils.Const.defaultMapZoom;
|
import static com.uam.wmi.findmytutor.utils.Const.defaultMapZoom;
|
||||||
import static com.uam.wmi.findmytutor.utils.Const.searchMapZoom;
|
import static com.uam.wmi.findmytutor.utils.Const.searchMapZoom;
|
||||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||||
@ -193,7 +195,10 @@ public abstract class BaseActivity
|
|||||||
public void stopBackgroundLocalizationTask() {
|
public void stopBackgroundLocalizationTask() {
|
||||||
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||||
stopIntent.putExtra("request_stop", true);
|
stopIntent.putExtra("request_stop", true);
|
||||||
startService(stopIntent);
|
Log.e("Localization", "JEstem w stop BG");
|
||||||
|
|
||||||
|
stopService(stopIntent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startBackgroundLocalizationTask() {
|
public void startBackgroundLocalizationTask() {
|
||||||
@ -209,12 +214,17 @@ public abstract class BaseActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleBackgroundTaskLifeCycle() {
|
public void handleBackgroundTaskLifeCycle() {
|
||||||
|
Log.e("Localization", String.valueOf(PrefUtils.isEnableSharingLocalization(getApplicationContext())));
|
||||||
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()) && isTutor;
|
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()) && isTutor;
|
||||||
|
Log.e("Localization", String.valueOf(shouldServiceRun));
|
||||||
|
|
||||||
if (shouldServiceRun) {
|
if (shouldServiceRun) {
|
||||||
startBackgroundLocalizationTask();
|
startBackgroundLocalizationTask();
|
||||||
|
Log.e("Localization", "JEstem i odpalam");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
stopBackgroundLocalizationTask();
|
stopBackgroundLocalizationTask();
|
||||||
|
Log.e("Localization", "JEstem i nie odpalam");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ import android.Manifest;
|
|||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Dialog;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -13,14 +11,11 @@ import android.support.v4.content.ContextCompat;
|
|||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
|
||||||
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.EditText;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.PopupWindow;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -74,8 +69,6 @@ import io.reactivex.schedulers.Schedulers;
|
|||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
|
||||||
|
|
||||||
public class MapActivity extends BaseActivity
|
public class MapActivity extends BaseActivity
|
||||||
implements PermissionsListener, OnMapReadyCallback {
|
implements PermissionsListener, OnMapReadyCallback {
|
||||||
|
|
||||||
@ -133,7 +126,7 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
findViewById(R.id.mapInfoImageButton).setOnClickListener(v-> InfoHelperUtils.infoPopUp(v, R.layout.info_popup_map));
|
findViewById(R.id.mapInfoImageButton).setOnClickListener(v -> InfoHelperUtils.infoPopUp(v, R.layout.info_popup_map));
|
||||||
selectLocationButton = findViewById(R.id.select_location_button);
|
selectLocationButton = findViewById(R.id.select_location_button);
|
||||||
removeLocationButton = findViewById(R.id.remove_location_button);
|
removeLocationButton = findViewById(R.id.remove_location_button);
|
||||||
mapView = findViewById(R.id.mapView);
|
mapView = findViewById(R.id.mapView);
|
||||||
@ -236,8 +229,6 @@ public class MapActivity extends BaseActivity
|
|||||||
private void showError(Throwable e) {
|
private void showError(Throwable e) {
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
Log.e("ERR", e.toString());
|
|
||||||
|
|
||||||
if (e instanceof HttpException) {
|
if (e instanceof HttpException) {
|
||||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||||
message = RestApiHelper.getErrorMessage(responseBody);
|
message = RestApiHelper.getErrorMessage(responseBody);
|
||||||
@ -340,10 +331,14 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
alertDialog.setOnShowListener(dialogInterface -> {
|
alertDialog.setOnShowListener(dialogInterface -> {
|
||||||
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
|
||||||
Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||||
|
|
||||||
dismissButton.setOnClickListener(view1 -> alertDialog.dismiss());
|
dismissButton.setOnClickListener(view1 -> {
|
||||||
|
PrefUtils.putCurrentManualLocationName(getApplicationContext(), "Inne");
|
||||||
|
PrefUtils.putCurrentManualLocation(getApplicationContext(), "-1");
|
||||||
|
|
||||||
|
alertDialog.dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
sendButton.setOnClickListener(view1 -> {
|
sendButton.setOnClickListener(view1 -> {
|
||||||
String body = modalUserInput.getText().toString();
|
String body = modalUserInput.getText().toString();
|
||||||
@ -353,7 +348,7 @@ public class MapActivity extends BaseActivity
|
|||||||
modalUserInput.requestFocus();
|
modalUserInput.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
sendLocation(body, latLng);
|
sendLocation(body, latLng);
|
||||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(),body);
|
PrefUtils.putCurrentManualLocationName(getApplicationContext(), body);
|
||||||
alertDialog.dismiss();
|
alertDialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -22,6 +22,7 @@ import com.uam.wmi.findmytutor.R;
|
|||||||
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.PredefinedStatusesService;
|
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
|
||||||
|
import com.uam.wmi.findmytutor.utils.Const;
|
||||||
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
|
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
|
||||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||||
@ -88,25 +89,27 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<PredefinedCoordViewModel> coords) {
|
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]);
|
|
||||||
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||||
|
|
||||||
List<Integer> activeId = Stream.of(coords).indexed()
|
List<String> predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList();
|
||||||
|
predefinedCoordsList.addAll(coords);
|
||||||
|
|
||||||
|
String[] stringnames = predefinedLocationsNames.toArray(new String[0]);
|
||||||
|
|
||||||
|
List<Integer> activesId = Stream.of(coords).indexed()
|
||||||
.filter(v -> v.getSecond().getPredefinedCoordinateId().equals(currentCoordId)).map(IntPair::getFirst).toList();
|
.filter(v -> v.getSecond().getPredefinedCoordinateId().equals(currentCoordId)).map(IntPair::getFirst).toList();
|
||||||
|
|
||||||
if (activeId.size() > 0)
|
if( activesId.size() == 0){
|
||||||
setListPreferenceData(manualLocationList, stringnames, activeId.get(0));
|
|
||||||
else {
|
|
||||||
setListPreferenceData(manualLocationList, stringnames, null);
|
setListPreferenceData(manualLocationList, stringnames, null);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
setListPreferenceData(manualLocationList, stringnames, activesId.get(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.error_location_fetch, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), R.string.error_location_fetch, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -140,7 +143,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
|
|
||||||
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
||||||
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
||||||
// manualLocationList.setSummary(PrefUtils.getManualLocation(getApplicationContext()));
|
|
||||||
/** Main sharing switch**/
|
/** Main sharing switch**/
|
||||||
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
|
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
|
||||||
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
|
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
|
||||||
@ -175,16 +178,14 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
|
|
||||||
/** Custom manual location list change listener **/
|
/** Custom manual location list change listener **/
|
||||||
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
|
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
Log.e("Change on manualList", (String) newValue);
|
|
||||||
|
|
||||||
ListPreference lp = (ListPreference) preference;
|
ListPreference lp = (ListPreference) preference;
|
||||||
CharSequence[] entries = lp.getEntries();
|
CharSequence[] entries = lp.getEntries();
|
||||||
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
|
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
|
||||||
|
|
||||||
|
//sharing dialog -> ask for start BG
|
||||||
if (!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
|
if (!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
|
||||||
EnableSharingDialog sharingDialog = new EnableSharingDialog();
|
EnableSharingDialog sharingDialog = new EnableSharingDialog();
|
||||||
sharingDialog.show(getFragmentManager(), "Sharing");
|
sharingDialog.show(getFragmentManager(), "Sharing");
|
||||||
//refresh view -> get new values from xml
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation());
|
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation());
|
||||||
@ -192,8 +193,6 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(), (String) lp.getEntries()[Integer.parseInt((String) newValue)]);
|
PrefUtils.putCurrentManualLocationName(getApplicationContext(), (String) lp.getEntries()[Integer.parseInt((String) newValue)]);
|
||||||
lp.setSummary(lp.getEntries()[Integer.parseInt((String) newValue)]);
|
lp.setSummary(lp.getEntries()[Integer.parseInt((String) newValue)]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -237,7 +236,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setListPreferenceData(ListPreference lp, String[] entries, Integer activeId) {
|
protected void setListPreferenceData(ListPreference lp, String[] entries, Integer activeId) {
|
||||||
Log.d("setlistpref", lp.getKey());
|
|
||||||
try {
|
try {
|
||||||
lp.setEntries(entries);
|
lp.setEntries(entries);
|
||||||
CharSequence[] entryValues = new CharSequence[entries.length];
|
CharSequence[] entryValues = new CharSequence[entries.length];
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.uam.wmi.findmytutor.utils;
|
package com.uam.wmi.findmytutor.utils;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -11,45 +10,6 @@ import android.widget.Toast;
|
|||||||
import com.uam.wmi.findmytutor.R;
|
import com.uam.wmi.findmytutor.R;
|
||||||
import com.uam.wmi.findmytutor.activity.MapActivity;
|
import com.uam.wmi.findmytutor.activity.MapActivity;
|
||||||
|
|
||||||
/*public class EnableSharingDialog extends DialogFragment {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
View rootView = inflater.inflate(R.layout.fragment_sample_dialog, container, false);
|
|
||||||
getDialog().setTitle("Simple Dialog");
|
|
||||||
return rootView;
|
|
||||||
}
|
|
||||||
public void createSharingDialog(Context context) {
|
|
||||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext());
|
|
||||||
View view = layoutInflaterAndroid.inflate(R.layout.user_list_modal, null);
|
|
||||||
|
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
|
|
||||||
dialogBuilder.setView(view);
|
|
||||||
|
|
||||||
dialogBuilder.setMessage(R.string.enable_sharing_question);
|
|
||||||
dialogBuilder.setCancelable(true);
|
|
||||||
|
|
||||||
dialogBuilder.setPositiveButton(R.string.possitive_dialog_button,
|
|
||||||
(dialog, id) -> {
|
|
||||||
dialogPositiveAnswer(context);
|
|
||||||
dialog.cancel();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
dialogBuilder.setNegativeButton(
|
|
||||||
R.string.negative_dialog_button,
|
|
||||||
(dialog, id) ->
|
|
||||||
dialog.cancel());
|
|
||||||
|
|
||||||
AlertDialog alert11 = dialogBuilder.create();
|
|
||||||
alert11.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dialogPositiveAnswer(Context context) {
|
|
||||||
PrefUtils.storeBackgroundLocationStatus(context, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public class EnableSharingDialog extends DialogFragment {
|
public class EnableSharingDialog extends DialogFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user