Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
refactor: Address feedback changes
Browse files Browse the repository at this point in the history
Fixes: LEARNER-9461
  • Loading branch information
HamzaIsrar12 committed Aug 7, 2023
1 parent b42f564 commit 1621295
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,17 @@ public void onActivityStopped() {

private void socialLogin(SocialAuthSource socialAuthSource) {
switch (socialAuthSource) {
case FACEBOOK:
facebook.login();
break;
case GOOGLE:
google.login();
break;
case MICROSOFT:
microsoft.login();
break;
case FACEBOOK -> facebook.login();
case GOOGLE -> google.login();
case MICROSOFT -> microsoft.login();

Check warning on line 136 in OpenEdXMobile/src/main/java/org/edx/mobile/social/SocialLoginDelegate.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/social/SocialLoginDelegate.java#L134-L136

Added lines #L134 - L136 were not covered by tests
}
}

private void socialLogout(SocialAuthSource socialAuthSource) {
switch (socialAuthSource) {
case FACEBOOK:
facebook.logout();
break;
case GOOGLE:
google.logout();
break;
case MICROSOFT:
microsoft.logout();
break;
case FACEBOOK -> facebook.logout();
case GOOGLE -> google.logout();
case MICROSOFT -> microsoft.logout();

Check warning on line 144 in OpenEdXMobile/src/main/java/org/edx/mobile/social/SocialLoginDelegate.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/social/SocialLoginDelegate.java#L142-L144

Added lines #L142 - L144 were not covered by tests
}
}

Expand Down
16 changes: 6 additions & 10 deletions OpenEdXMobile/src/main/java/org/edx/mobile/task/RegisterTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ public RegisterTask(Context context, Bundle parameters, String accessToken, Soci
@Override
protected AuthResponse doInBackground(Void... voids) {
try {
switch (socialAuthSource) {
case GOOGLE:
return loginAPI.registerUsingGoogle(parameters, accessToken);
case FACEBOOK:
return loginAPI.registerUsingFacebook(parameters, accessToken);
case MICROSOFT:
return loginAPI.registerUsingMicrosoft(parameters, accessToken);
}
// normal email address login
return loginAPI.registerUsingEmail(parameters);
return switch (socialAuthSource) {
case GOOGLE -> loginAPI.registerUsingGoogle(parameters, accessToken);
case FACEBOOK -> loginAPI.registerUsingFacebook(parameters, accessToken);
case MICROSOFT -> loginAPI.registerUsingMicrosoft(parameters, accessToken);
default -> loginAPI.registerUsingEmail(parameters);

Check warning on line 36 in OpenEdXMobile/src/main/java/org/edx/mobile/task/RegisterTask.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/task/RegisterTask.java#L33-L36

Added lines #L33 - L36 were not covered by tests
};
} catch (Exception e) {
handleException(e);
return null;
Expand Down
8 changes: 8 additions & 0 deletions OpenEdXMobile/src/main/java/org/edx/mobile/util/ConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class ConfigUtil {
return config.getAgreementUrl(urlType)
}

/**
* Determines whether a specific social feature is enabled based on the provided
* social authentication source and configuration.
*
* @param type The social authentication source for which to check the feature's enablement.
* @param config The global configuration containing individual social network configurations.
* @return `true` if the specified social feature is enabled; otherwise, `false`.
*/
@JvmStatic
fun isSocialFeatureEnabled(
type: SocialAuthSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class DiscoveryLaunchActivity extends PresenterActivity<DiscoveryLaunchPresenter, DiscoveryLaunchPresenter.ViewInterface> {

private static final String QUERY_PARAM = "query_param";
private static final String FOCUSED_VIEW = "focused_view";

private ActivityDiscoveryLaunchBinding binding;

Expand Down Expand Up @@ -86,13 +87,17 @@ public void navigateToMainDashboard() {
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(QUERY_PARAM, binding.svSearchCourses.getQuery().toString());
outState.putBoolean(FOCUSED_VIEW, binding.svSearchCourses.hasFocus());
}

Check warning on line 91 in OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java#L88-L91

Added lines #L88 - L91 were not covered by tests

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
String queryString = savedInstanceState.getString(QUERY_PARAM, "");
binding.svSearchCourses.setQuery(queryString, false);

Check warning on line 97 in OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java#L95-L97

Added lines #L95 - L97 were not covered by tests
if (savedInstanceState.getBoolean(FOCUSED_VIEW, false)) {
binding.svSearchCourses.postDelayed(() -> binding.svSearchCourses.requestFocus(), 100);

Check warning on line 99 in OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java#L99

Added line #L99 was not covered by tests
}
}

Check warning on line 101 in OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/DiscoveryLaunchActivity.java#L101

Added line #L101 was not covered by tests

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ class RegisterActivity : BaseFragmentActivity(), MobileLoginCallback {

// Send analytics event for Create Account button click
val appVersion = "${getString(R.string.android)} ${BuildConfig.VERSION_NAME}"
val backSourceType = SocialAuthSource.fromString(provider)
val socialAuthSource = SocialAuthSource.fromString(provider)

Check warning on line 297 in OpenEdXMobile/src/main/java/org/edx/mobile/view/RegisterActivity.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/RegisterActivity.kt#L297

Added line #L297 was not covered by tests
environment.analyticsRegistry.trackCreateAccountClicked(appVersion, provider)

@SuppressLint("StaticFieldLeak")
val task = object : RegisterTask(this, parameters, accessToken, backSourceType) {
val task = object : RegisterTask(this, parameters, accessToken, socialAuthSource) {

Check warning on line 301 in OpenEdXMobile/src/main/java/org/edx/mobile/view/RegisterActivity.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/RegisterActivity.kt#L301

Added line #L301 was not covered by tests
@Deprecated("Deprecated in Java")
override fun onPostExecute(auth: AuthResponse?) {
super.onPostExecute(auth)
Expand Down

0 comments on commit 1621295

Please sign in to comment.