[go: nahoru, domu]

Skip to content

Commit

Permalink
fixed conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Thulin committed Nov 26, 2015
2 parents 0ae36de + ee9a14b commit 8ce1ae7
Show file tree
Hide file tree
Showing 20 changed files with 359 additions and 97 deletions.
22 changes: 13 additions & 9 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.6.0"
minSdkVersion 14
targetSdkVersion 19
targetSdkVersion 23
}
}

Expand Down
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
Expand Up @@ -2,6 +2,9 @@

import android.test.InstrumentationTestCase;

import java.util.HashMap;
import java.util.Map;

public class UrlUtilsTest extends InstrumentationTestCase {
public void testGetDomainFromUrlWithEmptyStringDoesNotReturnNull() {
assertNotNull(UrlUtils.getDomainFromUrl(""));
Expand All @@ -17,4 +20,59 @@ public void testGetDomainFromUrlWithHostReturnsHost() {

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);
}
}
}
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 @@ -11,13 +11,12 @@
import java.util.NoSuchElementException;

/**
* A simple wrapper for Android log calls, enables recording and displaying log.
* simple wrapper for Android log calls, enables recording & displaying log
*/
public class AppLog {
// T for Tag
public enum T {READER, EDITOR, MEDIA, NUX, API, STATS, UTILS, NOTIFS, DB, POSTS, COMMENTS, THEMES, TESTS, PROFILING,
SIMPERIUM, SUGGESTION}

SIMPERIUM, SUGGESTION, MAIN}
public static final String TAG = "WordPress";
public static final int HEADER_LINE_COUNT = 2;

Expand Down Expand Up @@ -269,4 +268,4 @@ public static String toPlainText(Context context) {
}
return sb.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ public class BlogUtils {
public int compare(Object blog1, Object blog2) {
Map<String, Object> blogMap1 = (Map<String, Object>) blog1;
Map<String, Object> blogMap2 = (Map<String, Object>) blog2;
String blogName1 = getBlogNameOrHostNameFromAccountMap(blogMap1);
String blogName2 = getBlogNameOrHostNameFromAccountMap(blogMap2);
String blogName1 = getBlogNameOrHomeURLFromAccountMap(blogMap1);
String blogName2 = getBlogNameOrHomeURLFromAccountMap(blogMap2);
return blogName1.compareToIgnoreCase(blogName2);
}
};

