summaryrefslogtreecommitdiff
path: root/app/src/play/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java
blob: b9b4e891f72309a226fff5e2011fead615f16d9a (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
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;

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

    static void setupFlavoredUI(PreferenceController.PreferenceUI 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;
        });
    }
}