summaryrefslogtreecommitdiff
path: root/app/src/play/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java
blob: c9d52df0c1d89a27df81e94d7608b3fe4d1addaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package de.danoeh.antennapod.preferences;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;

import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.fragment.preferences.PlaybackPreferencesFragment;

/**
 * Implements functions from PreferenceController that are flavor dependent.
 */
public class PreferenceControllerFlavorHelper {

    public static void setupFlavoredUI(PlaybackPreferencesFragment ui) {
        //checks whether Google Play Services is installed on the device (condition necessary for Cast support)
        ui.findPreference(UserPreferences.PREF_CAST_ENABLED).setOnPreferenceChangeListener((preference, o) -> {
            if (o instanceof Boolean && ((Boolean) o)) {
                final int googlePlayServicesCheck = GoogleApiAvailability.getInstance()
                        .isGooglePlayServicesAvailable(ui.getActivity());
                if (googlePlayServicesCheck == ConnectionResult.SUCCESS) {
                    return true;
                } else {
                    GoogleApiAvailability.getInstance()
                            .getErrorDialog(ui.getActivity(), googlePlayServicesCheck, 0)
                            .show();
                    return false;
                }
            }
            return true;
        });
    }
}