Search in sources :

Example 6 with DaoSession

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

the class TestpressServiceProvider method getService.

/**
 * Get service for configured key provider
 * <p/>
 * This method gets an auth key and so it blocks and shouldn't be called on the main thread.
 *
 * @return testpress service
 * @throws java.io.IOException
 * @throws android.accounts.AccountsException
 */
public TestpressService getService(final Activity activity) throws IOException, AccountsException {
    if (authToken == null) {
        // The call to keyProvider.getAuthKey(...) is what initiates the login screen. Call that now.
        authToken = keyProvider.getAuthKey(activity);
        DaoSession daoSession = ((TestpressApplication) activity.getApplicationContext()).getDaoSession();
        InstituteSettingsDao instituteSettingsDao = daoSession.getInstituteSettingsDao();
        List<InstituteSettings> instituteSettingsList = instituteSettingsDao.queryBuilder().where(InstituteSettingsDao.Properties.BaseUrl.eq(Constants.Http.URL_BASE)).list();
        in.testpress.models.InstituteSettings settings;
        if (instituteSettingsList.isEmpty()) {
            settings = new in.testpress.models.InstituteSettings(Constants.Http.URL_BASE);
        } else {
            InstituteSettings instituteSettings = instituteSettingsList.get(0);
            settings = new in.testpress.models.InstituteSettings(instituteSettings.getBaseUrl()).setCoursesFrontend(instituteSettings.getShowGameFrontend()).setCoursesGamificationEnabled(instituteSettings.getCoursesEnableGamification()).setCommentsVotingEnabled(instituteSettings.getCommentsVotingEnabled()).setAccessCodeEnabled(false);
        }
        TestpressSdk.setTestpressSession(activity, new TestpressSession(settings, authToken));
    }
    // TODO: See how that affects the testpress service.
    return new TestpressService(restAdapter, authToken);
}
Also used : TestpressSession(in.testpress.core.TestpressSession) InstituteSettingsDao(in.testpress.testpress.models.InstituteSettingsDao) InstituteSettings(in.testpress.testpress.models.InstituteSettings) TestpressService(in.testpress.testpress.core.TestpressService) DaoSession(in.testpress.testpress.models.DaoSession)

Example 7 with DaoSession

use of in.testpress.testpress.models.DaoSession 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

DaoSession (in.testpress.testpress.models.DaoSession)7 Intent (android.content.Intent)5 TestpressApplication (in.testpress.testpress.TestpressApplication)5 InstituteSettings (in.testpress.testpress.models.InstituteSettings)4 TextView (android.widget.TextView)3 InstituteSettingsDao (in.testpress.testpress.models.InstituteSettingsDao)3 SharedPreferences (android.content.SharedPreferences)2 KeyEvent (android.view.KeyEvent)2 PostDao (in.testpress.testpress.models.PostDao)2 MainActivity (in.testpress.testpress.ui.MainActivity)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 ProgressDialog (android.app.ProgressDialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Paint (android.graphics.Paint)1 NonNull (android.support.annotation.NonNull)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 PasswordTransformationMethod (android.text.method.PasswordTransformationMethod)1