Skip to content

Commit ae35ac4

Browse files
committed
Client:新增发动态;与Server同步公共代码;改服务器地址
1 parent 427bf9b commit ae35ac4

File tree

8 files changed

+125
-32
lines changed

8 files changed

+125
-32
lines changed

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/MomentListActivity.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.content.Intent;
2020
import android.os.Bundle;
2121
import android.view.View;
22+
import android.widget.ImageView;
2223

2324
import com.alibaba.fastjson.JSONObject;
2425

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

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

138+
private boolean isCurrentUser = false;
139+
140+
private ImageView ivMomentListForward;
137141
private MomentListFragment fragment;
138142
@Override
139143
public void initView() {//必须在onCreate方法内调用
144+
ivMomentListForward = (ImageView) findViewById(R.id.ivMomentListForward);
145+
ivMomentListForward.setVisibility(showSearch ? View.VISIBLE : View.GONE);
146+
140147
String title;
141148
switch (range) {
142149
case MomentListFragment.RANGE_ALL:
@@ -146,7 +153,14 @@ public void initView() {//必须在onCreate方法内调用
146153
// title = "动态";
147154
// break;
148155
case MomentListFragment.RANGE_USER:
149-
title = APIJSONApplication.getInstance().isCurrentUser(id) ? "我的动态" : "TA的动态";
156+
isCurrentUser = APIJSONApplication.getInstance().isCurrentUser(id);
157+
title = isCurrentUser ? "我的动态" : "TA的动态";
158+
if (isCurrentUser) {
159+
ivMomentListForward.setVisibility(View.VISIBLE);
160+
ivMomentListForward.setImageResource(R.drawable.add);
161+
} else {
162+
ivMomentListForward.setVisibility(View.GONE);
163+
}
150164
break;
151165
case MomentListFragment.RANGE_USER_CIRCLE:
152166
title = "朋友圈";
@@ -158,10 +172,9 @@ public void initView() {//必须在onCreate方法内调用
158172
tvBaseTitle.setText(title);
159173
autoSetTitle();
160174

161-
findViewById(R.id.ivMomentListForward).setVisibility(showSearch ? View.VISIBLE : View.GONE);
162-
163175

164176
fragment = MomentListFragment.createInstance(range, id, search);
177+
fragment.setIsAdd(isCurrentUser);
165178

166179
fragmentManager
167180
.beginTransaction()

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/MomentListFragment.java

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import apijson.demo.client.application.APIJSONApplication;
3838
import apijson.demo.client.base.BaseHttpListFragment;
3939
import apijson.demo.client.interfaces.TopBarMenuCallback;
40+
import apijson.demo.client.model.Moment;
4041
import apijson.demo.client.model.MomentItem;
4142
import apijson.demo.client.util.CommentUtil;
4243
import apijson.demo.client.util.HttpRequest;
@@ -204,7 +205,7 @@ public void refreshAdapter() {
204205
});
205206
}
206207

207-
208+
208209
private TextView leftMenu;
209210
@SuppressLint("InflateParams")
210211
@Override
@@ -261,6 +262,12 @@ public void initData() {//必须调用
261262

262263
}
263264

265+
private boolean isAdd = false;
266+
public void setIsAdd(boolean isAdd) {
267+
this.isAdd = isAdd;
268+
}
269+
270+
264271
@Override
265272
public void getListAsync(final int page) {
266273
HttpRequest.getMomentList(range, id, search, getCacheCount(), page, -page, this);
@@ -332,10 +339,17 @@ public void onDragBottom(boolean rightToLeft) {
332339
return;
333340
}
334341

335-
showShortToast("输入为空则查看全部");
336-
toActivity(EditTextInfoWindow.createIntent(context
337-
, EditTextInfoWindow.TYPE_NAME, "关键词", null),
338-
REQUEST_TO_EDIT_TEXT_INFO, false);
342+
if (isAdd) {
343+
toActivity(EditTextInfoWindow.createIntent(context
344+
, EditTextInfoWindow.TYPE_NOTE, "发动态", "说点什么吧~"),
345+
REQUEST_TO_EDIT_TEXT_INFO, false);
346+
} else {
347+
showShortToast("输入为空则查看全部");
348+
toActivity(EditTextInfoWindow.createIntent(context
349+
, EditTextInfoWindow.TYPE_NAME, "关键词", null),
350+
REQUEST_TO_EDIT_TEXT_INFO, false);
351+
}
352+
339353
}
340354
}
341355

@@ -346,6 +360,35 @@ public void onDataChanged() {
346360
}
347361
}
348362

