diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2018-04-05 12:22:13 +0300 |
---|---|---|
committer | Aleksandr Zatsepin <alexzatsepin@users.noreply.github.com> | 2018-04-05 12:23:39 +0300 |
commit | 69d19aba1e8985d2585fe585e783712e1279b313 (patch) | |
tree | 1067f9438dc8014f732779de96b45c1dd0a4792f /android/src | |
parent | 9a5573859bb5c3fc3d15cb171c5aa01a4b4b2bc1 (diff) |
[android] Notifications. Review fixes
Diffstat (limited to 'android/src')
7 files changed, 79 insertions, 33 deletions
diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 53e6548186..513bd1f918 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -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; diff --git a/android/src/com/mapswithme/maps/auth/PassportAuthDialogFragment.java b/android/src/com/mapswithme/maps/auth/PassportAuthDialogFragment.java index e09fd19be8..f46e7a1b94 100644 --- a/android/src/com/mapswithme/maps/auth/PassportAuthDialogFragment.java +++ b/android/src/com/mapswithme/maps/auth/PassportAuthDialogFragment.java @@ -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() + { + super.onStart(); + mAuthorizer.attach(mAuthCallback); + } + + @Override + @CallSuper + public void onStop() { - return STYLE_NO_TITLE; + 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); + } } } diff --git a/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java b/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java index cb0329be12..9ddcee6cc9 100644 --- a/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java +++ b/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java @@ -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(); diff --git a/android/src/com/mapswithme/maps/background/NotificationService.java b/android/src/com/mapswithme/maps/background/NotificationService.java index 2aacb655ae..8bc637e421 100644 --- a/android/src/com/mapswithme/maps/background/NotificationService.java +++ b/android/src/com/mapswithme/maps/background/NotificationService.java @@ -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; } diff --git a/android/src/com/mapswithme/maps/background/Notifier.java b/android/src/com/mapswithme/maps/background/Notifier.java index 2611a7f2b8..fad56f5449 100644 --- a/android/src/com/mapswithme/maps/background/Notifier.java +++ b/android/src/com/mapswithme/maps/background/Notifier.java @@ -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); diff --git a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java index 367a5d98f1..a4670955f2 100644 --- a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java +++ b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java @@ -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(); } } diff --git a/android/src/com/mapswithme/maps/downloader/MapManager.java b/android/src/com/mapswithme/maps/downloader/MapManager.java index 1a8c67d7dd..d16218784c 100644 --- a/android/src/com/mapswithme/maps/downloader/MapManager.java +++ b/android/src/com/mapswithme/maps/downloader/MapManager.java @@ -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 { |