forked from organicmaps/organicmaps
[android] Statistics for osm authorization.
This commit is contained in:
parent
a7da17fecb
commit
247c6d9ea3
4 changed files with 66 additions and 17 deletions
|
@ -63,16 +63,16 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
switch (v.getId())
|
||||
{
|
||||
case R.id.login_osm:
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST, Statistics.params().add(Statistics.EventParam.TYPE, AuthType.OSM.name));
|
||||
loginOsm();
|
||||
break;
|
||||
case R.id.login_facebook:
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST);
|
||||
loginWebview(true);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST, Statistics.params().add(Statistics.EventParam.TYPE, AuthType.FACEBOOK.name));
|
||||
loginWebview(AuthType.FACEBOOK);
|
||||
break;
|
||||
case R.id.login_google:
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST);
|
||||
loginWebview(false);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST, Statistics.params().add(Statistics.EventParam.TYPE, AuthType.GOOGLE.name));
|
||||
loginWebview(AuthType.GOOGLE);
|
||||
break;
|
||||
case R.id.lost_password:
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST);
|
||||
|
@ -90,7 +90,7 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
getMwmActivity().replaceFragment(OsmAuthFragment.class, null, null);
|
||||
}
|
||||
|
||||
protected void loginWebview(final boolean facebook)
|
||||
protected void loginWebview(final AuthType type)
|
||||
{
|
||||
final WebView webview = new InputWebView(getActivity());
|
||||
final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(webview).create();
|
||||
|
@ -100,8 +100,8 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
final String[] auth = facebook ? OsmOAuth.nativeGetFacebookAuthUrl()
|
||||
: OsmOAuth.nativeGetGoogleAuthUrl();
|
||||
final String[] auth = (type == AuthType.FACEBOOK) ? OsmOAuth.nativeGetFacebookAuthUrl()
|
||||
: OsmOAuth.nativeGetGoogleAuthUrl();
|
||||
|
||||
UiThread.run(new Runnable()
|
||||
{
|
||||
|
@ -109,7 +109,7 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
public void run()
|
||||
{
|
||||
if (isAdded())
|
||||
loadWebviewAuth(dialog, webview, auth);
|
||||
loadWebviewAuth(dialog, webview, auth, type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
protected void loadWebviewAuth(final AlertDialog dialog, final WebView webview, @Size(3) final String[] auth)
|
||||
protected void loadWebviewAuth(final AlertDialog dialog, final WebView webview, @Size(3) final String[] auth, final AuthType type)
|
||||
{
|
||||
if (auth == null)
|
||||
{
|
||||
|
@ -138,7 +138,7 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
}
|
||||
else if (url.contains(OsmOAuth.URL_PARAM_VERIFIER))
|
||||
{
|
||||
finishWebviewAuth(auth[1], auth[2], getVerifierFromUrl(url));
|
||||
finishWebviewAuth(auth[1], auth[2], getVerifierFromUrl(url), type);
|
||||
dialog.cancel();
|
||||
return true;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
webview.loadUrl(authUrl);
|
||||
}
|
||||
|
||||
protected void finishWebviewAuth(final String key, final String secret, final String verifier)
|
||||
protected void finishWebviewAuth(final String key, final String secret, final String verifier, final AuthType type)
|
||||
{
|
||||
ThreadPool.getWorker().execute(new Runnable() {
|
||||
@Override
|
||||
|
@ -169,7 +169,7 @@ public class AuthFragment extends BaseAuthFragment implements View.OnClickListen
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
processAuth(auth);
|
||||
processAuth(auth, type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,22 +5,43 @@ import android.support.v7.app.AlertDialog;
|
|||
|
||||
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public abstract class BaseAuthFragment extends BaseMwmToolbarFragment
|
||||
{
|
||||
protected void processAuth(@Size(2) String[] auth)
|
||||
public enum AuthType
|
||||
{
|
||||
OSM("OSM"),
|
||||
FACEBOOK("Facebook"),
|
||||
GOOGLE("Google");
|
||||
|
||||
String name;
|
||||
|
||||
AuthType(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
protected void processAuth(@Size(2) String[] auth, AuthType type)
|
||||
{
|
||||
if (auth == null)
|
||||
{
|
||||
if (isAdded())
|
||||
{
|
||||
// TODO set correct text
|
||||
new AlertDialog.Builder(getActivity()).setTitle("Auth error!")
|
||||
.setPositiveButton(android.R.string.ok, null).show();
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST_RESULT,
|
||||
Statistics.params().add(Statistics.EventParam.IS_SUCCESS, false).add(Statistics.EventParam.TYPE, type.name));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
OsmOAuth.setAuthorization(auth[0], auth[1]);
|
||||
Utils.navigateToParent(getActivity());
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST_RESULT,
|
||||
Statistics.params().add(Statistics.EventParam.IS_SUCCESS, true).add(Statistics.EventParam.TYPE, type.name));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickLis
|
|||
enableInput(true);
|
||||
UiUtils.hide(mProgress);
|
||||
mTvLogin.setText(R.string.login);
|
||||
processAuth(auth);
|
||||
processAuth(auth, AuthType.OSM);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -114,9 +114,9 @@ public enum Statistics
|
|||
public static final String EDITOR_ERROR = "Editor_Edit_error";
|
||||
public static final String EDITOR_AUTH_DECLINED = "Editor_Auth_declined_by_user";
|
||||
public static final String EDITOR_AUTH_REQUEST = "Editor_Auth_request";
|
||||
public static final String EDITOR_AUTH_REQUEST_RESULT = "Editor_Auth_request_result";
|
||||
public static final String EDITOR_REG_REQUEST = "Editor_Reg_request";
|
||||
public static final String EDITOR_SYNC_SUCCESS = "Editor_DataSync_success";
|
||||
public static final String EDITOR_SYNC_ERROR = "Editor_DataSync_error";
|
||||
public static final String EDITOR_REG_RESULT = "Editor_Reg_request_result";
|
||||
public static final String EDITOR_SHARE_SHOW = "Editor_SecondTimeShare_show";
|
||||
public static final String EDITOR_SHARE_CLICK = "Editor_SecondTimeShare_click";
|
||||
public static final String EDITOR_REPORT = "Editor_Problem_report";
|
||||
|
@ -183,6 +183,10 @@ public enum Statistics
|
|||
public static final String SERVER_URL = "server_url";
|
||||
public static final String SERVER_PARAMS = "server_params_data";
|
||||
public static final String SERVER_RESPONSE = "server_response_data";
|
||||
public static final String OSM = "OSM";
|
||||
public static final String OSM_USERNAME = "osm_username";
|
||||
public static final String FACEBOOK = "Facebook";
|
||||
public static final String GOOGLE = "Google";
|
||||
public static final String UID = "uid";
|
||||
public static final String SHOWN = "shown";
|
||||
private EventParam() {}
|
||||
|
@ -381,6 +385,30 @@ public enum Statistics
|
|||
return this;
|
||||
}
|
||||
|
||||
public ParameterBuilder add(String key, boolean value)
|
||||
{
|
||||
mParams.put(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParameterBuilder add(String key, int value)
|
||||
{
|
||||
mParams.put(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParameterBuilder add(String key, float value)
|
||||
{
|
||||
mParams.put(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParameterBuilder add(String key, double value)
|
||||
{
|
||||
mParams.put(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> get()
|
||||
{
|
||||
return mParams;
|
||||
|
|
Loading…
Add table
Reference in a new issue