1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/fxa/login/State.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.fxa.login; 1.9 + 1.10 +import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate; 1.11 +import org.mozilla.gecko.sync.ExtendedJSONObject; 1.12 +import org.mozilla.gecko.sync.Utils; 1.13 + 1.14 +public abstract class State { 1.15 + public static final long CURRENT_VERSION = 2L; 1.16 + 1.17 + public enum StateLabel { 1.18 + Engaged, 1.19 + Cohabiting, 1.20 + Married, 1.21 + Separated, 1.22 + Doghouse, 1.23 + } 1.24 + 1.25 + public enum Action { 1.26 + NeedsUpgrade, 1.27 + NeedsPassword, 1.28 + NeedsVerification, 1.29 + None, 1.30 + } 1.31 + 1.32 + protected final StateLabel stateLabel; 1.33 + public final String email; 1.34 + public final String uid; 1.35 + public final boolean verified; 1.36 + 1.37 + public State(StateLabel stateLabel, String email, String uid, boolean verified) { 1.38 + Utils.throwIfNull(email, uid); 1.39 + this.stateLabel = stateLabel; 1.40 + this.email = email; 1.41 + this.uid = uid; 1.42 + this.verified = verified; 1.43 + } 1.44 + 1.45 + public StateLabel getStateLabel() { 1.46 + return this.stateLabel; 1.47 + } 1.48 + 1.49 + public ExtendedJSONObject toJSONObject() { 1.50 + ExtendedJSONObject o = new ExtendedJSONObject(); 1.51 + o.put("version", State.CURRENT_VERSION); 1.52 + o.put("email", email); 1.53 + o.put("uid", uid); 1.54 + o.put("verified", verified); 1.55 + return o; 1.56 + } 1.57 + 1.58 + public State makeSeparatedState() { 1.59 + return new Separated(email, uid, verified); 1.60 + } 1.61 + 1.62 + public State makeDoghouseState() { 1.63 + return new Doghouse(email, uid, verified); 1.64 + } 1.65 + 1.66 + public abstract void execute(ExecuteDelegate delegate); 1.67 + 1.68 + public abstract Action getNeededAction(); 1.69 +}