Skip to content

Commit

Permalink
更新 "在 Fragment 中使用"请求的服务器改为自建服务器,速度比雅虎财经的服务器快些
Browse files Browse the repository at this point in the history
  • Loading branch information
siterhow committed Apr 26, 2017
1 parent 4cb86dc commit 96bb586
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.chanven.lib.cptr.PtrFrameLayout;
import com.wordplat.quickstart.R;
import com.wordplat.quickstart.fragment.KLineFragment;
import com.wordplat.quickstart.mvp.YahooStockPresenter;
import com.wordplat.quickstart.mvp.StockPresenter;
import com.wordplat.quickstart.widget.pulllistview.PullListLayout;

import org.xutils.view.annotation.ContentView;
Expand Down Expand Up @@ -44,9 +44,9 @@ protected void onCreate(Bundle savedInstanceState) {
private void initUI() {
pullListLayout.setPtrHandler(ptrHandler);

dayKLineFragment = KLineFragment.newInstance(YahooStockPresenter.KLineType.DAY);
weekKLineFragment = KLineFragment.newInstance(YahooStockPresenter.KLineType.WEEK);
monthKLineFragment = KLineFragment.newInstance(YahooStockPresenter.KLineType.MONTH);
dayKLineFragment = KLineFragment.newInstance(StockPresenter.KLineType.DAY);
weekKLineFragment = KLineFragment.newInstance(StockPresenter.KLineType.WEEK);
monthKLineFragment = KLineFragment.newInstance(StockPresenter.KLineType.MONTH);

final String[] tabStrings = new String[]{"日K", "周K", "月K"};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.wordplat.quickstart.bean;

/**
* <p>YahooKLineBean</p>
* <p>KLineBean</p>
* <p>Date: 2017/4/11</p>
*
* @author afon
*/

public class YahooKLineBean {
public class KLineBean {

private float open;

Expand All @@ -21,36 +21,51 @@ public class YahooKLineBean {

private String date;

public YahooKLineBean(float open, float high, float low, float close, int volume, String date) {
this.open = open;
this.high = high;
this.low = low;
this.close = close;
this.volume = volume;
this.date = date;
}

public float getOpen() {
return open;
}

public void setOpen(float open) {
this.open = open;
}

public float getHigh() {
return high;
}

public void setHigh(float high) {
this.high = high;
}

public float getLow() {
return low;
}

public void setLow(float low) {
this.low = low;
}

public float getClose() {
return close;
}

public void setClose(float close) {
this.close = close;
}

public int getVolume() {
return volume;
}

public void setVolume(int volume) {
this.volume = volume;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.wordplat.quickstart.bean.request;

import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.wordplat.quickstart.BuildConfig;

import org.xutils.http.RequestParams;

import java.io.File;

/**
* <p>ServerRequestParams</p>
* <p>Date: 2017/4/5</p>
*
* @author afon
*/

public class ServerRequestParams extends RequestParams {
private static final String TAG = "ServerRequestParams";

private JSONObject params = null;

private JSONObject requestJson= null;

private String uploadKey = null;
private Object uploadValue = null;

public ServerRequestParams(String URL) {
super(URL);
params = new JSONObject();

requestJson = new JSONObject();
}

public void addRequestParams(String key, Object value) {
if (TextUtils.isEmpty(key) || value == null) {
return;
}

requestJson.put(key, value);
}

public void addCustomParams(String key, JSONObject jsonObject) {
if (TextUtils.isEmpty(key) || jsonObject == null) {
return;
}

params.put(key, jsonObject);
}

/**
* 上传文件
*
* @param value 可以是File, InputStream 或 byte[]
*/
public void upload(Object value) {
uploadKey = "uploadFile";
uploadValue = value;
}

/**
* 添加完参数或设置参数后调用此方法
*/
public void commit() {
params.put("RequestParams", requestJson);

if (BuildConfig.DEBUG) {
Log.i(TAG, "##d 请求数据: " + requestJson.toJSONString());
}

addBodyParameter("", requestJson.toJSONString());

if (!TextUtils.isEmpty(uploadKey) && uploadValue != null) {
if (uploadValue instanceof org.json.JSONArray) {
addParameter(uploadKey, uploadValue);

} else if(uploadValue instanceof String) {
addBodyParameter(uploadKey, new File((String) uploadValue));

} else if(uploadValue instanceof File) {
addBodyParameter(uploadKey, (File)uploadValue);

} else {
addBodyParameter(uploadKey, uploadValue, "image/jpeg", System.currentTimeMillis()+".jpg");
}
}
}

@Override
public String toString() {
return params.toJSONString();
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 96bb586

Please sign in to comment.