Search in sources :

Example 1 with InstituteSettingsDao

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

the class RegisterActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    Injector.inject(this);
    setContentView(R.layout.register_activity);
    ButterKnife.inject(this);
    DaoSession daoSession = ((TestpressApplication) getApplicationContext()).getDaoSession();
    InstituteSettingsDao instituteSettingsDao = daoSession.getInstituteSettingsDao();
    List<InstituteSettings> instituteSettingsList = instituteSettingsDao.queryBuilder().where(InstituteSettingsDao.Properties.BaseUrl.eq(Constants.Http.URL_BASE)).list();
    if (instituteSettingsList.size() != 0) {
        InstituteSettings instituteSettings = instituteSettingsList.get(0);
        verificationMethod = instituteSettings.getVerificationMethod().equals("M") ? MOBILE : EMAIL;
    } else {
        // Never happen, just for a safety.
        finish();
    }
    confirmPasswordText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == IME_ACTION_DONE && registerButton.isEnabled()) {
                register();
                return true;
            }
            return false;
        }
    });
    usernameText.addTextChangedListener(watcher);
    passwordText.addTextChangedListener(watcher);
    emailText.addTextChangedListener(watcher);
    if (verificationMethod.equals(MOBILE)) {
        phoneText.addTextChangedListener(watcher);
        phoneLayout.setVisibility(View.VISIBLE);
    } else {
        phoneLayout.setVisibility(View.GONE);
    }
    confirmPasswordText.addTextChangedListener(watcher);
}
Also used : KeyEvent(android.view.KeyEvent) InstituteSettingsDao(in.testpress.testpress.models.InstituteSettingsDao) TextView(android.widget.TextView) InstituteSettings(in.testpress.testpress.models.InstituteSettings) TestpressApplication(in.testpress.testpress.TestpressApplication) DaoSession(in.testpress.testpress.models.DaoSession)

Example 2 with InstituteSettingsDao

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

the class MainMenuFragment method onViewCreated.

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.inject(this, view);
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    fetchStarredCategories();
    AccountManager manager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);
    account = manager.getAccountsByType(Constants.Auth.TESTPRESS_ACCOUNT_TYPE);
    DaoSession daoSession = ((TestpressApplication) getActivity().getApplicationContext()).getDaoSession();
    InstituteSettingsDao instituteSettingsDao = daoSession.getInstituteSettingsDao();
    InstituteSettings instituteSettings = instituteSettingsDao.queryBuilder().where(InstituteSettingsDao.Properties.BaseUrl.eq(Constants.Http.URL_BASE)).list().get(0);
    LinkedHashMap<Integer, Integer> mMenuItemResIds = new LinkedHashMap<>();
    final boolean isUserAuthenticated = account.length > 0;
    if (isUserAuthenticated) {
        if (!instituteSettings.getShowGameFrontend()) {
            mMenuItemResIds.put(R.string.my_exams, R.drawable.exams);
        }
        if (instituteSettings.getDocumentsEnabled()) {
            mMenuItemResIds.put(R.string.documents, R.drawable.documents);
        }
        mMenuItemResIds.put(R.string.analytics, R.drawable.analytics);
        mMenuItemResIds.put(R.string.profile, R.drawable.ic_profile_details);
    }
    if (instituteSettings.getStoreEnabled()) {
        mMenuItemResIds.put(R.string.store, R.drawable.store);
    }
    if (instituteSettings.getPostsEnabled()) {
        mMenuItemResIds.put(R.string.posts, R.drawable.posts);
    }
    mMenuItemResIds.put(R.string.share, R.drawable.share);
    mMenuItemResIds.put(R.string.rate_us, R.drawable.heart);
    if (isUserAuthenticated) {
        mMenuItemResIds.put(R.string.logout, R.drawable.logout);
    } else {
        mMenuItemResIds.put(R.string.login, R.drawable.login);
    }
    MainMenuGridAdapter adapter = new MainMenuGridAdapter(getActivity(), mMenuItemResIds);
    grid = (GridView) view.findViewById(R.id.grid);
    grid.setAdapter(adapter);
    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent;
            switch((int) id) {
                case R.string.my_exams:
                    checkAuthenticatedUser(R.string.my_exams);
                    break;
                case R.string.store:
                    intent = new Intent(getActivity(), ProductsListActivity.class);
                    startActivity(intent);
                    break;
                case R.string.documents:
                    intent = new Intent(getActivity(), DocumentsListActivity.class);
                    startActivity(intent);
                    break;
                case R.string.orders:
                    intent = new Intent(getActivity(), OrdersListActivity.class);
                    startActivity(intent);
                    break;
                case R.string.posts:
                    intent = new Intent(getActivity(), PostsListActivity.class);
                    intent.putExtra("userAuthenticated", isUserAuthenticated);
                    startActivity(intent);
                    break;
                case R.string.analytics:
                    checkAuthenticatedUser(R.string.analytics);
                    break;
                case R.string.profile:
                    intent = new Intent(getActivity(), ProfileDetailsActivity.class);
                    startActivity(intent);
                    break;
                case R.string.share:
                    shareApp();
                    break;
                case R.string.rate_us:
                    rateApp();
                    break;
                case R.string.logout:
                    ((MainActivity) getActivity()).logout();
                    break;
                case R.string.login:
                    intent = new Intent(getActivity(), LoginActivity.class);
                    intent.putExtra(Constants.DEEP_LINK_TO, "home");
                    startActivity(intent);
                    break;
            }
        }
    });
}
Also used : InstituteSettingsDao(in.testpress.testpress.models.InstituteSettingsDao) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) InstituteSettings(in.testpress.testpress.models.InstituteSettings) GridView(android.widget.GridView) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) TestpressApplication(in.testpress.testpress.TestpressApplication) Paint(android.graphics.Paint) LinkedHashMap(java.util.LinkedHashMap) AccountManager(android.accounts.AccountManager) AdapterView(android.widget.AdapterView) DaoSession(in.testpress.testpress.models.DaoSession)

Example 3 with InstituteSettingsDao

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

DaoSession (in.testpress.testpress.models.DaoSession)3 InstituteSettings (in.testpress.testpress.models.InstituteSettings)3 InstituteSettingsDao (in.testpress.testpress.models.InstituteSettingsDao)3 TextView (android.widget.TextView)2 TestpressApplication (in.testpress.testpress.TestpressApplication)2 AccountManager (android.accounts.AccountManager)1 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 InjectView (butterknife.InjectView)1 TestpressSession (in.testpress.core.TestpressSession)1 TestpressService (in.testpress.testpress.core.TestpressService)1 LinkedHashMap (java.util.LinkedHashMap)1