package org.andstatus.todoagenda.task;

import android.app.Activity;
import android.content.Context;

import org.andstatus.todoagenda.EventProvider;
import org.andstatus.todoagenda.prefs.ApplicationPreferences;
import org.andstatus.todoagenda.task.dmfs.DmfsOpenTasksProvider;
import org.andstatus.todoagenda.task.samsung.SamsungTasksProvider;

import java.util.List;

public class TaskProvider extends EventProvider {

    private static final String PROVIDER_DMFS = "DMFS_OPEN_TASKS";
    private static final String PROVIDER_SAMSUNG = "SAMSUNG";

    public TaskProvider(Context context, int widgetId) {
        super(context, widgetId);
    }

    public List<TaskEvent> getEvents() {
        AbstractTaskProvider provider = getProvider();
        return provider.getTasks();
    }

    public boolean hasPermission() {
        AbstractTaskProvider provider = getProvider();
        return provider.hasPermission();
    }

    public void requestPermission(Activity activity) {
        AbstractTaskProvider provider = getProvider();
        provider.requestPermission(activity);
    }

    private AbstractTaskProvider getProvider() {
        String taskSource = ApplicationPreferences.getTaskSource(context);
        if (PROVIDER_DMFS.equals(taskSource)) {
            return new DmfsOpenTasksProvider(context, widgetId);
        }
        if (PROVIDER_SAMSUNG.equals(taskSource)) {
            return new SamsungTasksProvider(context, widgetId);
        }

        return new EmptyTaskProvider(context, widgetId);
    }
}

@@ -146,70 +146,8 @@
 er;%0A
-import org.andstatus.todoagenda.prefs.ApplicationPreferences;%0A
 impo
@@ -1101,30 +1101,21 @@
 e = 
-ApplicationPreferences
+getSettings()
 .get
@@ -1125,23 +1125,16 @@
 kSource(
-context
 );%0A     

Fix to correctly use per-widget taks source.