Merge pull request 'Changelog popup' (#296) from 262-changelog-popup into master

Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/296
This commit is contained in:
M M Arif 2020-03-29 14:18:20 +00:00
commit e89f12f61e
5 changed files with 160 additions and 2 deletions

View File

@ -285,7 +285,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
if(appUtil.checkIntegers(loginOTP_)) {
loginOTP = Integer.valueOf(loginOTP_);
loginOTP = Integer.parseInt(loginOTP_);
}
else {

View File

@ -11,6 +11,8 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
@ -32,6 +34,7 @@ import org.mian.gitnex.fragments.SettingsFragment;
import org.mian.gitnex.fragments.StarredRepositoriesFragment;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.ChangeLog;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.GiteaVersion;
import org.mian.gitnex.models.UserInfo;
@ -156,7 +159,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
final View hView = navigationView.getHeaderView(0);
final View hView = navigationView.getHeaderView(0);
ImageView navSubMenu = hView.findViewById(R.id.navSubMenu);
navSubMenu.setOnClickListener(new View.OnClickListener() {
@ -285,6 +288,23 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
}
// Changelog popup
int versionCode = 0;
try {
PackageInfo packageInfo = getApplicationContext().getPackageManager()
.getPackageInfo(getApplicationContext().getPackageName(), 0);
versionCode = packageInfo.versionCode;
}
catch (PackageManager.NameNotFoundException e) {
Log.e("changelogDialog", Objects.requireNonNull(e.getMessage()));
}
if (versionCode > tinyDb.getInt("versionCode")) {
tinyDb.putInt("versionCode", versionCode);
tinyDb.putBoolean("versionFlag", true);
ChangeLog changelogDialog = new ChangeLog(this);
changelogDialog.showDialog();
}
}
public void setActionBarTitle (@NonNull String title) {

View File

@ -0,0 +1,103 @@
package org.mian.gitnex.helpers;
import java.io.IOException;
import java.util.Objects;
import org.mian.gitnex.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
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;
/**
* Author M M Arif
*/
public class ChangeLog {
static final private String TAG = "ChangeLog";
static final private String CHANGELOG_XML_NODE = "changelog";
private Activity changelogActivity;
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"))) {
if ((eventType == XmlPullParser.START_TAG) && (aXml.getName().equals("change"))) {
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);
androidx.appcompat.app.AlertDialog.Builder builder = new AlertDialog.Builder(changelogActivity);
builder.setTitle(R.string.changelogTitle);
builder.setMessage(Html.fromHtml("<small>" + changelogMessage + "</small>"));
builder.setNegativeButton(R.string.close, (dialog, which) -> dialog.cancel());
builder.setCancelable(false);
builder.create();
builder.show();
}
}

View File

@ -560,4 +560,7 @@
<string name="shareIssue">Share Issue</string>
<string name="shareRepository">Share Repository</string>
<string name="createRepository">Create Repository</string>
<string name="changelogTitle" translatable="false">Changelog</string>
</resources>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog>
<release version="2.4.1" versioncode="91">
<change>Improvement: Show issues only in Issues Tabs</change>
<change>Bugfix: Files breadcrumb navigation links</change>
<change>Bugfix: Login with special characters</change>
</release>
<release version="2.4.0" versioncode="90">
<change>New: Light theme (choose from settings)</change>
<change>New: Icons</change>
<change>New: Download files in Fileviewer (needs write permission)</change>
<change>New: Custom fonts (choose from settings)</change>
<change>New: PDF support in Fileviewer</change>
<change>New: Night mode for PDF in Fileviewer (choose from settings)</change>
<change>New: Default list of repositories in Explore screen</change>
<change>New: Latvian language support</change>
<change>Improvement: Support more files in file viewer syntax highlighter</change>
<change>Improvement: Exclude BIN files rendering in diff viewer</change>
<change>Improvement: Exclude specific files in Fileviewer like doc, xls etc</change>
<change>Improvement: Single issue id and support copy title and description to clipboard</change>
<change>Improvement: Translation updates</change>
<change>Bugfix: Dont refresh repositories without action</change>
</release>
<release version="2.3.2" versioncode="82">
<change>Bugfix: Slashes in URL(file viewer)</change>
<change>Bugfix: No milestones when creating issue if user has other language selected</change>
</release>
</changelog>