Skip to content

Commit b7c1140

Browse files
committed
Merge branch 'develop' into feature/notifications-redesign
Conflicts: WordPress/src/main/java/org/wordpress/android/WordPress.java WordPress/src/main/java/org/wordpress/android/ui/WPActionBarActivity.java WordPress/src/main/java/org/wordpress/android/ui/notifications/FollowRow.java WordPress/src/main/res/values/strings.xml
2 parents 2e0d872 + e5ee549 commit b7c1140

File tree

10 files changed

+227
-81
lines changed

10 files changed

+227
-81
lines changed

WordPressUtils/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ dependencies {
2020
compile 'commons-lang:commons-lang:2.6'
2121
compile 'com.mcxiaoke.volley:library:1.0.+'
2222
compile 'com.github.castorflex.smoothprogressbar:library:0.4.0'
23-
compile 'org.wordpress:pulltorefresh-main:+@aar' // org.wordpress version includes some fixes
24-
compile 'com.android.support:support-v13:19.0.+'
23+
compile 'org.wordpress:pulltorefresh-main:0.9.7@aar' // org.wordpress version includes some fixes
24+
compile 'com.android.support:support-v13:19.1.0'
2525
}
2626

2727
android {
@@ -32,8 +32,7 @@ android {
3232

3333
defaultConfig {
3434
applicationId "org.wordpress.android.util"
35-
versionName "1.1.0"
36-
versionCode 1
35+
versionName "1.2.0"
3736
minSdkVersion 14
3837
targetSdkVersion 19
3938
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public static ArrayList<String> toHtmlList(Context context) {
175175
ArrayList<String> items = new ArrayList<String>();
176176

177177
// add version & device info - be sure to change HEADER_LINE_COUNT if additional lines are added
178-
items.add("<strong>WordPress Android version: " + ProfilingUtils.getVersionName(context) + "</strong>");
178+
items.add("<strong>WordPress Android version: " + PackageUtils.getVersionName(context) + "</strong>");
179179
items.add("<strong>Android device name: " + DeviceUtils.getInstance().getDeviceName(context) + "</strong>");
180180

181181
Iterator<LogEntry> it = mLogEntries.iterator();
@@ -193,7 +193,7 @@ public static String toPlainText(Context context) {
193193
StringBuilder sb = new StringBuilder();
194194

195195
// add version & device info
196-
sb.append("WordPress Android version: " + ProfilingUtils.getVersionName(context)).append("\n")
196+
sb.append("WordPress Android version: " + PackageUtils.getVersionName(context)).append("\n")
197197
.append("Android device name: " + DeviceUtils.getInstance().getDeviceName(context)).append("\n\n");
198198

199199
Iterator<LogEntry> it = mLogEntries.iterator();

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,15 @@ public int compare(Object blog1, Object blog2) {
2222
return blogName1.compareToIgnoreCase(blogName2);
2323
}
2424
};
25+
26+
/**
27+
* Return a blog name or blog url (host part only) if trimmed name is an empty string
28+
*/
29+
public static String getBlogNameFromAccountMap(Map<String, Object> account) {
30+
String blogName = StringUtils.unescapeHTML(MapUtils.getMapStr(account, "blogName"));
31+
if (blogName.trim().length() == 0) {
32+
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
33+
}
34+
return blogName;
35+
}
2536
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.wordpress.android.util;
2+
3+
import android.content.Context;
4+
import android.net.ConnectivityManager;
5+
import android.net.NetworkInfo;
6+
import android.os.Build;
7+
import android.provider.Settings;
8+
9+
/**
10+
* requires android.permission.ACCESS_NETWORK_STATE
11+
*/
12+
public class NetworkUtils {
13+
public static final int TYPE_UNKNOWN = -1;
14+
15+
/**
16+
* returns information on the active network connection
17+
*/
18+
private static NetworkInfo getActiveNetworkInfo(Context context) {
19+
if (context == null) {
20+
return null;
21+
}
22+
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
23+
if (cm == null) {
24+
return null;
25+
}
26+
// note that this may return null if no network is currently active
27+
return cm.getActiveNetworkInfo();
28+
}
29+
30+
/**
31+
* returns the ConnectivityManager.TYPE_xxx if there's an active connection, otherwise
32+
* returns TYPE_UNKNOWN
33+
*/
34+
private static int getActiveNetworkType(Context context) {
35+
NetworkInfo info = getActiveNetworkInfo(context);
36+
if (info == null || !info.isConnected()) {
37+
return TYPE_UNKNOWN;
38+
}
39+
return info.getType();
40+
}
41+
42+
/**
43+
* returns true if a network connection is available
44+
*/
45+
public static boolean isNetworkAvailable(Context context) {
46+
NetworkInfo info = getActiveNetworkInfo(context);
47+
return (info != null && info.isConnected());
48+
}
49+
50+
/**
51+
* returns true if the user is connected to WiFi
52+
*/
53+
public static boolean isWiFiConnected(Context context) {
54+
return (getActiveNetworkType(context) == ConnectivityManager.TYPE_WIFI);
55+
}
56+
57+
/**
58+
* returns true if airplane mode has been enabled
59+
*/
60+
public static boolean isAirplaneModeOn(Context context) {
61+
// prior to JellyBean 4.2 this was Settings.System.AIRPLANE_MODE_ON, JellyBean 4.2
62+
// moved it to Settings.Global
63+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
64+
return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
65+
} else {
66+
return Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
67+
}
68+
}
69+
70+
/**
71+
* returns true if there's an active network connection, otherwise displays a toast error
72+
* and returns false
73+
*/
74+
public static boolean checkConnection(Context context) {
75+
if (isNetworkAvailable(context)) {
76+
return true;
77+
}
78+
ToastUtils.showToast(context, R.string.no_network_message);
79+
return false;
80+
}
81+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.wordpress.android.util;
2+
3+
import android.content.Context;
4+
import android.content.pm.PackageInfo;
5+
import android.content.pm.PackageManager;
6+
7+
public class PackageUtils {
8+
/**
9+
* Return true if Debug build. false otherwise.
10+
*/
11+
public static boolean isDebugBuild() {
12+
return BuildConfig.DEBUG;
13+
}
14+
15+
public static PackageInfo getPackageInfo(Context context) {
16+
try {
17+
PackageManager manager = context.getPackageManager();
18+
return manager.getPackageInfo(context.getPackageName(), 0);
19+
} catch (PackageManager.NameNotFoundException e) {
20+
return null;
21+
}
22+
}
23+
24+
/**
25+
* Return version code, or 0 if it can't be read
26+
*/
27+
public static int getVersionCode(Context context) {
28+
PackageInfo packageInfo = getPackageInfo(context);
29+
if (packageInfo != null) {
30+
return packageInfo.versionCode;
31+
}
32+
return 0;
33+
}
34+
35+
/**
36+
* Return version name, or the string "0" if it can't be read
37+
*/
38+
public static String getVersionName(Context context) {
39+
PackageInfo packageInfo = getPackageInfo(context);
40+
if (packageInfo != null) {
41+
return packageInfo.versionName;
42+
}
43+
return "0";
44+
}
45+
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.wordpress.android.util;
22

3-
import android.content.Context;
4-
import android.content.pm.PackageInfo;
5-
import android.content.pm.PackageManager;
63
import android.os.SystemClock;
74

85
import org.wordpress.android.util.AppLog.T;
@@ -76,16 +73,5 @@ public void dumpToLog() {
7673
}
7774
AppLog.d(T.PROFILING, mLabel + ": end, " + (now - first) + " ms");
7875
}
79-
80-
// Returns app version name String
81-
public static String getVersionName(Context context) {
82-
PackageManager pm = context.getPackageManager();
83-
try {
84-
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
85-
return pi.versionName == null ? "" : pi.versionName;
86-
} catch (PackageManager.NameNotFoundException e) {
87-
return "";
88-
}
89-
}
9076
}
9177

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

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* adapted from existing ImageGetter code in NoteCommentFragment
2020
*/
2121
public class WPImageGetter implements Html.ImageGetter {
22-
private WeakReference<TextView> mWeakView;
23-
private int mMaxSize;
22+
private final WeakReference<TextView> mWeakView;
23+
private final int mMaxSize;
2424
private ImageLoader mImageLoader;
2525
private Drawable mLoadingDrawable;
2626
private Drawable mFailedDrawable;
@@ -43,18 +43,6 @@ public WPImageGetter(TextView view, int maxSize, ImageLoader imageLoader, Drawab
4343
mFailedDrawable = failedDrawable;
4444
}
4545

46-
public void setImageLoader(ImageLoader imageLoader) {
47-
mImageLoader = imageLoader;
48-
}
49-
50-
public void setLoadingDrawable(Drawable loadingDrawable) {
51-
mLoadingDrawable = loadingDrawable;
52-
}
53-
54-
public void setFailedDrawable(Drawable failedDrawable) {
55-
mFailedDrawable = failedDrawable;
56-
}
57-
5846
private TextView getView() {
5947
return mWeakView.get();
6048
}
@@ -80,9 +68,6 @@ public Drawable getDrawable(String source) {
8068
source = PhotonUtils.getPhotonImageUrl(source, mMaxSize, 0);
8169
}
8270

83-
TextView view = getView();
84-
// Drawable loading = view.getContext().getResources().getDrawable(R.drawable.remote_image); FIXME: here
85-
// Drawable failed = view.getContext().getResources().getDrawable(R.drawable.remote_failed);
8671
final RemoteDrawable remote = new RemoteDrawable(mLoadingDrawable, mFailedDrawable);
8772

8873
mImageLoader.get(source, new ImageLoader.ImageListener() {
@@ -97,43 +82,40 @@ public void onErrorResponse(VolleyError error) {
9782

9883
@Override
9984
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
100-
if (response.getBitmap() != null) {
101-
// make sure view is still valid
102-
TextView view = getView();
103-
if (view == null) {
104-
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
105-
return;
106-
}
107-
108-
Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
109-
final int oldHeight = remote.getBounds().height();
110-
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
111-
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
112-
maxWidth = mMaxSize;
113-
}
114-
remote.setRemoteDrawable(drawable, maxWidth);
115-
116-
// image is from cache? don't need to modify view height
117-
if (isImmediate) {
118-
return;
119-
}
120-
121-
int newHeight = remote.getBounds().height();
122-
view.invalidate();
123-
// For ICS
124-
view.setHeight(view.getHeight() + newHeight - oldHeight);
125-
// Pre ICS
126-
view.setEllipsize(null);
85+
if (response.getBitmap() == null) {
86+
AppLog.w(T.UTILS, "WPImageGetter null bitmap");
87+
}
88+
89+
TextView view = getView();
90+
if (view == null) {
91+
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
92+
return;
93+
}
94+
95+
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
96+
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
97+
maxWidth = mMaxSize;
98+
}
99+
100+
Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
101+
remote.setRemoteDrawable(drawable, maxWidth);
102+
103+
// force textView to resize correctly if image isn't cached by resetting the content
104+
// to itself - this way the textView will use the cached image, and resizing to
105+
// accommodate the image isn't necessary
106+
if (!isImmediate) {
107+
view.setText(view.getText());
127108
}
128109
}
129110
});
111+
130112
return remote;
131113
}
132114

133115
private static class RemoteDrawable extends BitmapDrawable {
134-
protected Drawable mRemoteDrawable;
135-
protected Drawable mLoadingDrawable;
136-
protected Drawable mFailedDrawable;
116+
Drawable mRemoteDrawable;
117+
final Drawable mLoadingDrawable;
118+
final Drawable mFailedDrawable;
137119
private boolean mDidFail = false;
138120

139121
public RemoteDrawable(Drawable loadingDrawable, Drawable failedDrawable) {
@@ -158,11 +140,6 @@ public void setBounds(int x, int y, int width, int height) {
158140
}
159141
}
160142

161-
public void setRemoteDrawable(Drawable remote) {
162-
mRemoteDrawable = remote;
163-
setBounds(0, 0, mRemoteDrawable.getIntrinsicWidth(), mRemoteDrawable.getIntrinsicHeight());
164-
}
165-
166143
public void setRemoteDrawable(Drawable remote, int maxWidth) {
167144
// null sentinel for now
168145
if (remote == null) {

0 commit comments

Comments
 (0)