Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PassportAuthDialogFragment.java « auth « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1500d874947fe10ee3d9fd304496efc4678a0a4a (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
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 com.mapswithme.maps.Framework;
import com.mapswithme.maps.background.Notifier;
import com.mapswithme.maps.base.BaseMwmDialogFragment;
import com.mapswithme.util.statistics.Statistics;

public class PassportAuthDialogFragment extends BaseMwmDialogFragment
    implements TargetFragmentCallback
{
  @NonNull
  private final Authorizer mAuthorizer = new Authorizer(this);

  @NonNull
  private final AuthCallback mAuthCallback = new AuthCallback();

  @Nullable
  private Bundle mSavedInstanceState;

  @Override
  public void onCreate(@Nullable Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    mSavedInstanceState = savedInstanceState;
  }

  @Override
  @CallSuper
  public void onStart()
  {
    super.onStart();
    mAuthorizer.attach(mAuthCallback);
    if (mSavedInstanceState == null)
      mAuthorizer.authorize();
  }

  @Override
  @CallSuper
  public void onStop()
  {
    super.onStop();
    mAuthorizer.detach();
  }

  @Override
  public void onTargetFragmentResult(int resultCode, @Nullable Intent data)
  {
    mAuthorizer.onTargetFragmentResult(resultCode, data);
    dismiss();
  }

  @Override
  public boolean isTargetAdded()
  {
    return isAdded();
  }

  private class AuthCallback implements Authorizer.Callback
  {
    @Override
    public void onAuthorizationFinish(boolean success)
    {
      dismiss();
      if (success)
      {
        Notifier notifier = Notifier.from(getActivity().getApplication());
        notifier.cancelNotification(Notifier.ID_IS_NOT_AUTHENTICATED);
      }
    }

    @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);
    }
  }
}