2323
2424import java .io .IOException ;
2525import java .io .UncheckedIOException ;
26+ import java .util .ArrayList ;
2627import java .util .HashMap ;
28+ import java .util .List ;
2729import java .util .Map ;
2830import java .util .Properties ;
31+ import java .util .function .Consumer ;
2932
3033@ SuppressWarnings ({"unchecked" , "rawtypes" })
3134public final class Devices {
3235
33- private static final String [] iPhones = {"iPhone 3G[S]" , "iPhone 4 (GSM)" ,
34- "iPhone 4 (GSM 2012)" , "iPhone 4 (CDMA)" , "iPhone 4[S]" , "iPhone 5 (GSM)" , "iPhone 5 (Global)" ,
35- "iPhone 5c (GSM)" , "iPhone 5c (Global)" , "iPhone 5s (GSM)" , "iPhone 5s (Global)" ,
36- "iPhone 6+" , "iPhone 6" , "iPhone 6s" , "iPhone 6s+" , "iPhone SE" , "iPhone 7 (Global)(iPhone9,1)" ,
37- "iPhone 7+ (Global)(iPhone9,2)" , "iPhone 7 (GSM)(iPhone9,3)" , "iPhone 7+ (GSM)(iPhone9,4)" ,
38- "iPhone 8 (iPhone10,1)" , "iPhone 8+ (iPhone10,2)" , "iPhone X (iPhone10,3)" , "iPhone 8 (iPhone10,4)" ,
39- "iPhone 8+ (iPhone10,5)" , "iPhone X (iPhone10,6)" , "iPhone XS (Global) (iPhone11,2)" ,
40- "iPhone XS Max (China) (iPhone11,4)" , "iPhone XS Max (iPhone11,6)" , "iPhone XR (iPhone11,8)" ,
41- "iPhone 11 (iPhone12,1)" , "iPhone 11 Pro (iPhone12,3)" , "iPhone 11 Pro Max (iPhone12,5)" ,
42- "iPhone SE 2 (iPhone12,8)" , "iPhone 12 mini (iPhone13,1)" , "iPhone 12 (iPhone13,2)" ,
43- "iPhone 12 Pro (iPhone13,3)" , "iPhone 12 Pro Max (iPhone13,4)" ,
44- "iPhone 13 Pro (iPhone14,2)" , "iPhone 13 Pro Max (iPhone14,3)" ,
45- "iPhone 13 mini (iPhone14,4)" , "iPhone 13 (iPhone14,5)" , "iPhone SE 3 (iPhone14,6)" , "iPhone 14 (iPhone14,7)" ,
46- "iPhone 14+ (iPhone14,8)" , "iPhone 14 Pro (iPhone15,2)" , "iPhone 14 Pro Max (iPhone15,3)" };
47- private static final String [] iPads = {"iPad 1" , "iPad 2 (WiFi)" , "iPad 2 (GSM)" ,
48- "iPad 2 (CDMA)" , "iPad 2 (Mid 2012)" , "iPad Mini (Wifi)" , "iPad Mini (GSM)" , "iPad Mini (Global)" ,
49- "iPad 3 (WiFi)" , "iPad 3 (CDMA)" , "iPad 3 (GSM)" , "iPad 4 (WiFi)" , "iPad 4 (GSM)" , "iPad 4 (Global)" ,
50- "iPad Air (Wifi)" , "iPad Air (Cellular)" , "iPad Air (China)" , "iPad Mini 2 (WiFi)" , "iPad Mini 2 (Cellular)" ,
51- "iPad Mini 2 (China)" , "iPad Mini 3 (WiFi)" , "iPad Mini 3 (Cellular)" , "iPad Mini 3 (China)" ,
52- "iPad Mini 4 (Wifi)" , "iPad Mini 4 (Cellular)" , "iPad Air 2 (WiFi)" , "iPad Air 2 (Cellular)" ,
53- "iPad Pro 9.7 (Wifi)" , "iPad Pro 9.7 (Cellular)" , "iPad Pro 12.9 (WiFi)" , "iPad Pro 12.9 (Cellular)" ,
54- "iPad 5 (Wifi)" , "iPad 5 (Cellular)" , "iPad Pro 2 12.9 (WiFi)(iPad7,1)" , "iPad Pro 2 12.9 (Cellular)(iPad7,2)" ,
55- "iPad Pro 10.5 (WiFi)(iPad7,3)" , "iPad Pro 10.5 (Cellular)(iPad7,4)" , "iPad 6 (WiFi)(iPad 7,5)" ,
56- "iPad 6 (Cellular)(iPad7,6)" , "iPad 7 (WiFi)(iPad7,11)" , "iPad 7 (Cellular)(iPad7,12)" ,
57- "iPad Pro 3 11' (WiFi)(iPad8,1)" , "iPad Pro 3 11' (WiFi)(iPad8,2)" , "iPad Pro 3 11' (Cellular)(iPad8,3)" ,
58- "iPad Pro 3 11' (Cellular)(iPad8,4)" , "iPad Pro 3 12.9'(WiFi)(iPad8,5)" , "iPad Pro 3 12.9 (WiFi)(iPad8,6)" ,
59- "iPad Pro 3 12.9 (Cellular)(iPad8,7)" , "iPad Pro 3 12.9 (Cellular)(iPad8,8)" , "iPad Pro 4 11' (WiFi)(iPad8,9)" ,
60- "iPad Pro 4 11' (Cellular)(iPad8,10)" , "iPad Pro 4 12.9' (WiFi)(iPad8,11)" ,
61- "iPad Pro 4 12.9' (Cellular)(iPad8,12)" , "iPad Mini 5 (WiFi)(iPad11,1)" , "iPad Mini 5 (Cellular)(iPad11,2)" ,
62- "iPad Air 3 (WiFi)(iPad11,3)" , "iPad Air 3 (Cellular)(iPad11,4)" , "iPad 8 (WiFi) (iPad11,6)" ,
63- "iPad 8 (Cellular) (iPad11,7)" , "iPad 9 (WiFi) (iPad12,1)" , "iPad 9 (Cellular) (iPad12,2)" ,
64- "iPad Air 4 (WiFi) (iPad13,1)" , "iPad Air 4 (Cellular) (iPad13,2)" ,
65- "iPad Pro 11' (3rd gen) (WiFi) (iPad13,4)" , "iPad Pro 11' (3rd gen) (WiFi) (iPad13,5)" ,
66- "iPad Pro 11' (3rd gen) (Cellular) (iPad13,6)" , "iPad Pro 11' (3rd gen) (Cellular) (iPad13,7)" ,
67- "iPad Pro 12.9' (5th gen) (WiFi) (iPad13,8)" , "iPad Pro 12.9' (5th gen) (WiFi) (iPad13,9)" ,
68- "iPad Pro 12.9' (5th gen) (Cellular) (iPad13,10)" , "iPad Pro 12.9' (5th gen) (Cellular) (iPad13,11)" ,
69- "iPad Mini 6 (WiFi) (iPad14,1)" , "iPad Mini 6 (Cellular) (iPad14,2)" , "iPad Air 5 (WiFi) (iPad13,16)" ,
70- "iPad Air 5 (Cellular) (iPad13,17)" , "iPad 10 (WiFi) (iPad13,18)" , "iPad 10 (Cellular) (iPad13,19)" ,
71- "iPad Pro 11' (4th gen) (WiFi) (iPad14,3)" , "iPad Pro 11' (4th gen) (Cellular) (iPad14,4)" ,
72- "iPad Pro 12.9' (6th gen) (WiFi) (iPad14,5)" , "iPad Pro 12.9' (6th gen) (Cellular) (iPad14,6)" };
73-
74- private static final String [] iBridges = {"iMac Pro (2017) (iMacPro1,1)" , "MacBook Pro 15' (2018-2019) (MacBookPro15,1)" ,
75- "MacBook Pro 13' 2018-2019) Four Thunderbolt 3 ports, (MacBookPro15,2)" , "Mac mini (2018) (Macmini8,1)" ,
76- "Mac Pro (2019) (MacPro7,1)" , "MacBook Pro 15' (2019, AMD Radeon Pro Vega graphics) (MacBookPro15,3)" ,
77- "MacBook Air 13' (Retina, 2018) (MacBookAir8,1)" , "MacBook Pro 13' (2019, Two Thunderbolt 3 ports) (MacBookPro15,4)" ,
78- "MacBook Air 13' (Retina, 2019) (MacBookAir8,2)" , "MacBook Pro 16' (2019) (MacBookPro16,1)" ,
79- "MacBook Air 13' (Retina, 2020) (MacBookAir9,1)" , "MacBook Pro 13' (2020, Four Thunderbolt 3 ports) (MacBookPro16,2)" ,
80- "iMac 27' (Retina 5K, 2020) (iMac20,1)" , "iMac 27' (Retina 5K, 2020) (iMac20,2)" ,
81- "MacBook Pro 13' (2020, Two Thunderbolt 3 ports) (MacBookPro16,3)" ,
82- "MacBook Pro 16' (2019, AMD Radeon Pro 5600M graphics) (MacBookPro16,4)" };
83-
84- private static final ObservableList <String > iPhoneList = FXCollections .observableArrayList (iPhones );
85- private static final ObservableList <String > iPadList = FXCollections .observableArrayList (iPads );
86- private static final ObservableList <String > iBridgeList = FXCollections .observableArrayList (iBridges );
36+ private static final List <String > iPhones = new ArrayList <>(), iPads = new ArrayList <>();
37+
38+ private static final ObservableList <String > iPhoneList , iPadList , iBridgeList = FXCollections .observableArrayList ();
8739
8840 private static final ObservableList <String > iPodList = unmodifiableArrayList ("iPod Touch 3" , "iPod Touch 4" ,
8941 "iPod Touch 5" , "iPod Touch 6" , "iPod Touch 7 (iPod9,1)" );
@@ -93,18 +45,20 @@ public final class Devices {
9345
9446 private static final ObservableList <String > deviceTypes = unmodifiableArrayList ("iPhone" , "iPod" , "iPad" , "AppleTV" , "T2 Mac" );
9547
96- private static final Map <String , String > boardConfigs ;
97-
98- private static final Map <String , String > deviceModelIdentifiers ;
48+ private static final Map <String , String > boardConfigs = (Map ) new Properties ();
9949
100- private static final Map <String , String > identifierDeviceModels = new HashMap <>();
50+ private static final Map <String , String > deviceModelIdentifiers = new HashMap <>(), identifierDeviceModels = new HashMap <>();
10151
10252 static {
10353 try {
104- deviceModelIdentifiers = loadProperties ("devicemodels.properties" );
105- deviceModelIdentifiers .forEach ((k , v ) -> identifierDeviceModels .put (v , k ));
54+ try (var stream = Devices .class .getResourceAsStream ("boardconfigs.properties" )) {
55+ ((Properties ) (Map ) boardConfigs ).load (stream );
56+ }
57+
58+ loadProperties ();
10659
107- boardConfigs = loadProperties ("boardconfigs.properties" );
60+ iPadList = FXCollections .observableArrayList (iPads );
61+ iPhoneList = FXCollections .observableArrayList (iPhones );
10862 } catch (IOException e ) {
10963 throw new UncheckedIOException (e );
11064 }
@@ -119,8 +73,8 @@ public static void updateLists() {
11973 if (Prefs .getShowOldDevices ()) {
12074 iPhoneList .setAll (iPhones );
12175 iPadList .setAll (iPads );
122- } else if (!iPhoneList .get (0 ).equals ("iPhone 6+ " )) {
123- iPhoneList .remove (0 , iPhoneList .indexOf ("iPhone 6+ " ));
76+ } else if (!iPhoneList .get (0 ).equals ("iPhone 6s " )) {
77+ iPhoneList .remove (0 , iPhoneList .indexOf ("iPhone 6s " ));
12478 iPadList .remove (0 , iPadList .indexOf ("iPad Mini 4 (Wifi)" ));
12579 }
12680 }
@@ -129,8 +83,6 @@ public static ObservableList<String> getiPhoneList() {
12983 return iPhoneList ;
13084 }
13185
132- // other accessors not used
133-
13486 public static ObservableList <String > getDeviceTypes () {
13587 return deviceTypes ;
13688 }
@@ -205,21 +157,46 @@ public static boolean doesRequireBoardConfig(String deviceIdentifier) {
205157 }
206158
207159 public static boolean doesRequireApnonce (String deviceIdentifier ) {
208- return deviceIdentifier .startsWith ("iPhone11," ) || deviceIdentifier .startsWith ("iPhone12," ) ||
209- deviceIdentifier .startsWith ("iPhone13," ) || deviceIdentifier .startsWith ("iPhone14," ) ||
210- deviceIdentifier .startsWith ("iPad8," ) || deviceIdentifier .startsWith ("iPad11," ) ||
211- deviceIdentifier .startsWith ("iPad12," ) || deviceIdentifier .startsWith ("iPad13," ) ||
212- deviceIdentifier .startsWith ("iPad14," );
160+ String model = identifierToModel (deviceIdentifier );
161+ if (deviceIdentifier .startsWith ("iPhone" )) {
162+ return iPhoneList .indexOf (model ) >= iPhoneList .indexOf (identifierToModel ("iPhone11,2" ));
163+ } else if (deviceIdentifier .startsWith ("iPad" )) {
164+ return iPadList .indexOf (model ) >= iPadList .indexOf ((identifierToModel ("iPad8,1" )));
165+ } else {
166+ return false ;
167+ }
213168 }
214169
215170 @ SafeVarargs
216171 private static <T > ObservableList <T > unmodifiableArrayList (T ... items ) {
217172 return FXCollections .unmodifiableObservableList (FXCollections .observableArrayList (items ));
218173 }
219174
220- private static Map <String , String > loadProperties (String resourceName ) throws IOException {
221- Properties properties = new Properties ();
222- properties .load (Devices .class .getResourceAsStream (resourceName ));
223- return (Map ) properties ;
175+ private static void loadProperties () throws IOException {
176+
177+ var loader = new Properties () {
178+ private Consumer <String > keyProcessor ;
179+
180+ void load (String resourceName , Consumer <String > keyProcessor ) throws IOException {
181+ this .keyProcessor = keyProcessor ;
182+ try (var stream = Devices .class .getResourceAsStream (resourceName )) {
183+ load (stream );
184+ }
185+ }
186+
187+ @ Override
188+ public Object put (Object key , Object value ) {
189+ deviceModelIdentifiers .put ((String ) key , (String ) value );
190+ identifierDeviceModels .put ((String ) value , (String ) key );
191+ keyProcessor .accept ((String ) key );
192+ return null ;
193+ }
194+ };
195+
196+ loader .load ("devicemodels/iPhones.properties" , iPhones ::add );
197+ loader .load ("devicemodels/iPads.properties" , iPads ::add );
198+ loader .load ("devicemodels/iBridges.properties" , iBridgeList ::add );
199+ loader .load ("devicemodels/others.properties" , o -> {
200+ });
224201 }
225202}
0 commit comments