package nodomain.freeyourgadget.gadgetbridge.devices.pebble;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;

import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;

public class PebbleCoordinator implements DeviceCoordinator {
    private MorpheuzSampleProvider sampleProvider;

    public PebbleCoordinator() {
        // FIXME: make this configurable somewhere else
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
        if (sharedPrefs.getBoolean("pebble_force_untested", false)) {
            sampleProvider = new PebbleGadgetBridgeSampleProvider();
        } else {
            sampleProvider = new MorpheuzSampleProvider();
        }
    }

    @Override
    public boolean supports(GBDeviceCandidate candidate) {
        return candidate.getName().startsWith("Pebble");
    }

    @Override
    public boolean supports(GBDevice device) {
        return getDeviceType().equals(device.getType());
    }

    @Override
    public DeviceType getDeviceType() {
        return DeviceType.PEBBLE;
    }

    @Override
    public Class<? extends Activity> getPairingActivity() {
        return null;
    }

    public Class<? extends Activity> getPrimaryActivity() {
        return AppManagerActivity.class;
    }

    @Override
    public SampleProvider getSampleProvider() {
        return sampleProvider;
    }

    @Override
    public InstallHandler findInstallHandler(Uri uri, Context context) {
        PBWInstallHandler installHandler = new PBWInstallHandler(uri, context);
        return installHandler.isValid() ? installHandler : null;
    }
}

@@ -830,483 +830,35 @@
    p
-rivate MorpheuzSampleProvider sampleProvider;%0A%0A    public PebbleCoordinator() %7B%0A        // FIXME: make this configurable somewhere else%0A        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());%0A        if (sharedPrefs.getBoolean(%22pebble_force_untested%22, false)) %7B%0A            sampleProvider = new PebbleGadgetBridgeSampleProvider();%0A        %7D else %7B%0A            sampleProvider = new MorpheuzSampleProvider();%0A        %7D
+ublic PebbleCoordinator() %7B
 %0A   
@@ -1502,30 +1502,376 @@
     
-return sampleProvider;
+// FIXME: make this configurable somewhere else.%0A        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());%0A        if (sharedPrefs.getBoolean(%22pebble_force_untested%22, false)) %7B%0A            return new PebbleGadgetBridgeSampleProvider();%0A        %7D else %7B%0A            return new MorpheuzSampleProvider();%0A        %7D
 %0A   

Fix for pebble sample provider switching without quitting gb)