package org.commcare.utils;

import android.content.Context;
import android.content.res.Resources;

import org.commcare.dalvik.R;
import org.commcare.util.ArrayDataSource;

/**
 * ArrayDataSource that uses the Android 'values' resources
 */

public class AndroidArrayDataSource implements ArrayDataSource {

    private Context context;

    public AndroidArrayDataSource(Context context){
        this.context = context;
    }

    @Override
    public String[] getArray(String key) {
        if(key.contains("ethiopian_months")){
            return context.getResources().getStringArray(R.array.ethiopian_months);
        } else if(key.contains("nepali_months")){
            return context.getResources().getStringArray(R.array.nepali_months);
        }
        throw new Resources.NotFoundException("Couldn't find Android array for key " + key);
    }
}

@@ -58,76 +58,8 @@
 xt;%0A
-import android.content.res.Resources;%0A%0Aimport org.commcare.dalvik.R;
 %0Aimp
@@ -424,137 +424,111 @@
    i
-f(key.contains(%22ethiopian_months%22))%7B%0A            return context.getResources().getStringArray(R.array.ethiopian_months
+nt resourceId = context.getResources().getIdentifier(key, %22array%22, context.getPackageName()
 );%0A
+%0A
         
 %7D el
@@ -527,128 +527,120 @@
     
-%7D else if(key.contains(%22nepali_months%22))%7B%0A            return context.getResources().getStringArray(R.array.nepali_months
+if (resourceId == 0) %7B%0A            throw new RuntimeException(%22Localized array data for '%22 + key + %22' not found%22
 );%0A 
@@ -648,24 +648,25 @@
       %7D%0A
+%0A
         
 throw ne
@@ -661,90 +661,63 @@
     
-throw new Resources.NotFoundException(%22Couldn't find Android array for key %22 + key
+return context.getResources().getStringArray(resourceId
 );%0A 

Revert data source change