Skip to content

Commit

Permalink
Client:同步adt版至studio版
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Oct 29, 2017
1 parent 4cf2f57 commit a907f71
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -737,23 +737,35 @@ public static String[] split(String s) {
return split(s, null);
}
/**将s用split分割成String[]
* trim = true;
* @param s
* @param split
* @return
*/
public static String[] split(String s, String split) {
return split(s, split, true);
}
/**将s用split分割成String[]
* @param s
* @param split
* @param trim 去掉前后两端的split
* @return
*/
public static String[] split(String s, String split, boolean trim) {
s = getString(s);
if (s.isEmpty()) {
return null;
}
if (isNotEmpty(split, false) == false) {
split = ",";
}
while (s.startsWith(split)) {
s = s.substring(split.length());
}
while (s.endsWith(split)) {
s = s.substring(0, s.length() - split.length());
if (trim) {
while (s.startsWith(split)) {
s = s.substring(split.length());
}
while (s.endsWith(split)) {
s = s.substring(0, s.length() - split.length());
}
}
return s.contains(split) ? s.split(split) : new String[]{s};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ public static boolean noDisturb() {
/**
* TODO 改为你的正式服务器地址
*/
public static final String URL_SERVER_ADDRESS_NORMAL_HTTP = "http://139.196.140.118:8080/";//正式服务器
public static final String URL_SERVER_ADDRESS_NORMAL_HTTP = "http://39.108.143.172:8080/";//正式服务器
/**
* TODO 改为你的正式服务器地址
*/
public static final String URL_SERVER_ADDRESS_NORMAL_HTTPS = "http://192.168.43.52:8080/";//正式服务器
public static final String URL_SERVER_ADDRESS_NORMAL_HTTPS = "http://39.108.143.172:8080/";//正式服务器
/**
* TODO 改为你的测试服务器地址,如果有的话
*/
public static final String URL_SERVER_ADDRESS_TEST = "http://192.168.0.118:8080/";//测试服务器
public static final String URL_SERVER_ADDRESS_TEST = "http://192.168.0.100:8080/";//测试服务器

/**获取当前服务器地址
* isHttps = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.alibaba.fastjson.JSONObject;

Expand Down Expand Up @@ -134,9 +135,15 @@ protected void onCreate(Bundle savedInstanceState) {

//UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

private boolean isCurrentUser = false;

private ImageView ivMomentListForward;
private MomentListFragment fragment;
@Override
public void initView() {//必须在onCreate方法内调用
ivMomentListForward = (ImageView) findViewById(R.id.ivMomentListForward);
ivMomentListForward.setVisibility(showSearch ? View.VISIBLE : View.GONE);

String title;
switch (range) {
case MomentListFragment.RANGE_ALL:
Expand All @@ -146,7 +153,14 @@ public void initView() {//必须在onCreate方法内调用
// title = "动态";
// break;
case MomentListFragment.RANGE_USER:
title = APIJSONApplication.getInstance().isCurrentUser(id) ? "我的动态" : "TA的动态";
isCurrentUser = APIJSONApplication.getInstance().isCurrentUser(id);
title = isCurrentUser ? "我的动态" : "TA的动态";
if (isCurrentUser) {
ivMomentListForward.setVisibility(View.VISIBLE);
ivMomentListForward.setImageResource(R.drawable.add);
} else {
ivMomentListForward.setVisibility(View.GONE);
}
break;
case MomentListFragment.RANGE_USER_CIRCLE:
title = "朋友圈";
Expand All @@ -158,10 +172,9 @@ public void initView() {//必须在onCreate方法内调用
tvBaseTitle.setText(title);
autoSetTitle();

findViewById(R.id.ivMomentListForward).setVisibility(showSearch ? View.VISIBLE : View.GONE);


fragment = MomentListFragment.createInstance(range, id, search);
fragment.setIsAdd(isCurrentUser);

fragmentManager
.beginTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import apijson.demo.client.application.APIJSONApplication;
import apijson.demo.client.base.BaseHttpListFragment;
import apijson.demo.client.interfaces.TopBarMenuCallback;
import apijson.demo.client.model.Moment;
import apijson.demo.client.model.MomentItem;
import apijson.demo.client.util.CommentUtil;
import apijson.demo.client.util.HttpRequest;
Expand Down Expand Up @@ -204,7 +205,7 @@ public void refreshAdapter() {
});
}


private TextView leftMenu;
@SuppressLint("InflateParams")
@Override
Expand Down Expand Up @@ -261,6 +262,12 @@ public void initData() {//必须调用

}

private boolean isAdd = false;
public void setIsAdd(boolean isAdd) {
this.isAdd = isAdd;
}


@Override
public void getListAsync(final int page) {
HttpRequest.getMomentList(range, id, search, getCacheCount(), page, -page, this);
Expand Down Expand Up @@ -332,10 +339,17 @@ public void onDragBottom(boolean rightToLeft) {
return;
}

showShortToast("输入为空则查看全部");
toActivity(EditTextInfoWindow.createIntent(context
, EditTextInfoWindow.TYPE_NAME, "关键词", null),
REQUEST_TO_EDIT_TEXT_INFO, false);
if (isAdd) {
toActivity(EditTextInfoWindow.createIntent(context
, EditTextInfoWindow.TYPE_NOTE, "发动态", "说点什么吧~"),
REQUEST_TO_EDIT_TEXT_INFO, false);
} else {
showShortToast("输入为空则查看全部");
toActivity(EditTextInfoWindow.createIntent(context
, EditTextInfoWindow.TYPE_NAME, "关键词", null),
REQUEST_TO_EDIT_TEXT_INFO, false);
}

}
}

Expand All @@ -346,6 +360,35 @@ public void onDataChanged() {
}
}

private static final int HTTP_ADD = 1;

@Override
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
switch (requestCode) {
case HTTP_ADD:
JSONResponse response = new JSONResponse(resultJson);
response = response.getJSONResponse(Moment.class.getSimpleName());

if (JSONResponse.isSuccess(response) == false) {
showShortToast("发布失败,请检查网络后重试");
} else {
runUiThread(new Runnable() {

@Override
public void run() {
showShortToast("发布成功");
lvBaseList.onRefresh();
}
});
}
break;
default:
super.onHttpResponse(requestCode, resultJson, e);
break;
}

}

//系统自带监听方法 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


Expand All @@ -363,14 +406,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case REQUEST_TO_EDIT_TEXT_INFO:
if (data != null) {
String value = StringUtil.getString(data.getStringExtra(EditTextInfoWindow.RESULT_VALUE));
String split = "";
JSONRequest search = new JSONRequest();
if (StringUtil.isNotEmpty(value, true)) {
split = ":";
search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER);

if (isAdd) {
HttpRequest.addMoment(value, HTTP_ADD, this);
} else {
String split = "";
JSONRequest search = new JSONRequest();
if (StringUtil.isNotEmpty(value, true)) {
split = ":";
search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER);
}
toActivity(MomentListActivity.createIntent(context, range, id, search, false)
.putExtra(INTENT_TITLE, "搜索" + split + value));
}
toActivity(MomentListActivity.createIntent(context, range, id, search, false)
.putExtra(INTENT_TITLE, "搜索" + split + value));
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Activity getActivity() {

public static final int TYPE_VERIFY = 0;
public static final int TYPE_REGISTER = 1;
public static final int TYPE_RESET = 3;
public static final int TYPE_RESET = 2;

private int type = TYPE_VERIFY;
private String phone;
Expand Down Expand Up @@ -212,7 +212,7 @@ private void getVerify() {

/**从服务器获取验证码
*/
private void getVerifyFromServer() {
private void getVerifyFromServer(int type) {
runUiThread(new Runnable() {

@Override
Expand All @@ -221,7 +221,7 @@ public void run() {
}
});

HttpRequest.getVerify(StringUtil.getTrimedString(etPasswordPhone), HTTP_GET_VERIFY, this);
HttpRequest.getVerify(type, StringUtil.getTrimedString(etPasswordPhone), HTTP_GET_VERIFY, this);
}

/**下一步
Expand All @@ -245,24 +245,28 @@ private void toNextStep() {
case TYPE_REGISTER:
register();
break;
default:
checkVerify(true);
case TYPE_VERIFY:
checkVerify(Verify.TYPE_LOGIN, true);
break;
case TYPE_RESET:
checkVerify(Verify.TYPE_PASSWORD, true);
break;
}
}

/**验证验证码
* @param type
* @param fromServer
*/
private boolean checkVerify(boolean fromServer) {
private boolean checkVerify(int type, boolean fromServer) {
if (EditTextUtil.isInputedCorrect(context, etPasswordPhone, EditTextUtil.TYPE_PHONE) == false
|| EditTextUtil.isInputedCorrect(context, etPasswordVerify, EditTextUtil.TYPE_VERIFY) == false) {
return false;
}

if (fromServer) {
showProgressDialog();
HttpRequest.checkVerify(StringUtil.getTrimedString(etPasswordPhone),
HttpRequest.checkVerify(type, StringUtil.getTrimedString(etPasswordPhone),
StringUtil.getTrimedString(etPasswordVerify), HTTP_CHECK_VERIFY, this);
}

Expand All @@ -271,7 +275,7 @@ private boolean checkVerify(boolean fromServer) {


private void register() {
if (checkVerify(false) == false) {
if (checkVerify(Verify.TYPE_REGISTER, false) == false) {
return;
}
showProgressDialog();
Expand Down Expand Up @@ -357,11 +361,11 @@ public void run() {
if (type == TYPE_REGISTER) {
showShortToast("手机号已经注册");
} else {
getVerifyFromServer();
getVerifyFromServer(type == TYPE_VERIFY ? Verify.TYPE_LOGIN : Verify.TYPE_PASSWORD);
}
} else {//手机号未被注册过
if (type == TYPE_REGISTER) {
getVerifyFromServer();
getVerifyFromServer(Verify.TYPE_REGISTER);
} else {
showShortToast("手机号未注册");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,15 @@ public void onDragBottom(boolean rightToLeft) {
if (searchType <= 0) {
searchType = EditTextInfoWindow.TYPE_PHONE;
}
if (searchType == EditTextInfoWindow.TYPE_NAME) {
// if (searchType == EditTextInfoWindow.TYPE_NAME) {
toActivity(EditTextInfoWindow.createIntent(context
, EditTextInfoWindow.TYPE_NAME, "姓名", null),
REQUEST_TO_EDIT_TEXT_INFO_SEARCH, false);
} else {
toActivity(EditTextInfoWindow.createIntent(context
, EditTextInfoWindow.TYPE_PHONE, "手机号", null),
REQUEST_TO_EDIT_TEXT_INFO_ADD, false);
}
// } else {
// toActivity(EditTextInfoWindow.createIntent(context
// , EditTextInfoWindow.TYPE_PHONE, "手机号", null),
// REQUEST_TO_EDIT_TEXT_INFO_ADD, false);
// }
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

package apijson.demo.client.model;

import zuo.biao.library.util.StringUtil;


/**验证码类
* @author Lemon
*/
Expand All @@ -26,32 +23,15 @@ public class Verify extends apijson.demo.server.model.Verify {
public Verify() {
super();
}
public Verify(long phone) {
super(phone);

public Verify(int type, String phone) {
super(type, phone);
}
public Verify(String verify) {
this();
setVerify(verify);
}



@Override
public Long getId() {
return value(super.getId());
}

/**服务器用id作为phone
* @return
*/
public String getPhone() {
return "" + getId();
}
public Verify setPhone(String phone) {
setId(Long.valueOf(0 + StringUtil.getNumber(phone)));
return this;
}
public Verify setPhone(Long phone) {
setId(Long.valueOf(0 + StringUtil.getNumber(phone)));
return this;
}

}
Loading

0 comments on commit a907f71

Please sign in to comment.