Ejemplo n.º 1
0
  private void doLogin() {

    mInstance = mInstanceEdit.getText().toString();
    if (mInstance == null || "".equals(mInstance)) return;
    if (mInstance.endsWith("/")) mInstance = mInstance.substring(0, mInstance.length() - 1);
    if (mInstance.toLowerCase().startsWith("http")) mSURL = mInstance;
    else {
      if (mForceSSLEdit.isChecked()) mSURL = "https://" + mInstance;
      else mSURL = "http://" + mInstance;
    }
    try {
      mURL = new URL(mSURL);
    } catch (MalformedURLException e) {
      new AlertDialog.Builder(BasicAuthLogin.this)
          .setTitle(getString(R.string.error))
          .setMessage(getString(R.string.error_invalid_url))
          .setNeutralButton(getString(R.string.close), null)
          .show();
      return;
    }
    // If it's twitter I force OAuth login
    if (mURL.getHost().equalsIgnoreCase("twitter.com")) {
      doOAuthLogin();
    }
    mUsername = mUsernameEdit.getText().toString();
    if (mUsername == null || "".equals(mUsername)) return;
    mPassword = mPasswordEdit.getText().toString();
    if (mPassword == null || "".equals(mPassword)) return;
    try {
      final long uid = mDbHelper.userExists(mUsername, mSURL);
      if (uid > 0) {
        new AlertDialog.Builder(BasicAuthLogin.this)
            .setTitle(getString(R.string.error))
            .setMessage(getString(R.string.error_duplicate_account))
            .setPositiveButton(
                R.string.yes,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface xdialog, int id) {
                    mDbHelper.deleteAccount(uid);
                    mDbHelper.resetDefaultAccounts();
                    new AuthenticateAccountTask().execute();
                  }
                })
            .setNeutralButton(R.string.no, null)
            .show();
        return;
      }
    } catch (Exception e) {
      Log.e(getClass().getCanonicalName(), e.toString());
      e.printStackTrace();
    }
    new AuthenticateAccountTask().execute();
  }
Ejemplo n.º 2
0
 public int execute(MustardDbAdapter dbHelper, StatusNet statusNet, int rowType, String extra)
     throws Exception {
   if (MustardApplication.DEBUG) Log.i(TAG, "background task - start");
   ArrayList<org.mumod.statusnet.Status> al = null;
   try {
     if (statusNet == null) {
       Log.e(TAG, "Statusnet is null!");
       return 0;
     }
     long maxId = dbHelper.fetchMaxStatusesId(0, rowType, extra);
     al = statusNet.get(rowType, extra, maxId, true);
     if (al == null || al.size() < 1) {
       return 0;
     } else {
       dbHelper.createStatuses(0, rowType, extra, al);
     }
   } catch (Exception e) {
     if (MustardApplication.DEBUG) e.printStackTrace();
     throw e;
   } finally {
     if (MustardApplication.DEBUG) Log.i(TAG, "background task - end ");
   }
   return 1;
 }
Ejemplo n.º 3
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    setTitle(getString(R.string.app_name) + " - " + getString(R.string.lbl_create_account));
    mDbHelper = new MustardDbAdapter(this);
    mDbHelper.open();
    mUsernameEdit = (EditText) findViewById(R.id.edit_username);
    mUsernameEdit.setText("");
    mPasswordEdit = (EditText) findViewById(R.id.edit_password);
    mPasswordEdit.setText("");
    mInstanceEdit = (EditText) findViewById(R.id.edit_instance);
    mInstanceEdit.setText("");
    mForceSSLEdit = (CheckBox) findViewById(R.id.force_ssl);

    Intent intent = getIntent();

    String instance = intent.getStringExtra(EXTRA_INSTANCE);
    if (instance != null && !"".equals(instance)) {
      mInstanceEdit.setText(instance);
    }

    mSaveButton = (Button) findViewById(R.id.button_login);
    mSaveButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            doLogin();
          }
        });

    mOAuthButton = (Button) findViewById(R.id.button_oauth);
    mOAuthButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            doOAuthLogin();
          }
        });
  }
Ejemplo n.º 4
0
 public void onDestroy() {
   if (mDbHelper != null) {
     mDbHelper.close();
   }
   super.onDestroy();
 }