/**
* Return a blog name or blog url (host part only) if trimmed name is an empty string
* Return a blog name or blog home URL if trimmed name is an empty string
*/
public static String getBlogNameOrHostNameFromAccountMap(Map<String, Object> account) {
public static String getBlogNameOrHomeURLFromAccountMap(Map<String, Object> account) {
String blogName = getBlogNameFromAccountMap(account);
if (blogName.trim().length() == 0) {
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
blogName = BlogUtils.getHomeURLOrHostNameFromAccountMap(account);
}
return blogName;
}
Expand All @@ -33,9 +33,16 @@ public static String getBlogNameFromAccountMap(Map<String, Object> account) {
}

/**
* Return blog url (host part only) if trimmed name is an empty string
* Return the blog home URL setting or the host name if home URL is an empty string.
*/
public static String getHostNameFromAccountMap(Map<String, Object> account) {
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
public static String getHomeURLOrHostNameFromAccountMap(Map<String, Object> account) {
String homeURL = UrlUtils.removeScheme(MapUtils.getMapStr(account, "homeURL"));
homeURL = StringUtils.removeTrailingSlash(homeURL);

if (homeURL.length() == 0) {
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
}

return homeURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public static int getDisplayPixelHeight(Context context) {
return (size.y);
}

public static float spToPx(Context context, float sp){
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
final float scale = displayMetrics.scaledDensity;
return sp * scale;
}

public static int dpToPx(Context context, int dp) {
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
context.getResources().getDisplayMetrics());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.text.TextUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

/**
* EditText utils
Expand All @@ -14,13 +15,10 @@ private EditTextUtils() {
}

/**
* returns text string from passed EditText
* returns non-null text string from passed TextView
*/
public static String getText(EditText edit) {
if (edit.getText() == null) {
return "";
}
return edit.getText().toString();
public static String getText(TextView textView) {
return (textView != null) ? textView.getText().toString() : "";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@
import org.wordpress.android.util.AppLog.T;

import java.util.ArrayList;
import java.util.Iterator;

public class JSONUtils {
private static String QUERY_SEPERATOR=".";
private static String QUERY_ARRAY_INDEX_START="[";
private static String QUERY_ARRAY_INDEX_END="]";
private static String QUERY_ARRAY_FIRST="first";
private static String QUERY_ARRAY_LAST="last";
private static String QUERY_SEPERATOR = ".";
private static String QUERY_ARRAY_INDEX_START = "[";
private static String QUERY_ARRAY_INDEX_END = "]";
private static String QUERY_ARRAY_FIRST = "first";
private static String QUERY_ARRAY_LAST = "last";

private static final String JSON_NULL_STR = "null";
private static final String TAG = "JSONUtils";

private static final String TAG="JSONUtils";
/**
* Given a JSONObject and a key path (e.g property.child) and a default it will
* traverse the object graph and pull out the desired property
*/
public static <U> U queryJSON(JSONObject source, String query, U defaultObject) {
if (source == null) {
AppLog.e(T.UTILS, "Parameter source is null, can't query a null object");
return defaultObject;
}
if (query == null) {
AppLog.e(T.UTILS, "Parameter query is null");
return defaultObject;
}
int nextSeperator = query.indexOf(QUERY_SEPERATOR);
int nextIndexStart = query.indexOf(QUERY_ARRAY_INDEX_START);
if (nextSeperator == -1 && nextIndexStart == -1) {
Expand All @@ -37,6 +44,8 @@ public static <U> U queryJSON(JSONObject source, String query, U defaultObject)
if (result.getClass().isAssignableFrom(defaultObject.getClass())) {
return (U) result;
} else {
AppLog.w(T.UTILS, String.format("The returned object type %s is not assignable to the type %s. Using default!",
result.getClass(),defaultObject.getClass()));
return defaultObject;
}
} catch (java.lang.ClassCastException e) {
Expand All @@ -56,9 +65,6 @@ public static <U> U queryJSON(JSONObject source, String query, U defaultObject)
String nextQuery = query.substring(endQuery);
String key = query.substring(0, endQuery);
try {
if (source == null) {
return defaultObject;
}
if (nextQuery.indexOf(QUERY_SEPERATOR) == 0) {
return queryJSON(source.getJSONObject(key), nextQuery.substring(1), defaultObject);
} else if (nextQuery.indexOf(QUERY_ARRAY_INDEX_START) == 0) {
Expand Down Expand Up @@ -89,7 +95,15 @@ public static <U> U queryJSON(JSONObject source, String query, U defaultObject)
* Acceptable indexes include negative numbers to reference items from the end of
* the list as well as "last" and "first" as more explicit references to "0" and "-1"
*/
public static <U> U queryJSON(JSONArray source, String query, U defaultObject){
public static <U> U queryJSON(JSONArray source, String query, U defaultObject) {
if (source == null) {
AppLog.e(T.UTILS, "Parameter source is null, can't query a null object");
return defaultObject;
}
if (query == null) {
AppLog.e(T.UTILS, "Parameter query is null");
return defaultObject;
}
// query must start with [ have an index and then have ]
int indexStart = query.indexOf(QUERY_ARRAY_INDEX_START);
int indexEnd = query.indexOf(QUERY_ARRAY_INDEX_END);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static boolean isVideo(String url) {
}
return url.endsWith(".ogv") || url.endsWith(".mp4") || url.endsWith(".m4v") || url.endsWith(".mov") ||
url.endsWith(".wmv") || url.endsWith(".avi") || url.endsWith(".mpg") || url.endsWith(".3gp") ||
url.endsWith(".3g2");
url.endsWith(".3g2") || url.contains("video");
}

public static boolean isAudio(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public static boolean isAirplaneModeOn(Context context) {
* and returns false
*/
public static boolean checkConnection(Context context) {
if (context == null) {
return false;
}
if (isNetworkAvailable(context)) {
return true;
}
Expand Down
Loading

0 comments on commit 8ce1ae7

Please sign in to comment.