Search in sources :

Example 1 with TestpressService

use of in.testpress.testpress.core.TestpressService in project android by testpress.

the class SplashScreenActivity method authenticateUser.

private void authenticateUser(final Uri uri) {
    final Activity activity = SplashScreenActivity.this;
    final List<String> pathSegments = uri.getPathSegments();
    CommonUtils.getAuth(activity, serviceProvider, new CommonUtils.CheckAuthCallBack() {

        @Override
        public void onSuccess(TestpressService testpressService) {
            TestpressSession testpressSession = TestpressSdk.getTestpressSession(activity);
            Assert.assertNotNull("TestpressSession must not be null.", testpressSession);
            switch(pathSegments.get(0)) {
                case "exams":
                    if (pathSegments.size() == 2) {
                        if (!pathSegments.get(1).equals("available") || !pathSegments.get(1).equals("upcoming") || !pathSegments.get(1).equals("history")) {
                            // If exam slug is present, directly goto the start exam screen
                            TestpressExam.showExamAttemptedState(activity, pathSegments.get(1), testpressSession);
                            return;
                        }
                    }
                    // Show exams list
                    TestpressExam.show(activity, testpressSession);
                    finish();
                    break;
                case "analytics":
                    TestpressExam.showAnalytics(activity, SUBJECT_ANALYTICS_PATH, testpressSession);
                    break;
                case "chapters":
                    deepLinkToChapter(uri, testpressSession);
                    break;
            }
        }
    });
}
Also used : TestpressSession(in.testpress.core.TestpressSession) CommonUtils(in.testpress.testpress.util.CommonUtils) ResetPasswordActivity(in.testpress.testpress.authenticator.ResetPasswordActivity) LoginActivity(in.testpress.testpress.authenticator.LoginActivity) Activity(android.app.Activity) TestpressService(in.testpress.testpress.core.TestpressService)

Example 2 with TestpressService

use of in.testpress.testpress.core.TestpressService 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)

Aggregations

TestpressSession (in.testpress.core.TestpressSession)2 TestpressService (in.testpress.testpress.core.TestpressService)2 Activity (android.app.Activity)1 LoginActivity (in.testpress.testpress.authenticator.LoginActivity)1 ResetPasswordActivity (in.testpress.testpress.authenticator.ResetPasswordActivity)1 DaoSession (in.testpress.testpress.models.DaoSession)1 InstituteSettings (in.testpress.testpress.models.InstituteSettings)1 InstituteSettingsDao (in.testpress.testpress.models.InstituteSettingsDao)1 CommonUtils (in.testpress.testpress.util.CommonUtils)1