forked from organicmaps/organicmaps
[android] Fixed crash during enter to app via connectivity change listener
[android] Refactore init core/platform methods
This commit is contained in:
parent
84f6b9b0a8
commit
b7e0413ca5
8 changed files with 23 additions and 29 deletions
|
@ -167,7 +167,12 @@ public class MwmApplication extends Application
|
|||
mBackgroundTracker.addListener(mVisibleAppLaunchListener);
|
||||
}
|
||||
|
||||
public void initNativePlatform()
|
||||
public void initPlatformAndCore(){
|
||||
initNativePlatform();
|
||||
initNativeCore();
|
||||
}
|
||||
|
||||
private void initNativePlatform()
|
||||
{
|
||||
if (mIsPlatformInitialized)
|
||||
return;
|
||||
|
@ -217,7 +222,7 @@ public class MwmApplication extends Application
|
|||
}
|
||||
}
|
||||
|
||||
public void initNativeCore()
|
||||
private void initNativeCore()
|
||||
{
|
||||
if (mIsFrameworkInitialized)
|
||||
return;
|
||||
|
@ -287,13 +292,9 @@ public class MwmApplication extends Application
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean isFrameworkInitialized()
|
||||
public boolean arePlatformAndCoreInitialized()
|
||||
{
|
||||
return mIsFrameworkInitialized;
|
||||
}
|
||||
public boolean isPlatformInitialized()
|
||||
{
|
||||
return mIsPlatformInitialized;
|
||||
return mIsFrameworkInitialized && mIsPlatformInitialized;
|
||||
}
|
||||
|
||||
public String getApkPath()
|
||||
|
|
|
@ -228,8 +228,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
|
||||
private void init()
|
||||
{
|
||||
MwmApplication.get().initNativePlatform();
|
||||
MwmApplication.get().initNativeCore();
|
||||
MwmApplication.get().initPlatformAndCore();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -22,7 +22,10 @@ public class ConnectivityChangedReceiver extends BroadcastReceiver
|
|||
if (!PermissionsUtils.isExternalStorageGranted())
|
||||
return;
|
||||
|
||||
MwmApplication.get().initNativePlatform();
|
||||
MwmApplication application = MwmApplication.get();
|
||||
if (!application.arePlatformAndCoreInitialized())
|
||||
application.initPlatformAndCore();
|
||||
|
||||
if (!ConnectionState.isWifiConnected()
|
||||
|| MapManager.nativeNeedMigrate())
|
||||
return;
|
||||
|
@ -35,8 +38,6 @@ public class ConnectivityChangedReceiver extends BroadcastReceiver
|
|||
.putLong(DOWNLOAD_UPDATE_TIMESTAMP, System.currentTimeMillis())
|
||||
.apply();
|
||||
|
||||
MwmApplication.get().initNativeCore();
|
||||
|
||||
MapManager.checkUpdates();
|
||||
WorkerService.startActionCheckLocation(context);
|
||||
}
|
||||
|
|
|
@ -7,18 +7,17 @@ import android.content.SharedPreferences;
|
|||
import android.location.Location;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.downloader.CountryItem;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.editor.Editor;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.util.LocationUtils;
|
||||
import com.mapswithme.util.PermissionsUtils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class WorkerService extends IntentService
|
||||
{
|
||||
private static final String ACTION_CHECK_LOCATIION = "com.mapswithme.maps.action.check_location";
|
||||
|
@ -52,13 +51,6 @@ public class WorkerService extends IntentService
|
|||
super("WorkerService");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
MwmApplication.get().initNativeCore();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent)
|
||||
{
|
||||
|
@ -128,8 +120,9 @@ public class WorkerService extends IntentService
|
|||
if (!PermissionsUtils.isExternalStorageGranted())
|
||||
return false;
|
||||
|
||||
MwmApplication.get().initNativePlatform();
|
||||
MwmApplication.get().initNativeCore();
|
||||
MwmApplication application = MwmApplication.get();
|
||||
if (!application.arePlatformAndCoreInitialized())
|
||||
application.initPlatformAndCore();
|
||||
|
||||
Location l = LocationHelper.INSTANCE.getLastKnownLocation();
|
||||
if (l == null)
|
||||
|
|
|
@ -53,7 +53,7 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
if (!MwmApplication.get().isPlatformInitialized()
|
||||
if (!MwmApplication.get().arePlatformAndCoreInitialized()
|
||||
|| !PermissionsUtils.isExternalStorageGranted())
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
@ -10,7 +10,7 @@ public class GPSCheck extends BroadcastReceiver
|
|||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (MwmApplication.get().isFrameworkInitialized() && MwmApplication.backgroundTracker().isForeground())
|
||||
if (MwmApplication.get().arePlatformAndCoreInitialized() && MwmApplication.backgroundTracker().isForeground())
|
||||
{
|
||||
LocationHelper.INSTANCE.restart();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class SensorHelper implements SensorEventListener
|
|||
@Override
|
||||
public void onSensorChanged(SensorEvent event)
|
||||
{
|
||||
if (!MwmApplication.get().isFrameworkInitialized())
|
||||
if (!MwmApplication.get().arePlatformAndCoreInitialized())
|
||||
return;
|
||||
|
||||
boolean hasOrientation = false;
|
||||
|
|
|
@ -478,7 +478,7 @@ public class Utils
|
|||
public static void detachFragmentIfCoreNotInitialized(@NonNull Context context,
|
||||
@NonNull Fragment fragment)
|
||||
{
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().arePlatformAndCoreInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
|
|
Loading…
Add table
Reference in a new issue