Search in sources :

Example 1 with PostDao

use of in.testpress.testpress.models.PostDao in project android by testpress.

the class TestpressServiceProvider method logout.

public void logout(final Activity activity, TestpressService testpressService, TestpressServiceProvider serviceProvider, LogoutService logoutService) {
    final ProgressDialog progressDialog = new ProgressDialog(activity, R.style.AppCompatAlertDialogStyle);
    progressDialog.setTitle(R.string.label_logging_out);
    progressDialog.setMessage(activity.getString(R.string.please_wait));
    progressDialog.setCancelable(false);
    UIUtils.setIndeterminateDrawable(activity, progressDialog, 4);
    progressDialog.show();
    serviceProvider.invalidateAuthToken(activity);
    SharedPreferences preferences = activity.getSharedPreferences(Constants.GCM_PREFERENCE_NAME, Context.MODE_PRIVATE);
    preferences.edit().putBoolean(GCMPreference.SENT_TOKEN_TO_SERVER, false).apply();
    CommonUtils.registerDevice(activity, testpressService, serviceProvider);
    DaoSession daoSession = ((TestpressApplication) activity.getApplicationContext()).getDaoSession();
    PostDao postDao = daoSession.getPostDao();
    postDao.deleteAll();
    daoSession.clear();
    TestpressSdk.clearActiveSession(activity);
    TestpressSDKDatabase.clearDatabase(activity);
    logoutService.logout(new Runnable() {

        @Override
        public void run() {
            Intent intent;
            if (activity.getClass() == MainActivity.class) {
                intent = activity.getIntent();
            } else {
                intent = new Intent(activity, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            }
            progressDialog.dismiss();
            activity.finish();
            activity.startActivity(intent);
        }
    });
}
Also used : PostDao(in.testpress.testpress.models.PostDao) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) MainActivity(in.testpress.testpress.ui.MainActivity) ProgressDialog(android.app.ProgressDialog) DaoSession(in.testpress.testpress.models.DaoSession)

Example 2 with PostDao

use of in.testpress.testpress.models.PostDao in project android by testpress.

the class LoginActivity method finishLogin.

/**
 * Called when response is received from the server for authentication
 * request. See onAuthenticationResult(). Sets the
 * AccountAuthenticatorResult which is sent back to the caller. Also sets
 * the authToken in AccountManager for this account.
 */
protected void finishLogin() {
    SharedPreferences sharedPreferences = getSharedPreferences(Constants.GCM_PREFERENCE_NAME, Context.MODE_PRIVATE);
    sharedPreferences.edit().putBoolean(GCMPreference.SENT_TOKEN_TO_SERVER, false).apply();
    CommonUtils.registerDevice(this, testpressService);
    final Account account = new Account(username, Constants.Auth.TESTPRESS_ACCOUNT_TYPE);
    if (requestNewAccount) {
        accountManager.addAccountExplicitly(account, password, null);
        accountManager.setAuthToken(account, Constants.Auth.TESTPRESS_ACCOUNT_TYPE, authToken);
    } else {
        accountManager.setPassword(account, password);
    }
    DaoSession daoSession = ((TestpressApplication) getApplicationContext()).getDaoSession();
    PostDao postDao = daoSession.getPostDao();
    postDao.deleteAll();
    daoSession.clear();
    if (authTokenType != null && authTokenType.equals(Constants.Auth.AUTHTOKEN_TYPE)) {
        final Intent intent = new Intent();
        intent.putExtra(KEY_ACCOUNT_NAME, username);
        intent.putExtra(KEY_ACCOUNT_TYPE, Constants.Auth.TESTPRESS_ACCOUNT_TYPE);
        intent.putExtra(KEY_AUTHTOKEN, authToken);
        setAccountAuthenticatorResult(intent.getExtras());
        setResult(RESULT_OK, intent);
    } else {
        Intent intent = new Intent(this, MainActivity.class);
        if (getIntent().getStringExtra(Constants.DEEP_LINK_TO) != null) {
            switch(getIntent().getStringExtra(Constants.DEEP_LINK_TO)) {
                case Constants.DEEP_LINK_TO_PAYMENTS:
                    intent = new Intent(this, OrderConfirmActivity.class);
                    intent.putExtra(Constants.IS_DEEP_LINK, true);
                    intent.putExtras(getIntent().getExtras());
                    break;
                case Constants.DEEP_LINK_TO_POST:
                    intent = new Intent(this, PostActivity.class);
                    intent.putExtra(Constants.IS_DEEP_LINK, true);
                    intent.putExtras(getIntent().getExtras());
                    break;
                default:
                    intent = new Intent(this, MainActivity.class);
                    break;
            }
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    }
    finish();
}
Also used : Account(android.accounts.Account) PostDao(in.testpress.testpress.models.PostDao) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) MainActivity(in.testpress.testpress.ui.MainActivity) OrderConfirmActivity(in.testpress.testpress.ui.OrderConfirmActivity) PostActivity(in.testpress.testpress.ui.PostActivity) TestpressApplication(in.testpress.testpress.TestpressApplication) DaoSession(in.testpress.testpress.models.DaoSession)

Aggregations

Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 DaoSession (in.testpress.testpress.models.DaoSession)2 PostDao (in.testpress.testpress.models.PostDao)2 MainActivity (in.testpress.testpress.ui.MainActivity)2 Account (android.accounts.Account)1 ProgressDialog (android.app.ProgressDialog)1 TestpressApplication (in.testpress.testpress.TestpressApplication)1 OrderConfirmActivity (in.testpress.testpress.ui.OrderConfirmActivity)1 PostActivity (in.testpress.testpress.ui.PostActivity)1