Search in sources :

Example 1 with Engine

use of com.frostwire.android.gui.services.Engine in project frostwire by frostwire.

the class ApplicationFragment method setupConnectSwitch.

private void setupConnectSwitch() {
    SwitchPreferenceCompat preference = findPreference("frostwire.prefs.internal.connect_disconnect");
    preference.setOnPreferenceChangeListener((preference1, newValue) -> {
        boolean newStatus = (boolean) newValue;
        Engine e = Engine.instance();
        if (e.isStarted() && !newStatus) {
            disconnect();
            UIUtils.showShortMessage(getView(), R.string.toast_on_disconnect);
        } else if (newStatus && (e.isStopped() || e.isDisconnected())) {
            NetworkManager networkManager = NetworkManager.instance();
            if (getPreferenceManager().getSharedPreferences().getBoolean(Constants.PREF_KEY_NETWORK_BITTORRENT_ON_VPN_ONLY, false) && !networkManager.isTunnelUp()) {
                UIUtils.showShortMessage(getView(), R.string.cannot_start_engine_without_vpn);
                return false;
            } else if (getPreferenceManager().getSharedPreferences().getBoolean(Constants.PREF_KEY_NETWORK_USE_WIFI_ONLY, false) && networkManager.isDataMobileUp()) {
                UIUtils.showShortMessage(getView(), R.string.wifi_network_unavailable);
                return false;
            } else {
                connect();
            }
        }
        return true;
    });
    updateConnectSwitchStatus();
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) NetworkManager(com.frostwire.android.gui.NetworkManager) Engine(com.frostwire.android.gui.services.Engine)

Example 2 with Engine

use of com.frostwire.android.gui.services.Engine in project frostwire by frostwire.

the class ApplicationFragment method updateConnectSwitchStatus.

private void updateConnectSwitchStatus() {
    SwitchPreferenceCompat preference = findPreference("frostwire.prefs.internal.connect_disconnect");
    Engine e = Engine.instance();
    if (e.isStarted()) {
        setChecked(preference, true, false);
    } else if (e.isStopped() || e.isDisconnected()) {
        setChecked(preference, false, false);
    }
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) Engine(com.frostwire.android.gui.services.Engine)

Aggregations

SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)2 Engine (com.frostwire.android.gui.services.Engine)2 NetworkManager (com.frostwire.android.gui.NetworkManager)1