예제 #1
0
  // Before goint go HomeListActivity, we should check ClientAuthentication is valid.
  void openHomeListActivity(final boolean goToLoginIfFail) {
    progressDialog = new LoadingProgressDialog<MainActivity>(this);

    final WeakReference<MainActivity> weakThis = new WeakReference<>(this);
    MODEApp.getCurrentAuthenticationState(
        getApplicationContext(),
        DataHolder.getClientAuthentication(),
        new MODEApp.Completion<MODEData.AuthenticationInfo>() {
          @Override
          public void done(MODEData.AuthenticationInfo ret, Throwable e) {
            MainActivity activity = weakThis.get();
            progressDialog.hide();
            if (e != null) {
              MiscUtils.showAlert(getApplicationContext(), getClass(), e);
            } else if (ret.type.equals("user")) {
              if (activity != null) {
                if (DataHolder.getClientAuthentication() != null) {
                  if (DataHolder.getClientAuthentication().userId != ret.userId) {
                    MiscUtils.showAlert(
                        getApplicationContext(),
                        getClass(),
                        new Error(
                            "Wrong userId so clear the token userId: "
                                + Integer.toString(ret.userId)));
                    DataHolder.setClientAuthentication(null);
                    DataHolder.saveData(getApplicationContext());
                  } else {
                    DeviceManager.getInstance()
                        .startListenToEvents(DataHolder.getClientAuthentication());
                    startActivity(new Intent(activity, HomeListActivity.class));
                  }
                } else {
                  DeviceManager.getInstance().stopListenToEvents();
                  DeviceManager.getInstance().clearAllDelegators();
                }
              }
            } else if (goToLoginIfFail) {
              if (activity != null) {
                startActivity(new Intent(activity, LoginActivity.class));
              }
            }
          }
        });
  }
예제 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DataHolder.loadData(getApplicationContext());

    logger.i("The target APIHost is " + DataHolder.getAPIHost());
    MODEApp.setAPIHost(DataHolder.getAPIHost());
    MODEEventListener.setWebsocketHost(DataHolder.getAPIHost());

    setContentView(R.layout.activity_main);

    if (DataHolder.getProjectId() == 0) {
      onClickSetting(null);
    }

    if (DataHolder.getClientAuthentication() != null) {
      openHomeListActivity(false);
    }
  }