aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2014-06-11 23:52:18 +0200
committerrsudev <rasch@munin-soft.de>2014-06-12 00:15:20 +0200
commitf04d04a2b2438416335e6a5b03a21568912fa15f (patch)
tree975afd91c3d1ea0ee07f7cd7b3ff5ee3478cc697 /main/src
parent24e030f2e68796d0d37f2762d70181b2fb12b862 (diff)
downloadcgeo-f04d04a2b2438416335e6a5b03a21568912fa15f.zip
cgeo-f04d04a2b2438416335e6a5b03a21568912fa15f.tar.gz
cgeo-f04d04a2b2438416335e6a5b03a21568912fa15f.tar.bz2
Implements #3894, Only show Changelog on startup if hash code changed
- switched from version checking to checksum checking
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/MainActivity.java9
-rw-r--r--main/src/cgeo/geocaching/settings/Settings.java10
-rw-r--r--main/src/cgeo/geocaching/utils/TextUtils.java20
3 files changed, 27 insertions, 12 deletions
diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java
index d901e05..84bc960 100644
--- a/main/src/cgeo/geocaching/MainActivity.java
+++ b/main/src/cgeo/geocaching/MainActivity.java
@@ -23,6 +23,7 @@ import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.ui.dialog.Dialogs;
import cgeo.geocaching.utils.DatabaseBackupUtils;
import cgeo.geocaching.utils.Log;
+import cgeo.geocaching.utils.TextUtils;
import cgeo.geocaching.utils.Version;
import com.google.zxing.integration.android.IntentIntegrator;
@@ -732,11 +733,11 @@ public class MainActivity extends AbstractActionBarActivity {
}
private void checkShowChangelog() {
- final int lastVersion = Settings.getLastChangelogVersion();
- final int version = Version.getVersionCode(this);
- Settings.setLastChangelogVersion(version);
+ final long lastChecksum = Settings.getLastChangelogChecksum();
+ final long checksum = TextUtils.checksum(getString(R.string.changelog_master) + getString(R.string.changelog_release));
+ Settings.setLastChangelogChecksum(checksum);
// don't show change log after new install...
- if (lastVersion > 0 && version != lastVersion) {
+ if (lastChecksum > 0 && lastChecksum != checksum) {
AboutActivity.showChangeLog(this);
}
}
diff --git a/main/src/cgeo/geocaching/settings/Settings.java b/main/src/cgeo/geocaching/settings/Settings.java
index 133df5c..0ed5aef 100644
--- a/main/src/cgeo/geocaching/settings/Settings.java
+++ b/main/src/cgeo/geocaching/settings/Settings.java
@@ -1007,13 +1007,13 @@ public class Settings {
return getString(R.string.pref_ec_icons, "1");
}
- /* Store last version for the changelog display */
- public static int getLastChangelogVersion() {
- return getInt(R.string.pref_changelog_last_version, 0);
+ /* Store last checksum of changelog for changelog display */
+ public static long getLastChangelogChecksum() {
+ return getLong(R.string.pref_changelog_last_checksum, 0);
}
- public static void setLastChangelogVersion(final int version) {
- putInt(R.string.pref_changelog_last_version, version);
+ public static void setLastChangelogChecksum(final long checksum) {
+ putLong(R.string.pref_changelog_last_checksum, checksum);
}
public static List<String> getLastOpenedCaches() {
diff --git a/main/src/cgeo/geocaching/utils/TextUtils.java b/main/src/cgeo/geocaching/utils/TextUtils.java
index ef09f32..77aa167 100644
--- a/main/src/cgeo/geocaching/utils/TextUtils.java
+++ b/main/src/cgeo/geocaching/utils/TextUtils.java
@@ -4,11 +4,13 @@
package cgeo.geocaching.utils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
import org.eclipse.jdt.annotation.Nullable;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.zip.CRC32;
/**
* Misc. utils. All methods don't use Android specific stuff to use these methods in plain JUnit tests.
@@ -52,7 +54,7 @@ public final class TextUtils {
result = matcher.group(group);
}
if (null != result) {
- Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(result);
+ final Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(result);
result = remover.replaceAll(" ");
return trim ? new String(result).trim() : new String(result);
@@ -134,7 +136,7 @@ public final class TextUtils {
data.getChars(0, length, chars, 0);
int resultSize = 0;
boolean lastWasWhitespace = true;
- for (char c : chars) {
+ for (final char c : chars) {
if (c == ' ' || c == '\n' || c == '\r' || c == '\t') {
if (!lastWasWhitespace) {
chars[resultSize++] = ' ';
@@ -167,8 +169,20 @@ public final class TextUtils {
* @return
*/
public static String removeControlCharacters(final String input) {
- Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(input);
+ final Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(input);
return remover.replaceAll(" ").trim();
}
+ /**
+ * Calculate a simple checksum for change-checking (not usable for security/cryptography!)
+ *
+ * @param input
+ * String to check
+ * @return resulting checksum
+ */
+ public static long checksum(final String input) {
+ final CRC32 checksum = new CRC32();
+ checksum.update(input.getBytes());
+ return checksum.getValue();
+ }
}