GitNex-Android-App/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java

105 lines
2.6 KiB
Java
Raw Normal View History

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.text.Html;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
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
/**
* Author M M Arif
*/
public class ChangeLog {
static final private String TAG = "ChangeLog";
static final private String CHANGELOG_XML_NODE = "changelog";
2020-03-17 16:56:37 +01:00
private Activity changelogActivity;
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);
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
AlertDialog.Builder builder = new AlertDialog.Builder(changelogActivity);
2020-03-17 16:56:37 +01:00
builder.setTitle(R.string.changelogTitle);
builder.setMessage(Html.fromHtml("<small>" + changelogMessage + "</small>"));
builder.setNeutralButton(R.string.close, null);
2020-03-21 19:52:52 +01:00
builder.setCancelable(false);
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
builder.create().show();
2020-03-17 16:56:37 +01:00
}
}