package org.edx.mobile.module.prefs;


import android.content.Context;
import android.os.Environment;

import org.edx.mobile.model.api.ProfileModel;

import java.io.File;

public class UserPrefs {

    private Context context;

    public UserPrefs(Context context) {
        this.context = context;
    }

    /**
     * Returns true if the "download over wifi only" is turned ON, false otherwise.
     * @return
     */
    public boolean isDownloadOverWifiOnly() {
        // check if download is only allowed over wifi
        final PrefManager wifiPrefManager = new PrefManager(context,
                PrefManager.Pref.WIFI);
        boolean onlyWifi = wifiPrefManager.getBoolean(
                PrefManager.Key.DOWNLOAD_ONLY_ON_WIFI, true);
        return onlyWifi;
    }
    
    /**
     * Returns user storage directory under /Android/data/ folder for the currently logged in user.
     * This is the folder where all video downloads should be kept.
     * @return
     */
    public File getDownloadFolder() {
        PrefManager pref = new PrefManager(context, PrefManager.Pref.LOGIN);
        ProfileModel profile = pref.getCurrentUserProfile();
        
        File android = new File(Environment.getExternalStorageDirectory(), "Android");
        File downloadsDir = new File(android, "data");
        File packDir = new File(downloadsDir, context.getPackageName());
        File edxDir = new File(packDir, profile.username);
        edxDir.mkdirs();
        
        return edxDir;
    }

    public ProfileModel getProfile() {
        PrefManager pm = new PrefManager(context, PrefManager.Pref.LOGIN);
        return pm.getCurrentUserProfile();
    }
}

@@ -96,16 +96,53 @@
 nment;%0A%0A
+import org.edx.mobile.logger.Logger;%0A
 import o
@@ -200,16 +200,44 @@
 io.File;
+%0Aimport java.io.IOException;
 %0A%0Apublic
@@ -284,16 +284,84 @@
 context;
+%0A    private final Logger logger = new Logger(getClass().getName());
 %0A%0A    pu
@@ -1590,24 +1590,311 @@
 r.mkdirs();%0A
+        try %7B%0A            File noMediaFile = new File(edxDir, %22.nomedia%22);%0A            if (!noMediaFile.createNewFile()) %7B%0A                logger.debug(%22.NoMedia file not created%22);%0A            %7D%0A        %7Dcatch (IOException ioException)%7B%0A            logger.error(ioException);%0A        %7D%0A
         %0A   

Create .nomedia file in Videos directory to hide Videos