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 @@ -5,5 +5,5 @@
*/
public class Constants {
public static final String BaseUrl = "http://www.mzitu.com/";
public static String CoverUrl =BaseUrl+"/page/";
public static final String CoverUrl =BaseUrl+"/page/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public void doRightOut() {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
container = (ViewGroup) inflater.inflate(R.layout.fragment_meizi, container, false);
Toolbar toolbar = (Toolbar) container.findViewById(R.id.toolbar);
swipeCardsView = (SwipeCardsView) container.findViewById(R.id.swipCardsView);
ViewGroup inflatedContainer = (ViewGroup) inflater.inflate(R.layout.fragment_meizi, container, false);
Toolbar toolbar = (Toolbar) inflatedContainer.findViewById(R.id.toolbar);
swipeCardsView = (SwipeCardsView) inflatedContainer.findViewById(R.id.swipCardsView);
activity = (MainActivity) getActivity();
activity.setSupportActionBar(toolbar);
getData();
Expand Down Expand Up @@ -87,7 +87,7 @@ public void onItemClick(View cardImageView, int index) {
toast("点击了 position=" + index);
}
});
return container;
return inflatedContainer;
}

public void getData() {
Expand Down
20 changes: 6 additions & 14 deletions app/src/main/java/com/huxq17/example/http/HttpSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,23 @@ public HttpResponse postSync(final String url, LinkedHashMap<String, String> hea

public void get(String url, LinkedHashMap<String, String> headers, String params,
final LoadListener listener, Object... tag) {
if (!TextUtils.isEmpty(params)) {
url = url + "?" + params;
}
HttpRequest.Builder builder = new HttpRequest.Builder();
builder.url(url);
builder.url(!TextUtils.isEmpty(params) ? url + "?" + params : url);
addHeaders(builder, headers);
builder.setResponseType(ResponseType.String);
mHttpBase.get(builder.build(), listener, tag);
}

public HttpResponse getInputStreamSync(String url, LinkedHashMap<String, String> headers, String params, Object... tag) {
if (!TextUtils.isEmpty(params)) {
url = url + "?" + params;
}
public HttpResponse getInputStreamSync(String url, Map<String, String> headers, String params, Object... tag) {
HttpRequest.Builder builder = new HttpRequest.Builder();
builder.url(url).synchron().setResponseType(ResponseType.InputStream);
builder.url(!TextUtils.isEmpty(params) ? url + "?" + params : url).synchron().setResponseType(ResponseType.InputStream);
addHeaders(builder, headers);
return mHttpBase.get(builder.build(), null, tag);
}
public HttpResponse getSync(String url, LinkedHashMap<String, String> headers, String params, Object... tag){
if (!TextUtils.isEmpty(params)) {
url = url + "?" + params;
}

public HttpResponse getSync(String url, Map<String, String> headers, String params, Object... tag){
HttpRequest.Builder builder = new HttpRequest.Builder();
builder.url(url).synchron().setResponseType(ResponseType.String);
builder.url(!TextUtils.isEmpty(params) ? url + "?" + params : url).synchron().setResponseType(ResponseType.String);
addHeaders(builder, headers);
return mHttpBase.get(builder.build(), null, tag);
}
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/huxq17/example/http/OKHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.andbase.tractor.task.TaskPool;
import com.andbase.tractor.utils.LogUtils;
import com.huxq17.example.http.body.FileBody;
import com.huxq17.example.http.body.exception.SwipeCardsException;
import com.huxq17.example.http.request.CountingRequestBody;
import com.huxq17.example.http.request.HttpHeader;
import com.huxq17.example.http.request.HttpMethod;
Expand Down Expand Up @@ -96,7 +97,7 @@ public HttpResponse post(HttpRequest request, LoadListener listener, Object... t

RequestBody requestBody = buildRequestBody(requestParams);
if (requestBody == null) {
throw new RuntimeException("requestBody==null");
throw new SwipeCardsException("requestBody==null");
}
Request.Builder builder = getBuilder().url(url).post(requestBody);
addHeader(builder, header);
Expand All @@ -120,14 +121,14 @@ public HttpResponse request(HttpRequest request, LoadListener listener, Object..
String charset = requestParams.getCharSet();

if (TextUtils.isEmpty(contentType) || TextUtils.isEmpty(charset)) {
throw new RuntimeException("contentType is empty || charset is empty");
throw new SwipeCardsException("contentType is empty || charset is empty");
}
addHeader(builder, header);

if (HttpMethod.permitsRequestBody(method)) {
if (HttpMethod.requiresRequestBody(method)) {
if (requestParams.isEmpty()) {
throw new RuntimeException("method:" + method.toString() + "must have params");
throw new SwipeCardsException("method:" + method.toString() + "must have params");
}
}
if (!requestParams.isEmpty()) {
Expand All @@ -150,7 +151,7 @@ private RequestBody buildRequestBody(RequestParams requestParams) {
String params = requestParams.toString();
LinkedHashMap<String, Object> paramsHashmap = requestParams.getmParams();
if (params == null || TextUtils.isEmpty(contentType) || TextUtils.isEmpty(charset)) {
throw new RuntimeException("params is null");
throw new SwipeCardsException("params is null");
}
if (files != null && files.size() > 0) {
LogUtils.d("upload file.size=" + files.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.huxq17.example.http.body.exception;

/**
* Created by georgekankava on 5/9/16.
*/
public class SwipeCardsException extends RuntimeException {

public SwipeCardsException() {
super();
}

public SwipeCardsException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.huxq17.example.http.request;

import com.huxq17.example.http.body.exception.SwipeCardsException;
import com.huxq17.example.http.response.ResponseType;

import java.io.File;
Expand Down Expand Up @@ -108,7 +109,7 @@ public Builder removeHeader(String name) {

public Builder setParams(LinkedHashMap<String, Object> params) {
if (params == null) {
throw new RuntimeException("params==null");
throw new SwipeCardsException("params==null");
}
this.requestParams.setParams(params);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.andbase.tractor.utils.LogUtils;
import com.huxq17.example.http.body.FileBody;
import com.huxq17.example.http.body.exception.SwipeCardsException;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void setStringParams(String stringParams) {
*/
public void addFile(File file) {
if (file == null || !file.exists()) {
throw new RuntimeException("file==null||!file.exists()");
throw new SwipeCardsException("file==null||!file.exists()");
}
FileBody body = new FileBody(file.getName(), file.getAbsolutePath(), file);
mFiles.add(body);
Expand All @@ -74,7 +75,7 @@ public void addFile(File file) {
*/
public void addFile(String name, File file) {
if (file == null || !file.exists()) {
throw new RuntimeException("file==null||!file.exists()");
throw new SwipeCardsException("file==null||!file.exists()");
}
FileBody body = new FileBody(name, file.getAbsolutePath(), file);
mFiles.add(body);
Expand All @@ -87,7 +88,7 @@ public void addFile(String name, File file) {
*/
public void addFile(String name, File file, String contentType) {
if (file == null || !file.exists()) {
throw new RuntimeException("file==null||!file.exists()");
throw new SwipeCardsException("file==null||!file.exists()");
}
FileBody body = new FileBody(name, file.getAbsolutePath(), file, contentType);
mFiles.add(body);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.huxq17.example.http.response;

import com.huxq17.example.http.body.exception.SwipeCardsException;

import java.io.InputStream;
import java.io.Serializable;

Expand Down Expand Up @@ -34,7 +36,7 @@ private void check(ResponseType requstType) {
stringBuffer.append(" builder.setResponseType(ResponseType.InputStream);");
break;
}
throw new RuntimeException(stringBuffer.toString());
throw new SwipeCardsException(stringBuffer.toString());
}
}

Expand Down