]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/json/API.java
add support for hledger-web 1.23 json schema
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / json / API.java
1 /*
2  * Copyright © 2020 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.json;
19
20 import android.content.res.Resources;
21 import android.util.SparseArray;
22
23 import net.ktnx.mobileledger.R;
24
25 public enum API {
26     auto(0), html(-1), v1_14(-2), v1_15(-3), v1_19_1(-4), v1_23(-5);
27     private static final SparseArray<API> map = new SparseArray<>();
28     public static API[] allVersions = {v1_23, v1_19_1, v1_15, v1_14};
29
30     static {
31         for (API item : API.values()) {
32             map.put(item.value, item);
33         }
34     }
35
36     private final int value;
37
38     API(int value) {
39         this.value = value;
40     }
41     public static API valueOf(int i) {
42         return map.get(i, auto);
43     }
44     public int toInt() {
45         return this.value;
46     }
47     public String getDescription(Resources resources) {
48         switch (this) {
49             case auto:
50                 return resources.getString(R.string.api_auto);
51             case html:
52                 return resources.getString(R.string.api_html);
53             case v1_14:
54                 return resources.getString(R.string.api_1_14);
55             case v1_15:
56                 return resources.getString(R.string.api_1_15);
57             case v1_19_1:
58                 return resources.getString(R.string.api_1_19_1);
59             case v1_23:
60                 return resources.getString(R.string.api_1_23);
61             default:
62                 throw new IllegalStateException("Unexpected value: " + value);
63         }
64     }
65     public String getDescription() {
66         switch (this) {
67             case auto:
68                 return "(automatic)";
69             case html:
70                 return "(HTML)";
71             case v1_14:
72                 return "1.14";
73             case v1_15:
74                 return "1.15";
75             case v1_19_1:
76                 return "1.19.1";
77             case v1_23:
78                 return "1.23";
79             default:
80                 throw new IllegalStateException("Unexpected value: " + this);
81         }
82     }
83 }