Search in sources :

Example 1 with TestpressApplication

use of in.testpress.testpress.TestpressApplication in project android by testpress.

the class PostActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.post_details_layout);
    Injector.inject(this);
    ButterKnife.inject(this);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    postDetails.setVisibility(View.GONE);
    progressBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_IN);
    postDao = ((TestpressApplication) getApplicationContext()).getDaoSession().getPostDao();
    simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    shortWebUrl = getIntent().getStringExtra(SHORT_WEB_URL);
    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getResources().getString(R.string.please_wait));
    progressDialog.setCancelable(false);
    in.testpress.util.UIUtils.setIndeterminateDrawable(this, progressDialog, 4);
    ViewUtils.setTypeface(new TextView[] { loadPreviousCommentsText, commentsLabel, loadNewCommentsText, title }, TestpressSdk.getRubikMediumFont(this));
    ViewUtils.setTypeface(new TextView[] { date, summary, commentsEmptyView, commentsEditText }, TestpressSdk.getRubikRegularFont(this));
    if (shortWebUrl != null) {
        List<Post> posts = postDao.queryBuilder().where(PostDao.Properties.Short_web_url.eq(shortWebUrl)).list();
        if (!posts.isEmpty()) {
            post = posts.get(0);
            if (post.getContentHtml() != null) {
                displayPost(post);
                return;
            }
        }
        // If there is no post in this url in db or
        // If it content_html is null then fetch the post
        fetchPost();
    } else {
        setEmptyText(R.string.invalid_post, R.string.try_after_sometime, R.drawable.ic_error_outline_black_18dp);
    }
}
Also used : Post(in.testpress.testpress.models.Post) ProgressDialog(android.app.ProgressDialog) SimpleDateFormat(java.text.SimpleDateFormat) TestpressApplication(in.testpress.testpress.TestpressApplication)

Example 2 with TestpressApplication

use of in.testpress.testpress.TestpressApplication in project android by testpress.

the class LoginActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    Injector.inject(this);
    accountManager = AccountManager.get(this);
    final Intent intent = getIntent();
    username = intent.getStringExtra(PARAM_USERNAME);
    authTokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
    confirmCredentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false);
    requestNewAccount = username == null;
    if (AccessToken.getCurrentAccessToken() != null) {
        LoginManager.getInstance().logOut();
    }
    setContentView(layout.login_activity);
    ButterKnife.inject(this);
    UIUtils.setIndeterminateDrawable(this, progressBar, 4);
    passwordText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == IME_ACTION_SEND && signInButton.isEnabled()) {
                signIn();
                return true;
            }
            return false;
        }
    });
    usernameText.addTextChangedListener(watcher);
    usernameText.setSingleLine();
    passwordText.addTextChangedListener(watcher);
    passwordText.setTypeface(Typeface.DEFAULT);
    passwordText.setTransformationMethod(new PasswordTransformationMethod());
    callbackManager = CallbackManager.Factory.create();
    fbLoginButton.invalidate();
    fbLoginButton.setReadPermissions("email");
    fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            loginLayout.setVisibility(View.GONE);
            username = loginResult.getAccessToken().getUserId();
            authenticate(loginResult.getAccessToken().getUserId(), loginResult.getAccessToken().getToken(), TestpressSdk.Provider.FACEBOOK);
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException error) {
            if (error.getMessage().contains("CONNECTION_FAILURE")) {
                showAlert(getString(R.string.no_internet_try_again));
            } else {
                Log.e("Facebook sign in error", "check hashes");
                showAlert(getString(R.string.something_went_wrong_please_try_after));
            }
        }
    });
    GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(getString(R.string.server_client_id)).build();
    googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {

        @Override
        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
            if (connectionResult.getErrorMessage() != null) {
                showAlert(connectionResult.getErrorMessage());
            } else {
                showAlert(connectionResult.toString());
            }
        }
    }).addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions).build();
    orLabel.setTypeface(TestpressSdk.getRubikMediumFont(this));
    DaoSession daoSession = ((TestpressApplication) getApplicationContext()).getDaoSession();
    instituteSettingsDao = daoSession.getInstituteSettingsDao();
    List<InstituteSettings> instituteSettingsList = instituteSettingsDao.queryBuilder().where(InstituteSettingsDao.Properties.BaseUrl.eq(Constants.Http.URL_BASE)).list();
    if (instituteSettingsList.size() == 0) {
        getInstituteSettings();
    } else {
        instituteSettings = instituteSettingsList.get(0);
        updateInstituteSpecificFields();
    }
}
Also used : LoginResult(com.facebook.login.LoginResult) Intent(android.content.Intent) InstituteSettings(in.testpress.testpress.models.InstituteSettings) TestpressApplication(in.testpress.testpress.TestpressApplication) KeyEvent(android.view.KeyEvent) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) FacebookException(com.facebook.FacebookException) NonNull(android.support.annotation.NonNull) ConnectionResult(com.google.android.gms.common.ConnectionResult) TextView(android.widget.TextView) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) DaoSession(in.testpress.testpress.models.DaoSession)

Example 3 with TestpressApplication

use of in.testpress.testpress.TestpressApplication 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 4 with TestpressApplication

use of in.testpress.testpress.TestpressApplication in project android by testpress.

the class MainActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    Injector.inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    ButterKnife.inject(this);
    if (savedInstanceState != null) {
        mSelectedItem = savedInstanceState.getInt(SELECTED_ITEM);
    }
    viewPager.setVisibility(View.INVISIBLE);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            CommonUtils.registerDevice(MainActivity.this, testpressService, serviceProvider);
        }
    };
    DaoSession daoSession = ((TestpressApplication) getApplicationContext()).getDaoSession();
    instituteSettingsDao = daoSession.getInstituteSettingsDao();
    fetchInstituteSettings();
}
Also used : Context(android.content.Context) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) TestpressApplication(in.testpress.testpress.TestpressApplication) DaoSession(in.testpress.testpress.models.DaoSession)

Example 5 with TestpressApplication

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

Aggregations

TestpressApplication (in.testpress.testpress.TestpressApplication)6 DaoSession (in.testpress.testpress.models.DaoSession)5 Intent (android.content.Intent)4 TextView (android.widget.TextView)3 InstituteSettings (in.testpress.testpress.models.InstituteSettings)3 KeyEvent (android.view.KeyEvent)2 InstituteSettingsDao (in.testpress.testpress.models.InstituteSettingsDao)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 SharedPreferences (android.content.SharedPreferences)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 View (android.view.View)1 AdapterView (android.widget.AdapterView)1