Search in sources :

Example 1 with Config

use of org.edx.mobile.util.Config in project edx-app-android by edx.

the class LoginActivity method createView.

@NonNull
@Override
protected LoginPresenter.LoginViewInterface createView(@Nullable Bundle savedInstanceState) {
    activityLoginBinding = DataBindingUtil.setContentView(this, R.layout.activity_login);
    hideSoftKeypad();
    socialLoginDelegate = new SocialLoginDelegate(this, savedInstanceState, this, environment.getConfig(), environment.getLoginPrefs());
    activityLoginBinding.socialAuth.facebookButton.getRoot().setOnClickListener(socialLoginDelegate.createSocialButtonClickHandler(SocialFactory.SOCIAL_SOURCE_TYPE.TYPE_FACEBOOK));
    activityLoginBinding.socialAuth.googleButton.getRoot().setOnClickListener(socialLoginDelegate.createSocialButtonClickHandler(SocialFactory.SOCIAL_SOURCE_TYPE.TYPE_GOOGLE));
    activityLoginBinding.loginButtonLayout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Check for Validation˜
            callServerForLogin();
        }
    });
    activityLoginBinding.forgotPasswordTv.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Calling help dialog
            if (NetworkUtil.isConnected(LoginActivity.this)) {
                showResetPasswordDialog();
            } else {
                showAlertDialog(getString(R.string.reset_no_network_title), getString(R.string.network_not_connected));
            }
        }
    });
    String platformName = environment.getConfig().getPlatformName();
    CharSequence licenseText = ResourceUtil.getFormattedString(getResources(), R.string.licensing_agreement, "platform_name", platformName);
    activityLoginBinding.endUserAgreementTv.setText(licenseText);
    activityLoginBinding.endUserAgreementTv.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showEulaDialog();
        }
    });
    environment.getAnalyticsRegistry().trackScreenView(Analytics.Screens.LOGIN);
    // enable login buttons at launch
    tryToSetUIInteraction(true);
    Config config = environment.getConfig();
    setTitle(getString(R.string.login_title));
    String envDisplayName = config.getEnvironmentDisplayName();
    if (envDisplayName != null && envDisplayName.length() > 0) {
        activityLoginBinding.versionEnvTv.setVisibility(View.VISIBLE);
        String versionName = BuildConfig.VERSION_NAME;
        String text = String.format("%s %s %s", getString(R.string.label_version), versionName, envDisplayName);
        activityLoginBinding.versionEnvTv.setText(text);
    }
    return new LoginPresenter.LoginViewInterface() {

        @Override
        public void disableToolbarNavigation() {
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.setHomeButtonEnabled(false);
                actionBar.setDisplayHomeAsUpEnabled(false);
                actionBar.setDisplayShowHomeEnabled(false);
            }
        }

        @Override
        public void setSocialLoginButtons(boolean googleEnabled, boolean facebookEnabled) {
            if (!facebookEnabled && !googleEnabled) {
                activityLoginBinding.panelLoginSocial.setVisibility(View.GONE);
            } else if (!facebookEnabled) {
                activityLoginBinding.socialAuth.facebookButton.getRoot().setVisibility(View.GONE);
            } else if (!googleEnabled) {
                activityLoginBinding.socialAuth.googleButton.getRoot().setVisibility(View.GONE);
            }
        }
    };
}
Also used : Config(org.edx.mobile.util.Config) BuildConfig(org.edx.mobile.BuildConfig) OnClickListener(android.view.View.OnClickListener) View(android.view.View) SocialLoginDelegate(org.edx.mobile.social.SocialLoginDelegate) ActionBar(android.support.v7.app.ActionBar) NonNull(android.support.annotation.NonNull)

Example 2 with Config

use of org.edx.mobile.util.Config in project edx-app-android by edx.

the class CacheManager method convert.

/**
 * Convert the response URL from the new formats used in the Retrofit implementation, to the
 * previous formats used in the original Apache HTTP client implementation, which was what
 * populated this cache.
 *
 * @param url The URL to convert.
 * @return The converted URL.
 */
