forked from upstream-mirrors/quik
Pull the changes from firebase and sort them
This commit is contained in:
@@ -2,6 +2,8 @@ package com.moez.QKSMS.common;
|
||||
|
||||
import android.util.Log;
|
||||
import com.android.volley.toolbox.StringRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.data.Conversation;
|
||||
import com.moez.QKSMS.transaction.SmsHelper;
|
||||
@@ -10,7 +12,11 @@ import com.moez.QKSMS.ui.base.QKActivity;
|
||||
import com.moez.QKSMS.ui.dialog.DefaultSmsHelper;
|
||||
import com.moez.QKSMS.ui.dialog.QKDialog;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -68,10 +74,27 @@ public class DialogHelper {
|
||||
String url = "https://qksms-changelog.firebaseio.com/changes.json";
|
||||
|
||||
StringRequest request = new StringRequest(url, response -> {
|
||||
Log.d(TAG, "onComplete: " + response);
|
||||
Gson gson = new Gson();
|
||||
Change[] changes = gson.fromJson(response, Change[].class);
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
SimpleDateFormat formatWithRevision = new SimpleDateFormat("yyyy-MM-dd-'r'H"); // For multiple updates in a day
|
||||
for (Change change : changes) {
|
||||
try {
|
||||
if (change.date.length() > 11) {
|
||||
change.dateLong = formatWithRevision.parse(change.date).getTime();
|
||||
} else {
|
||||
change.dateLong = format.parse(change.date).getTime();
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Arrays.sort(changes, (lhs, rhs) -> Long.valueOf(rhs.dateLong).compareTo(lhs.dateLong));
|
||||
|
||||
context.hideProgressDialog();
|
||||
}, error -> {
|
||||
Log.d(TAG, "onError: " + error.getMessage());
|
||||
context.hideProgressDialog();
|
||||
context.makeToast(R.string.toast_changelog_error);
|
||||
});
|
||||
@@ -79,4 +102,17 @@ public class DialogHelper {
|
||||
context.getRequestQueue().add(request);
|
||||
}
|
||||
|
||||
private class Change implements Comparator<Long> {
|
||||
@SerializedName("changes") ArrayList<String> changes;
|
||||
@SerializedName("release_date") String date;
|
||||
@SerializedName("version_name") String version;
|
||||
|
||||
long dateLong = 0;
|
||||
|
||||
@Override
|
||||
public int compare(Long lhs, Long rhs) {
|
||||
return lhs.compareTo(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user