Search in sources :

Example 6 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class AuthenticatorActivity method onRestoreInstanceState.

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    // AsyncTask
    boolean inProgress = savedInstanceState.getBoolean(KEY_ASYNC_TASK_IN_PROGRESS);
    if (inProgress) {
        String username = savedInstanceState.getString(KEY_USERNAME);
        String password = savedInstanceState.getString(KEY_PASSWORD);
        OwnCloudCredentials credentials = null;
        if (BASIC_TOKEN_TYPE.equals(mAuthTokenType)) {
            String version = savedInstanceState.getString(KEY_OC_VERSION);
            OwnCloudVersion ocVersion = (version != null) ? new OwnCloudVersion(version) : null;
            credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password, (ocVersion != null && ocVersion.isPreemptiveAuthenticationPreferred()));
        } else if (OAUTH_TOKEN_TYPE.equals(mAuthTokenType)) {
            credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);
        }
        accessRootFolder(credentials);
    }
}
Also used : OwnCloudCredentials(com.owncloud.android.lib.common.OwnCloudCredentials) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Example 7 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class AuthenticatorActivity method initServerPreFragment.

/**
     * 
     * @param savedInstanceState        Saved activity state, as in {{@link #onCreate(Bundle)}
     */
private void initServerPreFragment(Bundle savedInstanceState) {
    boolean checkHostUrl = true;
    /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)
    boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input);
    if (savedInstanceState == null) {
        if (mAccount != null) {
            mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
            // TODO do next in a setter for mBaseUrl
            mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
            mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount);
        } else {
            mServerInfo.mBaseUrl = getString(R.string.server_url).trim();
            mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
        }
    } else {
        mServerStatusText = savedInstanceState.getString(KEY_SERVER_STATUS_TEXT);
        mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);
        mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID);
        mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED);
        // TODO parcelable
        mServerInfo.mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);
        mServerInfo.mBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);
        String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);
        if (ocVersion != null) {
            mServerInfo.mVersion = new OwnCloudVersion(ocVersion);
        }
        mServerInfo.mAuthMethod = AuthenticationMethod.valueOf(savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));
    }
    /// step 2 - set properties of UI elements (text, visibility, enabled...)
    mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);
    // Convert IDN to Unicode
    mHostUrlInput.setText(DisplayUtils.convertIdn(mServerInfo.mBaseUrl, false));
    if (mAction != ACTION_CREATE) {
        /// lock things that should not change
        mHostUrlInput.setEnabled(false);
        mHostUrlInput.setFocusable(false);
    }
    if (isUrlInputAllowed) {
        if (mServerInfo.mBaseUrl.isEmpty()) {
            checkHostUrl = false;
        }
        mRefreshButton = findViewById(R.id.embeddedRefreshButton);
    } else {
        findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);
        mRefreshButton = findViewById(R.id.centeredRefreshButton);
    }
    showRefreshButton(mServerIsChecked && !mServerIsValid && mWaitingForOpId > Integer.MAX_VALUE);
    mServerStatusView = (TextView) findViewById(R.id.server_status_text);
    showServerStatus();
    /// step 3 - bind some listeners and options
    mHostUrlInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    mHostUrlInput.setOnEditorActionListener(this);
    /// step 4 - create listeners that will be bound at onResume
    mHostUrlInputWatcher = new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (mOkButton.isEnabled() && !mServerInfo.mBaseUrl.equals(normalizeUrl(s.toString(), mServerInfo.mIsSslConn))) {
                mOkButton.setEnabled(false);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mAuthStatusIcon != 0) {
                Log_OC.d(TAG, "onTextChanged: hiding authentication status");
                mAuthStatusIcon = 0;
                mAuthStatusText = "";
                showAuthStatus();
            }
        }
    };
    // TODO find out if this is really necessary, or if it can done in a different way
    findViewById(R.id.scroll).setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType) && mHostUrlInput.hasFocus()) {
                    checkOcServer();
                }
            }
            return false;
        }
    });
    /// step 4 - mark automatic check to be started when OperationsService is ready
    mPendingAutoCheck = (savedInstanceState == null && (mAction != ACTION_CREATE || checkHostUrl));
}
Also used : OnTouchListener(android.view.View.OnTouchListener) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) MotionEvent(android.view.MotionEvent)

