forked from organicmaps/organicmaps
[android] Notifications. Review fixes
This commit is contained in:
parent
9a5573859b
commit
69d19aba1e
7 changed files with 79 additions and 33 deletions
|
@ -328,6 +328,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
.putExtra(DownloadResourcesLegacyActivity.EXTRA_COUNTRY, countryId);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Intent createAuthenticateIntent()
|
||||
{
|
||||
return new Intent(MwmApplication.get(), MwmActivity.class)
|
||||
|
@ -547,7 +548,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
// }
|
||||
//});
|
||||
//getWindow().getDecorView().addOnLayoutChangeListener(mVisibleRectMeasurer);
|
||||
boolean isConsumed = processIntent(getIntent());
|
||||
boolean isConsumed = savedInstanceState == null && processIntent(getIntent());
|
||||
// If the map activity is launched by any incoming intent (deeplink, update maps event, etc)
|
||||
// we haven't to try restoring the route. Also, if savedInstanceState != null it means that
|
||||
// the app is being restored by the system at the moment, so we don't need to restore the route.
|
||||
|
@ -2414,6 +2415,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public boolean run(MwmActivity target)
|
||||
{
|
||||
Fragment f = target.getSupportFragmentManager().findFragmentByTag(mDialogName);
|
||||
if (f != null)
|
||||
return true;
|
||||
|
||||
final DialogFragment fragment = (DialogFragment) Fragment.instantiate(target, mDialogName);
|
||||
fragment.show(target.getSupportFragmentManager(), mDialogName);
|
||||
return true;
|
||||
|
|
|
@ -2,22 +2,32 @@ package com.mapswithme.maps.auth;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class PassportAuthDialogFragment extends BaseMwmDialogFragment
|
||||
{
|
||||
private Authorizer mAuthorizer = new Authorizer(this);
|
||||
@NonNull
|
||||
private final Authorizer mAuthorizer = new Authorizer(this);
|
||||
@NonNull
|
||||
private final AuthCallback mAuthCallback = new AuthCallback();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
mAuthorizer.authorize();
|
||||
if (savedInstanceState == null)
|
||||
mAuthorizer.authorize();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -31,8 +41,44 @@ public class PassportAuthDialogFragment extends BaseMwmDialogFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int getStyle()
|
||||
@CallSuper
|
||||
public void onStart()
|
||||
{
|
||||
return STYLE_NO_TITLE;
|
||||
super.onStart();
|
||||
mAuthorizer.attach(mAuthCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
mAuthorizer.detach();
|
||||
}
|
||||
|
||||
private static class AuthCallback implements Authorizer.Callback
|
||||
{
|
||||
@Override
|
||||
public void onAuthorizationFinish(boolean success)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthorizationStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSocialAuthenticationCancel(@Framework.AuthTokenType int type)
|
||||
{
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.UGC_AUTH_DECLINED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSocialAuthenticationError(@Framework.AuthTokenType int type,
|
||||
@Nullable String error)
|
||||
{
|
||||
Statistics.INSTANCE.trackUGCAuthFailed(type, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class SocialAuthDialogFragment extends BaseMwmDialogFragment
|
|||
boolean isCancel)
|
||||
{
|
||||
Fragment caller = getTargetFragment();
|
||||
if (caller == null)
|
||||
if (caller == null || !caller.isAdded())
|
||||
return;
|
||||
|
||||
Intent data = new Intent();
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.IntentService;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapswithme.maps.LightFramework;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
|
@ -13,6 +14,7 @@ import com.mapswithme.util.PermissionsUtils;
|
|||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||
import static com.mapswithme.maps.MwmApplication.prefs;
|
||||
|
||||
public class NotificationService extends IntentService
|
||||
|
@ -22,8 +24,6 @@ public class NotificationService extends IntentService
|
|||
private static final String LAST_AUTH_NOTIFICATION_TIMESTAMP = "DownloadOrUpdateTimestamp";
|
||||
private static final int MIN_COUNT_UNSENT_UGC = 2;
|
||||
private static final long MIN_AUTH_EVENT_DELTA_MILLIS = 5 * 24 * 60 * 60 * 1000; // 5 days
|
||||
private static final String CONNECTIVITY_CHANGED =
|
||||
"com.mapswithme.maps.notification_service.action.connectivity_changed";
|
||||
|
||||
private interface NotificationExecutor
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ public class NotificationService extends IntentService
|
|||
static void startOnConnectivityChanged(Context context)
|
||||
{
|
||||
final Intent intent = new Intent(context, NotificationService.class);
|
||||
intent.setAction(NotificationService.CONNECTIVITY_CHANGED);
|
||||
intent.setAction(CONNECTIVITY_ACTION);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class NotificationService extends IntentService
|
|||
LightFramework.nativeIsAuthenticated() ||
|
||||
LightFramework.nativeGetNumberUnsentUGC() < MIN_COUNT_UNSENT_UGC)
|
||||
{
|
||||
LOGGER.d(TAG, "Authentication nofification is rejected. External storage granted: " +
|
||||
LOGGER.d(TAG, "Authentication notification is rejected. External storage granted: " +
|
||||
PermissionsUtils.isExternalStorageGranted() + ". Is user authenticated: " +
|
||||
LightFramework.nativeIsAuthenticated() + ". Current network usage status: " +
|
||||
NetworkPolicy.getCurrentNetworkUsageStatus() + ". Number of unsent UGC: " +
|
||||
|
@ -56,7 +56,7 @@ public class NotificationService extends IntentService
|
|||
if (MwmApplication.get().arePlatformAndCoreInitialized() &&
|
||||
RoutingController.get().isNavigating())
|
||||
{
|
||||
LOGGER.d(TAG, "Authentication nofification is rejected. The user is in navigation mode.");
|
||||
LOGGER.d(TAG, "Authentication notification is rejected. The user is in navigation mode.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -64,17 +64,17 @@ public class NotificationService extends IntentService
|
|||
|
||||
if (System.currentTimeMillis() - lastEventTimestamp > MIN_AUTH_EVENT_DELTA_MILLIS)
|
||||
{
|
||||
LOGGER.d(TAG, "Authentication nofification will be sent.");
|
||||
LOGGER.d(TAG, "Authentication notification will be sent.");
|
||||
|
||||
prefs().edit()
|
||||
.putLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, System.currentTimeMillis())
|
||||
.apply();
|
||||
|
||||
Notifier.notifyIsNotAuthenticated();
|
||||
Notifier.notifyAuthentication();
|
||||
|
||||
return true;
|
||||
}
|
||||
LOGGER.d(TAG, "Authentication nofification is rejected. Last event timestamp: " +
|
||||
LOGGER.d(TAG, "Authentication notification is rejected. Last event timestamp: " +
|
||||
lastEventTimestamp + "Current time milliseconds: " + System.currentTimeMillis());
|
||||
return false;
|
||||
}
|
||||
|
@ -92,12 +92,12 @@ public class NotificationService extends IntentService
|
|||
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (action == null)
|
||||
if (TextUtils.isEmpty(action))
|
||||
return;
|
||||
|
||||
switch(action)
|
||||
{
|
||||
case CONNECTIVITY_CHANGED:
|
||||
case CONNECTIVITY_ACTION:
|
||||
onConnectivityChanged();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -20,12 +20,13 @@ import java.lang.annotation.RetentionPolicy;
|
|||
|
||||
public final class Notifier
|
||||
{
|
||||
private static final String EXTRA_CANCEL_NOTIFICATION = "mwm.extra.intent.cancel_notification";
|
||||
private static final String EXTRA_NOTIFICATION_CLICKED = "mwm.extra.intent.notification_clicked";
|
||||
private static final String EXTRA_CANCEL_NOTIFICATION = "extra_cancel_notification";
|
||||
private static final String EXTRA_NOTIFICATION_CLICKED = "extra_notification_clicked";
|
||||
private static final MwmApplication APP = MwmApplication.get();
|
||||
|
||||
public final static int ID_NONE = 0;
|
||||
public final static int ID_DOWNLOAD_FAILED = 1;
|
||||
public final static int ID_IS_NOT_AUTHENTICATED = 2;
|
||||
public static final int ID_NONE = 0;
|
||||
public static final int ID_DOWNLOAD_FAILED = 1;
|
||||
public static final int ID_IS_NOT_AUTHENTICATED = 2;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({ ID_NONE, ID_DOWNLOAD_FAILED, ID_IS_NOT_AUTHENTICATED })
|
||||
|
@ -33,8 +34,6 @@ public final class Notifier
|
|||
{
|
||||
}
|
||||
|
||||
private static final MwmApplication APP = MwmApplication.get();
|
||||
|
||||
private Notifier()
|
||||
{
|
||||
}
|
||||
|
@ -52,7 +51,7 @@ public final class Notifier
|
|||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN);
|
||||
}
|
||||
|
||||
public static void notifyIsNotAuthenticated()
|
||||
public static void notifyAuthentication()
|
||||
{
|
||||
Intent authIntent = MwmActivity.createAuthenticateIntent();
|
||||
authIntent.putExtra(EXTRA_CANCEL_NOTIFICATION, Notifier.ID_IS_NOT_AUTHENTICATED);
|
||||
|
|
|
@ -268,10 +268,7 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
|
||||
private void goToSplashScreen(@Nullable Intent initialIntent)
|
||||
{
|
||||
Class<? extends Activity> type = null;
|
||||
if (!(this instanceof MwmActivity) || initialIntent != null)
|
||||
type = getClass();
|
||||
SplashActivity.start(this, type, initialIntent);
|
||||
SplashActivity.start(this, getClass(), initialIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,15 @@ import android.support.annotation.UiThread;
|
|||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.background.Notifier;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
@UiThread
|
||||
public final class MapManager
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue