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

Commit

Permalink
Fix issue exist in disabling the download to sd-card feature by default
Browse files Browse the repository at this point in the history
- LEARNER-7419
- There was a bug in the code, in some scenarios sd-card feature was
getting enabled from settings by default.
  • Loading branch information
farhan committed Sep 24, 2019
1 parent f57f535 commit 27aa5cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.edx.mobile.core.IEdxEnvironment;
import org.edx.mobile.logger.Logger;
import org.edx.mobile.model.api.ProfileModel;
import org.edx.mobile.util.AppConstants;
import org.edx.mobile.util.FileUtil;
import org.edx.mobile.util.Sha1Util;

import java.io.File;
import java.io.IOException;

@Singleton
public class UserPrefs {
Expand Down Expand Up @@ -46,9 +38,9 @@ public boolean isDownloadOverWifiOnly() {
return onlyWifi;
}

public boolean isDownloadToSDCardEnabled(){
public boolean isDownloadToSDCardEnabled() {
final PrefManager prefManger = new PrefManager(context, PrefManager.Pref.USER_PREF);
return prefManger.getBoolean(PrefManager.Key.DOWNLOAD_TO_SDCARD, true);
return prefManger.getBoolean(PrefManager.Key.DOWNLOAD_TO_SDCARD, false);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.google.inject.Inject;

import org.edx.mobile.core.IEdxEnvironment;
import org.edx.mobile.event.MediaStatusChangeEvent;
import org.edx.mobile.model.VideoModel;
import org.edx.mobile.model.db.DownloadEntry;
Expand Down Expand Up @@ -37,6 +38,9 @@ public class MediaStatusReceiver extends RoboBroadcastReceiver {

private PrefManager prefManager;

@Inject
protected IEdxEnvironment environment;

public MediaStatusReceiver() {
}

Expand Down Expand Up @@ -97,7 +101,7 @@ private void handleSDCardMounted(final Context context, String hashedUsername) {
public void onResult(List<VideoModel> result) {
final String externalAppDir = FileUtil.getExternalAppDir(context).getAbsolutePath();
final String removableStorageAppDir = FileUtil.getRemovableStorageAppDir(context).getAbsolutePath();
final boolean downloadToSdCard = prefManager.getBoolean(PrefManager.Key.DOWNLOAD_TO_SDCARD, true);
final boolean downloadToSdCard = environment.getUserPrefs().isDownloadToSDCardEnabled();
for (VideoModel videoModel : result) {
updateVideoDownloadFilePathState(
videoModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void updateSDCardSwitch() {
EventBus.getDefault().registerSticky(this);
}
sdCardSwitch.setOnCheckedChangeListener(null);
sdCardSwitch.setChecked(prefManager.getBoolean(PrefManager.Key.DOWNLOAD_TO_SDCARD, false));
sdCardSwitch.setChecked(environment.getUserPrefs().isDownloadToSDCardEnabled());
sdCardSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
Expand Down

0 comments on commit 27aa5cc

Please sign in to comment.