Alguém teria um exemplo de como mostrar uma barra de progresso a fazer a leitura de um arquivo em um servidor FTP?
Eu já tenho ele funcionando mas tem arquivo muito grande (20 mil linhas) que precisa que o usuário acompanhe o download (na verdade é a leitura de linha a linha do arquivo) e preciso mostrar o progresso numa AsyncTask.
No momento eu mostro uma ProgressBar somente dizendo pra ele aguardar.
Estou usando o Apache Commons Net para o download/upload no FTP.
[code] public ArrayList lerArquivo(String arquivo) throws IOException {
ArrayList rows = new ArrayList();
boolean connected = isFtpConnected();
if (connected) {
mFTPClient.setBufferSize(1024 * 1024);
InputStream stream = mFTPClient.retrieveFileStream(arquivo.toUpperCase());
if (stream != null) {
Scanner fileScanner = new Scanner(new InputStreamReader(stream));
while (fileScanner.hasNextLine()) {
String rowContent = fileScanner.nextLine();
rows.add(rowContent);
}
fileScanner.close();
}
if (mFTPClient != null) {
mFTPClient.logout();
mFTPClient.disconnect();
}
}
return rows;
}
[/code]
Na minha task:[code]…
@Override
protected Integer doInBackground(String… params) {
if (bean.trim().equals("")) {
bean = params[0];
}
String file = “USERS.TXT”;
int total = 0;
try {
FtpServerUtil ftp = new FtpServerUtil();
ArrayList fileRows = ftp.lerArquivo(file);
total = insertRecords(bean, fileRows);
} catch (IOException e) {
Log.e(Const.TAG, “Lendo arquivo no FTP”, e);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.i(Const.TAG, "Na UI...");
}
});
return total;
}
[/code]