From 2b24027b16d658f0e0a3b370ade340a0c0f1ee18 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 24 Mar 2021 08:36:50 +0200 Subject: [PATCH] add percent complete to legacyurdecoder, bump to 1.5.3 --- README.md | 2 +- build.gradle | 2 +- .../hummingbird/LegacyURDecoder.java | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2724b5..32eb48f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It contains both the classes to represent a UR, and a UR encoder and decoder to Hummingbird is hosted in Maven Central and can be added as a dependency with the following: ``` -implementation('com.sparrowwallet:hummingbird:1.5.2') +implementation('com.sparrowwallet:hummingbird:1.5.3') ``` ## Usage diff --git a/build.gradle b/build.gradle index 772365d..f3cec5b 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'com.bmuschko.nexus' archivesBaseName = 'hummingbird' group 'com.sparrowwallet' -version '1.5.2' +version '1.5.3' repositories { mavenCentral() diff --git a/src/main/java/com/sparrowwallet/hummingbird/LegacyURDecoder.java b/src/main/java/com/sparrowwallet/hummingbird/LegacyURDecoder.java index 5221e81..51fcf68 100644 --- a/src/main/java/com/sparrowwallet/hummingbird/LegacyURDecoder.java +++ b/src/main/java/com/sparrowwallet/hummingbird/LegacyURDecoder.java @@ -27,6 +27,24 @@ public class LegacyURDecoder { return true; } + public double getPercentComplete() { + if(fragments.isEmpty()) { + return 0d; + } + + String fragment = fragments.iterator().next(); + String[] components = fragment.split("/"); + if(components.length > 3) { + int[] sequence = checkAndGetSequence(components[1]); + int total = sequence[1]; + if(total > 0 && fragments.size() <= total) { + return (double)fragments.size() / total; + } + } + + return 1d; + } + public static boolean isLegacyURFragment(String fragment) { String[] components = fragment.split("/");