Example 8 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class UpdateOCVersionOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    AccountManager accountMngr = AccountManager.get(mContext);
    String statUrl = accountMngr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
    statUrl += AccountUtils.STATUS_PATH;
    RemoteOperationResult result = null;
    GetMethod getMethod = null;
    try {
        getMethod = new GetMethod(statUrl);
        int status = client.executeMethod(getMethod);
        if (status != HttpStatus.SC_OK) {
            result = new RemoteOperationResult(false, getMethod);
            client.exhaustResponse(getMethod.getResponseBodyAsStream());
        } else {
            String response = getMethod.getResponseBodyAsString();
            if (response != null) {
                JSONObject json = new JSONObject(response);
                if (json != null && json.getString("version") != null) {
                    String version = json.getString("version");
                    mOwnCloudVersion = new OwnCloudVersion(version);
                    if (mOwnCloudVersion.isVersionValid()) {
                        accountMngr.setUserData(mAccount, Constants.KEY_OC_VERSION, mOwnCloudVersion.getVersion());
                        Log_OC.d(TAG, "Got new OC version " + mOwnCloudVersion.toString());
                        result = new RemoteOperationResult(ResultCode.OK);
                    } else {
                        Log_OC.w(TAG, "Invalid version number received from server: " + json.getString("version"));
                        result = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION);
                    }
                }
            }
            if (result == null) {
                result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
            }
        }
        Log_OC.i(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage());
    } catch (JSONException e) {
        result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
        Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
    } finally {
        if (getMethod != null)
            getMethod.releaseConnection();
    }
    return result;
}
Also used : JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONException(org.json.JSONException) AccountManager(android.accounts.AccountManager) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) JSONException(org.json.JSONException)

Example 9 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class AccountUtilsTest method testGetWebdavPathAndOCVersion.

public void testGetWebdavPathAndOCVersion() {
    OwnCloudVersion ocv12 = new OwnCloudVersion(0x010200);
    OwnCloudVersion ocv12s = new OwnCloudVersion("1.2");
    OwnCloudVersion ocv22 = new OwnCloudVersion(0x020200);
    OwnCloudVersion ocv30 = new OwnCloudVersion(0x030000);
    OwnCloudVersion ocv33s = new OwnCloudVersion("3.3.3");
    OwnCloudVersion ocv45 = new OwnCloudVersion(0x040500);
    OwnCloudVersion ocv70 = new OwnCloudVersion(0x070000);
    assertTrue(AccountUtils.getWebdavPath(ocv12, false, false).equals("/webdav/owncloud.php"));
    assertTrue(AccountUtils.getWebdavPath(ocv12s, false, false).equals("/webdav/owncloud.php"));
    assertTrue(AccountUtils.getWebdavPath(ocv22, false, false).equals("/files/webdav.php"));
    assertTrue(AccountUtils.getWebdavPath(ocv30, false, false).equals("/files/webdav.php"));
    assertTrue(AccountUtils.getWebdavPath(ocv33s, false, false).equals("/files/webdav.php"));
    assertTrue(AccountUtils.getWebdavPath(ocv45, false, false).equals("/remote.php/webdav"));
    assertTrue(AccountUtils.getWebdavPath(ocv70, false, false).equals("/remote.php/webdav"));
    assertNull(AccountUtils.getWebdavPath(null, false, false));
    assertTrue(AccountUtils.getWebdavPath(ocv12, true, false).equals("/remote.php/odav"));
    assertTrue(AccountUtils.getWebdavPath(ocv12s, true, false).equals("/remote.php/odav"));
    assertTrue(AccountUtils.getWebdavPath(ocv22, true, false).equals("/remote.php/odav"));
    assertTrue(AccountUtils.getWebdavPath(ocv30, true, false).equals("/remote.php/odav"));
    assertTrue(AccountUtils.getWebdavPath(ocv33s, true, false).equals("/remote.php/odav"));
    assertTrue(AccountUtils.getWebdavPath(ocv45, true, false).equals("/remote.php/odav"));
    assertTrue(AccountUtils.getWebdavPath(ocv70, true, false).equals("/remote.php/odav"));
    OwnCloudVersion invalidVer = new OwnCloudVersion("a.b.c");
    assertFalse(invalidVer.isVersionValid());
    assertTrue(ocv45.toString().equals("4.5.0"));
}
Also used : OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Aggregations

OwnCloudVersion (com.owncloud.android.lib.resources.status.OwnCloudVersion)9 AccountManager (android.accounts.AccountManager)3 OCFile (com.owncloud.android.datamodel.OCFile)2 Account (android.accounts.Account)1 Message (android.os.Message)1 Parcelable (android.os.Parcelable)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 OnTouchListener (android.view.View.OnTouchListener)1 WebView (android.webkit.WebView)1 CompoundButton (android.widget.CompoundButton)1 TextView (android.widget.TextView)1 OCUpload (com.owncloud.android.db.OCUpload)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 OwnCloudCredentials (com.owncloud.android.lib.common.OwnCloudCredentials)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)1 Vector (java.util.Vector)1