Implemented Class to convert DownloadManager error codes to

human-readable Strings
This commit is contained in:
daniel oeh 2012-06-17 19:22:37 +02:00
parent 20ca5f78cd
commit 113ccff68f
3 changed files with 35 additions and 0 deletions

View File

@ -43,4 +43,9 @@
<string name="other_pref">Other</string>
<string name="about_pref">About</string>
<string name="show_download_log">Show Log</string>
<string name="download_error_device_not_found">Storage device not found</string>
<string name="download_error_insufficient_space">Insufficient space</string>
<string name="download_error_file_error">File error</string>
<string name="download_error_http_data_error">HTTP Data Error</string>
<string name="download_error_error_unknown">Unknown Error</string>
</resources>

View File

@ -17,6 +17,7 @@ import de.podfetcher.feed.FeedFile;
import de.podfetcher.feed.FeedImage;
import de.podfetcher.feed.FeedMedia;
import de.podfetcher.service.DownloadStatus;
import de.podfetcher.util.DownloadError;
/** Displays a list of DownloadStatus entries. */
public class DownloadLogAdapter extends ArrayAdapter<DownloadStatus> {
@ -65,6 +66,7 @@ public class DownloadLogAdapter extends ArrayAdapter<DownloadStatus> {
} else {
holder.successful.setTextColor(Color.parseColor("red"));
holder.successful.setText("Download failed");
holder.reason.setText(DownloadError.getErrorString(getContext(), status.getReason()));
}
} else {
holder = (Holder) convertView.getTag();

View File

@ -0,0 +1,28 @@
package de.podfetcher.util;
import de.podfetcher.R;
import android.app.DownloadManager;
import android.content.Context;
/** Utility class for Download Errors. */
public class DownloadError {
/** Get a human-readable string for a specific error code. */
public static String getErrorString(Context context, int code) {
int resId;
switch(code) {
case DownloadManager.ERROR_DEVICE_NOT_FOUND:
resId = R.string.download_error_insufficient_space;
break;
case DownloadManager.ERROR_FILE_ERROR:
resId = R.string.download_error_file_error;
break;
case DownloadManager.ERROR_HTTP_DATA_ERROR:
resId = R.string.download_error_http_data_error;
break;
default:
resId = R.string.download_error_error_unknown;
}
return context.getString(resId);
}
}