Skip to content

Commit f95d9d2

Browse files
committed
Client:忽略bin,gen,build;完成点赞
1 parent e64f304 commit f95d9d2

4 files changed

Lines changed: 84 additions & 48 deletions

File tree

.gitignore

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
.DS_Store
2-
APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/bin
2+
APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/bin
3+
APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/gen
4+
5+
APIJSON(Android)/APIJSON(ADT)/APIJSONApp/QRCodeLibrary/bin
6+
APIJSON(Android)/APIJSON(ADT)/APIJSONApp/QRCodeLibrary/gen
7+
8+
APIJSON(Android)/APIJSON(ADT)/APIJSONApp/ZBLibrary/bin
9+
APIJSON(Android)/APIJSON(ADT)/APIJSONApp/ZBLibrary/gen
10+
311
APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/bin
12+
APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/gen
13+
14+
APIJSON(Android)/APIJSON(ADT)/APIJSONTest/bin
15+
APIJSON(Android)/APIJSON(ADT)/APIJSONTest/gen
16+
17+
18+
APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONTest/build
19+
APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONTest/APIJSONLibrary/build
20+
APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONTest/app/build
21+
422

523
*.class

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/model/MomentItem.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public boolean getIsPraised(final long userId) {
140140
}
141141
return value(isPraised);
142142
}
143+
public MomentItem setIsPraised(boolean isPraised) {
144+
return setIsPraised(isPraised, APIJSONApplication.getInstance().getCurrentUserId());
145+
}
143146
public MomentItem setIsPraised(boolean isPraised, long userId) {
144147
this.isPraised = isPraised;
145148

@@ -154,6 +157,7 @@ public MomentItem setIsPraised(boolean isPraised, long userId) {
154157
list.add(userId);
155158
}
156159
}
160+
getMoment().setPraiseUserIdList(list);
157161

158162
return this;
159163
}
@@ -196,12 +200,14 @@ public MomentItem setIsCommented(boolean isCommented, long userId) {
196200
list.add(userId);
197201
}
198202
}
203+
getMoment().setCommentIdList(list);
204+
199205
return this;
200206
}
201207

202-
// public int getCommentCount() {
203-
// return getMoment().getCommentCount();
204-
// }
208+
// public int getCommentCount() {
209+
// return getMoment().getCommentCount();
210+
// }
205211

