forked from organicmaps/organicmaps
[android] Added stats for maplayers, refactored traffic state types
This commit is contained in:
parent
c9649224f9
commit
7a72e3c66c
5 changed files with 191 additions and 106 deletions
|
@ -2,10 +2,8 @@ package com.mapswithme.maps.maplayer.subway;
|
|||
|
||||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.content.AbstractContextualListener;
|
||||
|
||||
public interface OnTransitSchemeChangedListener
|
||||
|
@ -29,10 +27,7 @@ public interface OnTransitSchemeChangedListener
|
|||
return;
|
||||
|
||||
TransitSchemeState state = TransitSchemeState.makeInstance(index);
|
||||
if (state != TransitSchemeState.NO_DATA)
|
||||
return;
|
||||
|
||||
Toast.makeText(app, R.string.subway_data_unavailable, Toast.LENGTH_SHORT).show();
|
||||
state.onReceived(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,32 @@
|
|||
package com.mapswithme.maps.maplayer.subway;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public enum TransitSchemeState
|
||||
{
|
||||
DISABLED,
|
||||
ENABLED,
|
||||
NO_DATA;
|
||||
ENABLED
|
||||
{
|
||||
@Override
|
||||
public void onReceived(@NonNull MwmApplication app)
|
||||
{
|
||||
Statistics.INSTANCE.trackSubwayEvent(Statistics.ParamValue.SUCCESS);
|
||||
}
|
||||
},
|
||||
NO_DATA
|
||||
{
|
||||
@Override
|
||||
public void onReceived(@NonNull MwmApplication app)
|
||||
{
|
||||
Toast.makeText(app, R.string.subway_data_unavailable, Toast.LENGTH_SHORT).show();
|
||||
Statistics.INSTANCE.trackSubwayEvent(Statistics.ParamValue.UNAVAILABLE);
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
public static TransitSchemeState makeInstance(int index)
|
||||
|
@ -15,4 +35,9 @@ public enum TransitSchemeState
|
|||
throw new IllegalArgumentException("No value for index = " + index);
|
||||
return TransitSchemeState.values()[index];
|
||||
}
|
||||
|
||||
public void onReceived(@NonNull MwmApplication app)
|
||||
{
|
||||
/* Do nothing by default */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.mapswithme.maps.maplayer.traffic;
|
|||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
|
@ -17,14 +16,16 @@ public enum TrafficManager
|
|||
private final String mTag = TrafficManager.class.getSimpleName();
|
||||
@NonNull
|
||||
private final Logger mLogger = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.TRAFFIC);
|
||||
|
||||
@NonNull
|
||||
private final TrafficState.StateChangeListener mStateChangeListener = new TrafficStateListener();
|
||||
@TrafficState.Value
|
||||
private int mState = TrafficState.DISABLED;
|
||||
@TrafficState.Value
|
||||
private int mLastPostedState = mState;
|
||||
|
||||
@NonNull
|
||||
private TrafficState.Type mState = TrafficState.Type.DISABLED;
|
||||
|
||||
@NonNull
|
||||
private final List<TrafficCallback> mCallbacks = new ArrayList<>();
|
||||
|
||||
private boolean mInitialized = false;
|
||||
|
||||
public void initialize()
|
||||
|
@ -80,7 +81,7 @@ public enum TrafficManager
|
|||
|
||||
private void postPendingState()
|
||||
{
|
||||
mStateChangeListener.onTrafficStateChanged(mState);
|
||||
mStateChangeListener.onTrafficStateChanged(mState.ordinal());
|
||||
}
|
||||
|
||||
public void detachAll()
|
||||
|
@ -124,61 +125,12 @@ public enum TrafficManager
|
|||
@MainThread
|
||||
public void onTrafficStateChanged(@TrafficState.Value int state)
|
||||
{
|
||||
mLogger.d(mTag, "onTrafficStateChanged current state = " + TrafficState.nameOf(mState)
|
||||
+ " new value = " + TrafficState.nameOf(state));
|
||||
mState = state;
|
||||
TrafficState.Type newTrafficState = TrafficState.getType(state);
|
||||
mLogger.d(mTag, "onTrafficStateChanged current state = " + mState
|
||||
+ " new value = " + newTrafficState);
|
||||
|
||||
iterateOverCallbacks(new Utils.Proc<TrafficCallback>()
|
||||
{
|
||||
@Override
|
||||
public void invoke(@NonNull TrafficCallback callback)
|
||||
{
|
||||
switch (mState)
|
||||
{
|
||||
case TrafficState.DISABLED:
|
||||
callback.onDisabled();
|
||||
break;
|
||||
|
||||
case TrafficState.ENABLED:
|
||||
callback.onEnabled();
|
||||
break;
|
||||
|
||||
case TrafficState.WAITING_DATA:
|
||||
callback.onWaitingData();
|
||||
break;
|
||||
|
||||
case TrafficState.NO_DATA:
|
||||
callback.onNoData(mLastPostedState != mState);
|
||||
break;
|
||||
|
||||
case TrafficState.OUTDATED:
|
||||
callback.onOutdated();
|
||||
break;
|
||||
|
||||
case TrafficState.NETWORK_ERROR:
|
||||
callback.onNetworkError();
|
||||
break;
|
||||
|
||||
case TrafficState.EXPIRED_DATA:
|
||||
callback.onExpiredData(mLastPostedState != mState);
|
||||
break;
|
||||
|
||||
case TrafficState.EXPIRED_APP:
|
||||
callback.onExpiredApp(mLastPostedState != mState);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported traffic state: " + mState);
|
||||
}
|
||||
mLastPostedState = mState;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void iterateOverCallbacks(@NonNull Utils.Proc<TrafficCallback> proc)
|
||||
{
|
||||
for (TrafficCallback callback : mCallbacks)
|
||||
proc.invoke(callback);
|
||||
newTrafficState.onReceived(mCallbacks, mState);
|
||||
mState = newTrafficState;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,11 @@ import android.support.annotation.IntDef;
|
|||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
|
||||
final class TrafficState
|
||||
{
|
||||
|
@ -24,14 +27,16 @@ final class TrafficState
|
|||
|
||||
// These values should correspond to
|
||||
// TrafficManager::TrafficState enum (from map/traffic_manager.hpp)
|
||||
static final int DISABLED = 0;
|
||||
static final int ENABLED = 1;
|
||||
static final int WAITING_DATA = 2;
|
||||
static final int OUTDATED = 3;
|
||||
static final int NO_DATA = 4;
|
||||
static final int NETWORK_ERROR = 5;
|
||||
static final int EXPIRED_DATA = 6;
|
||||
static final int EXPIRED_APP = 7;
|
||||
private static final int DISABLED = 0;
|
||||
private static final int ENABLED = 1;
|
||||
private static final int WAITING_DATA = 2;
|
||||
private static final int OUTDATED = 3;
|
||||
private static final int NO_DATA = 4;
|
||||
private static final int NETWORK_ERROR = 5;
|
||||
private static final int EXPIRED_DATA = 6;
|
||||
private static final int EXPIRED_APP = 7;
|
||||
|
||||
private TrafficState() {}
|
||||
|
||||
@MainThread
|
||||
static native void nativeSetListener(@NonNull StateChangeListener listener);
|
||||
|
@ -40,38 +45,120 @@ final class TrafficState
|
|||
static native void nativeDisable();
|
||||
static native boolean nativeIsEnabled();
|
||||
|
||||
private TrafficState() {}
|
||||
|
||||
static String nameOf(int state)
|
||||
public enum Type
|
||||
{
|
||||
switch (state)
|
||||
DISABLED
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onDisabled();
|
||||
}
|
||||
},
|
||||
ENABLED(Statistics.ParamValue.SUCCESS)
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onEnabled();
|
||||
}
|
||||
},
|
||||
|
||||
WAITING_DATA
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onWaitingData();
|
||||
}
|
||||
},
|
||||
OUTDATED
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onOutdated();
|
||||
}
|
||||
},
|
||||
NO_DATA(Statistics.ParamValue.UNAVAILABLE)
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onNoData(lastPostedState != NO_DATA);
|
||||
}
|
||||
},
|
||||
NETWORK_ERROR(Statistics.ParamValue.ERROR)
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onNetworkError();
|
||||
}
|
||||
},
|
||||
EXPIRED_DATA
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onExpiredData(lastPostedState != EXPIRED_DATA);
|
||||
}
|
||||
},
|
||||
EXPIRED_APP
|
||||
{
|
||||
@Override
|
||||
protected void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
param.onExpiredApp(lastPostedState != EXPIRED_APP);
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
private final String mAnalyticsParamName;
|
||||
|
||||
Type()
|
||||
{
|
||||
case DISABLED:
|
||||
return "DISABLED";
|
||||
|
||||
case ENABLED:
|
||||
return "ENABLED";
|
||||
|
||||
case WAITING_DATA:
|
||||
return "WAITING_DATA";
|
||||
|
||||
case OUTDATED:
|
||||
return "OUTDATED";
|
||||
|
||||
case NO_DATA:
|
||||
return "NO_DATA";
|
||||
|
||||
case NETWORK_ERROR:
|
||||
return "NETWORK_ERROR";
|
||||
|
||||
case EXPIRED_DATA:
|
||||
return "EXPIRED_DATA";
|
||||
|
||||
case EXPIRED_APP:
|
||||
return "EXPIRED_APP";
|
||||
|
||||
default:
|
||||
return "Unknown: " + state;
|
||||
mAnalyticsParamName = name();
|
||||
}
|
||||
|
||||
Type(@NonNull String analyticsParamName)
|
||||
{
|
||||
mAnalyticsParamName = analyticsParamName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getAnalyticsParamName()
|
||||
{
|
||||
return mAnalyticsParamName;
|
||||
}
|
||||
|
||||
public void onReceived(@NonNull List<TrafficManager.TrafficCallback> trafficCallbacks,
|
||||
@NonNull Type lastPostedState)
|
||||
{
|
||||
for (TrafficManager.TrafficCallback callback : trafficCallbacks)
|
||||
{
|
||||
onReceivedInternal(callback, lastPostedState);
|
||||
Statistics.INSTANCE.trackTrafficEvent(getAnalyticsParamName());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void onReceivedInternal(@NonNull TrafficManager.TrafficCallback param,
|
||||
@NonNull Type lastPostedState);
|
||||
}
|
||||
|
||||
public static Type getType(int index)
|
||||
{
|
||||
if (index < 0 || index >= Type.values().length)
|
||||
throw new IllegalArgumentException("Not found value for index = " + index);
|
||||
|
||||
return Type.values()[index];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -306,6 +306,7 @@ public enum Statistics
|
|||
public static final String UGC_AUTH_DECLINED = "UGC_Auth_declined";
|
||||
public static final String UGC_AUTH_EXTERNAL_REQUEST_SUCCESS = "UGC_Auth_external_request_success";
|
||||
public static final String UGC_AUTH_ERROR = "UGC_Auth_error";
|
||||
public static final String MAP_LAYER = "Map_Layers_activate";
|
||||
|
||||
public static class Settings
|
||||
{
|
||||
|
@ -392,6 +393,9 @@ public enum Statistics
|
|||
public static final String PRICE_CATEGORY = "price_category";
|
||||
public static final String DATE = "date";
|
||||
static final String HAS_AUTH = "has_auth";
|
||||
public static final String NAME_LOWER_CASE = "name";
|
||||
public static final String STATUS = "status";
|
||||
|
||||
private EventParam() {}
|
||||
}
|
||||
|
||||
|
@ -435,6 +439,11 @@ public enum Statistics
|
|||
static final String DISK_NO_SPACE = "disk_no_space";
|
||||
static final String BACKUP = "backup";
|
||||
static final String RESTORE = "restore";
|
||||
static final String SUBWAY = "subway";
|
||||
static final String TRAFFIC = "traffic";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String UNAVAILABLE = "unavailable";
|
||||
public static final String ERROR = "error";
|
||||
}
|
||||
|
||||
// Initialized once in constructor and does not change until the process restarts.
|
||||
|
@ -630,6 +639,23 @@ public enum Statistics
|
|||
PushwooshHelper.nativeSendEditorEditObjectTag();
|
||||
}
|
||||
|
||||
public void trackSubwayEvent(@NonNull String status)
|
||||
{
|
||||
trackMapLayerEvent(ParamValue.SUBWAY, status);
|
||||
}
|
||||
|
||||
public void trackTrafficEvent(@NonNull String status)
|
||||
{
|
||||
trackMapLayerEvent(ParamValue.TRAFFIC, status);
|
||||
}
|
||||
|
||||
private void trackMapLayerEvent(@NonNull String eventName, @NonNull String status)
|
||||
{
|
||||
ParameterBuilder builder = new ParameterBuilder().add(EventParam.NAME_LOWER_CASE, eventName)
|
||||
.add(EventParam.STATUS, status);
|
||||
trackEvent(EventName.MAP_LAYER, builder);
|
||||
}
|
||||
|
||||
public void trackEditorSuccess(boolean newObject)
|
||||
{
|
||||
trackEvent(newObject ? EventName.EDITOR_SUCCESS_CREATE : EventName.EDITOR_SUCCESS_EDIT,
|
||||
|
|
Loading…
Add table
Reference in a new issue