use of com.moez.QKSMS.model.ChangeModel in project qksms by moezbhatti.
the class DialogHelper method showChangelog.
public static void showChangelog(QKActivity context) {
context.showProgressDialog();
String url = "https://qksms-changelog.firebaseio.com/changes.json";
StringRequest request = new StringRequest(url, response -> {
Gson gson = new Gson();
ChangeModel[] changes = gson.fromJson(response, ChangeModel[].class);
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dateRevisionParser = new SimpleDateFormat("yyyy-MM-dd-'r'H");
SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMM d, yyyy");
for (ChangeModel change : changes) {
try {
Date date;
if (change.getDate().length() > 11) {
date = dateRevisionParser.parse(change.getDate());
} else {
date = dateParser.parse(change.getDate());
}
change.setDate(dateFormatter.format(date));
change.setDateLong(date.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
Arrays.sort(changes, (lhs, rhs) -> Long.valueOf(rhs.getDateLong()).compareTo(lhs.getDateLong()));
boolean currentVersionReached = false;
ArrayList<String> versions = new ArrayList<>();
ArrayList<String> dates = new ArrayList<>();
ArrayList<String> changelists = new ArrayList<>();
for (ChangeModel change : changes) {
if (change.getVersion().equals(BuildConfig.VERSION_NAME)) {
currentVersionReached = true;
}
if (currentVersionReached) {
versions.add(change.getVersion());
dates.add(change.getDate());
String changelist = "";
for (int i = 0; i < change.getChanges().size(); i++) {
String changeItem = change.getChanges().get(i);
changelist += " • ";
changelist += changeItem;
if (i < change.getChanges().size() - 1) {
changelist += "\n";
}
}
changelists.add(changelist);
}
}
context.hideProgressDialog();
new QKDialog().setContext(context).setTitle(R.string.title_changelog).setTripleLineItems(versions.toArray(new String[versions.size()]), dates.toArray(new String[versions.size()]), changelists.toArray(new String[versions.size()]), null).show();
}, error -> {
context.hideProgressDialog();
context.makeToast(R.string.toast_changelog_error);
});
context.getRequestQueue().add(request);
}
Aggregations