Skip to content

Commit

Permalink
Squashed 'libs/utils/' changes from 40225ecccc..f9d0196b83
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aforcier committed Nov 10, 2020
1 parent 454736b commit 46b149a
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 135 deletions.
30 changes: 27 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,46 @@ version: 2.1
orbs:
android: wordpress-mobile/android@0.0.22

commands:
copy-gradle-properties:
steps:
- run:
name: Setup gradle.properties
command: cp gradle.properties-example gradle.properties

jobs:
Lint:
executor:
executor:
name: android/default
api-version: "27"
steps:
- checkout
- copy-gradle-properties
- android/restore-gradle-cache
- run:
name: Lint & Checkstyle
command: ./gradlew --stacktrace lint checkstyle
- android/save-gradle-cache
- android/save-lint-results
Test:
executor:
name: android/default
api-version: "27"
steps:
- checkout
- copy-gradle-properties
- android/restore-gradle-cache
- run:
name: Test
command: ./gradlew --stacktrace test
- android/save-gradle-cache
Build:
executor:
executor:
name: android/default
api-version: "27"
steps:
- checkout
- copy-gradle-properties
- android/restore-gradle-cache
- run:
name: Build
Expand All @@ -32,4 +53,7 @@ workflows:
WordPress-Utils-Android:
jobs:
- Lint
- Build
- Test
- Build:
requires:
- Test
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Collection of utility methods for Android and WordPress.
* In your build.gradle:
```groovy
dependencies {
compile 'org.wordpress:utils:1.22.0' // use version 1.22.0
compile 'org.wordpress:utils:1.30.0' // use version 1.30.0
}
```

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

## Publish it to Bintray

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

```shell
$ ./gradlew assemble test bintrayUpload -PbintrayUser=FIXME -PbintrayKey=FIXME -PdryRun=false
$ ./gradlew clean build
$ ./gradlew bintrayUpload -PbintrayUser=FIXME -PbintrayKey=FIXME
```

## Apps and libraries using WordPress-Utils-Android:
Expand Down
54 changes: 37 additions & 17 deletions WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.novoda:bintray-release:0.9.1'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

repositories {
google()
Expand All @@ -35,7 +36,7 @@ dependencies {

testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation "org.robolectric:robolectric:4.3.1"
testImplementation "org.robolectric:robolectric:4.4"
testImplementation 'androidx.test:core:1.0.0'

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

compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
versionName "1.26"
versionName "1.30"
minSdkVersion 18
targetSdkVersion 26

Expand Down Expand Up @@ -87,15 +87,35 @@ android.libraryVariants.all { variant ->
}
}

publish {
artifactId = 'utils'
userOrg = 'wordpress-mobile'
groupId = 'org.wordpress'
uploadName = 'utils'
desc = 'Utils library for Android'
publishVersion = android.defaultConfig.versionName
licences = ['MIT', 'GPL']
website = 'https://github.com/wordpress-mobile/WordPress-Utils-Android/'
dryRun = 'false'
autoPublish = 'true'
bintray {
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : System.getenv('BINTRAY_KEY')
publications = ['UtilsPublication']
publish = true
pkg {
repo = 'maven'
name = 'utils'
userOrg = 'wordpress-mobile'
licenses = ['MIT', 'GPL']
vcsUrl = 'https://github.com/wordpress-mobile/WordPress-Utils-Android.git'
version {
name = android.defaultConfig.versionName
desc = 'Utils library for Android'
released = new Date()
}
}
}

project.afterEvaluate {
publishing {
publications {
UtilsPublication(MavenPublication) {
from components.release
groupId 'org.wordpress'
artifactId 'utils'
version android.defaultConfig.versionName
}
}
}
}

1 change: 1 addition & 0 deletions WordPressUtils/gradle.properties-example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
android.useAndroidX=true
ossrhUsername=hello
ossrhPassword=world

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.util.TypedValue;
Expand Down Expand Up @@ -39,6 +40,10 @@ public static int getDisplayPixelHeight(Context context) {
return (size.y);
}

public static int getDisplayPixelWidth() {
return Resources.getSystem().getDisplayMetrics().widthPixels;
}

public static float spToPx(Context context, float sp) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
final float scale = displayMetrics.scaledDensity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,25 @@ public static final String formatFileSize(long size, final String[] unitStrings)
* returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.25 returns 25%
*/
public static final String formatPercentage(double value) {
return formatPercentageLimit100(value, false);
}

/*
* returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.251 returns 25.1%
* if limit100 is true, it limits the percentage to 100%
*/
public static final String formatPercentageLimit100(double value, boolean limit100) {
double limit = 1.0001;

NumberFormat percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
return percentFormat.format(value);

if (limit100 && value > limit) {
value = limit;
}

String percentage = percentFormat.format(value);

return percentage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.wordpress.android.util.helpers.WPHtmlTagHandler;
import org.wordpress.android.util.helpers.WPQuoteSpan;

import static org.wordpress.android.util.AppLog.T.UTILS;

public class HtmlUtils {
/**
* Removes html from the passed string - relies on Html.fromHtml which handles invalid HTML,
Expand Down Expand Up @@ -126,8 +128,15 @@ public static SpannableStringBuilder fromHtml(String source, ImageGetter imageGe
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, new WPHtmlTagHandler());
} catch (RuntimeException runtimeException) {
// In case our tag handler fails
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, null);
try {
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, null);
} catch (IllegalArgumentException illegalArgumentException) {
// In case the html is missing a required parameter (for example: "src" missing from img)
html = new SpannableStringBuilder("");
AppLog.w(UTILS, "Could not parse html");
}
}

EmoticonsUtils.replaceEmoticonsWithEmoji(html);
QuoteSpan[] spans = html.getSpans(0, html.length(), QuoteSpan.class);
for (QuoteSpan span : spans) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,17 @@ private static String getDocumentProviderPathKitkatOrHigher(final Context contex

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

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

// https://github.com/Javernaut/WhatTheCodec/issues/2
if (id != null && id.startsWith("msf:")) {
id = id.substring(4);
}

String[] contentUriPrefixesToTry = new String[]{
"content://downloads/public_downloads",
"content://downloads/my_downloads",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;

import androidx.annotation.Nullable;

import org.wordpress.android.util.AppLog.T;

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

public static @Nullable String getPageJumpOrNull(String url) {
if (TextUtils.isEmpty(url)) {
return null;
}

if (url.contains("#")
&& url.indexOf("#") < url.length() - 1
&& url.split("#").length == 2) {
return url.substring(url.indexOf('#') + 1);
}

return null;
}

private static boolean isAtomicImageProxyUrl(String urlString) {
return urlString.startsWith(ATOMIC_MEDIA_PROXY_URL_PREFIX) && urlString.endsWith(ATOMIC_MEDIA_PROXY_URL_SUFFIX);
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties-example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android.useAndroidX=true
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Jul 11 13:17:12 EEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Loading

0 comments on commit 46b149a

Please sign in to comment.