use of im.actor.runtime.storage.PreferencesStorage in project actor-platform by actorapp.
the class AuthActivity method updateState.
private void updateState(AuthState state, boolean force) {
if (this.state != null && (this.state == state && !force)) {
return;
}
PreferencesStorage preferences = messenger().getPreferences();
preferences.putLong("currentPhone", currentPhone);
preferences.putString("currentEmail", currentEmail);
preferences.putString("transactionHash", transactionHash);
preferences.putBool("isRegistered", isRegistered);
preferences.putBool("codeValidated", codeValidated);
preferences.putString("currentName", currentName);
preferences.putInt("signType", signType);
preferences.putString("auth_state", state.toString());
// e.g when the GSM data is off and after trying to send code we go to settings to turn on, app is going invisible and ...
if (state != AuthState.LOGGED_IN && getIsResumed() == false) {
return;
}
this.state = state;
switch(state) {
case AUTH_START:
if (signType == SIGN_TYPE_UP) {
updateState(AuthState.SIGN_UP);
} else if (signType == SIGN_TYPE_IN) {
showFragment(new SignInFragment(), false);
}
break;
case SIGN_UP:
if (currentName != null && !currentName.isEmpty()) {
startAuth(currentName);
} else {
showFragment(new SignUpFragment(), false);
}
break;
case AUTH_PHONE:
currentAuthType = AUTH_TYPE_PHONE;
currentCode = "";
showFragment(ActorSDK.sharedActor().getDelegatedFragment(ActorSDK.sharedActor().getDelegate().getAuthStartIntent(), new SignPhoneFragment(), BaseAuthFragment.class), false);
break;
case AUTH_EMAIL:
currentCode = "";
currentAuthType = AUTH_TYPE_EMAIL;
showFragment(ActorSDK.sharedActor().getDelegatedFragment(ActorSDK.sharedActor().getDelegate().getAuthStartIntent(), new SignEmailFragment(), BaseAuthFragment.class), false);
break;
case CODE_VALIDATION_PHONE:
case CODE_VALIDATION_EMAIL:
Fragment signInFragment = new ValidateCodeFragment();
Bundle args = new Bundle();
args.putString("authType", state == AuthState.CODE_VALIDATION_EMAIL ? ValidateCodeFragment.AUTH_TYPE_EMAIL : ValidateCodeFragment.AUTH_TYPE_PHONE);
args.putBoolean(ValidateCodeFragment.AUTH_TYPE_SIGN, signType == SIGN_TYPE_IN);
args.putString("authId", state == AuthState.CODE_VALIDATION_EMAIL ? currentEmail : Long.toString(currentPhone));
signInFragment.setArguments(args);
showFragment(signInFragment, false);
break;
case LOGGED_IN:
finish();
ActorSDK.sharedActor().startAfterLoginActivity(this);
break;
}
}
use of im.actor.runtime.storage.PreferencesStorage in project actor-platform by actorapp.
the class ClcJavaPreferenceStorageTest method getString.
@Test
public void getString() {
PreferencesStorage pref = new ClcJavaPreferenceStorage();
pref.putString("key", "string");
// assertEquals("string", pref.getString("key"));
}
use of im.actor.runtime.storage.PreferencesStorage in project actor-platform by actorapp.
the class ClcJavaPreferenceStorageTest method getLong.
@Test
public void getLong() {
PreferencesStorage pref = new ClcJavaPreferenceStorage();
pref.putLong("key", 1);
// assertEquals(1, pref.getLong("key", 0));
// assertEquals(0, pref.getLong("nokey", 0));
}
use of im.actor.runtime.storage.PreferencesStorage in project actor-platform by actorapp.
the class AuthActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
authActor = ActorSystem.system().actorOf(Props.create(new ActorCreator() {
@Override
public Actor create() {
return new Actor();
}
}), "actor/auth_promises_actor");
signType = getIntent().getIntExtra(SIGN_TYPE_KEY, SIGN_TYPE_IN);
PreferencesStorage preferences = messenger().getPreferences();
currentPhone = preferences.getLong("currentPhone", 0);
currentEmail = preferences.getString("currentEmail");
transactionHash = preferences.getString("transactionHash");
isRegistered = preferences.getBool("isRegistered", false);
codeValidated = preferences.getBool("codeValidated", false);
currentName = preferences.getString("currentName");
signType = preferences.getInt("signType", signType);
String savedState = preferences.getString("auth_state");
state = Enum.valueOf(AuthState.class, savedState != null ? savedState : "AUTH_START");
updateState(state, true);
}
use of im.actor.runtime.storage.PreferencesStorage in project actor-platform by actorapp.
the class ClcJavaPreferenceStorageTest method getBytes.
@Test
public void getBytes() {
PreferencesStorage pref = new ClcJavaPreferenceStorage();
pref.putBytes("key", new byte[] { 1, 2, 3 });
byte[] arr = pref.getBytes("key");
// assertEquals((byte)1, arr[0]);
// assertEquals((byte)2, arr[1]);
// assertEquals((byte)3, arr[2]);
}
Aggregations