Skip to content

Commit f826435

Browse files
committed
Client:同步adt版至studio版;优化数据排序;解决删除动态崩溃
1 parent 99c9635 commit f826435

16 files changed

Lines changed: 86 additions & 327 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/adapter/MomentAdapter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public void onDataChanged() {
4545
}
4646
MomentItem data = itemView.getData();
4747
if (data == null) {
48-
list.remove(itemView.getPosition());
48+
if (itemView.getPosition() >= 0 && itemView.getPosition() < list.size()) {
49+
list.remove(itemView.getPosition());
50+
notifyDataSetChanged();
51+
}
4952
} else {
5053
list.set(itemView.getPosition(), data);
5154
itemView.bindView(data);

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public static void delete(JSONObject request, int requestCode, OnHttpResponseLis
142142
public static final String KEY_TYPE = "type";
143143

144144

145+
146+
public static final String DATE_UP = "date+";//同 "date ASC"
147+
public static final String DATE_DOWN = "date-";//同 "date DESC"
148+
145149
public static final String ID_AT = KEY_ID + "@";
146150
public static final String USER_ID_AT = KEY_USER_ID + "@";
147151
public static final String MOMENT_ID_AT = "momentId@";
@@ -315,9 +319,10 @@ public static void getUserList(int range, long id, com.alibaba.fastjson.JSONObje
315319
if (idList != null) {
316320
userItem.put(ID_IN, idList);
317321
} else {
322+
apijson.demo.client.model.User currentUser = APIJSONApplication.getInstance().getCurrentUser();
318323
switch (range) {
319-
case RANGE_ALL:
320-
//do nothing
324+
case RANGE_ALL://1.首推注册时间长的(也可以是级别高的);2.给男性用户首推女性用户
325+
userItem.setOrder(DATE_UP + (currentUser.getSex() == 0 ? ",sex-" : ""));
321326
break;
322327
case RANGE_SINGLE:
323328
case RANGE_USER:
@@ -329,7 +334,6 @@ public static void getUserList(int range, long id, com.alibaba.fastjson.JSONObje
329334
Log.e(TAG, "只允许查看当前用户的!");
330335
return;
331336
}
332-
apijson.demo.client.model.User currentUser = APIJSONApplication.getInstance().getCurrentUser();
333337
List<Long> list = currentUser == null ? null : currentUser.getFriendIdList();
334338
if (list == null) {//不能放在range == RANGE_USER_CIRCLE里面,为null不会当成查询条件!
335339
list = new ArrayList<Long>();
@@ -340,6 +344,7 @@ public static void getUserList(int range, long id, com.alibaba.fastjson.JSONObje
340344
list.remove(currentUser.getId());//避免误添加
341345
}
342346
userItem.put(ID_IN, list);
347+
userItem.setOrder("name+");
343348
break;
344349
case RANGE_MOMENT:
345350
JSONObject moment = new JSONObject(new Moment(id));
@@ -383,12 +388,12 @@ public static void getMoment(long id, int requestCode, OnHttpResponseListener li
383388

384389
JSONRequest request = new JSONRequest(new Moment(id));
385390
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Moment/userId"));
386-
// //praise <<<<<<<<<<<<<<<<<<
387-
// JSONRequest userItem = new JSONRequest();
388-
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "Moment/praiseUserIdList")
389-
// .setColumn(COLUMNS_USER_SIMPLE));
390-
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
391-
// //praise >>>>>>>>>>>>>>>>>>
391+
// //praise <<<<<<<<<<<<<<<<<<
392+
// JSONRequest userItem = new JSONRequest();
393+
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "Moment/praiseUserIdList")
394+
// .setColumn(COLUMNS_USER_SIMPLE));
395+
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
396+
// //praise >>>>>>>>>>>>>>>>>>
392397

393398
get(request, requestCode, listener);
394399
}
@@ -437,22 +442,23 @@ public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONOb
437442
default:
438443
break;
439444
}
445+
moment.setOrder(DATE_DOWN);
440446
moment.add(search);
441447

442448
request.put(Moment.class.getSimpleName(), moment);
443449
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Moment/userId").setColumn(COLUMNS_USER));
444450

445-
// //praise <<<<<<<<<<<<<<<<<<
446-
// JSONRequest userItem = new JSONRequest();
447-
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "[]/Moment/praiseUserIdList")
448-
// .setColumn(COLUMNS_USER_SIMPLE));
449-
//
450-
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
451+
// //praise <<<<<<<<<<<<<<<<<<
452+
// JSONRequest userItem = new JSONRequest();
453+
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "[]/Moment/praiseUserIdList")
454+
// .setColumn(COLUMNS_USER_SIMPLE));
455+
//
456+
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
451457
//praise >>>>>>>>>>>>>>>>>>
452458

453459
//comment <<<<<<<<<<<<<<<<<<
454460
JSONRequest commentItem = new JSONRequest();
455-
commentItem.put(Comment.class.getSimpleName(), new JSONRequest(MOMENT_ID_AT, "[]/Moment/id"));
461+
commentItem.put(Comment.class.getSimpleName(), new JSONRequest(MOMENT_ID_AT, "[]/Moment/id").setOrder(DATE_UP));
456462
commentItem.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Comment/userId")
457463
.setColumn(COLUMNS_USER_SIMPLE));
458464