363+
private static final int HTTP_ADD = 1;
364+
365+
@Override
366+
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
367+
switch (requestCode) {
368+
case HTTP_ADD:
369+
JSONResponse response = new JSONResponse(resultJson);
370+
response = response.getJSONResponse(Moment.class.getSimpleName());
371+
372+
if (JSONResponse.isSuccess(response) == false) {
373+
showShortToast("发布失败,请检查网络后重试");
374+
} else {
375+
runUiThread(new Runnable() {
376+
377+
@Override
378+
public void run() {
379+
showShortToast("发布成功");
380+
lvBaseList.onRefresh();
381+
}
382+
});
383+
}
384+
break;
385+
default:
386+
super.onHttpResponse(requestCode, resultJson, e);
387+
break;
388+
}
389+
390+
}
391+
349392
//系统自带监听方法 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
350393

351394

@@ -363,14 +406,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
363406
case REQUEST_TO_EDIT_TEXT_INFO:
364407
if (data != null) {
365408
String value = StringUtil.getString(data.getStringExtra(EditTextInfoWindow.RESULT_VALUE));
366-
String split = "";
367-
JSONRequest search = new JSONRequest();
368-
if (StringUtil.isNotEmpty(value, true)) {
369-
split = ":";
370-
search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER);
409+
410+
if (isAdd) {
411+
HttpRequest.addMoment(value, HTTP_ADD, this);
412+
} else {
413+
String split = "";
414+
JSONRequest search = new JSONRequest();
415+
if (StringUtil.isNotEmpty(value, true)) {
416+
split = ":";
417+
search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER);
418+
}
419+
toActivity(MomentListActivity.createIntent(context, range, id, search, false)
420+
.putExtra(INTENT_TITLE, "搜索" + split + value));
371421
}
372-
toActivity(MomentListActivity.createIntent(context, range, id, search, false)
373-
.putExtra(INTENT_TITLE, "搜索" + split + value));
374422
}
375423
break;
376424
default:

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/UserListFragment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@ public void onDragBottom(boolean rightToLeft) {
337337
if (searchType <= 0) {
338338
searchType = EditTextInfoWindow.TYPE_PHONE;
339339
}
340-
if (searchType == EditTextInfoWindow.TYPE_NAME) {
340+
// if (searchType == EditTextInfoWindow.TYPE_NAME) {
341341
toActivity(EditTextInfoWindow.createIntent(context
342342
, EditTextInfoWindow.TYPE_NAME, "姓名", null),
343343
REQUEST_TO_EDIT_TEXT_INFO_SEARCH, false);
344-
} else {
345-
toActivity(EditTextInfoWindow.createIntent(context
346-
, EditTextInfoWindow.TYPE_PHONE, "手机号", null),
347-
REQUEST_TO_EDIT_TEXT_INFO_ADD, false);
348-
}
344+
// } else {
345+
// toActivity(EditTextInfoWindow.createIntent(context
346+
// , EditTextInfoWindow.TYPE_PHONE, "手机号", null),
347+
// REQUEST_TO_EDIT_TEXT_INFO_ADD, false);
348+
// }
349349
}
350350

351351
}

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/util/HttpRequest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,25 @@ public static void praiseMoment(long id, boolean toPraise, int requestCode, OnHt
571571
put(new JSONRequest(MOMENT_, data).setTag(MOMENT_), requestCode, listener);
572572
}
573573

