[Android] Work without location permission granted

Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
This commit is contained in:
Roman Tsisyk 2021-05-15 21:15:44 +03:00
parent ddbe11c010
commit 2cf30bee97
5 changed files with 18 additions and 26 deletions

View file

@ -833,7 +833,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
PermissionsResult result = PermissionsUtils.computePermissionsResult(permissions, grantResults);
if (result.isLocationGranted())
{
myPositionClick();
}
else
{
Utils.showSnackbar(getActivity(), findViewById(R.id.coordinator), findViewById(R.id.menu_frame),
R.string.location_is_disabled_long_text);
}
}
@Override
@ -2041,12 +2048,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (!PermissionsUtils.isLocationGranted(getApplicationContext()))
{
PermissionsUtils.requestLocationPermission(MwmActivity.this, REQ_CODE_LOCATION_PERMISSION);
if (!PermissionsUtils.isLocationGranted(getApplicationContext()))
{
Utils.showSnackbar(getActivity(), findViewById(R.id.coordinator), findViewById(R.id.menu_frame),
R.string.enable_location_services);
return;
}
return;
}
myPositionClick();

View file

@ -15,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.mapswithme.maps.base.BaseActivity;
import com.mapswithme.maps.base.BaseActivityDelegate;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.util.Config;
import com.mapswithme.util.Counters;
import com.mapswithme.util.PermissionsUtils;
import com.mapswithme.util.ThemeUtils;
@ -89,7 +90,7 @@ public class SplashActivity extends AppCompatActivity implements BaseActivity
mBaseDelegate.onResume();
if (mCanceled)
return;
if (!PermissionsUtils.isLocationGranted(this))
if (!Config.isLocationRequested() && !PermissionsUtils.isLocationGranted(this))
{
PermissionsUtils.requestLocationPermission(SplashActivity.this, REQUEST_PERMISSIONS);
return;
@ -146,11 +147,7 @@ public class SplashActivity extends AppCompatActivity implements BaseActivity
if (requestCode != REQUEST_PERMISSIONS)
throw new AssertionError("Unexpected requestCode");
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (!PermissionsUtils.isLocationGranted(this))
{
showFatalErrorDialog(R.string.enable_location_services, R.string.location_is_disabled_long_text);
return;
}
Config.setLocationRequested();
// No-op here - onResume() calls init();
}
@ -166,7 +163,7 @@ public class SplashActivity extends AppCompatActivity implements BaseActivity
return;
}
if (Counters.isFirstLaunch(this))
if (Counters.isFirstLaunch(this) && PermissionsUtils.isLocationGranted(this))
{
LocationHelper.INSTANCE.onEnteredIntoFirstRun();
if (!LocationHelper.INSTANCE.isActive())

View file

@ -21,7 +21,6 @@ import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.SplashActivity;
import com.mapswithme.util.Config;
import com.mapswithme.util.PermissionsUtils;
import com.mapswithme.util.ThemeUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
@ -217,12 +216,6 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
protected void onResume()
{
super.onResume();
if (!PermissionsUtils.isLocationGranted(getApplicationContext()))
{
goToSplashScreen(null);
return;
}
mBaseDelegate.onResume();
}

View file

@ -146,7 +146,7 @@ public enum LocationHelper implements Initializable<Context>
private final LocationState.LocationPendingTimeoutListener mLocationPendingTimeoutListener =
() -> {
stop();
if (LocationUtils.areLocationServicesTurnedOn(mContext))
if (PermissionsUtils.isLocationGranted(mContext) && LocationUtils.areLocationServicesTurnedOn(mContext))
notifyLocationNotFound();
};

View file

@ -31,7 +31,7 @@ public final class Config
private static final String KEY_PREF_USE_GS = "UseGoogleServices";
private static final String KEY_MISC_DISCLAIMER_ACCEPTED = "IsDisclaimerApproved";
private static final String KEY_MISC_KITKAT_MIGRATED = "KitKatMigrationCompleted";
private static final String KEY_MISC_LOCATION_REQUESTED = "LocationRequested";
private static final String KEY_MISC_UI_THEME = "UiTheme";
private static final String KEY_MISC_UI_THEME_SETTINGS = "UiThemeSettings";
private static final String KEY_MISC_USE_MOBILE_DATA = "UseMobileData";
@ -198,14 +198,14 @@ public final class Config
setBool(KEY_MISC_DISCLAIMER_ACCEPTED);
}
public static boolean isKitKatMigrationComplete()
public static boolean isLocationRequested()
{
return getBool(KEY_MISC_KITKAT_MIGRATED);
return getBool(KEY_MISC_LOCATION_REQUESTED);
}
public static void setKitKatMigrationComplete()
public static void setLocationRequested()
{
setBool(KEY_MISC_KITKAT_MIGRATED);
setBool(KEY_MISC_LOCATION_REQUESTED);
}
@NonNull