@@ -472,7 +478,8 @@ public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONOb
472478
public static void getCommentList(long momentId, int count, int page
473479
, int requestCode, OnHttpResponseListener listener) {
474480
JSONRequest request = new JSONRequest();
475-
request.put(new Comment().setMomentId(momentId));
481+
JSONObject comment = new JSONObject(new Comment().setMomentId(momentId));
482+
request.put(Comment.class.getSimpleName(), comment.setOrder(DATE_UP));
476483
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Comment/userId").setColumn(COLUMNS_USER));
477484
get(request.toArray(count, page), requestCode, listener);
478485
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ public void onHttpResponse(int requestCode, String result, Exception e) {
441441
data.setMyStatus(MomentItem.STATUS_NORMAL);
442442
bindView(data);
443443
}
444+
break;
444445
case HTTP_GET_PRAISE:
445446
if (response.isSucceed()) {
446447
List<User> list = response.getList(User.class.getSimpleName() + "[]", User.class);

APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MainTabActivity.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,6 @@ protected Fragment getFragment(int position) {
134134
default:
135135
return MomentListFragment.createInstance();
136136
}
137-
// switch (position) {
138-
// case 1:
139-
// UserListFragment fragment = UserListFragment.createInstance(isLoggedIn ?
140-
// MomentListFragment.RANGE_USER_CIRCLE : MomentListFragment.RANGE_ALL,
141-
// currentUserId);
142-
// fragment.setSearchType(EditTextInfoWindow.TYPE_NAME);
143-
// return fragment;
144-
// case 2:
145-
// return SettingFragment.createInstance();
146-
// default:
147-
// return MomentListFragment.createInstance(isLoggedIn ?
148-
// MomentListFragment.RANGE_USER_CIRCLE : MomentListFragment.RANGE_ALL,
149-
// currentUserId);
150-
// }
151137
}
152138

153139
private static final String[] TAB_NAMES = {"圈子", "朋友", "我的"};
@@ -315,8 +301,7 @@ public void onReceive(Context context, Intent intent) {
315301
}
316302

317303
if (ActionUtil.ACTION_RELOAD_CURRENT_USER.equals(action)) {
318-
// fragmentManager show remove等都会崩溃
319-
reloadAll();
304+
reloadAll();// fragmentManager show remove等都会崩溃
320305
}
321306
}
322307
};

APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/ScanActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import android.content.Context;
2121
import android.content.Intent;
2222
import android.os.Bundle;
23-
import android.view.SurfaceHolder.Callback;
2423
import android.view.SurfaceView;
2524
import android.view.View;
2625
import android.view.View.OnClickListener;
@@ -34,7 +33,7 @@
3433
* @author Lemon
3534
* @use toActivity(ScanActivity.createIntent(...));
3635
*/
37-
public class ScanActivity extends CaptureActivity implements Callback, ActivityPresenter, OnClickListener {
36+
public class ScanActivity extends CaptureActivity implements ActivityPresenter, OnClickListener {
3837
public static final String TAG = "ScanActivity";
3938

4039
//启动方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONApp/app/src/main/java/apijson/demo/client/adapter/MomentAdapter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public void onDataChanged() {
4545
}
4646
MomentItem data = itemView.getData();
4747
if (data == null) {
48-
list.remove(itemView.getPosition());
48+
if (itemView.getPosition() >= 0 && itemView.getPosition() < list.size()) {
49+
list.remove(itemView.getPosition());
50+
notifyDataSetChanged();
51+
}
4952
} else {
5053
list.set(itemView.getPosition(), data);
5154
itemView.bindView(data);

APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONApp/app/src/main/java/apijson/demo/client/util/FunctionUtil.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

APIJSON(Android)/APIJSON(AndroidStudio)/APIJSONApp/app/src/main/java/apijson/demo/client/util/HttpRequest.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public static void delete(JSONObject request, int requestCode, OnHttpResponseLis
142142
public static final String KEY_TYPE = "type";
143143

144144

145+
146+
public static final String DATE_UP = "date+";//同 "date ASC"
147+
public static final String DATE_DOWN = "date-";//同 "date DESC"
148+
145149
public static final String ID_AT = KEY_ID + "@";
146150
public static final String USER_ID_AT = KEY_USER_ID + "@";
147151
public static final String MOMENT_ID_AT = "momentId@";
@@ -315,9 +319,10 @@ public static void getUserList(int range, long id, com.alibaba.fastjson.JSONObje
315319
if (idList != null) {
316320
userItem.put(ID_IN, idList);
317321
} else {
322+
apijson.demo.client.model.User currentUser = APIJSONApplication.getInstance().getCurrentUser();
318323
switch (range) {
319-
case RANGE_ALL:
320-
//do nothing
324+
case RANGE_ALL://1.首推注册时间长的(也可以是级别高的);2.给男性用户首推女性用户
325+
userItem.setOrder(DATE_UP + (currentUser.getSex() == 0 ? ",sex-" : ""));
321326
break;
322327
case RANGE_SINGLE:
323328
case RANGE_USER:
@@ -329,7 +334,6 @@ public static void getUserList(int range, long id, com.alibaba.fastjson.JSONObje
329334
Log.e(TAG, "只允许查看当前用户的!");
330335
return;
331336
}
332-
apijson.demo.client.model.User currentUser = APIJSONApplication.getInstance().getCurrentUser();
333337
List<Long> list = currentUser == null ? null : currentUser.getFriendIdList();
334338
if (list == null) {//不能放在range == RANGE_USER_CIRCLE里面,为null不会当成查询条件!
335339
list = new ArrayList<Long>();
@@ -340,6 +344,7 @@ public static void getUserList(int range, long id, com.alibaba.fastjson.JSONObje
340344
list.remove(currentUser.getId());//避免误添加
341345
}
342346
userItem.put(ID_IN, list);
347+
userItem.setOrder("name+");
343348
break;
344349
case RANGE_MOMENT:
345350
JSONObject moment = new JSONObject(new Moment(id));
@@ -383,12 +388,12 @@ public static void getMoment(long id, int requestCode, OnHttpResponseListener li
383388

384389
JSONRequest request = new JSONRequest(new Moment(id));
385390
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Moment/userId"));
386-
// //praise <<<<<<<<<<<<<<<<<<
387-
// JSONRequest userItem = new JSONRequest();
388-
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "Moment/praiseUserIdList")
389-
// .setColumn(COLUMNS_USER_SIMPLE));
390-
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
391-
// //praise >>>>>>>>>>>>>>>>>>
391+
// //praise <<<<<<<<<<<<<<<<<<
392+
// JSONRequest userItem = new JSONRequest();
393+
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "Moment/praiseUserIdList")
394+
// .setColumn(COLUMNS_USER_SIMPLE));
395+
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
396+
// //praise >>>>>>>>>>>>>>>>>>
392397

393398
get(request, requestCode, listener);
394399
}
@@ -437,22 +442,23 @@ public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONOb
437442
default:
438443
break;
439444
}
445+
moment.setOrder(DATE_DOWN);
440446
moment.add(search);
441447

442448
request.put(Moment.class.getSimpleName(), moment);
443449
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Moment/userId").setColumn(COLUMNS_USER));
444450

445-
// //praise <<<<<<<<<<<<<<<<<<
446-
// JSONRequest userItem = new JSONRequest();
447-
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "[]/Moment/praiseUserIdList")
448-
// .setColumn(COLUMNS_USER_SIMPLE));
449-
//
450-
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
451+
// //praise <<<<<<<<<<<<<<<<<<
452+
// JSONRequest userItem = new JSONRequest();
453+
// userItem.put(User.class.getSimpleName(), new JSONRequest(ID_IN+"@", "[]/Moment/praiseUserIdList")
454+
// .setColumn(COLUMNS_USER_SIMPLE));
455+
//
456+
// request.add(userItem.toArray(20, 0, User.class.getSimpleName()));
451457
//praise >>>>>>>>>>>>>>>>>>
452458

453459
//comment <<<<<<<<<<<<<<<<<<
454460
JSONRequest commentItem = new JSONRequest();
455-
commentItem.put(Comment.class.getSimpleName(), new JSONRequest(MOMENT_ID_AT, "[]/Moment/id"));
461+
commentItem.put(Comment.class.getSimpleName(), new JSONRequest(MOMENT_ID_AT, "[]/Moment/id").setOrder(DATE_UP));
456462
commentItem.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Comment/userId")
457463
.setColumn(COLUMNS_USER_SIMPLE));
458464

@@ -472,7 +478,8 @@ public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONOb
472478
public static void getCommentList(long momentId, int count, int page
473479
, int requestCode, OnHttpResponseListener listener) {
474480
JSONRequest request = new JSONRequest();
475-
request.put(new Comment().setMomentId(momentId));
481+
JSONObject comment = new JSONObject(new Comment().setMomentId(momentId));
482+
request.put(Comment.class.getSimpleName(), comment.setOrder(DATE_UP));
476483
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Comment/userId").setColumn(COLUMNS_USER));
477484
get(request.toArray(count, page), requestCode, listener);
478485
}

0 commit comments

Comments
 (0)