private static void ensureLoaded() { if (versionHistoryEntries == null) { versionHistoryEntries = new ArrayList<VersionHistoryEntry>(); SharedPreferences prefs = ApptentiveInternal.getInstance().getGlobalSharedPrefs(); if (prefs != null) { try { String json = prefs.getString(Constants.PREF_KEY_VERSION_HISTORY_V2, "[]"); JSONArray baseArray = new JSONArray(json); for (int i = 0; i < baseArray.length(); i++) { VersionHistoryEntry entry = new VersionHistoryEntry(baseArray.getJSONObject(i)); versionHistoryEntries.add(entry); } } catch (Exception e) { ApptentiveLog.w(CONVERSATION, e, "Error loading VersionHistoryStore."); logException(e); } } } }
public static synchronized void updateVersionHistory(Integer newVersionCode, String newVersionName, double date) { ensureLoaded(); try { boolean exists = false; for (VersionHistoryEntry entry : versionHistoryEntries) { if (entry.getVersionCode() == newVersionCode && entry.getVersionName().equals(newVersionName)) { exists = true; } } // Only modify the store if the version hasn't been seen. if (!exists) { VersionHistoryEntry entry = new VersionHistoryEntry(newVersionCode, newVersionName, date); ApptentiveLog.v(CONVERSATION, "Adding Version History entry: %s", entry); versionHistoryEntries.add(new VersionHistoryEntry(newVersionCode, newVersionName, date)); save(); } } catch (Exception e) { ApptentiveLog.w(CONVERSATION, e, "Error updating VersionHistoryStore."); logException(e); } }
private void migrateVersionHistory() { // An existing static initializer will trigger the V1 to V2 migration of VersionHistory when VersionHistoryStore is loaded below. // Then migrate to V3, which is stored in the Conversation object. JSONArray versionHistoryOld = VersionHistoryStore.getBaseArray(); try { if (versionHistoryOld != null && versionHistoryOld.length() > 0) { VersionHistory versionHistory = conversation.getVersionHistory(); for (int i = 0; i < versionHistoryOld.length(); i++) { VersionHistoryEntry versionHistoryEntryOld = new VersionHistoryEntry((JSONObject) versionHistoryOld.get(i)); versionHistory.updateVersionHistory(versionHistoryEntryOld.getTimestamp(), versionHistoryEntryOld.getVersionCode(), versionHistoryEntryOld.getVersionName()); } } } catch (Exception e) { ApptentiveLog.w(CONVERSATION, e, "Error migrating VersionHistory entries V2 to V3."); logException(e); } }