My Dears, I'm flighting to can read multiple CSV Files from Google Cloud Firebase Store.
I'm doing that:
new GetCompaniesCsvFile().execute("companies.csv");
and
new GetLinesCsvFile().execute("lines.csv");
Both Classes Does that:
private static class GetLinesCsvFile
extends AsyncTask<String, Integer, Reader>
{
@Override
protected Reader doInBackground(String... tableName) {
return getLinesCsvFile(tableName[0]);
}
@Override
protected void onPostExecute(Reader reader) {
importLinesFromCsv(reader);
}
}
private static void importLinesFromCsv(Reader reader) {
try {
CsvReader csvReader = new CsvReader(reader);
// nextLine[] is an array of values from the line
while (csvReader.getHasNext()) {
csvReader.readNext(linesStringArray);
}
} catch (Exception ex) {
Log.d("CsvUtil", ex.getMessage());
}
}
My readNext(List list) Method Does That:
private static final class GetNextLine extends AsyncTask<Void, Integer, String>
implements ParseLine.TaskDelegate {
private List<String[]> list;
public GetNextLine(List<String[]> l) {
list = l;
}
@Override
protected String doInBackground(Void... companies) {
try {
return getNextLine();
} catch (IOException ex) {
Log.e("CsvReader", ex.getMessage());
}
return null;
}
@Override
protected void onPostExecute(String nextLine) {
if (nextLine != null) {
ParseLine parseLine = new ParseLine(this);
parseLine.execute(nextLine);
}
}
@Override
public void onTaskEndWithResult(String[] parseLine) {
list.add(parseLine);
}
}
And ParseLine Class That:
public static final class ParseLine extends AsyncTask<String, Integer, String[]> {
private TaskDelegate delegate;
public ParseLine(TaskDelegate delegate) {
this.delegate = delegate;
}
public interface TaskDelegate {
public void onTaskEndWithResult(String[] parseLine);
}
@Override
protected String[] doInBackground(String... nextLine) {
try {
return parseLine(nextLine[0]);
} catch (IOException ex) {
Log.e("CsvReader", ex.getMessage());
}
return null;
}
@Override
protected void onPostExecute(String[] parseLine) {
if (parseLine != null && delegate != null)
delegate.onTaskEndWithResult(parseLine);
}
}
Just Read Only the First File and I need read 2 CSV Files with Some Lines and Some Fields, but the application can read only one file with AsyncTask, may you help me please, I lost a lot of hours in this issue, Help me please, Thanks a lot.