Skip to content

Commit

Permalink
优化 v1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
GinGod committed Sep 20, 2017
2 parents 28fc239 + 7c842d5 commit 5b8b401
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 22 deletions.
Expand Up @@ -54,8 +54,7 @@ private void geneItems() {
}

private void onLoad() {
mListView.stopRefresh();
mListView.stopLoadMore();
mListView.resetStatus();
mListView.setRefreshTime("刚刚");
BasisLogUtils.e("refresh");
}
Expand Down
Expand Up @@ -98,7 +98,12 @@ public void onSuccess(Call call, Response response, String result) {
}

@Override
public void onFailure(Call call, IOException e, String message) {
public void onFailure(String url, String content, Call call, IOException e, String message) {

}

@Override
public void onException(String url, String content, String result, Exception e, String errorMessage) {

}
});
Expand Down Expand Up @@ -132,9 +137,16 @@ public void onSuccess(Call call, Response response, String result) {
}

@Override
public void onFailure(Call call, IOException e, String message) {
public void onFailure(String url, String content, Call call, IOException e, String message) {

}

@Override
public void onException(String url, String content, String result, Exception e, String errorMessage) {

}


});
}

Expand Down
Expand Up @@ -129,10 +129,16 @@ public void onProgress(long totalSize, long currentSize, long progress) {
}

@Override
public void onFailure(Call call, Exception e, String message) {
public void onFailure(String url, String content, Call call, Exception e, String message) {
BasisProgressDialogUtils.dismiss();
toast(message);
}

@Override
public void onException(String url, String content, String result, Exception e, String errorMessage) {

}

});

// BasisOkHttpUtils.download().url(url).fileName(null).build().execute(new BasisDownloadCallback() {
Expand Down Expand Up @@ -310,9 +316,16 @@ public void onSuccess(Call call, Response response, String result) {
}

