Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
*/
public class NetroidLog {

private NetroidLog() {
/* cannot be instantiated */
}

public static String TAG = "Netroid";

public static boolean DEBUG = Log.isLoggable(TAG, Log.VERBOSE);

private NetroidLog() {
/* cannot be instantiated */
}

/**
* Customize the log tag for your application, so that other apps
* using Netroid don't mix their logs with yours.
Expand Down
30 changes: 16 additions & 14 deletions library/src/main/java/com/vincestyling/netroid/NetworkResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
* Data and headers returned from {@link Network#performRequest(Request)}.
*/
public class NetworkResponse {

/**
* The HTTP status code.
*/
public final int statusCode;

/**
* Raw data from this response.
*/
public final byte[] data;

/**
* Charset from this response.
*/
public final String charset;

/**
* Creates a new network response.
*
Expand All @@ -42,18 +58,4 @@ public NetworkResponse(byte[] data, String charset) {
this(HttpStatus.SC_OK, data, charset);
}

/**
* The HTTP status code.
*/
public final int statusCode;

/**
* Raw data from this response.
*/
public final byte[] data;

/**
* Charset from this response.
*/
public final String charset;
}
15 changes: 8 additions & 7 deletions library/src/main/java/com/vincestyling/netroid/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public interface Method {
*/
private Object mTag;


/**
* Indicates DeliverPreExecute operation is done or not,
* because the {@link CacheDispatcher} and {@link NetworkDispatcher}
* both will call this deliver, and we must ensure just invoke once.
*/
private boolean mIsDeliverPreExecute;

/**
* Creates a new request with the given method (one of the values from {@link Method}),
* URL, and error listener. Note that the normal response listener is not provided here as
Expand Down Expand Up @@ -598,13 +606,6 @@ public void deliverCancel() {
}
}

/**
* Indicates DeliverPreExecute operation is done or not,
* because the {@link CacheDispatcher} and {@link NetworkDispatcher}
* both will call this deliver, and we must ensure just invoke once.
*/
private boolean mIsDeliverPreExecute;

/**
* Delivers request is handling to the Listener.
*/
Expand Down
43 changes: 23 additions & 20 deletions library/src/main/java/com/vincestyling/netroid/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@
*/
public class Response<T> {

/**
* Returns a successful response containing the parsed result.
*/
public static <T> Response<T> success(T result, NetworkResponse response) {
return new Response<>(result, response);
}

/**
* Returns a failed response containing the given error code and an optional
* localized message displayed to the user.
*/
public static <T> Response<T> error(NetroidError error) {
return new Response<>(error);
}

/**
* Parsed response, or null in the case of error.
Expand All @@ -59,12 +45,6 @@ public static <T> Response<T> error(NetroidError error) {
*/
public boolean intermediate = false;

/**
* Returns whether this response is considered successful.
*/
public boolean isSuccess() {
return errorDetail == null;
}

private Response(T result, NetworkResponse response) {
this.result = result;
Expand All @@ -77,4 +57,27 @@ private Response(NetroidError error) {
this.cacheEntry = null;
this.errorDetail = error;
}

/**
* Returns a successful response containing the parsed result.
*/
public static <T> Response<T> success(T result, NetworkResponse response) {
return new Response<>(result, response);
}

/**
* Returns a failed response containing the given error code and an optional
* localized message displayed to the user.
*/
public static <T> Response<T> error(NetroidError error) {
return new Response<>(error);
}

/**
* Returns whether this response is considered successful.
*/
public boolean isSuccess() {
return errorDetail == null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,6 @@ public void setCharset(String charset) {
* Data and metadata for an entry returned by the cache.
*/
public static class Entry {
public Entry() {
}

public Entry(byte[] data, String charset) {
this.data = data;
this.charset = charset;
}

/**
* The data returned from cache.
Expand All @@ -475,6 +468,14 @@ public Entry(byte[] data, String charset) {
*/
private String charset;

public Entry() {
}

public Entry(byte[] data, String charset) {
this.data = data;
this.charset = charset;
}

/**
* True if the entry is expired.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class ByteArrayPool {
*/
private final int mSizeLimit;

/**
* Singleton for this class.
*/
private static ByteArrayPool mPool;

/**
* Compares buffers by size
*/
Expand All @@ -81,10 +86,6 @@ private ByteArrayPool(int sizeLimit) {
mSizeLimit = sizeLimit;
}

/**
* Singleton for this class.
*/
private static ByteArrayPool mPool;

/**
* Get the singleton instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ private class DownloadTask {
long fileSize;
long downloadedSize;

private DownloadTask(String storeFileName, String url) {
this.storeFileName = storeFileName;
this.url = url;
}

private void onProgressChange(long fileSize, long downloadedSize) {
this.fileSize = fileSize;
this.downloadedSize = downloadedSize;
Expand Down Expand Up @@ -276,9 +281,5 @@ private void invalidate() {
txvFileSize.setText(Formatter.formatFileSize(FileDownloadActivity.this, fileSize));
}

private DownloadTask(String storeFileName, String url) {
this.storeFileName = storeFileName;
this.url = url;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class GridViewActivity extends BaseActivity {
private BaseAdapter mAdapter;
private List<Book> bookList;

private Toast mToast;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gridview_p0);
Expand Down Expand Up @@ -134,8 +136,6 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
});
}

private Toast mToast;

private void showToast(CharSequence msg) {
if (mToast != null) mToast.cancel();
mToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
Expand Down