From e8c223ba1d47b2cb895c8aea0304e3a385fc67c4 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 30 Apr 2022 13:55:14 +0200 Subject: [PATCH] Fix various bugs (#1118) 1. bad layout on translation settings 2. fix ACRA notifications (happened during the cleanup of the deprecated code) 3. final newline in file viewer 4. top newline in diffs 5. missing newline if diff has multiple parts Closes https://codeberg.org/gitnex/GitNex/issues/1093 Co-authored-by: qwerty287 Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1118 Reviewed-by: M M Arif Co-authored-by: qwerty287 Co-committed-by: qwerty287 --- .../org/mian/gitnex/core/MainApplication.java | 3 +- .../java/org/mian/gitnex/helpers/AppUtil.java | 9 ++---- .../org/mian/gitnex/helpers/FileDiffView.java | 10 +++++-- .../org/mian/gitnex/helpers/ParseDiff.java | 5 +++- .../gitnex/views/SyntaxHighlightedArea.java | 10 +------ .../layout/activity_settings_translation.xml | 29 ++++++++++--------- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/core/MainApplication.java b/app/src/main/java/org/mian/gitnex/core/MainApplication.java index 955a4e47..289c9564 100644 --- a/app/src/main/java/org/mian/gitnex/core/MainApplication.java +++ b/app/src/main/java/org/mian/gitnex/core/MainApplication.java @@ -17,7 +17,6 @@ import org.mian.gitnex.helpers.FontsOverride; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.contexts.AccountContext; import org.mian.gitnex.notifications.Notifications; -import java.nio.charset.StandardCharsets; /** * @author opyale @@ -59,7 +58,7 @@ public class MainApplication extends Application { ACRABuilder.withBuildConfigClass(BuildConfig.class).withReportContent(ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.STACK_TRACE, ReportField.AVAILABLE_MEM_SIZE, ReportField.BRAND).setReportFormat(StringFormat.KEY_VALUE_LIST); ACRABuilder.getPluginConfigurationBuilder(NotificationConfigurationBuilder.class).withResTitle(R.string.crashTitle) - .withResIcon(R.drawable.gitnex_transparent).withResChannelName(R.string.setCrashReports).withResText(R.string.crashMessage); + .withResIcon(R.drawable.gitnex_transparent).withResChannelName(R.string.setCrashReports).withResText(R.string.crashMessage).withEnabled(true); ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).withMailTo(getResources().getString(R.string.appEmail)) .withSubject(getResources().getString(R.string.crashReportEmailSubject, AppUtil .getAppBuildNo(context))) diff --git a/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java b/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java index a2c7d85a..b9ae5f8c 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java +++ b/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java @@ -338,7 +338,9 @@ public class AppUtil { public static long getLineCount(String s) { - long lines = 0; + if(s.length() < 1) return 0; + + long lines = 1; // we start counting at 1 because there is always at least one line Pattern pattern = Pattern.compile("(\r\n|\n)"); Matcher matcher = pattern.matcher(s); @@ -346,11 +348,6 @@ public class AppUtil { while(matcher.find()) lines++; - // Sometimes there may be text, but no line breaks. - // This should still count as one line. - if(s.length() > 0 && lines == 0) - return 1; - return lines; } diff --git a/app/src/main/java/org/mian/gitnex/helpers/FileDiffView.java b/app/src/main/java/org/mian/gitnex/helpers/FileDiffView.java index 44e20d52..28111096 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/FileDiffView.java +++ b/app/src/main/java/org/mian/gitnex/helpers/FileDiffView.java @@ -1,11 +1,12 @@ package org.mian.gitnex.helpers; +import androidx.annotation.NonNull; import java.io.Serializable; import java.util.List; /** - * Author M M Arif - * Author 6543 + * @author M M Arif + * @author 6543 */ public class FileDiffView implements Serializable { @@ -137,12 +138,17 @@ public class FileDiffView implements Serializable { return fileInfo; } + @NonNull + @Override public String toString() { StringBuilder raw = new StringBuilder(); if(this.contents != null) { for(Content c : this.contents) { raw.append(c.getRaw()); + if(!c.getRaw().endsWith("\n")) { + raw.append("\n"); + } } } return raw.toString(); diff --git a/app/src/main/java/org/mian/gitnex/helpers/ParseDiff.java b/app/src/main/java/org/mian/gitnex/helpers/ParseDiff.java index 4bbf0172..b697a8a3 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/ParseDiff.java +++ b/app/src/main/java/org/mian/gitnex/helpers/ParseDiff.java @@ -7,7 +7,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Author 6543 + * @author 6543 */ public class ParseDiff { @@ -108,6 +108,9 @@ public class ParseDiff { if(rawDiff.length <= 1) { continue; } + if(rawDiff[1].startsWith("\n")) { + rawDiff[1] = rawDiff[1].substring(1); + } // extract the diff stats info of the first line String statsLine = rawDiffs[j].split("\n")[0].split(" @@")[0]; diff --git a/app/src/main/java/org/mian/gitnex/views/SyntaxHighlightedArea.java b/app/src/main/java/org/mian/gitnex/views/SyntaxHighlightedArea.java index edac1092..7feee465 100644 --- a/app/src/main/java/org/mian/gitnex/views/SyntaxHighlightedArea.java +++ b/app/src/main/java/org/mian/gitnex/views/SyntaxHighlightedArea.java @@ -107,15 +107,7 @@ public class SyntaxHighlightedArea extends LinearLayout { .create(new Prism4j(mainGrammarLocator), prism4jTheme, MainGrammarLocator.DEFAULT_FALLBACK_LANGUAGE) .highlight(mainGrammarLocator.fromExtension(extension), source); - getActivity().runOnUiThread(() -> { - if(highlightedSource.charAt(highlightedSource.length() - 1) == '\n') { - // Removes a line break which is probably added by Prism4j but not actually present in the source. - // This line should be altered in case this gets fixed. - sourceView.setText(highlightedSource.subSequence(0, highlightedSource.length() - 1)); - } else { - sourceView.setText(highlightedSource); - } - }); + getActivity().runOnUiThread(() -> sourceView.setText(highlightedSource)); } catch(Throwable ignored) { // Fall back to plaintext if something fails diff --git a/app/src/main/res/layout/activity_settings_translation.xml b/app/src/main/res/layout/activity_settings_translation.xml index ffda7c7a..381bfe3c 100644 --- a/app/src/main/res/layout/activity_settings_translation.xml +++ b/app/src/main/res/layout/activity_settings_translation.xml @@ -55,8 +55,7 @@ android:focusable="true" android:clickable="true" android:orientation="vertical" - android:padding="15dp" - android:layout_marginBottom="5dp"> + android:padding="15dp"> - - + +