Implemented Class to convert DownloadManager error codes to
human-readable Strings
This commit is contained in:
parent
20ca5f78cd
commit
113ccff68f
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue