@Override protected Integer doInBackground(Void... voids) { int yearClass = YearClass.CLASS_UNKNOWN; SharedPreferences prefs = getSharedPreferences(PREF_FILE, 0); if (prefs.contains(PREF_NAME)) { yearClass = prefs.getInt(PREF_NAME, YearClass.CLASS_UNKNOWN); } //Try again if device was previously unknown. if (yearClass == YearClass.CLASS_UNKNOWN) { yearClass = YearClass.get(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(PREF_NAME, yearClass); editor.apply(); } return yearClass; }
/** * Function to be shared to React-native, it returns the * year this Android device was considered high-end. * * @return { Promise } yearClass */ @ReactMethod public void getYearClass(Promise promise) { try { int yearClass; yearClass = YearClass.get(getCurrentActivity()); promise.resolve(yearClass); } catch (Exception e) { promise.reject(e); } }
@Override public int getDeviceYear() { return YearClass.get(getApplication()); }