Search in sources :

Example 1 with PrefManager

use of org.edx.mobile.module.prefs.PrefManager in project edx-app-android by edx.

the class DownloadEntry method getBestEncodingUrl.

public String getBestEncodingUrl(Context context) {
    PrefManager prefs = new PrefManager(context, PrefManager.Pref.WIFI);
    float kbs = prefs.getFloat(PrefManager.Key.SPEED_TEST_KBPS, 0.0f);
    float thresholdKps = (float) context.getResources().getInteger(R.integer.threshold_kbps_for_video);
    EncodingsModel.EncodingLevel level = kbs > thresholdKps ? EncodingsModel.EncodingLevel.HIGH : EncodingsModel.EncodingLevel.LOW;
    switch(level) {
        case HIGH:
            if (!TextUtils.isEmpty(url_high_quality)) {
                return url_high_quality;
            }
            break;
        case LOW:
            if (!TextUtils.isEmpty(url_low_quality)) {
                return url_low_quality;
            }
            break;
    }
    return getVideoUrl();
}
Also used : EncodingsModel(org.edx.mobile.model.api.EncodingsModel) PrefManager(org.edx.mobile.module.prefs.PrefManager)

Example 2 with PrefManager

use of org.edx.mobile.module.prefs.PrefManager in project edx-app-android by edx.

the class DownloadSpeedService method setCurrentDownloadSpeed.

private void setCurrentDownloadSpeed(float downloadSpeedKps) {
    PrefManager manager = new PrefManager(this, PrefManager.Pref.WIFI);
    manager.put(PrefManager.Key.SPEED_TEST_KBPS, downloadSpeedKps);
}
Also used : PrefManager(org.edx.mobile.module.prefs.PrefManager)

Example 3 with PrefManager

use of org.edx.mobile.module.prefs.PrefManager in project edx-app-android by edx.

the class SettingsFragment method updateWifiSwitch.

private void updateWifiSwitch() {
    final PrefManager wifiPrefManager = new PrefManager(getActivity().getBaseContext(), PrefManager.Pref.WIFI);
    wifiSwitch.setOnCheckedChangeListener(null);
    wifiSwitch.setChecked(wifiPrefManager.getBoolean(PrefManager.Key.DOWNLOAD_ONLY_ON_WIFI, true));
    wifiSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                wifiPrefManager.put(PrefManager.Key.DOWNLOAD_ONLY_ON_WIFI, true);
                wifiPrefManager.put(PrefManager.Key.DOWNLOAD_OFF_WIFI_SHOW_DIALOG_FLAG, true);
            } else {
                showWifiDialog();
            }
        }
    });
}
Also used : CompoundButton(android.widget.CompoundButton) PrefManager(org.edx.mobile.module.prefs.PrefManager)

Example 4 with PrefManager

use of org.edx.mobile.module.prefs.PrefManager in project edx-app-android by edx.

the class SettingsFragment method showWifiDialog.

protected void showWifiDialog() {
    final NetworkCheckDialogFragment newFragment = NetworkCheckDialogFragment.newInstance(getString(R.string.wifi_dialog_title_help), getString(R.string.wifi_dialog_message_help), new IDialogCallback() {

        @Override
        public void onPositiveClicked() {
            try {
                PrefManager wifiPrefManager = new PrefManager(getActivity().getBaseContext(), PrefManager.Pref.WIFI);
                wifiPrefManager.put(PrefManager.Key.DOWNLOAD_ONLY_ON_WIFI, false);
                updateWifiSwitch();
            } catch (Exception ex) {
                logger.error(ex);
            }
        }

        @Override
        public void onNegativeClicked() {
            try {
                PrefManager wifiPrefManager = new PrefManager(getActivity().getBaseContext(), PrefManager.Pref.WIFI);
                wifiPrefManager.put(PrefManager.Key.DOWNLOAD_ONLY_ON_WIFI, true);
                wifiPrefManager.put(PrefManager.Key.DOWNLOAD_OFF_WIFI_SHOW_DIALOG_FLAG, true);
                updateWifiSwitch();
            } catch (Exception ex) {
                logger.error(ex);
            }
        }
    });
    newFragment.setCancelable(false);
    newFragment.show(getActivity().getSupportFragmentManager(), "dialog");
}
Also used : NetworkCheckDialogFragment(org.edx.mobile.view.dialog.NetworkCheckDialogFragment) IDialogCallback(org.edx.mobile.view.dialog.IDialogCallback) PrefManager(org.edx.mobile.module.prefs.PrefManager)

Aggregations

PrefManager (org.edx.mobile.module.prefs.PrefManager)4 CompoundButton (android.widget.CompoundButton)1 EncodingsModel (org.edx.mobile.model.api.EncodingsModel)1 IDialogCallback (org.edx.mobile.view.dialog.IDialogCallback)1 NetworkCheckDialogFragment (org.edx.mobile.view.dialog.NetworkCheckDialogFragment)1