package com.aluxoft.earrecognition.loader;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;

import com.aluxoft.earrecognition.common.EarData;

/**
 * Created by josejuliomartinez on 13/10/15.
 */
public class EarDataLoaderCommcare extends EarDataLoader {

    @Override
    public EarData load(Activity current) {

        EarData data = new EarData();

        Cursor c = current.managedQuery(Uri.parse("content://org.commcare.dalvik.case/casedb/case"), null, null, null, null);

        if (c == null) {
            return data;
        }

        while (c.moveToNext()) {
            String caseId = c.getString(c.getColumnIndex("case_id"));
            Uri uri = Uri.parse("content://org.commcare.dalvik.case/casedb/data/" + caseId);
            Cursor caseCursor = current.managedQuery(uri, null, null, null, null);
            if (caseCursor == null) {
                continue;
            }
            while (caseCursor.moveToNext()) {
                String gender = caseCursor.getString(caseCursor.getColumnIndex("gender"));
                String features = caseCursor.getString(caseCursor.getColumnIndex("features"));
                // Agregar el gender, caseid y features a data
            }
        }

        return data;
    }
}
