Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AppBaseTransitionListener.java « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cfa6200fe7083dc45ac26b70f26d09dafa557a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.mapswithme.maps;

import android.location.Location;
import androidx.annotation.NonNull;
import android.util.Log;

import com.mapswithme.maps.background.AppBackgroundTracker;
import com.mapswithme.maps.geofence.GeofenceLocation;
import com.mapswithme.maps.geofence.GeofenceRegistry;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationPermissionNotGrantedException;
import com.mapswithme.util.log.LoggerFactory;

class AppBaseTransitionListener implements AppBackgroundTracker.OnTransitionListener
{
  @NonNull
  private final MwmApplication mApplication;

  AppBaseTransitionListener(@NonNull MwmApplication application)
  {
    mApplication = application;
  }

  @Override
  public void onTransit(boolean foreground)
  {
    if (!foreground && LoggerFactory.INSTANCE.isFileLoggingEnabled())
    {
      Log.i(MwmApplication.TAG, "The app goes to background. All logs are going to be zipped.");
      LoggerFactory.INSTANCE.zipLogs(null);
    }

    if (foreground)
      return;

    updateGeofences();
  }

  private void updateGeofences()
  {
    Location lastKnownLocation = LocationHelper.INSTANCE.getLastKnownLocation();
    if (lastKnownLocation == null)
      return;

    GeofenceRegistry geofenceRegistry = mApplication.getGeofenceRegistry();
    try
    {
      geofenceRegistry.unregisterGeofences();
      geofenceRegistry.registerGeofences(GeofenceLocation.from(lastKnownLocation));
    }
    catch (LocationPermissionNotGrantedException e)
    {
      mApplication.getLogger().d(MwmApplication.TAG, "Location permission not granted!", e);
    }
  }
}