First attempt
This commit is contained in:
parent
5fc5140866
commit
5e51be5d0b
@ -77,6 +77,7 @@ public abstract class BaseActivity
|
||||
|
||||
private Fragment userListFragment;
|
||||
private ActiveFragment activeFragment = ActiveFragment.NONE;
|
||||
private Fragment activeBottomMenu = null;
|
||||
private SearchView searchView;
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@ -351,7 +352,7 @@ public abstract class BaseActivity
|
||||
} else if (itemId == R.id.nav_user_list) {
|
||||
loadUserListFragment();
|
||||
}
|
||||
|
||||
selectBottomNavigationBarItem(itemId);
|
||||
}, 300);
|
||||
|
||||
return true;
|
||||
@ -363,6 +364,7 @@ public abstract class BaseActivity
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.activity_content, sharingFragment);
|
||||
ft.commit();
|
||||
|
||||
}
|
||||
|
||||
private void loadUserListFragment() {
|
||||
@ -372,8 +374,8 @@ public abstract class BaseActivity
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.activity_content, userListFragment);
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateNavigationBarState() {
|
||||
int actionId = getNavigationMenuItemId();
|
||||
@ -385,9 +387,6 @@ public abstract class BaseActivity
|
||||
item.setChecked(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
abstract int getNavigationMenuItemId();
|
||||
|
||||
abstract int getContentViewId();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.android.gms.location.FusedLocationProviderClient;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
@ -36,16 +37,21 @@ import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
|
||||
import org.apache.commons.collections4.Predicate;
|
||||
import org.apache.commons.collections4.queue.CircularFifoQueue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
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 timber.log.Timber;
|
||||
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.presenceApproximatedName;
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.presenceLatitude;
|
||||
@ -59,6 +65,10 @@ public class BackgroundLocalizationService extends Service {
|
||||
private static final float LOCATION_DISTANCE = 5f;
|
||||
public static String str_receiver = "background.location.broadcast";
|
||||
private static long notify_interval = 10000;
|
||||
private static long notify_interval_inside_building = 10000;
|
||||
private static long notify_interval_outside_building = 20000;
|
||||
//private static long notify_interval_outside_building = 900000;
|
||||
private CircularFifoQueue<Location> coordinatesHistory = new CircularFifoQueue<Location>(5);
|
||||
Location mLastLocation;
|
||||
Boolean stopService = false;
|
||||
Intent intent;
|
||||
@ -82,7 +92,6 @@ public class BackgroundLocalizationService extends Service {
|
||||
new LocationListener(LocationManager.NETWORK_PROVIDER),
|
||||
new LocationListener(LocationManager.PASSIVE_PROVIDER)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,23 +155,42 @@ public class BackgroundLocalizationService extends Service {
|
||||
}
|
||||
|
||||
if (!stopService) {
|
||||
|
||||
|
||||
mStatusChecker = () -> {
|
||||
try {
|
||||
fn_getlocation();
|
||||
changeBackgroundMode();
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, notify_interval);
|
||||
}
|
||||
};
|
||||
|
||||
AsyncTask.execute(mStatusChecker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void changeBackgroundMode() {
|
||||
Predicate<Boolean> p2 = v -> !v;
|
||||
if(coordinatesHistory.size() > 4){
|
||||
Boolean shouldExtendTimeInterval = Stream.of(coordinatesHistory)
|
||||
.map(MapUtils::checkIfCoordinateIsValid).takeWhile( s-> !s).toList().size() == 5;
|
||||
|
||||
if(shouldExtendTimeInterval){
|
||||
notify_interval = notify_interval_outside_building;
|
||||
}else{
|
||||
notify_interval = notify_interval_inside_building;
|
||||
}
|
||||
}
|
||||
|
||||
Log.e("COORD_HISTORY", String.valueOf(Stream.of(coordinatesHistory)
|
||||
.map(MapUtils::checkIfCoordinateIsValid).toList()));
|
||||
Log.e("COORD_HISTORY", String.valueOf(coordinatesHistory));
|
||||
Log.e("NEW INTERVAL", String.valueOf(notify_interval));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startMyOwnForeground() {
|
||||
|
||||
@ -198,29 +226,38 @@ public class BackgroundLocalizationService extends Service {
|
||||
|
||||
List<String> providers1 = mLocationManager.getProviders(true);
|
||||
Location bestLocation = null;
|
||||
|
||||
|
||||
for (String provider : providers1) {
|
||||
Location location = mLocationManager.getLastKnownLocation(provider);
|
||||
|
||||
if (location == null) {
|
||||
continue;
|
||||
}
|
||||
if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) {
|
||||
bestLocation = location;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Log.e("Best localization:", String.valueOf(bestLocation));
|
||||
AtomicReference<Boolean> triggerAnotherLocationListener = new AtomicReference<>(false);
|
||||
|
||||
mFusedLocationClient.getLastLocation().addOnSuccessListener(
|
||||
location -> {
|
||||
if (location != null) {
|
||||
mLastLocation = location;
|
||||
coordinatesHistory.add(location);
|
||||
fn_update(location);
|
||||
}
|
||||
|
||||
triggerAnotherLocationListener.set(true);
|
||||
});
|
||||
|
||||
if(triggerAnotherLocationListener.get()){
|
||||
for (String provider : providers1) {
|
||||
Location location = mLocationManager.getLastKnownLocation(provider);
|
||||
|
||||
if (location == null) {
|
||||
continue;
|
||||
}
|
||||
if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) {
|
||||
bestLocation = location;
|
||||
}
|
||||
}
|
||||
|
||||
coordinatesHistory.add(bestLocation);
|
||||
Log.e("Best localization:", String.valueOf(bestLocation));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void fn_update(Location location) {
|
||||
@ -333,6 +370,8 @@ public class BackgroundLocalizationService extends Service {
|
||||
approximatedBuildingPart = PrefUtils.getManualLocationApproximation(getApplicationContext());
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latitude,
|
||||
|
@ -44,8 +44,6 @@ public class ManualLocationUtils {
|
||||
activityContext = context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
if (error instanceof HttpException) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user