574+
/**新增动态
575+
* @param content
576+
* @param requestCode
577+
* @param listener
578+
*/
579+
public static void addMoment(String content, int requestCode, OnHttpResponseListener listener) {
580+
List<String> list = new ArrayList<String>();
581+
list.add("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000");
582+
list.add("http://common.cnblogs.com/images/icon_weibo_24.png");
583+
584+
post(new JSONRequest(
585+
new Moment()
586+
.setUserId(application.getCurrentUserId())
587+
.setContent(content)
588+
.setPictureList(list)
589+
).setTag(MOMENT_)
590+
, requestCode, listener);
591+
}
592+
574593
/**删除动态
575594
* @param id
576595
* @param requestCode
@@ -580,6 +599,7 @@ public static void deleteMoment(Long id, int requestCode, OnHttpResponseListener
580599
delete(new JSONRequest(new Moment(id)).setTag(MOMENT_), requestCode, listener);
581600
}
582601

602+
583603
//Moment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
584604

585605

APIJSON-Android/APIJSON-ADT/APIJSONApp/ZBLibrary/src/zuo/biao/library/util/SettingUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ public static boolean noDisturb() {
229229
/**
230230
* TODO 改为你的正式服务器地址
231231
*/
232-
public static final String URL_SERVER_ADDRESS_NORMAL_HTTP = "http://139.196.140.118:8080/";//正式服务器
232+
public static final String URL_SERVER_ADDRESS_NORMAL_HTTP = "http://39.108.143.172:8080/";//正式服务器
233233
/**
234234
* TODO 改为你的正式服务器地址
235235
*/
236-
public static final String URL_SERVER_ADDRESS_NORMAL_HTTPS = "http://192.168.43.52:8080/";//正式服务器
236+
public static final String URL_SERVER_ADDRESS_NORMAL_HTTPS = "http://39.108.143.172:8080/";//正式服务器
237237
/**
238238
* TODO 改为你的测试服务器地址,如果有的话
239239
*/
240-
public static final String URL_SERVER_ADDRESS_TEST = "http://192.168.0.118:8080/";//测试服务器
240+
public static final String URL_SERVER_ADDRESS_TEST = "http://192.168.0.100:8080/";//测试服务器
241241

242242
/**获取当前服务器地址
243243
* isHttps = false

APIJSON-Android/APIJSON-ADT/APIJSONLibrary/src/zuo/biao/apijson/StringUtil.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,23 +737,35 @@ public static String[] split(String s) {
737737
return split(s, null);
738738
}
739739
/**将s用split分割成String[]
740+
* trim = true;
740741
* @param s
741742
* @param split
742743
* @return
743744
*/
744745
public static String[] split(String s, String split) {
746+
return split(s, split, true);
747+
}
748+
/**将s用split分割成String[]
749+
* @param s
750+
* @param split
751+
* @param trim 去掉前后两端的split
752+
* @return
753+
*/
754+
public static String[] split(String s, String split, boolean trim) {
745755
s = getString(s);
746756
if (s.isEmpty()) {
747757
return null;
748758
}
749759
if (isNotEmpty(split, false) == false) {
750760
split = ",";
751761
}
752-
while (s.startsWith(split)) {
753-
s = s.substring(split.length());
754-
}
755-
while (s.endsWith(split)) {
756-
s = s.substring(0, s.length() - split.length());
762+
if (trim) {
763+
while (s.startsWith(split)) {
764+
s = s.substring(split.length());
765+
}
766+
while (s.endsWith(split)) {
767+
s = s.substring(0, s.length() - split.length());
768+
}
757769
}
758770
return s.contains(split) ? s.split(split) : new String[]{s};
759771
}

APIJSON-Android/APIJSON-ADT/APIJSONTest/src/apijson/demo/ui/RequestActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected void onCreate(Bundle savedInstanceState) {
121121

122122

123123
etRequestUrl.setText(StringUtil.getString(StringUtil.isNotEmpty(url, true)
124-
? url : "http://139.196.140.118:8080/"));//TODO 把这个ip地址改成你自己服务器的
124+
? url : "http://39.108.143.172:8080/"));//TODO 把这个ip地址改成你自己服务器的
125125
btnRequestRequest.setText(method);
126126

127127
error = String.format(getResources().getString(R.string.request_error), StringUtil.getTrimedString(btnRequestRequest));

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/zuo/biao/apijson/RequestMethod.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public enum RequestMethod {
5757

5858
/**是否为GET请求方法
5959
* @param method
60-
* @param containPrivate 包含私密(非明文)获取方法POST_GET
60+
* @param containPrivate 包含私密(非明文)获取方法GETS
6161
* @return
6262
*/
6363
public static boolean isGetMethod(RequestMethod method, boolean containPrivate) {
@@ -67,7 +67,7 @@ public static boolean isGetMethod(RequestMethod method, boolean containPrivate)
6767

6868
/**是否为HEAD请求方法
6969
* @param method
70-
* @param containPrivate 包含私密(非明文)获取方法POST_HEAD
70+
* @param containPrivate 包含私密(非明文)获取方法HEADS
7171
* @return
7272
*/
7373
public static boolean isHeadMethod(RequestMethod method, boolean containPrivate) {

0 commit comments

Comments
 (0)