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.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -46,6 +47,7 @@ import io.reactivex.functions.Function;
|
||||
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.searchMapZoom;
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||
@ -193,7 +195,10 @@ public abstract class BaseActivity
|
||||
public void stopBackgroundLocalizationTask() {
|
||||
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
stopIntent.putExtra("request_stop", true);
|
||||
startService(stopIntent);
|
||||
Log.e("Localization", "JEstem w stop BG");
|
||||
|
||||
stopService(stopIntent);
|
||||
|
||||
}
|
||||
|
||||
public void startBackgroundLocalizationTask() {
|
||||
@ -209,12 +214,17 @@ public abstract class BaseActivity
|
||||
}
|
||||
|
||||
public void handleBackgroundTaskLifeCycle() {
|
||||
Log.e("Localization", String.valueOf(PrefUtils.isEnableSharingLocalization(getApplicationContext())));
|
||||
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()) && isTutor;
|
||||
Log.e("Localization", String.valueOf(shouldServiceRun));
|
||||
|
||||
if (shouldServiceRun) {
|
||||
startBackgroundLocalizationTask();
|
||||
Log.e("Localization", "JEstem i odpalam");
|
||||
|
||||
} else {
|
||||
stopBackgroundLocalizationTask();
|
||||
Log.e("Localization", "JEstem i nie odpalam");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@ import android.Manifest;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -13,14 +11,11 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -74,8 +69,6 @@ import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
public class MapActivity extends BaseActivity
|
||||
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);
|
||||
removeLocationButton = findViewById(R.id.remove_location_button);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
@ -236,8 +229,6 @@ public class MapActivity extends BaseActivity
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
Log.e("ERR", e.toString());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
@ -340,10 +331,14 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
alertDialog.setOnShowListener(dialogInterface -> {
|
||||
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
|
||||
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 -> {
|
||||
String body = modalUserInput.getText().toString();
|
||||
@ -353,7 +348,7 @@ public class MapActivity extends BaseActivity
|
||||
modalUserInput.requestFocus();
|
||||
} else {
|
||||
sendLocation(body, latLng);
|
||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(),body);
|
||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(), body);
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
@ -22,6 +22,7 @@ import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
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.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
@ -88,25 +89,27 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
|
||||
@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]);
|
||||
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();
|
||||
|
||||
if (activeId.size() > 0)
|
||||
setListPreferenceData(manualLocationList, stringnames, activeId.get(0));
|
||||
else {
|
||||
if( activesId.size() == 0){
|
||||
setListPreferenceData(manualLocationList, stringnames, null);
|
||||
}
|
||||
else {
|
||||
setListPreferenceData(manualLocationList, stringnames, activesId.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
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()));
|
||||
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
||||
// manualLocationList.setSummary(PrefUtils.getManualLocation(getApplicationContext()));
|
||||
|
||||
/** Main sharing switch**/
|
||||
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
|
||||
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
|
||||
@ -175,16 +178,14 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
|
||||
/** Custom manual location list change listener **/
|
||||
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
Log.e("Change on manualList", (String) newValue);
|
||||
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
CharSequence[] entries = lp.getEntries();
|
||||
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())) {
|
||||
EnableSharingDialog sharingDialog = new EnableSharingDialog();
|
||||
sharingDialog.show(getFragmentManager(), "Sharing");
|
||||
//refresh view -> get new values from xml
|
||||
}
|
||||
|
||||
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)]);
|
||||
lp.setSummary(lp.getEntries()[Integer.parseInt((String) newValue)]);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -237,7 +236,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
}
|
||||
|
||||
protected void setListPreferenceData(ListPreference lp, String[] entries, Integer activeId) {
|
||||
Log.d("setlistpref", lp.getKey());
|
||||
|
||||
try {
|
||||
lp.setEntries(entries);
|
||||
CharSequence[] entryValues = new CharSequence[entries.length];
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
@ -11,45 +10,6 @@ import android.widget.Toast;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user