| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 47b6082 commit 58f8315
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,6 @@ | |||
| 43 | 43 | import apijson.demo.client.application.APIJSONApplication; | |
| 44 | 44 | import apijson.demo.client.base.BaseFragment; | |
| 45 | 45 | import apijson.demo.client.interfaces.TopBarMenuCallback; | |
| 46 | - import apijson.demo.client.model.Login; | ||
| 47 | 46 | import apijson.demo.client.model.User; | |
| 48 | 47 | import apijson.demo.client.util.HttpRequest; | |
| 49 | 48 | ||
@@ -320,7 +319,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) { | |||
| 320 | 319 | } | |
| 321 | 320 | switch (requestCode) { | |
| 322 | 321 | case HTTP_LOUOUT: | |
| 323 | - JSONResponse response = new JSONResponse(resultJson).getJSONResponse(Login.class.getSimpleName()); | ||
| 322 | + JSONResponse response = new JSONResponse(resultJson).getJSONResponse(User.class.getSimpleName()); | ||
| 324 | 323 | boolean succeed = JSONResponse.isSuccess(response); | |
| 325 | 324 | Log.d(TAG, succeed ? "服务端退出成功" : "服务端退出失败"); | |
| 326 | 325 | showShortToast(succeed ? "服务端退出成功" : "服务端退出失败"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,7 @@ | |||
| 33 | 33 | import android.widget.TextView; | |
| 34 | 34 | import apijson.demo.client.R; | |
| 35 | 35 | import apijson.demo.client.util.HttpRequest; | |
| 36 | - import apijson.demo.server.model.Password; | ||
| 36 | + import apijson.demo.server.model.Privacy; | ||
| 37 | 37 | ||
| 38 | 38 | /**支付密码设置界面activity | |
| 39 | 39 | * @author Lemon | |
@@ -371,7 +371,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { | |||
| 371 | 371 | if (data != null) { | |
| 372 | 372 | password = data.getStringExtra(NumberPasswordActivity.RESULT_PASSWORD); | |
| 373 | 373 | if (StringUtil.isNotEmpty(password, true)) { | |
| 374 | - HttpRequest.setPassword(Password.TYPE_PAY, password, phone, verify | ||
| 374 | + HttpRequest.setPassword(Privacy.PASSWORD_TYPE_PAY, password, phone, verify | ||
| 375 | 375 | , HTTP_SET_PASSWORD, this); | |
| 376 | 376 | } | |
| 377 | 377 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,6 @@ | |||
| 29 | 29 | import android.view.View.OnClickListener; | |
| 30 | 30 | import android.widget.TextView; | |
| 31 | 31 | import apijson.demo.client.R; | |
| 32 | - import apijson.demo.client.model.Wallet; | ||
| 33 | 32 | import apijson.demo.client.util.HttpRequest; | |
| 34 | 33 | import apijson.demo.server.model.Privacy; | |
| 35 | 34 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | import zuo.biao.apijson.JSONObject; | |
| 21 | 21 | import zuo.biao.apijson.JSONRequest; | |
| 22 | 22 | import zuo.biao.apijson.JSONResponse; | |
| 23 | + import zuo.biao.apijson.RequestRole; | ||
| 23 | 24 | import zuo.biao.library.manager.HttpManager.OnHttpResponseListener; | |
| 24 | 25 | import zuo.biao.library.util.Log; | |
| 25 | 26 | import zuo.biao.library.util.SettingUtil; | |
@@ -30,11 +31,9 @@ | |||
| 30 | 31 | import apijson.demo.server.model.Comment; | |
| 31 | 32 | import apijson.demo.server.model.Login; | |
| 32 | 33 | import apijson.demo.server.model.Moment; | |
| 33 | - import apijson.demo.server.model.Password; | ||
| 34 | 34 | import apijson.demo.server.model.Privacy; | |
| 35 | 35 | import apijson.demo.server.model.User; | |
| 36 | 36 | import apijson.demo.server.model.Verify; | |
| 37 | - import apijson.demo.server.model.Wallet; | ||
| 38 | 37 | ||
| 39 | 38 | /**HTTP请求工具类 | |
| 40 | 39 | * @author Lemon | |
@@ -132,19 +131,17 @@ public static void delete(JSONObject request, int requestCode, OnHttpResponseLis | |||
| 132 | 131 | ||
| 133 | 132 | ||
| 134 | 133 | ||
| 135 | - //加 _ 表示class名,避免PASSWORD不知道是 Password 还是 password 这种冲突 | ||
| 134 | + //加 _ 表示class名,避免VERIFY不知道是 Verify 还是 verify 这种冲突 | ||
| 136 | 135 | public static final String USER_; | |
| 137 | 136 | public static final String PRIVACY_; | |
| 138 | 137 | public static final String MOMENT_; | |
| 139 | 138 | public static final String COMMENT_; | |
| 140 | - public static final String WALLET_; | ||
| 141 | 139 | public static final String VERIFY_; | |
| 142 | 140 | static { | |
| 143 | 141 | USER_ = User.class.getSimpleName(); | |
| 144 | 142 | PRIVACY_ = Privacy.class.getSimpleName(); | |
| 145 | 143 | MOMENT_ = Moment.class.getSimpleName(); | |
| 146 | 144 | COMMENT_ = Comment.class.getSimpleName(); | |
| 147 | - WALLET_ = Wallet.class.getSimpleName(); | ||
| 148 | 145 | VERIFY_ = Verify.class.getSimpleName(); | |
| 149 | 146 | } | |
| 150 | 147 | ||
@@ -157,7 +154,6 @@ public static void delete(JSONObject request, int requestCode, OnHttpResponseLis | |||
| 157 | 154 | ||
| 158 | 155 | public static final String ID = "id"; | |
| 159 | 156 | public static final String USER_ID = "userId"; | |
| 160 | - public static final String CURRENT_USER_ID = "currentUserId"; | ||
| 161 | 157 | ||
| 162 | 158 | public static final String NAME = "name"; | |
| 163 | 159 | public static final String PHONE = "phone"; | |
@@ -209,30 +205,12 @@ public static void delete(JSONObject request, int requestCode, OnHttpResponseLis | |||
| 209 | 205 | */ | |
| 210 | 206 | public static void register(String verify, String phone, String password, String name, int sex | |
| 211 | 207 | , int requestCode, OnHttpResponseListener listener) { | |
| 212 | - JSONObject request = new JSONRequest(new User().setName(name).setSex(sex)) | ||
| 213 | - .setTag(USER_); | ||
| 214 | - request.put(VERIFY, verify); | ||
| 215 | - request.put(PHONE, phone); | ||
| 216 | - request.put(PASSWORD, password); | ||
| 208 | + JSONObject request = new JSONRequest(new Privacy(phone, password)); | ||
| 209 | + request.puts(new User().setName(name).setSex(sex)); | ||
| 210 | + request.puts(VERIFY, verify); | ||
| 217 | 211 | HttpManager.getInstance().post(URL_BASE + "register", request, requestCode, listener); | |
| 218 | 212 | } | |
| 219 | - /**重置密码 | ||
| 220 | - * @param verify | ||
| 221 | - * @param phone | ||
| 222 | - * @param password | ||
| 223 | - * @param requestCode | ||
| 224 | - * @param listener | ||
| 225 | - */ | ||
| 226 | - public static void setPassword(String verify, String phone, String password | ||
| 227 | - , int requestCode, OnHttpResponseListener listener) { | ||
| 228 | - JSONRequest request = new JSONRequest(); | ||
| 229 | - request.put(PHONE, phone); | ||
| 230 | - request.put(VERIFY, verify); | ||
| 231 | - request.put(PASSWORD, password); | ||
| 232 | 213 | ||
| 233 | - HttpManager.getInstance().post(URL_BASE + "put/password" | ||
| 234 | - , request.setTag(PASSWORD), requestCode, listener); | ||
| 235 | - } | ||
| 236 | 214 | /** | |
| 237 | 215 | * @param phone | |
| 238 | 216 | * @param requestCode | |
@@ -253,22 +231,14 @@ public static void login(String phone, String password, int type, int requestCod | |||
| 253 | 231 | request.put(TYPE, type); | |
| 254 | 232 | request.put(PHONE, phone); | |
| 255 | 233 | request.put(PASSWORD, password); | |
| 256 | - HttpManager.getInstance().post( | ||
| 257 | - URL_BASE + "login/" | ||
| 258 | - , request.setTag(Login.class.getSimpleName()) | ||
| 259 | - , requestCode, listener | ||
| 260 | - ); | ||
| 234 | + HttpManager.getInstance().post(URL_BASE + "login/", request, requestCode, listener); | ||
| 261 | 235 | } | |
| 262 | 236 | /**退出登录 | |
| 263 | 237 | * @param requestCode | |
| 264 | 238 | * @param listener | |
| 265 | 239 | */ | |
| 266 | 240 | public static void logout(int requestCode, OnHttpResponseListener listener) { | |
| 267 | - HttpManager.getInstance().post( | ||
| 268 | - URL_BASE + "logout/" | ||
| 269 | - , new JSONRequest().setTag(Login.class.getSimpleName()) | ||
| 270 | - , requestCode, listener | ||
| 271 | - ); | ||
| 241 | + HttpManager.getInstance().post(URL_BASE + "logout/", new JSONRequest(), requestCode, listener); | ||
| 272 | 242 | //不能在传到服务器之前销毁session | |
| 273 | 243 | new Handler().postDelayed(new Runnable() { | |
| 274 | 244 | ||
@@ -279,6 +249,38 @@ public void run() { | |||
| 279 | 249 | }, 500); | |
| 280 | 250 | } | |
| 281 | 251 | ||
| 252 | + /**重置登录密码 | ||
| 253 | + * @param verify | ||
| 254 | + * @param phone | ||
| 255 | + * @param password | ||
| 256 | + * @param requestCode | ||
| 257 | + * @param listener | ||
| 258 | + */ | ||
| 259 | + public static void setPassword(String verify, String phone, String password | ||
| 260 | + , int requestCode, OnHttpResponseListener listener) { | ||
| 261 | + setPassword(verify, phone, password, Privacy.PASSWORD_TYPE_LOGIN, requestCode, listener); | ||
| 262 | + } | ||
| 263 | + /**重置密码 | ||
| 264 | + * @param verify | ||
| 265 | + * @param phone | ||
| 266 | + * @param password | ||
| 267 | + * @param type | ||
| 268 | + * @param requestCode | ||
| 269 | + * @param listener | ||
| 270 | + */ | ||
| 271 | + public static void setPassword(String verify, String phone, String password, int type | ||
| 272 | + , int requestCode, OnHttpResponseListener listener) { | ||
| 273 | + JSONRequest request = new JSONRequest(); | ||
| 274 | + request.put(VERIFY, verify); | ||
| 275 | + request.put(PHONE, phone); | ||
| 276 | + request.put(PASSWORD, password); | ||
| 277 | + request.put(TYPE, type); | ||
| 278 | + | ||
| 279 | + HttpManager.getInstance().post(URL_BASE + "put/password", request, requestCode, listener); | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + | ||
| 283 | + | ||
| 282 | 284 | /**获取验证码 | |
| 283 | 285 | * @param phone | |
| 284 | 286 | * @param requestCode | |
@@ -316,11 +318,11 @@ public static void checkVerify(String phone, String verify, int requestCode, OnH | |||
| 316 | 318 | */ | |
| 317 | 319 | public static void setPassword(int type, String password, String phone, String verify | |
| 318 | 320 | , int requestCode, OnHttpResponseListener listener) { | |
| 319 | - Password pwd = new Password(phone, password).setType(type); | ||
| 320 | - JSONRequest request = new JSONRequest(pwd); | ||
| 321 | + Privacy privacy = new Privacy(phone, password); | ||
| 322 | + JSONRequest request = new JSONRequest(privacy); | ||
| 321 | 323 | request.put(VERIFY, verify); | |
| 322 | 324 | ||
| 323 | - put(request.setTag(Password.class.getSimpleName()), requestCode, listener); | ||
| 325 | + put(request.setTag(PRIVACY_), requestCode, listener); | ||
| 324 | 326 | } | |
| 325 | 327 | ||
| 326 | 328 | //account>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
@@ -635,7 +637,12 @@ public static void addComment(long momentId, long toCommentId, long toUserId, St | |||
| 635 | 637 | * @param listener | |
| 636 | 638 | */ | |
| 637 | 639 | public static void deleteComment(long id, int requestCode, OnHttpResponseListener listener) { | |
| 638 | - delete(new JSONRequest(new Comment(id)).setTag(COMMENT_), requestCode, listener); | ||
| 640 | + delete(new JSONRequest( | ||
| 641 | + new JSONObject( | ||
| 642 | + new Comment(id) | ||
| 643 | + ).setRole(application.isCurrentUser(id) ? RequestRole.OWNER.name() : RequestRole.ADMIN.name()) | ||
| 644 | + ).setTag(COMMENT_) | ||
| 645 | + , requestCode, listener); | ||
| 639 | 646 | } | |
| 640 | 647 | ||
| 641 | 648 | //Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -250,4 +250,53 @@ public static double value(Double value) { | |||
| 250 | 250 | } | |
| 251 | 251 | //获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| 252 | 252 | ||
| 253 | + /**index是否在arr长度范围内 | ||
| 254 | + * @param index | ||
| 255 | + * @param array | ||
| 256 | + * @return | ||
| 257 | + */ | ||
| 258 | + public static boolean isIndexInRange(Integer index, Object[] array) { | ||
| 259 | + return index != null && index >= 0 && index < count(array); | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + /**获取在arr长度范围内的index | ||
| 263 | + * defaultIndex = 0 | ||
| 264 | + * @param index | ||
| 265 | + * @param array | ||
| 266 | + * @return | ||
| 267 | + */ | ||
| 268 | + public static int getIndexInRange(Integer index, Object[] array) { | ||
| 269 | + return getIndexInRange(index, array, 0); | ||
| 270 | + } | ||
| 271 | + /**获取在arr长度范围内的index | ||
| 272 | + * @param index | ||
| 273 | + * @param array | ||
| 274 | + * @param defaultIndex | ||
| 275 | + * @return | ||
| 276 | + */ | ||
| 277 | + public static int getIndexInRange(Integer index, Object[] array, int defaultIndex) { | ||
| 278 | + return isIndexInRange(index, array) ? index : defaultIndex; | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + /**获取在arr长度范围内的index | ||
| 282 | + * defaultIndex = 0 | ||
| 283 | + * @param <T> | ||
| 284 | + * @param index | ||
| 285 | + * @param array | ||
| 286 | + * @return | ||
| 287 | + */ | ||
| 288 | + public static <T> T getInRange(Integer index, T[] array) { | ||
| 289 | + return getInRange(index, array, 0); | ||
| 290 | + } | ||
| 291 | + /**获取在arr长度范围内的index | ||
| 292 | + * @param <T> | ||
| 293 | + * @param index | ||
| 294 | + * @param array | ||
| 295 | + * @param defaultIndex | ||
| 296 | + * @return | ||
| 297 | + */ | ||
| 298 | + public static <T> T getInRange(Integer index, T[] array, int defaultIndex) { | ||
| 299 | + return get(array, getIndexInRange(index, array, defaultIndex)); | ||
| 300 | + } | ||
| 301 | + | ||
| 253 | 302 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments