summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/util/DownloadError.java
blob: 1a64991a625b48e6ac3aecef5caf43b80f459017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package de.danoeh.antennapod.util;

import android.content.Context;
import de.danoeh.antennapod.R;

/** Utility class for Download Errors. */
public enum DownloadError {
	SUCCESS(0, R.string.download_successful),
	ERROR_PARSER_EXCEPTION(1, R.string.download_error_parser_exception),
	ERROR_UNSUPPORTED_TYPE(2, R.string.download_error_unsupported_type),
	ERROR_CONNECTION_ERROR(3, R.string.download_error_connection_error),
	ERROR_MALFORMED_URL(4, R.string.download_error_error_unknown),
	ERROR_IO_ERROR(5, R.string.download_error_io_error),
	ERROR_FILE_EXISTS(6, R.string.download_error_error_unknown),
	ERROR_DOWNLOAD_CANCELLED(7, R.string.download_error_error_unknown),
	ERROR_DEVICE_NOT_FOUND(8, R.string.download_error_device_not_found),
	ERROR_HTTP_DATA_ERROR(9, R.string.download_error_http_data_error),
	ERROR_NOT_ENOUGH_SPACE(10, R.string.download_error_insufficient_space),
	ERROR_UNKNOWN_HOST(11, R.string.download_error_unknown_host),
	ERROR_REQUEST_ERROR(12, R.string.download_error_request_error),
    ERROR_DB_ACCESS_ERROR(13, R.string.download_error_db_access),
    ERROR_UNAUTHORIZED(14, R.string.download_error_unauthorized);

	private final int code;
	private final int resId;

	private DownloadError(int code, int resId) {
		this.code = code;
		this.resId = resId;
	}

	/** Return DownloadError from its associated code. */
	public static DownloadError fromCode(int code) {
		for (DownloadError reason : values()) {
			if (reason.getCode() == code) {
				return reason;
			}
		}
		throw new IllegalArgumentException("unknown code: " + code);
	}

	/** Get machine-readable code. */
	public int getCode() {
		return code;
	}

	/** Get a human-readable string. */
	public String getErrorString(Context context) {
		return context.getString(resId);
	}

}