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;
}
}
});
}
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);
}
Aggregations