Skip to content

Commit

Permalink
Squashed 'libs/utils/' changes from 4520f51..c611f1e
Browse files Browse the repository at this point in the history
c611f1e 1.9.0 version bump
28f8cd3 Merge pull request #4 from wordpress-mobile/sync-wpandroid
db6e3fc Removed unused StringUtils.getLanguageString method
1857d7e Added ShortcodeUtils with methods for converting VideoPress ids to shortcodes and vice versa
920ea46 Merge develop into site-settings-review
a731d83 1.8.0 version bump
73af369 Merge commit '355e34b84ad8c79589065dafb7cf19b619eb957c' into develop
c21f969 Add utility methods to check if a URL is wpcom. Add utility methods  that check if it's safe to add the Authentication token to the request.
821c32c kill StringUtils.getHost function
bec2b0b s/getDomainFromUri/getHost/
355e34b 1.7.0 version bump
261e48b Moved setupUrlConnection() to the utils library
aa8a1d3 Merge branch 'develop' into feature/visual-editor
29087c9 4.9-rc-2 / 228 version bump
5f7cdf8 fix #3521: use the simplest UnderlineSpan subclass
5d281f1 Merge branch 'develop' into feature/site-settings-review
ae44dd4 Allow photon to resize GIFs
e4b151f Merge branch 'develop' into feature/visual-editor
151c4b5 Merge commit '7c21964c64da28781fbb63fa9ea22509d320bb0f' into develop
7c21964 remove old reference to a non existing screenshot
8c562ca Merge branch 'develop' into feature/site-settings-review
d037515 Merge branch 'develop' into feature/visual-editor
0ea8c37 added @code blocks to comments
4c4594c fix #3372:Resource Leak in SqlUtils.java
736bd30 Changedcomment lines so JavaDoc generation doesnt complain
8ce1ae7 fixed conflicts
0ae36de Changed comments that caused errors when generating the JavaDoc
ee9a14b Merge remote-tracking branch 'origin/master' into develop
a25e017 added javadoc generation to build file
480fcb3 Moved the check for video to within ImageUtils
4171cfd Merge branch 'develop' into feature/visual-editor
0a7732e Merge branch 'develop' into feature/site-settings-review
19786e0 suppress lint on missing permission
8f5dba9 Updating gradle plugin to 1.5.0 and support/build tools to latest for sub projects
d84f13a Add log line that could help us in case of errors in the JSON parsing with queryJSON.
c600314 Merge branch 'develop' into feature/site-settings-review
7506241 Better solution: Fix the url within PhotonUtils. Hattip @nbradbury
b7cf042 Revert "Fixes issue where private blog images wouldn't load."
aaa16e5 Revert "Killing whitespace."
e214408 Killing whitespace.
bee8b4d Fixes issue where private blog images wouldn't load.
4750b89 Merge branch 'release/4.7' into feature/site-settings-review
cf71309 Merge branch 'develop' into feature/visual-editor-sync
7eabf5a Moved permission check and request to PermissionUtils
6ac29ba Checking media permission when attempting to add media to post
826a711 Merge branch 'release/4.6' into issue/3115-runtime-permissions
dab25aa first step for runtime location request
62266e2 Obey maximum image width (from blog settings) when uploading images from visual editor
c1e2716 Merge branch 'develop' into feature/site-settings-review
5bc77ff Merge branch 'hotfix/4.5.2' into release/4.6 plus bump version for beta release
679e90e test queryJSON calls with null params
f0da5e5 Check null query string
79839e0 check null source in JSONUtils.queryJSON()
6fcdac2 Merge branch 'develop' into feature/site-settings-review
15e8684 update ProfilingUtils usage
2411844 Merge branch 'develop' into feature/site-settings-review
43eac0e Add two new functions to Utils that remove the traling slash in a string, and remove the scheme from URL string.
8447eea Use homeURL instead of hostName to show the blog address. WordPress can be installed in a sub-directory, and so the host name will be the same for two subdir installations on the same host.
b465a2e URL Utils test fix
53c3a16 Merge branch 'develop' into feature/site-settings-review
2c0b2d5 generic approach to add parameters to a URL
79b9497 new UrlUtils method: appendPreviewURLParameter
e0237c1 Updating build tools to 23.0.1
24e47d5 Merge branch 'develop' into feature/site-settings-review
41a6352 set targetSdkVersion to 23 and clean up lib dependencies
1147f17 migrate from mavenCentral to jcenter (which is now the default for Android Studio)
1e21a88 fix lint errors
53d9465 update to gradle plugin 1.3.1 and gradle 2.6
a3b4ece upgrade to gradle 2.5 and gradle plugin 1.3.0
2ebe23b Merge branch 'develop' into feature/update-to-gradle-2.4
99d239b Merge branch 'develop' into feature/update-to-gradle-2.4
bc27690 Updating ActionBar title. Save button is now Undo.
8632009 Merge branch 'hotfix/4.1.1' into release/4.2
17c4c41 Merge pull request #2878 from wordpress-mobile/issue/2860-npe-post-settings-update
349ced2 Updating EditTextUtils.getText method instead of creating new one.
2ee9d3e limit text to 524288 characters which is always < 2Mb with UTF-8
324f061 Merge branch 'hotfix/4.1.1' into release/4.2
e6d8067 fix #2855: delete big comments and truncate new inserted comments
9720b45 Coding Styles
5426142 Make sure the context passed to checkConnection is not null
b8ef02a Updated support library and build tools
1ec8f40 update to gradle android plugin 1.2.3
00c8e7d update support lib to 22
4f3c8ee update to android-gradle plugin 1.1.3 and build tools 22.0.1
b00745e Introduce our version of MarkView
090e027 bump version number to 1.6.0
bbed10b Fixed notifications fragment for self-hosted
12646dc Merge branch 'release/4.0' into develop
f782492 Removing potential race condition with WP image loading threads.
9fd8ee1 Returning to the post editor won't crash if Activity was destroyed.
b259e6c Add more audio formats
79c326c Handle audio files in media browser
7614498 Merge branch 'release/4.0' into develop
e7656bd Merge branch 'hotfix/3.9.1' into release/4.0
4347d57 Catching other unknown URL exception.
5864710 Making sure Cursor is closed if exception gets thrown.
003f846 Catching unknown URL exceptions.
4ddfb8b javadocs
bbfb8e3 If string is empty return empty string instead of null
ca69d4e Merge branch 'develop' of https://github.com/wordpress-mobile/WordPress-Android into feature/viewpager-main-activity
d692f39 javadocs
eb06e80 Merge branch 'develop' of https://github.com/wordpress-mobile/WordPress-Android into feature/viewpager-main-activity
f917e18 If string is empty return empty string instead of null
5851c3d Updated ViewSiteActivity and WebViewActivity to use support toolbar w/o drawer
6c7c91c 1.5.0 version bump
37f1009 Merge branch 'develop' into feature/modularize-editor
2879710 Added support for `WPWebViewClient` to pass the token for image requests.
7d96a03 Merge branch 'hotfix/3.8.1' into release/3.9
88e501b fix #2437: clear uploading posts state if the PostUploadService is not running during PostList creation
b3a848e Merge branch 'develop' into feature/modularize-editor
8373246 fix #2328: sort blogs with an empty title by their hostname
53329df Merge branch '1628-mediapicker' into feature/modularize-editor
61abebc Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Android into feature/modularize-editor
f132045 comment CustomSwipeRefreshLayout.onTouchEvent
f34c956 new CustomSwipeRefreshLayout with a workaround to catch onTouchEvent IllegalArgumentException
a2c4b16 Merge branch 'develop' into feature/modularize-editor
3f8bedb Merge pull request #2365 from wordpress-mobile/issue/1827-post-stuck-in-uploading-state
e3f237e Merge branch 'develop' into feature/modularize-editor
36a3c9d fix typo in a comment
adb0889 delay the refreshing anim by 50ms to workaround https://code.google.com/p/android/issues/detail?id=77712
c8374fe styling update
153aa40 Merge branch 'release/3.7' into develop
0f47623 Merge branch 'develop' into feature/modularize-editor
9aa990c fix #2336: check for null text entry, replace them with a string
f25f93e split MediaUtils in MediaUtils and WordPressMediaUtils - remove references to WordPress.java in MediaUtils
3bde544 move WPUnderlineSpan.java and MediaGalleryImageSpan.java to WPUtils
8015176 Merge branch 'develop' into feature/modularize-editor
34aab4c Merge branch 'develop' of https://github.com/wordpress-mobile/WordPress-Android into issue/2306-reader-feed-preview
9046278 All gravatar requests now default to 404.
5a0da37 Added DEFAULT_BLAVATAR constant
8436629 WPNetworkImageView now accepts a default error image resource, also forcing size when showing blavatars in ReaderBlogAdapter
06e9f21 Moved fixAvatar routine to GravatarUtils
d132f67 Added DefaultImage enum to GravatarUtils
d7d1b96 move WPImageSpan and MediaFile to WPUtils - also create a WPEditImageSpan class
01379c8 Removed blogUrl param from showBlogPreview(), added new routines for following/unfollowing blogs & feeds
4a532c0 remove extraneous static field
3fa0af6 Merge branch 'develop' into feature/modularize-editor
71fec7a move WPEditText to WordPressUtils and reorganize WordPressUtils
9657f22 First step at extracting the old editor (moving Media related method to the EditPostActivity, they should end up in their own class/lib)
9c1c94c Blavatar defaults to 404
8b1a9a9 Added blavatars to ManageBlogsActivity
e9aa0ff Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Android into develop
9aef78d Merge branch 'release/3.7' into develop
9b74d4e comment addUrlSchemeIfNeeded and why removeLeadingDoubleSlash is used there
93ddd8b Add strip=all to all Photon requests
02c361f fix #2293: remove leading double slash in URLs returned by wporg servers

