From e40eb5e6a140e938358192f9bd1c7fb81f87c168 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Tue, 17 Mar 2020 20:56:37 +0500 Subject: [PATCH 1/4] changelog popup initial working draft --- .../mian/gitnex/activities/MainActivity.java | 5 + .../org/mian/gitnex/helpers/ChangeLog.java | 102 ++++++++++++++++++ app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/changelog.xml | 26 +++++ 4 files changed, 136 insertions(+) create mode 100644 app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java create mode 100644 app/src/main/res/xml/changelog.xml diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index cc32f911..f866625f 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java @@ -32,6 +32,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; @@ -285,6 +286,10 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig } + // Changelog popup + ChangeLog changelogDialog = new ChangeLog(this); + changelogDialog.showDialog(); + } public void setActionBarTitle (@NonNull String title) { diff --git a/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java b/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java new file mode 100644 index 00000000..613638fe --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java @@ -0,0 +1,102 @@ +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") + "
"); + 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("
"); + } + eventType = aXml.next(); + + } + strBuilder.append("
"); + + 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("" + changelogMessage + "")); + builder.setNegativeButton(R.string.okButton, (dialog, which) -> dialog.cancel()); + builder.create(); + builder.show(); + + } + +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bba9dfb9..b90740a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -560,4 +560,7 @@ Share Issue Share Repository Create Repository + + Changelog + diff --git a/app/src/main/res/xml/changelog.xml b/app/src/main/res/xml/changelog.xml new file mode 100644 index 00000000..1ec657c7 --- /dev/null +++ b/app/src/main/res/xml/changelog.xml @@ -0,0 +1,26 @@ + + + + + New: Light theme (choose from settings) + New: Icons + New: Download files in Fileviewer (needs write permission) + New: Custom fonts (choose from settings) + New: PDF support in Fileviewer + New: Night mode for PDF in Fileviewer (choose from settings) + New: Default list of repositories in Explore screen + New: Latvian language support + Improvement: Support more files in file viewer syntax highlighter + Improvement: Exclude BIN files rendering in diff viewer + Improvement: Exclude specific files in Fileviewer like doc, xls etc + Improvement: Single issue id and support copy title and description to clipboard + Improvement: Translation updates + Bugfix: Don’t refresh repositories without action + + + + Bugfix: Slashes in URL(file viewer) + Bugfix: No milestones when creating issue if user has other language selected + + + \ No newline at end of file From a9b8e158127f9f76279cb4755c4a637791f175b0 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Thu, 19 Mar 2020 18:54:20 +0500 Subject: [PATCH 2/4] use StandardCharsets instead --- .../main/java/org/mian/gitnex/activities/LoginActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java b/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java index ccea51a6..cc4d3bc1 100644 --- a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java @@ -32,6 +32,7 @@ import org.mian.gitnex.util.AppUtil; import org.mian.gitnex.util.TinyDB; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Objects; import java.util.UUID; @@ -284,7 +285,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener if(appUtil.checkIntegers(loginOTP_)) { - loginOTP = Integer.valueOf(loginOTP_); + loginOTP = Integer.parseInt(loginOTP_); } else { @@ -530,7 +531,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener private void letTheUserIn(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP) { - final String credential = Credentials.basic(loginUid, loginPass, Charset.forName("UTF-8")); + final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8); Call> call; if(loginOTP != 0) { From c3c0749a7a192dd346cc05a2ab42a689a2b36202 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Sat, 21 Mar 2020 23:52:52 +0500 Subject: [PATCH 3/4] show when update/install app --- .../mian/gitnex/activities/MainActivity.java | 33 +++++++++++++++++-- .../org/mian/gitnex/helpers/ChangeLog.java | 5 +-- app/src/main/res/xml/changelog.xml | 6 ++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index f866625f..80dac10f 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java @@ -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; @@ -157,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() { @@ -287,8 +289,33 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig } // Changelog popup - ChangeLog changelogDialog = new ChangeLog(this); - changelogDialog.showDialog(); + 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 (!tinyDb.getBoolean("versionFlag")) { + if (versionCode > tinyDb.getInt("versionCode")) { + tinyDb.putInt("versionCode", versionCode); + tinyDb.putBoolean("versionFlag", true); + } + else { + tinyDb.putBoolean("versionFlag", false); + } + } + else { + tinyDb.putBoolean("versionFlag", false); + } + + if(tinyDb.getBoolean("versionFlag")) { + ChangeLog changelogDialog = new ChangeLog(this); + changelogDialog.showDialog(); + } } diff --git a/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java b/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java index 613638fe..c85e5a77 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java +++ b/app/src/main/java/org/mian/gitnex/helpers/ChangeLog.java @@ -35,7 +35,7 @@ public class ChangeLog { while ((eventType != XmlPullParser.END_TAG) || (aXml.getName().equals("change"))) { - if ((eventType == XmlPullParser.START_TAG) &&(aXml.getName().equals("change"))) { + if ((eventType == XmlPullParser.START_TAG) && (aXml.getName().equals("change"))) { eventType = aXml.next(); strBuilder.append(aXml.getText()).append("
"); } @@ -93,7 +93,8 @@ public class ChangeLog { androidx.appcompat.app.AlertDialog.Builder builder = new AlertDialog.Builder(changelogActivity); builder.setTitle(R.string.changelogTitle); builder.setMessage(Html.fromHtml("" + changelogMessage + "")); - builder.setNegativeButton(R.string.okButton, (dialog, which) -> dialog.cancel()); + builder.setNegativeButton(R.string.close, (dialog, which) -> dialog.cancel()); + builder.setCancelable(false); builder.create(); builder.show(); diff --git a/app/src/main/res/xml/changelog.xml b/app/src/main/res/xml/changelog.xml index 1ec657c7..09181e95 100644 --- a/app/src/main/res/xml/changelog.xml +++ b/app/src/main/res/xml/changelog.xml @@ -1,6 +1,12 @@ + + Improvement: Show issues only in Issues Tabs + Bugfix: Files breadcrumb navigation links + Bugfix: Login with special characters + + New: Light theme (choose from settings) New: Icons From 25c6a9558f277dc97a8edce1f2ee9fc1c1148f2d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 29 Mar 2020 16:02:33 +0200 Subject: [PATCH 4/4] simplify code --- .../mian/gitnex/activities/MainActivity.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index 80dac10f..b7ce42d5 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java @@ -299,24 +299,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig Log.e("changelogDialog", Objects.requireNonNull(e.getMessage())); } - if (!tinyDb.getBoolean("versionFlag")) { - if (versionCode > tinyDb.getInt("versionCode")) { - tinyDb.putInt("versionCode", versionCode); - tinyDb.putBoolean("versionFlag", true); - } - else { - tinyDb.putBoolean("versionFlag", false); - } - } - else { - tinyDb.putBoolean("versionFlag", false); - } - - if(tinyDb.getBoolean("versionFlag")) { + 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) {