@NonNull
private String convert(@NonNull final String url) {
    /* The course structure URL was stripped of it's non-definitive query parameters before
         * being stored in the cache, to prevent it not becoming non-accessible after internal API
         * changes on the query parameters. The course ID parameter was retained, but not URL-
         * escaped.
         */
    if (courseStructureGetUrlConversionPattern == null) {
        final RoboInjector injector = RoboGuice.getInjector(context);
        final Config config = injector.getInstance(Config.class);
        String baseUrl = config.getApiHostURL();
        if (!baseUrl.endsWith("/")) {
            baseUrl += '/';
        }
        courseStructureGetUrlConversionPattern = Pattern.compile("^(" + baseUrl + "api/courses/v1/blocks/\\?)(?:[^=&;]+?=[^=&;]+?[&;])*?(course_id=)([^=&;]+)");
    }
    final Matcher urlMatcher = courseStructureGetUrlConversionPattern.matcher(url);
    if (urlMatcher.matches()) {
        final StringBuffer urlConversionBuffer = new StringBuffer(url.length());
        urlMatcher.appendReplacement(urlConversionBuffer, "$1$2" + Uri.decode(urlMatcher.group(3)));
        return urlConversionBuffer.toString();
    }
    return url;
}
Also used : RoboInjector(roboguice.inject.RoboInjector) Matcher(java.util.regex.Matcher) Config(org.edx.mobile.util.Config) NonNull(android.support.annotation.NonNull)

Example 3 with Config

use of org.edx.mobile.util.Config in project edx-app-android by edx.

the class BaseTestCase method setUp.

@Before
public void setUp() throws Exception {
    context = RuntimeEnvironment.application;
    config = new Config(generateConfigProperties());
    module = new CustomGuiceModule();
    glueInjections();
    // Set time zone to a constant value to make time-based tests predictable
    TimeZone.setDefault(TimeUtilsForTests.DEFAULT_TIME_ZONE);
    print("Started Test Case: " + getClass().getName());
}
Also used : Config(org.edx.mobile.util.Config) Before(org.junit.Before)

Example 4 with Config

use of org.edx.mobile.util.Config in project edx-app-android by edx.

the class ConfigTests method testGoogleEmptyConfig.

@Test
public void testGoogleEmptyConfig() {
    JsonObject googleConfig = new JsonObject();
    JsonObject configBase = new JsonObject();
    configBase.add(GOOGLE, googleConfig);
    Config config = new Config(configBase);
    assertFalse(config.getGoogleConfig().isEnabled());
}
Also used : Config(org.edx.mobile.util.Config) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 5 with Config

use of org.edx.mobile.util.Config in project edx-app-android by edx.

the class ConfigTests method testEnrollmentNoConfig.

@Test
public void testEnrollmentNoConfig() {
    JsonObject configBase = new JsonObject();
    Config config = new Config(configBase);
    assertFalse(config.getCourseDiscoveryConfig().isCourseDiscoveryEnabled());
    assertFalse(config.getCourseDiscoveryConfig().isWebviewCourseDiscoveryEnabled());
    assertNull(config.getCourseDiscoveryConfig().getCourseSearchUrl());
    assertNull(config.getCourseDiscoveryConfig().getCourseInfoUrlTemplate());
}
Also used : Config(org.edx.mobile.util.Config) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Aggregations

Config (org.edx.mobile.util.Config)33 Test (org.junit.Test)28 JsonObject (com.google.gson.JsonObject)24 JsonPrimitive (com.google.gson.JsonPrimitive)10 PresenterTest (org.edx.mobile.test.PresenterTest)4 LoginPresenter (org.edx.mobile.view.login.LoginPresenter)4 NonNull (android.support.annotation.NonNull)2 View (android.view.View)2 BuildConfig (org.edx.mobile.BuildConfig)2 Resources (android.content.res.Resources)1 ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 SearchView (android.support.v7.widget.SearchView)1 MenuItem (android.view.MenuItem)1 OnClickListener (android.view.View.OnClickListener)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 EventBus (de.greenrobot.event.EventBus)1 ArrayList (java.util.ArrayList)1