2020-03-17 16:56:37 +01:00
|
|
|
package org.mian.gitnex.helpers;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.res.XmlResourceParser;
|
|
|
|
import android.util.Log;
|
2021-01-26 16:10:31 +01:00
|
|
|
import androidx.core.text.HtmlCompat;
|
2022-08-12 04:01:51 +02:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2020-11-08 19:58:47 +01:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Objects;
|
2020-03-17 16:56:37 +01:00
|
|
|
|
|
|
|
/**
|
2022-04-04 10:00:54 +02:00
|
|
|
* @author M M Arif
|
2020-03-17 16:56:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class ChangeLog {
|
|
|
|
|
|
|
|
static final private String TAG = "ChangeLog";
|
|
|
|
static final private String CHANGELOG_XML_NODE = "changelog";
|
2020-08-08 17:43:14 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
private final Activity changelogActivity;
|
2020-08-08 17:43:14 +02:00
|
|
|
|
2020-03-17 16:56:37 +01:00
|
|
|
public ChangeLog(Activity context) {
|
|
|
|
changelogActivity = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String ParseReleaseTag(XmlResourceParser aXml) throws XmlPullParserException, IOException {
|
|
|
|
|
|
|
|
StringBuilder strBuilder = new StringBuilder(aXml.getAttributeValue(null, "version") + "<br>");
|
|
|
|
int eventType = aXml.getEventType();
|
|
|
|
|
|
|
|
while ((eventType != XmlPullParser.END_TAG) || (aXml.getName().equals("change"))) {
|
|
|
|
|
2020-03-21 19:52:52 +01:00
|
|
|
if ((eventType == XmlPullParser.START_TAG) && (aXml.getName().equals("change"))) {
|
2020-03-17 16:56:37 +01:00
|
|
|
eventType = aXml.next();
|
|
|
|
strBuilder.append(aXml.getText()).append("<br>");
|
|
|
|
}
|
|
|
|
eventType = aXml.next();
|
|
|
|
|
|
|
|
}
|
|
|
|
strBuilder.append("<br>");
|
|
|
|
|
|
|
|
return strBuilder.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getChangelog(int resId, Resources res) {
|
|
|
|
|
|
|
|
StringBuilder strBuilder = new StringBuilder();
|
|
|
|
try (XmlResourceParser xml = res.getXml(resId)) {
|
|
|
|
|
|
|
|
int eventType = xml.getEventType();
|
|
|
|
while (eventType != XmlPullParser.END_DOCUMENT) {
|
|
|
|
|
|
|
|
if ((eventType == XmlPullParser.START_TAG) && (xml.getName().equals("release"))) {
|
|
|
|
strBuilder.append(ParseReleaseTag(xml));
|
|
|
|
|
|
|
|
}
|
|
|
|
eventType = xml.next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (XmlPullParserException | IOException e) {
|
|
|
|
Log.e(TAG, Objects.requireNonNull(e.getMessage()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return strBuilder.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showDialog() {
|
|
|
|
|
|
|
|
String packageName = changelogActivity.getPackageName();
|
|
|
|
Resources res = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
res = changelogActivity.getPackageManager().getResourcesForApplication(packageName);
|
|
|
|
}
|
|
|
|
catch (PackageManager.NameNotFoundException e) {
|
|
|
|
Log.e(TAG, Objects.requireNonNull(e.getMessage()));
|
|
|
|
}
|
|
|
|
|
|
|
|
assert res != null;
|
|
|
|
int resId = res.getIdentifier(CHANGELOG_XML_NODE, "xml", packageName);
|
|
|
|
|
|
|
|
String changelogMessage = getChangelog(resId, res);
|
|
|
|
|
2022-08-12 04:01:51 +02:00
|
|
|
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(changelogActivity)
|
|
|
|
.setTitle(R.string.changelogTitle)
|
|
|
|
.setMessage(HtmlCompat.fromHtml("<small>" + changelogMessage + "</small>", HtmlCompat.FROM_HTML_MODE_LEGACY))
|
|
|
|
.setCancelable(false)
|
|
|
|
.setNeutralButton(R.string.close, null);
|
2020-03-17 16:56:37 +01:00
|
|
|
|
2022-08-12 04:01:51 +02:00
|
|
|
materialAlertDialogBuilder.create().show();
|
2020-03-17 16:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|