Skip to content

Commit 46b149a

Browse files
committed
Squashed 'libs/utils/' changes from 40225ecccc..f9d0196b83
f9d0196b83 Run unit tests in CI (#42) da6e11beb1 Add CI step to run the tests d0e8cdbb40 Remove trailing whitespaces from CircleCI config 2aade32249 Merge pull request #39 from wordpress-mobile/fix-bintray-upload-missing-artifacts a4fd2e4ab4 Adds components.release to Bintray publication b3921b9359 Merge pull request #38 from wordpress-mobile/updates-from-wpandroid-with-gradle-6 4c5e2bcb83 Updates from wpandroid with gradle 6 853a26bdc3 Merge pull request #37 from wordpress-mobile/update-version-to-1.29 2b28190305 Update version to 1.29 a6401c4dc0 Merge pull request #36 from wordpress-mobile/upgrade-version-to-1.28 f79ccd177d Update version number to 1.28 d70f573de8 Merge pull request #35 from wordpress-mobile/merge/wpandroid-12813 0ee53abc26 Adds DisplayUtils.getDisplayPixelWidth 806693e808 Merge pull request #34 from wordpress-mobile/manually-update-changes-from-wpandroid 0d527acf54 Update gradle wrapper files a396ad49ef Manually applied consolidated changes from WPAndroid a28f653460 Merge pull request #33 from wordpress-mobile/merge/WordPress-Android/12569 6caa352edd Bumping utils version. 87167d8bbd Limit storage percentage to 100% git-subtree-dir: libs/utils git-subtree-split: f9d0196b83addc26eab2447cc962d489824f5bcf
1 parent 454736b commit 46b149a

File tree

15 files changed

+263
-135
lines changed

15 files changed

+263
-135
lines changed

.circleci/config.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,46 @@ version: 2.1
33
orbs:
44
android: wordpress-mobile/android@0.0.22
55

6+
commands:
7+
copy-gradle-properties:
8+
steps:
9+
- run:
10+
name: Setup gradle.properties
11+
command: cp gradle.properties-example gradle.properties
12+
613
jobs:
714
Lint:
8-
executor:
15+
executor:
916
name: android/default
1017
api-version: "27"
1118
steps:
1219
- checkout
20+
- copy-gradle-properties
1321
- android/restore-gradle-cache
1422
- run:
1523
name: Lint & Checkstyle
1624
command: ./gradlew --stacktrace lint checkstyle
1725
- android/save-gradle-cache
1826
- android/save-lint-results
27+
Test:
28+
executor:
29+
name: android/default
30+
api-version: "27"
31+
steps:
32+
- checkout
33+
- copy-gradle-properties
34+
- android/restore-gradle-cache
35+
- run:
36+
name: Test
37+
command: ./gradlew --stacktrace test
38+
- android/save-gradle-cache
1939
Build:
20-
executor:
40+
executor:
2141
name: android/default
2242
api-version: "27"
2343
steps:
2444
- checkout
45+
- copy-gradle-properties
2546
- android/restore-gradle-cache
2647
- run:
2748
name: Build
@@ -32,4 +53,7 @@ workflows:
3253
WordPress-Utils-Android:
3354
jobs:
3455
- Lint
35-
- Build
56+
- Test
57+
- Build:
58+
requires:
59+
- Test

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Collection of utility methods for Android and WordPress.
77
* In your build.gradle:
88
```groovy
99
dependencies {
10-
compile 'org.wordpress:utils:1.22.0' // use version 1.22.0
10+
compile 'org.wordpress:utils:1.30.0' // use version 1.30.0
1111
}
1212
```
1313

@@ -21,10 +21,11 @@ $ ./gradlew assemble test publishToMavenLocal
2121

2222
## Publish it to Bintray
2323

24-
When a new version is ready to be published to the remote repository, use the following command to upload it to Bintray:
24+
When a new version is ready to be published to the remote repository, use the following command to publish it to Bintray:
2525

2626
```shell
27-
$ ./gradlew assemble test bintrayUpload -PbintrayUser=FIXME -PbintrayKey=FIXME -PdryRun=false
27+
$ ./gradlew clean build
28+
$ ./gradlew bintrayUpload -PbintrayUser=FIXME -PbintrayKey=FIXME
2829
```
2930

3031
## Apps and libraries using WordPress-Utils-Android:

WordPressUtils/build.gradle

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ buildscript {
88
}
99
dependencies {
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
11-
classpath 'com.android.tools.build:gradle:3.5.1'
12-
classpath 'com.novoda:bintray-release:0.9.1'
11+
classpath 'com.android.tools.build:gradle:4.0.1'
12+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
1313
}
1414
}
1515