@Override
public void onFailure(Call call, IOException e, String message) {
public void onFailure(String url, String content, Call call, IOException e, String message) {

}

@Override
public void onException(String url, String content, String result, Exception e, String errorMessage) {

}


});

}
Expand Down
Expand Up @@ -124,10 +124,19 @@ protected void onStart() {

@Override
protected void onDestroy() {
destory();
super.onDestroy();
}

/**
* activity destory前的操作
*/
public void destory() {
if (mReceiver != null) {
unregisterReceiver(mReceiver);//取消注册广播
}
super.onDestroy();

mHandler.removeCallbacksAndMessages(null);//清空所有消息
}

/**
Expand Down Expand Up @@ -494,6 +503,23 @@ public void startActivityAndFinish(Class<?> cls) {
finish();
}

/**
* 获取控件, 并设置可点击
*/
public <T extends View> T getView(int id) {
View view = findViewById(id);
view.setClickable(true);
return (T) view;
}

/**
* 获取控件, 不设置可点击
*/
public <T extends View> T getViewNoClickable(int id) {
View view = findViewById(id);
return (T) view;
}

/**
* TextView查找并设置监听
*/
Expand Down Expand Up @@ -582,6 +608,24 @@ public RecyclerView findRecyclerView(int id) {
return (RecyclerView) findViewById(id);
}

/**
* 设置text
*/
public TextView setTvText(int id, String text) {
TextView view = findTextView(id);
view.setText(showStr(text));
return view;
}

/**
* 设置text
*/
public EditText setEtText(int id, String text) {
EditText view = findEditText(id);
view.setText(showStr(text));
return view;
}

/**
* 延迟获取焦点
*/
Expand Down
Expand Up @@ -109,10 +109,19 @@ public void additionalLogic() {

@Override
public void onDestroyView() {
destory();
super.onDestroyView();
}

/**
* fragment destory前的操作
*/
public void destory() {
if (mReceiver != null) {
mActivity.unregisterReceiver(mReceiver);//取消注册广播
}
super.onDestroyView();

mHandler.removeCallbacksAndMessages(null);//清空所有消息
}

/**
Expand Down Expand Up @@ -390,6 +399,23 @@ public void startActivity(Class<?> cls) {
mActivity.startActivity(new Intent(mActivity, cls));
}

/**
* 获取控件, 并设置可点击
*/
public <T extends View> T getView(int id) {
View view = mBaseView.findViewById(id);
view.setClickable(true);
return (T) view;
}

/**
* 获取控件, 不设置可点击
*/
public <T extends View> T getViewNoClickable(int id) {
View view = mBaseView.findViewById(id);
return (T) view;
}

/**
* TextView查找并设置监听
*/
Expand Down Expand Up @@ -471,6 +497,24 @@ public GridView findGridView(int id) {
return (GridView) mBaseView.findViewById(id);
}

/**
* 设置text
*/
public TextView setTvText(int id, String text) {
TextView view = findTextView(id);
view.setText(showStr(text));
return view;
}

/**
* 设置text
*/
public EditText setEtText(int id, String text) {
EditText view = findEditText(id);
view.setText(showStr(text));
return view;
}

/**
* 延迟获取焦点
*/
Expand Down
Expand Up @@ -61,10 +61,19 @@ public void additionalLogic() {

@Override
public void onDestroy() {
destory();
super.onDestroy();
}

/**
* service destory前的操作
*/
public void destory() {
if (mReceiver != null) {
unregisterReceiver(mReceiver);//取消注册广播
}
super.onDestroy();

mHandler.removeCallbacksAndMessages(null);//清空所有消息
}

/**
Expand Down
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.util.SparseArray;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -99,7 +100,9 @@ public BasisLvGvViewHolder setTvText(int viewId, String text) {

public BasisLvGvViewHolder setTvTextListener(int viewId, String text, View.OnClickListener listener) {
TextView tv = getView(viewId);
tv.setText(text == null ? "" : text);
if (!TextUtils.isEmpty(text)) {
tv.setText(text == null ? "" : text);
}
tv.setOnClickListener(listener);
return this;
}
Expand Down
Expand Up @@ -24,5 +24,10 @@ public interface BasisBitmapCallback {
/**
* 请求网络失败
*/
void onFailure(Call call, Exception e, String message);
void onFailure(String url, String content, Call call, Exception e, String message);

/**
* 处理成功结果异常
*/
void onException(String url, String content, String result, Exception e, String errorMessage);
}
Expand Up @@ -19,5 +19,10 @@ public interface BasisCallback {
/**
* 请求网络失败
*/
void onFailure(Call call, IOException e, String message);
void onFailure(String url, String content, Call call, IOException e, String message);

/**
* 处理成功结果异常
*/
void onException(String url, String content, String result, Exception e, String errorMessage);
}
Expand Up @@ -176,9 +176,19 @@ private void success(final Call call, final Response response, final String file
public void run() {
if (basisCallback != null) {
if (basisCallback instanceof BasisDownloadCallback) {
((BasisDownloadCallback) basisCallback).onSuccess(call, response, filePath);
try {
((BasisDownloadCallback) basisCallback).onSuccess(call, response, filePath);
} catch (Exception e) {
((BasisDownloadCallback) basisCallback).onException(url, "", filePath, e, e.getMessage());
e.printStackTrace();
}
} else if (basisCallback instanceof BasisBitmapCallback) {
((BasisBitmapCallback) basisCallback).onSuccess(call, response, getBitmap(filePath), filePath);
try {
((BasisBitmapCallback) basisCallback).onSuccess(call, response, getBitmap(filePath), filePath);
} catch (Exception e) {
((BasisBitmapCallback) basisCallback).onException(url, "", filePath, e, e.getMessage());
e.printStackTrace();
}
}
}
}
Expand Down Expand Up @@ -213,9 +223,9 @@ private void failure(final Call call, final Exception e, final String message, f
public void run() {
if (basisCallback != null) {
if (basisCallback instanceof BasisDownloadCallback) {
((BasisDownloadCallback) basisCallback).onFailure(call, e, message);
((BasisDownloadCallback) basisCallback).onFailure(url, "", call, e, message);
} else if (basisCallback instanceof BasisBitmapCallback) {
((BasisBitmapCallback) basisCallback).onFailure(call, e, message);
((BasisBitmapCallback) basisCallback).onFailure(url, "", call, e, message);
}
}
}
Expand Down
Expand Up @@ -22,5 +22,10 @@ public interface BasisDownloadCallback {
/**
* 请求网络失败
*/
void onFailure(Call call, Exception e, String message);
void onFailure(String url, String content, Call call, Exception e, String message);

/**
* 处理成功结果异常
*/
void onException(String url, String content, String result, Exception e, String errorMessage);
}
Expand Up @@ -144,7 +144,7 @@ public void onFailure(final Call call, final IOException e) {
mHandler.post(new Runnable() {
@Override
public void run() {
basisCallback.onFailure(call, e, message);
basisCallback.onFailure(url, content, call, e, message);
}
});
}
Expand All @@ -156,14 +156,19 @@ public void onResponse(final Call call, final Response response) throws IOExcept
if (response != null && response.body() != null) {
message = response.body().string();
} else {
message = "";
message = "";
}
BasisLogUtils.e("onSuccess: " + message);
if (basisCallback != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
basisCallback.onSuccess(call, response, message);
try {
basisCallback.onSuccess(call, response, message);
} catch (Exception e) {
basisCallback.onException(url, content, message, e, e.getMessage());
e.printStackTrace();
}
}
});
}
Expand Down
Expand Up @@ -136,7 +136,11 @@ public void onFailure(final Call call, final IOException e) {
mHandler.post(new Runnable() {
@Override
public void run() {
basisCallback.onFailure(call, e, message);
try {
basisCallback.onFailure(url, content, call, e, message);
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
}
Expand All @@ -155,7 +159,12 @@ public void onResponse(final Call call, final Response response) throws IOExcept
mHandler.post(new Runnable() {
@Override
public void run() {
basisCallback.onSuccess(call, response, message);
try {
basisCallback.onSuccess(call, response, message);
} catch (Exception e) {
basisCallback.onException(url, content, message, e, e.getMessage());
e.printStackTrace();
}
}
});
}
Expand Down

0 comments on commit 5b8b401

Please sign in to comment.