1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package com.mapswithme.maps.editor;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.annotation.Size;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import com.mapswithme.maps.R;
import com.mapswithme.util.Constants;
import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.Statistics;
public abstract class OsmAuthFragmentDelegate implements View.OnClickListener
{
private final Fragment mFragment;
protected abstract void loginOsm();
public OsmAuthFragmentDelegate(Fragment fragment)
{
mFragment = fragment;
}
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
for (@IdRes int childId : new int[] {R.id.login_osm, R.id.register})
{
final View v = view.findViewById(childId);
if (v != null)
v.setOnClickListener(this);
}
}
@Override
public void onClick(View v)
{
// TODO show/hide spinners
switch (v.getId())
{
case R.id.login_osm:
Statistics.INSTANCE.trackAuthRequest(OsmOAuth.AuthType.OSM);
loginOsm();
break;
case R.id.register:
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_REG_REQUEST);
register();
break;
}
}
protected void processAuth(@Size(2) String[] auth, OsmOAuth.AuthType type, String username)
{
if (auth == null)
{
if (mFragment.isAdded())
{
new AlertDialog.Builder(mFragment.getActivity()).setTitle(R.string.editor_login_error_dialog)
.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], username);
if (mFragment.isAdded())
Utils.navigateToParent(mFragment.getActivity());
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_AUTH_REQUEST_RESULT,
Statistics.params().add(Statistics.EventParam.IS_SUCCESS, true).add(Statistics.EventParam.TYPE, type.name));
}
protected void register()
{
mFragment.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.Url.OSM_REGISTER)));
}
}
|