206212
private int commentCount;
207213
public int getCommentCount() {

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,17 @@ public static void getMoment(long id, int requestCode, OnHttpResponseListener li
346346
// moment.put("praiseCount()", "count(Collection:praiseUserIdList)");//测试成功
347347
// moment.put("praised()", "isContain(Collection:praiseUserIdList, userId)");//测试成功
348348
// moment.put("plus()", "plus(long:id,long:userId)");//测试成功
349-
// moment.put("@commentCount@", "Comment[]/total");
349+
// moment.put("@commentCount@", "Comment[]/total");
350350
request.put(Moment.class.getSimpleName(), moment);
351351

352352
// request.put(new Moment(id));
353353
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Moment/userId"));
354354

355355
JSONRequest commentItem = new JSONRequest();
356356
commentItem.put(Comment.class.getSimpleName(), new JSONRequest(MOMENT_ID_AT, "Moment/id"));
357-
// commentItem.put("release", "total:Moment/commentCount");
357+
// commentItem.put("release", "total:Moment/commentCount");
358358
request.add(commentItem.toArray(3, 0, Comment.class.getSimpleName()));
359-
// request.put("commentCount@", "Comment[]/total");
359+
// request.put("commentCount@", "Comment[]/total");
360360
get(request, requestCode, listener);
361361
}
362362

@@ -372,8 +372,8 @@ public static void getMoment(long id, int requestCode, OnHttpResponseListener li
372372
public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONObject search
373373
, int count, int page, int requestCode, OnHttpResponseListener listener) {
374374
JSONRequest request = new JSONRequest();
375-
// request.put("commentCount@", "[]/CommentItem[]/total");
376-
375+
// request.put("commentCount@", "[]/CommentItem[]/total");
376+
377377
JSONRequest moment = new JSONRequest();
378378
switch (range) {
379379
case RANGE_ALL:
@@ -404,7 +404,7 @@ public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONOb
404404
default:
405405
break;
406406
}
407-
// moment.put("@commentCount@", "[]/CommentItem[]/total");
407+
// moment.put("@commentCount@", "[]/CommentItem[]/total");
408408
moment.add(search);
409409
//测试远程函数调用成功
410410
// moment.put("praiseCount()", "count(Collection:praiseUserIdList)");
@@ -417,16 +417,16 @@ public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONOb
417417
JSONRequest commentItem = new JSONRequest();
418418
commentItem.put(Comment.class.getSimpleName(), new JSONRequest(MOMENT_ID_AT, "[]/Moment/id"));
419419
commentItem.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Comment/userId").setColumns(COLUMNS_USER));
420-
420+
421421
JSONObject toUserObject = new JSONObject();
422422
toUserObject.put(User.class.getSimpleName()
423423
, new JSONRequest(ID_AT, "[]/CommentItem[]/Comment/toUserId").setColumns(COLUMNS_USER_SIMPLE));
424424
commentItem.put("toUserObject", toUserObject);
425-
426-
// commentItem.put("release", "total:[]/Moment/commentCount");
425+
426+
// commentItem.put("release", "total:[]/Moment/commentCount");
427427
request.add(commentItem.toArray(3, 0, CommentItem.class.getSimpleName()));
428428
//comment >>>>>>>>>>>>>>>>>>
429-
429+
430430
get(request.toArray(count, page), requestCode, listener);
431431
}
432432

@@ -458,7 +458,12 @@ public static void getCommentList(long momentId, int count, int page
458458
* @param listener
459459
*/
460460
public static void praiseMoment(long id, boolean toPraise, int requestCode, OnHttpResponseListener listener) {
461-
get(null, requestCode, listener);
461+
JSONObject data = new JSONObject(new Moment(id));
462+
List<Long> list = new ArrayList<Long>();
463+
list.add(APIJSONApplication.getInstance().getCurrentUserId());
464+
data.put("praiseUserIdList" + (toPraise ? "+" : "-"), list, true);
465+
put(new JSONRequest(Moment.class.getSimpleName(), data).setTag(Moment.class.getSimpleName())
466+
, requestCode, listener);
462467
}
463468

464469
/**删除动态
@@ -467,7 +472,7 @@ public static void praiseMoment(long id, boolean toPraise, int requestCode, OnHt
467472
* @param listener
468473
*/
469474
public static void deleteMoment(Long id, int requestCode, OnHttpResponseListener listener) {
470-
get(null, requestCode, listener);
475+
delete(new JSONRequest(new Moment(id)).setTag(Moment.class.getSimpleName()), requestCode, listener);
471476
}
472477

473478
/**获取钱包

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/view/MomentView.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
import zuo.biao.apijson.JSONResponse;
67
import zuo.biao.library.base.BaseView;
78
import zuo.biao.library.manager.HttpManager.OnHttpResponseListener;
89
import zuo.biao.library.model.Entry;
@@ -137,8 +138,8 @@ public View createView(LayoutInflater inflater) {
137138
public void bindView(MomentItem data_){
138139
llMomentViewContainer.setVisibility(data_ == null ? View.GONE : View.VISIBLE);
139140
if (data_ == null) {
140-
Log.e(TAG, "bindView data_ == null >> return;");
141-
return;
141+
Log.w(TAG, "bindView data_ == null >> data_ = new MomentItem();");
142+
data_ = new MomentItem();
142143
}
143144
this.data = data_;
144145
this.user = data.getUser();
@@ -199,7 +200,7 @@ public void setComment(boolean joined, int total, List<CommentItem> list) {
199200
}
200201
tvMomentViewComment.setText(total <= 0 ? "评论" : "" + total);
201202
tvMomentViewComment.setTextColor(getColor(joined ? R.color.blue : R.color.black));
202-
203+
203204
if (showComment == false) {
204205
Log.i(TAG, "setComment showComment == false >> return;");
205206
return;
@@ -365,13 +366,13 @@ private boolean isLoggedIn() {
365366
/**赞
366367
* @param toPraise
367368
*/
368-
public void praiseWork(boolean toPraise) {
369-
// setPraise(toPraise, moment.getPraiseCount() + (toPraise ? 1 : -1));
370-
// if (toPraise == moment.getIsPraised()) {
371-
// Log.e(TAG, "praiseWork toPraise == moment.getIsPraise() >> return;");
372-
// return;
373-
// }
374-
HttpRequest.praiseMoment(momentId, toPraise, HTTP_PRAISE, this);
369+
public void praise(boolean toPraise) {
370+
if (toPraise == data.getIsPraised()) {
371+
Log.e(TAG, "praiseWork toPraise == moment.getIsPraise() >> return;");
372+
return;
373+
}
374+
// setPraise(toPraise, data.getPraiseCount() + (toPraise ? 1 : -1));
375+
HttpRequest.praiseMoment(momentId, toPraise, toPraise ? HTTP_PRAISE : HTTP_CANCLE_PRAISE, this);
375376
}
376377

377378
//Data数据区(存在数据获取或处理代码,但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -397,30 +398,36 @@ public void onDialogButtonClick(int requestCode, boolean isPositive) {
397398

398399

399400
public static final int HTTP_PRAISE = 1;
401+
public static final int HTTP_CANCLE_PRAISE = 2;
400402
public static final int HTTP_DELETE = 3;
401403
@Override
402404
public void onHttpResponse(int requestCode, String result, Exception e) {
403-
// switch (requestCode) {
404-
// case HTTP_PRAISE:
405-
// if(resultCode == HttpRequest.RESULT_PRAISE_WORK_SUCCEED) {
406-
// moment.setPraiseCount(moment.getPraiseCount() + 1);
407-
// moment.setIsPraise(true);
408-
// } else if (resultCode == HttpRequest.RESULT_CANCEL_PRAISE_WORK_SUCCEED) {
409-
// moment.setPraiseCount(moment.getPraiseCount() -1);
410-
// moment.setIsPraise(false);
411-
// }
412-
// setPraise(moment.getIsPraised(), moment.getPraiseCount());
413-
// break;
414-
// case HTTP_DELETE:
415-
// if(resultCode == HttpRequest.RESULT_DELETE_WORK_SUCCEED) {
416-
// context.sendBroadcast(new Intent(ActionUtil.REFRESH_WORK)
417-
// .putExtra(ActionUtil.TYPE, ActionUtil.TYPE_DELETE_WORK)
418-
// .putExtra(ActionUtil.RESULT_WORK, Json.toJSONString(moment)));
419-
// } else {
420-
// bindView(moment);
421-
// }
422-
// break;
423-
// }
405+
if (data == null) {
406+
Log.e(TAG, "onHttpResponse data == null >> return;");
407+
return;
408+
}
409+
JSONResponse response = new JSONResponse(result);
410+
switch (requestCode) {
411+
case HTTP_PRAISE:
412+
case HTTP_CANCLE_PRAISE:
413+
response = response.getJSONResponse(Moment.class.getSimpleName());
414+
if (JSONResponse.isSucceed(response)) {
415+
data.setIsPraised(requestCode == HTTP_PRAISE);
416+
bindView(data);
417+
} else {
418+
showShortToast((requestCode == HTTP_PRAISE ? "点赞" : "取消点赞") + "失败,请检查网络后重试");
419+
}
420+
break;
421+
// case HTTP_DELETE:
422+
// if(resultCode == HttpRequest.RESULT_DELETE_WORK_SUCCEED) {
423+
// context.sendBroadcast(new Intent(ActionUtil.REFRESH_WORK)
424+
// .putExtra(ActionUtil.TYPE, ActionUtil.TYPE_DELETE_WORK)
425+
// .putExtra(ActionUtil.RESULT_WORK, Json.toJSONString(moment)));
426+
// } else {
427+
// bindView(data);
428+
// }
429+
// break;
430+
}
424431
}
425432

426433

@@ -458,7 +465,7 @@ public void onClick(View v) {
458465
}
459466
switch (v.getId()) {
460467
case R.id.llMomentViewPraise:
461-
// praiseWork(! moment.getIsPraised());
468+
praise(! data.getIsPraised());
462469
break;
463470
case R.id.llMomentViewComment:
464471
toCommentActivity(true);

0 commit comments

Comments
 (0)