git-subtree-dir: libs/utils
git-subtree-split: c611f1e
  • Loading branch information
aforcier committed Feb 12, 2016
1 parent 1824f63 commit 0b9c608
Show file tree
Hide file tree
Showing 44 changed files with 2,077 additions and 365 deletions.
38 changes: 28 additions & 10 deletions WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:1.5.0'
}
}

Expand All @@ -12,25 +12,29 @@ apply plugin: 'maven'
apply plugin: 'signing'

repositories {
mavenCentral()
jcenter()
}

dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'com.mcxiaoke.volley:library:1.0.10'
compile 'com.android.support:support-v13:21.0.3'
compile('commons-lang:commons-lang:2.6') {
exclude group: 'commons-logging'
}
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.android.support:support-v13:23.1.1'
}

android {
useLibrary 'org.apache.http.legacy'

publishNonDefault true

compileSdkVersion 19
buildToolsVersion "21.1.1"
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
versionName "1.3.0"
versionName "1.9.0"
minSdkVersion 14
targetSdkVersion 19
targetSdkVersion 23
}
}

Expand Down Expand Up @@ -87,3 +91,17 @@ uploadArchives {
}
}
}

android.libraryVariants.all { variant ->

task("generate${variant.name}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
classpath = files(variant.javaCompile.classpath.files, android.getBootClasspath())

options {
links "http://docs.oracle.com/javase/7/docs/api/"
}
exclude '**/R.java'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;

import org.json.JSONArray;
import org.json.JSONObject;

public class JSONUtilsTest extends InstrumentationTestCase {
public void testQueryJSONNullSource1() {
JSONUtils.queryJSON((JSONObject) null, "", "");
}

public void testQueryJSONNullSource2() {
JSONUtils.queryJSON((JSONArray) null, "", "");
}

public void testQueryJSONNullQuery1() {
JSONUtils.queryJSON(new JSONObject(), null, "");
}

public void testQueryJSONNullQuery2() {
JSONUtils.queryJSON(new JSONArray(), null, "");
}

public void testQueryJSONNullReturnValue1() {
JSONUtils.queryJSON(new JSONObject(), "", null);
}

public void testQueryJSONNullReturnValue2() {
JSONUtils.queryJSON(new JSONArray(), "", null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;

public class ShortcodeUtilsTest extends InstrumentationTestCase {
public void testGetVideoPressShortcodeFromId() {
assertEquals("[wpvideo abcd1234]", ShortcodeUtils.getVideoPressShortcodeFromId("abcd1234"));
}

public void testGetVideoPressShortcodeFromNullId() {
assertEquals("", ShortcodeUtils.getVideoPressShortcodeFromId(null));
}

public void testGetVideoPressIdFromCorrectShortcode() {
assertEquals("abcd1234", ShortcodeUtils.getVideoPressIdFromShortCode("[wpvideo abcd1234]"));
}

public void testGetVideoPressIdFromInvalidShortcode() {
assertEquals("", ShortcodeUtils.getVideoPressIdFromShortCode("[other abcd1234]"));
}

public void testGetVideoPressIdFromNullShortcode() {
assertEquals("", ShortcodeUtils.getVideoPressIdFromShortCode(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class UrlUtilsTest extends InstrumentationTestCase {
public void testGetDomainFromUrlWithEmptyStringDoesNotReturnNull() {
assertNotNull(UrlUtils.getHost(""));
}

public void testGetDomainFromUrlWithNoHostDoesNotReturnNull() {
assertNotNull(UrlUtils.getHost("wordpress"));
}

public void testGetDomainFromUrlWithHostReturnsHost() {
String url = "http://www.wordpress.com";
String host = UrlUtils.getHost(url);

assertTrue(host.equals("www.wordpress.com"));
}

public void testAppendUrlParameter1() {
String url = UrlUtils.appendUrlParameter("http://wp.com/test", "preview", "true");
assertEquals("http://wp.com/test?preview=true", url);
}

public void testAppendUrlParameter2() {
String url = UrlUtils.appendUrlParameter("http://wp.com/test?q=pony", "preview", "true");
assertEquals("http://wp.com/test?q=pony&preview=true", url);
}

public void testAppendUrlParameter3() {
String url = UrlUtils.appendUrlParameter("http://wp.com/test?q=pony#unicorn", "preview", "true");
assertEquals("http://wp.com/test?q=pony&preview=true#unicorn", url);
}

public void testAppendUrlParameter4() {
String url = UrlUtils.appendUrlParameter("/relative/test", "preview", "true");
assertEquals("/relative/test?preview=true", url);
}

public void testAppendUrlParameter5() {
String url = UrlUtils.appendUrlParameter("/relative/", "preview", "true");
assertEquals("/relative/?preview=true", url);
}

public void testAppendUrlParameter6() {
String url = UrlUtils.appendUrlParameter("http://wp.com/test/", "preview", "true");
assertEquals("http://wp.com/test/?preview=true", url);
}

public void testAppendUrlParameter7() {
String url = UrlUtils.appendUrlParameter("http://wp.com/test/?q=pony", "preview", "true");
assertEquals("http://wp.com/test/?q=pony&preview=true", url);
}

public void testAppendUrlParameters1() {
Map<String, String> params = new HashMap<>();
params.put("w", "200");
params.put("h", "300");
String url = UrlUtils.appendUrlParameters("http://wp.com/test", params);
if (!url.equals("http://wp.com/test?h=300&w=200") && !url.equals("http://wp.com/test?w=200&h=300")) {
assertTrue("failed test on url: " + url, false);
}
}

public void testAppendUrlParameters2() {
Map<String, String> params = new HashMap<>();
params.put("h", "300");
params.put("w", "200");
String url = UrlUtils.appendUrlParameters("/relative/test", params);
if (!url.equals("/relative/test?h=300&w=200") && !url.equals("/relative/test?w=200&h=300")) {
assertTrue("failed test on url: " + url, false);
}
}

public void testHttps1() {
assertFalse(UrlUtils.isHttps(buildURL("http://wordpress.com/xmlrpc.php")));
}

public void testHttps2() {
assertFalse(UrlUtils.isHttps(buildURL("http://wordpress.com#.b.com/test")));
}

public void testHttps3() {
assertFalse(UrlUtils.isHttps(buildURL("http://wordpress.com/xmlrpc.php")));
}

public void testHttps4() {
assertTrue(UrlUtils.isHttps(buildURL("https://wordpress.com")));
}

public void testHttps5() {
assertTrue(UrlUtils.isHttps(buildURL("https://wordpress.com/test#test")));
}

private URL buildURL(String address) {
URL url = null;
try {
url = new URL(address);
} catch (MalformedURLException e) {}
return url;
}
}
2 changes: 1 addition & 1 deletion WordPressUtils/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.wordpress.android.util">

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.content.Context;
import android.content.DialogInterface;

public class AlertUtil {
public class AlertUtils {
/**
* Show Alert Dialog
* @param context
Expand All @@ -30,10 +30,10 @@ public class AlertUtil {
*/
public static void showAlert(Context context, int titleId, int messageId) {
Dialog dlg = new AlertDialog.Builder(context)
.setTitle(titleId)
.setPositiveButton(android.R.string.ok, null)
.setMessage(messageId)
.create();
.setTitle(titleId)
.setPositiveButton(android.R.string.ok, null)
.setMessage(messageId)
.create();

dlg.show();
}
Expand All @@ -42,14 +42,14 @@ public static void showAlert(Context context, int titleId, int messageId) {
* Show Alert Dialog
* @param context
* @param titleId
* @param messageId
* @param message
*/
public static void showAlert(Context context, int titleId, String message) {
Dialog dlg = new AlertDialog.Builder(context)
.setTitle(titleId)
.setPositiveButton(android.R.string.ok, null)
.setMessage(message)
.create();
.setTitle(titleId)
.setPositiveButton(android.R.string.ok, null)
.setMessage(message)
.create();

dlg.show();
}
Expand All @@ -65,15 +65,15 @@ public static void showAlert(Context context, int titleId, String message) {
* @param negativeListener
*/
public static void showAlert(Context context, int titleId, int messageId,
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener,
CharSequence negativeButtontxt, DialogInterface.OnClickListener negativeListener) {
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener,
CharSequence negativeButtontxt, DialogInterface.OnClickListener negativeListener) {
Dialog dlg = new AlertDialog.Builder(context)
.setTitle(titleId)
.setPositiveButton(positiveButtontxt, positiveListener)
.setNegativeButton(negativeButtontxt, negativeListener)
.setMessage(messageId)
.setCancelable(false)
.create();
.setTitle(titleId)
.setPositiveButton(positiveButtontxt, positiveListener)
.setNegativeButton(negativeButtontxt, negativeListener)
.setMessage(messageId)
.setCancelable(false)
.create();

dlg.show();
}
Expand All @@ -82,20 +82,19 @@ public static void showAlert(Context context, int titleId, int messageId,
* Show Alert Dialog
* @param context
* @param titleId
* @param messageId
* @param message
* @param positiveButtontxt
* @param positiveListener
*/
public static void showAlert(Context context, int titleId, String message,
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener) {
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener) {
Dialog dlg = new AlertDialog.Builder(context)
.setTitle(titleId)
.setPositiveButton(positiveButtontxt, positiveListener)
.setMessage(message)
.setCancelable(false)
.create();
.setTitle(titleId)
.setPositiveButton(positiveButtontxt, positiveListener)
.setMessage(message)
.setCancelable(false)
.create();

dlg.show();
}
}

}
Loading

0 comments on commit 0b9c608

Please sign in to comment.