1616
apply plugin: 'com.android.library'
1717
apply plugin: 'kotlin-android'
1818
apply plugin: 'kotlin-android-extensions'
19-
apply plugin: 'com.novoda.bintray-release'
19+
apply plugin: 'maven-publish'
20+
apply plugin: 'com.jfrog.bintray'
2021

2122
repositories {
2223
google()
@@ -35,7 +36,7 @@ dependencies {
3536

3637
testImplementation 'junit:junit:4.12'
3738
testImplementation 'org.assertj:assertj-core:3.11.1'
38-
testImplementation "org.robolectric:robolectric:4.3.1"
39+
testImplementation "org.robolectric:robolectric:4.4"
3940
testImplementation 'androidx.test:core:1.0.0'
4041

4142
lintChecks 'org.wordpress:lint:1.0.1'
@@ -50,10 +51,9 @@ android {
5051
useLibrary 'org.apache.http.legacy'
5152

5253
compileSdkVersion 28
53-
buildToolsVersion '28.0.3'
5454

5555
defaultConfig {
56-
versionName "1.26"
56+
versionName "1.30"
5757
minSdkVersion 18
5858
targetSdkVersion 26
5959

@@ -87,15 +87,35 @@ android.libraryVariants.all { variant ->
8787
}
8888
}
8989

90-
publish {
91-
artifactId = 'utils'
92-
userOrg = 'wordpress-mobile'
93-
groupId = 'org.wordpress'
94-
uploadName = 'utils'
95-
desc = 'Utils library for Android'
96-
publishVersion = android.defaultConfig.versionName
97-
licences = ['MIT', 'GPL']
98-
website = 'https://github.com/wordpress-mobile/WordPress-Utils-Android/'
99-
dryRun = 'false'
100-
autoPublish = 'true'
90+
bintray {
91+
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
92+
key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : System.getenv('BINTRAY_KEY')
93+
publications = ['UtilsPublication']
94+
publish = true
95+
pkg {
96+
repo = 'maven'
97+
name = 'utils'
98+
userOrg = 'wordpress-mobile'
99+
licenses = ['MIT', 'GPL']
100+
vcsUrl = 'https://github.com/wordpress-mobile/WordPress-Utils-Android.git'
101+
version {
102+
name = android.defaultConfig.versionName
103+
desc = 'Utils library for Android'
104+
released = new Date()
105+
}
106+
}
101107
}
108+
109+
project.afterEvaluate {
110+
publishing {
111+
publications {
112+
UtilsPublication(MavenPublication) {
113+
from components.release
114+
groupId 'org.wordpress'
115+
artifactId 'utils'
116+
version android.defaultConfig.versionName
117+
}
118+
}
119+
}
120+
}
121+

WordPressUtils/gradle.properties-example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
android.useAndroidX=true
12
ossrhUsername=hello
23
ossrhPassword=world
34

WordPressUtils/src/main/java/org/wordpress/android/util/DisplayUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.res.Configuration;
5+
import android.content.res.Resources;
56
import android.graphics.Point;
67
import android.util.DisplayMetrics;
78
import android.util.TypedValue;
@@ -39,6 +40,10 @@ public static int getDisplayPixelHeight(Context context) {
3940
return (size.y);
4041
}
4142

43+
public static int getDisplayPixelWidth() {
44+
return Resources.getSystem().getDisplayMetrics().widthPixels;
45+
}
46+
4247
public static float spToPx(Context context, float sp) {
4348
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
4449
final float scale = displayMetrics.scaledDensity;

WordPressUtils/src/main/java/org/wordpress/android/util/FormatUtils.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,25 @@ public static final String formatFileSize(long size, final String[] unitStrings)
5555
* returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.25 returns 25%
5656
*/
5757
public static final String formatPercentage(double value) {
58+
return formatPercentageLimit100(value, false);
59+
}
60+
61+
/*
62+
* returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.251 returns 25.1%
63+
* if limit100 is true, it limits the percentage to 100%
64+
*/
65+
public static final String formatPercentageLimit100(double value, boolean limit100) {
66+
double limit = 1.0001;
67+
5868
NumberFormat percentFormat = NumberFormat.getPercentInstance();
5969
percentFormat.setMaximumFractionDigits(1);
60-
return percentFormat.format(value);
70+
71+
if (limit100 && value > limit) {
72+
value = limit;
73+
}
74+
75+
String percentage = percentFormat.format(value);
76+
77+
return percentage;
6178
}
6279
}

WordPressUtils/src/main/java/org/wordpress/android/util/HtmlUtils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.wordpress.android.util.helpers.WPHtmlTagHandler;
1515
import org.wordpress.android.util.helpers.WPQuoteSpan;
1616

17+
import static org.wordpress.android.util.AppLog.T.UTILS;
18+
1719
public class HtmlUtils {
1820
/**
1921
* Removes html from the passed string - relies on Html.fromHtml which handles invalid HTML,
@@ -126,8 +128,15 @@ public static SpannableStringBuilder fromHtml(String source, ImageGetter imageGe
126128
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, new WPHtmlTagHandler());
127129
} catch (RuntimeException runtimeException) {
128130
// In case our tag handler fails
129-
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, null);
131+
try {
132+
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, null);
133+
} catch (IllegalArgumentException illegalArgumentException) {
134+
// In case the html is missing a required parameter (for example: "src" missing from img)
135+
html = new SpannableStringBuilder("");
136+
AppLog.w(UTILS, "Could not parse html");
137+
}
130138
}
139+
131140
EmoticonsUtils.replaceEmoticonsWithEmoji(html);
132141
QuoteSpan[] spans = html.getSpans(0, html.length(), QuoteSpan.class);
133142
for (QuoteSpan span : spans) {

WordPressUtils/src/main/java/org/wordpress/android/util/MediaUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,17 @@ private static String getDocumentProviderPathKitkatOrHigher(final Context contex
443443

444444
// TODO handle non-primary volumes
445445
} else if (isDownloadsDocument(uri)) {
446-
final String id = DocumentsContract.getDocumentId(uri);
446+
String id = DocumentsContract.getDocumentId(uri);
447447

448448
if (id != null && id.startsWith("raw:")) {
449449
return id.substring(4);
450450
}
451451

452+
// https://github.com/Javernaut/WhatTheCodec/issues/2
453+
if (id != null && id.startsWith("msf:")) {
454+
id = id.substring(4);
455+
}
456+
452457
String[] contentUriPrefixesToTry = new String[]{
453458
"content://downloads/public_downloads",
454459
"content://downloads/my_downloads",

WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.webkit.MimeTypeMap;
66
import android.webkit.URLUtil;
77

8+
import androidx.annotation.Nullable;
9+
810
import org.wordpress.android.util.AppLog.T;
911

1012
import java.io.UnsupportedEncodingException;
@@ -257,6 +259,20 @@ public static boolean isImageUrl(String url) {
257259
|| cleanedUrl.endsWith("gif") || cleanedUrl.endsWith("png");
258260
}
259261

262+
public static @Nullable String getPageJumpOrNull(String url) {
263+
if (TextUtils.isEmpty(url)) {
264+
return null;
265+
}
266+
267+
if (url.contains("#")
268+
&& url.indexOf("#") < url.length() - 1
269+
&& url.split("#").length == 2) {
270+
return url.substring(url.indexOf('#') + 1);
271+
}
272+
273+
return null;
274+
}
275+
260276
private static boolean isAtomicImageProxyUrl(String urlString) {
261277
return urlString.startsWith(ATOMIC_MEDIA_PROXY_URL_PREFIX) && urlString.endsWith(ATOMIC_MEDIA_PROXY_URL_SUFFIX);
262278
}

0 commit comments

Comments
 (0)