mobile/android/base/fxa/login/State.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:181fdcbb214f
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.gecko.fxa.login;
6
7 import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate;
8 import org.mozilla.gecko.sync.ExtendedJSONObject;
9 import org.mozilla.gecko.sync.Utils;
10
11 public abstract class State {
12 public static final long CURRENT_VERSION = 2L;
13
14 public enum StateLabel {
15 Engaged,
16 Cohabiting,
17 Married,
18 Separated,
19 Doghouse,
20 }
21
22 public enum Action {
23 NeedsUpgrade,
24 NeedsPassword,
25 NeedsVerification,
26 None,
27 }
28
29 protected final StateLabel stateLabel;
30 public final String email;
31 public final String uid;
32 public final boolean verified;
33
34 public State(StateLabel stateLabel, String email, String uid, boolean verified) {
35 Utils.throwIfNull(email, uid);
36 this.stateLabel = stateLabel;
37 this.email = email;
38 this.uid = uid;
39 this.verified = verified;
40 }
41
42 public StateLabel getStateLabel() {
43 return this.stateLabel;
44 }
45
46 public ExtendedJSONObject toJSONObject() {
47 ExtendedJSONObject o = new ExtendedJSONObject();
48 o.put("version", State.CURRENT_VERSION);
49 o.put("email", email);
50 o.put("uid", uid);
51 o.put("verified", verified);
52 return o;
53 }
54
55 public State makeSeparatedState() {
56 return new Separated(email, uid, verified);
57 }
58
59 public State makeDoghouseState() {
60 return new Doghouse(email, uid, verified);
61 }
62
63 public abstract void execute(ExecuteDelegate delegate);
64
65 public abstract Action getNeededAction();
66 }

mercurial