From da90005e42e92dd3de5716d8c29294e22aabb4d0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Tue, 7 Apr 2020 04:15:56 +0000 Subject: [PATCH] hide ReleaseCounter Badge on old Gitea instances (#367) Hide Release Count on old Gitea Instances fix compareVersion Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/367 Reviewed-by: M M Arif --- .../gitnex/activities/RepoDetailActivity.java | 15 +++++++++------ .../org/mian/gitnex/helpers/VersionCheck.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java b/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java index 20c83d77..29033221 100644 --- a/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java @@ -37,6 +37,7 @@ import org.mian.gitnex.fragments.PullRequestsFragment; import org.mian.gitnex.fragments.ReleasesFragment; import org.mian.gitnex.fragments.RepoInfoFragment; import org.mian.gitnex.helpers.Authorization; +import org.mian.gitnex.helpers.VersionCheck; import org.mian.gitnex.models.UserRepositories; import org.mian.gitnex.models.WatchRepository; import org.mian.gitnex.util.AppUtil; @@ -168,12 +169,14 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF } // release count - if (textViewBadgeRelease.getText() != "") { // only show if API returned a number - Objects.requireNonNull(tabLayout.getTabAt(6)).setCustomView(tabHeader6); - TabLayout.Tab tabOpenRelease = tabLayout.getTabAt(6); - assert tabOpenRelease != null; - TextView openReleaseTabView = Objects.requireNonNull(tabOpenRelease.getCustomView()).findViewById(R.id.counterBadgeReleaseText); - openReleaseTabView.setTextColor(textColor); + if (VersionCheck.compareVersion("1.11.5", tinyDb.getString("giteaVersion")) < 1) { + if(textViewBadgeRelease.getText() != "") { // only show if API returned a number + Objects.requireNonNull(tabLayout.getTabAt(6)).setCustomView(tabHeader6); + TabLayout.Tab tabOpenRelease = tabLayout.getTabAt(6); + assert tabOpenRelease != null; + TextView openReleaseTabView = Objects.requireNonNull(tabOpenRelease.getCustomView()).findViewById(R.id.counterBadgeReleaseText); + openReleaseTabView.setTextColor(textColor); + } } } diff --git a/app/src/main/java/org/mian/gitnex/helpers/VersionCheck.java b/app/src/main/java/org/mian/gitnex/helpers/VersionCheck.java index 12a25232..ae69c1e4 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/VersionCheck.java +++ b/app/src/main/java/org/mian/gitnex/helpers/VersionCheck.java @@ -102,6 +102,22 @@ public enum VersionCheck { * 2 = more */ public static int compareVersion(String A, String B) { + final Pattern pattern_stable_release = Pattern.compile("^(\\d)\\.(\\d+)\\.(\\d+)"); + final Pattern pattern_dev_release = Pattern.compile("^(\\d).(\\d+).(\\d+)(\\D)(.+)"); + Matcher match; + match = pattern_dev_release.matcher(A); + if (match.find()) { + match = pattern_stable_release.matcher(A); + match.find(); + A = match.group(); + } + match = pattern_dev_release.matcher(B); + if (match.find()) { + match = pattern_stable_release.matcher(B); + match.find(); + B = match.group(); + } + //throw new IllegalArgumentException if((!A.matches("[0-9]+(\\.[0-9]+)*")) || (!B.matches("[0-9]+(\\.[0-9]+)*"))) throw new IllegalArgumentException("Invalid version format");