增加网络请求接口

完善获取数据的接口逻辑
增加RAP2测试
0515
panqihua 5 years ago
parent f836df523b
commit c6b093e822
  1. 13
      app/build.gradle
  2. 3
      app/src/main/AndroidManifest.xml
  3. 37
      app/src/main/java/com/community/pocket/data/adapter/VisitorAdpter.java
  4. 27
      app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java
  5. 38
      app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java
  6. 32
      app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java
  7. 30
      app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java
  8. 20
      app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java
  9. 29
      app/src/main/java/com/community/pocket/data/main/forum/ForumRequest.java
  10. 27
      app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java
  11. 57
      app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java
  12. 32
      app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java
  13. 24
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java
  14. 33
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java
  15. 27
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java
  16. 8
      app/src/main/java/com/community/pocket/data/model/Visitor.java
  17. 27
      app/src/main/java/com/community/pocket/data/model/VisitorPeople.java
  18. 23
      app/src/main/java/com/community/pocket/data/resetpwd/ResetPwdRequest.java
  19. 4
      app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java
  20. 42
      app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java
  21. 25
      app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java
  22. 3
      app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotViewModel.java
  23. 3
      app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumViewModel.java
  24. 3
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java
  25. 3
      app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java
  26. 14
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java
  27. 5
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java
  28. 23
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java
  29. 41
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostResponse.java
  30. 14
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java
  31. 1
      app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java
  32. 3
      app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java
  33. 1
      app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java
  34. 6
      app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteViewModel.java
  35. 6
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java
  36. 41
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java
  37. 13
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoViewModel.java
  38. 36
      app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java
  39. 9
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java
  40. 44
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorResponse.java
  41. 24
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java
  42. 3
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java
  43. 3
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java
  44. 2
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResponse.java
  45. 35
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java
  46. 15
      app/src/main/java/com/community/pocket/util/HttpParse.java
  47. 14
      app/src/main/java/com/community/pocket/util/HttpRequest.java
  48. 76
      app/src/main/java/com/community/pocket/util/HttpResponse.java
  49. 108
      app/src/main/java/com/community/pocket/util/HttpUtil.java
  50. 5
      app/src/main/java/com/community/pocket/util/MyCallBack.java
  51. 20
      app/src/main/java/com/community/pocket/util/Result.java
  52. 39
      app/src/main/java/com/community/pocket/util/SimpleHttpParse.java
  53. 1
      app/src/main/java/com/community/pocket/util/Valid.java
  54. 9
      app/src/test/java/com/community/pocket/ExampleUnitTest.java

@ -1,3 +1,7 @@
ext {
API_HOST = 'http://localhost:3000/'
RAP2_API_HOST = 'http://192.168.3.132:38080/app/mock/1'
}
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'multi-languages' apply plugin: 'multi-languages'
android { android {
@ -15,9 +19,15 @@ android {
} }
buildTypes { buildTypes {
debug{
buildConfigField('String','API_HOST',"\""+RAP2_API_HOST+"\"")
}
release { release {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField('String','API_HOST',"\""+API_HOST+"\"")
} }
} }
sourceSets { sourceSets {
@ -58,4 +68,7 @@ dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0' implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
implementation 'org.conscrypt:conscrypt-android:2.2.1'
} }

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.community.pocket"> package="com.community.pocket">
<!-- 添加网络访问权限-->
<uses-permission android:name="android.permission.INTERNET" />
<application <application
android:name=".util.InitApp" android:name=".util.InitApp"
android:allowBackup="true" android:allowBackup="true"

@ -3,7 +3,10 @@ package com.community.pocket.data.adapter;
import android.content.Context; import android.content.Context;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import com.community.pocket.data.model.VisitorPeople;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -12,19 +15,26 @@ import java.util.Map;
*/ */
public class VisitorAdpter extends ArrayAdapter<String> { public class VisitorAdpter extends ArrayAdapter<String> {
private Map<String, List<String>> map; private List<VisitorPeople> dataList;
private List<String> list; private List<String> list = new ArrayList<>();
private Map<String, VisitorPeople> map = new HashMap<>();
public VisitorAdpter(Map<String, List<String>> map, Context context) { public VisitorAdpter(List<VisitorPeople> dataList, Context context) {
super(context, android.R.layout.simple_list_item_1); super(context, android.R.layout.simple_list_item_1);
addAll(map); addAll(dataList);
} }
public void addAll(Map<String, List<String>> map) { public void addAll(List<VisitorPeople> dataList) {
this.map = map;
this.list = new ArrayList<>(this.map.keySet());
clear(); clear();
this.list.clear();
this.map.clear();
this.dataList = dataList;
for (VisitorPeople people : this.dataList) {
this.list.add(people.getName());
this.map.put(people.getName(), people);
}
addAll(this.list); addAll(this.list);
} }
@ -33,10 +43,19 @@ public class VisitorAdpter extends ArrayAdapter<String> {
} }
public List<String> getTime(String name) { public List<String> getTime(String name) {
return map.get(name); VisitorPeople people = map.get(name);
if (people != null) {
return people.getTime();
} else {
return new ArrayList<>();
}
} }
public List<String> getList() { public List<String> getList() {
return list; return list;
} }
public List<VisitorPeople> getDataList() {
return dataList;
}
} }

@ -1,13 +1,15 @@
package com.community.pocket.data.main.forum; package com.community.pocket.data.main.forum;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.ForumContent;
import com.community.pocket.ui.main.ui.forum.data.ForumDataResponse; import com.community.pocket.ui.main.ui.forum.data.ForumDataResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import com.community.pocket.util.Valid; import com.community.pocket.util.Valid;
import java.util.ArrayList; import okhttp3.FormBody;
import java.util.List;
import java.util.Random;
/** /**
* 帖子详情数据接口 * 帖子详情数据接口
@ -32,17 +34,10 @@ public class ForumDataRequest {
} }
//获取帖子详情数据 //获取帖子详情数据
public ForumDataResponse<List<ForumContent>> loadData(int forumId) { @HttpRequest("/forum/content")
return new ForumDataResponse<List<ForumContent>>().setSuccess(R.string.forum_data_ok).setBody(new ArrayList<ForumContent>() {{ public void loadData(MutableLiveData<ForumDataResponse> liveData, int forumId) {
for (int i = 1; i < 10; i++) { HttpUtil.getRequest(HttpUtil.Method.GET,
ForumContent forumContent = new ForumContent(); new SimpleHttpParse<ForumDataResponse>(liveData, R.string.forum_data_ok, R.string.forum_data_fail).getInterface(ForumDataResponse.class),
forumContent.setUsername("fffname" + i); new FormBody.Builder().add("forumId", String.valueOf(forumId)).build());
forumContent.setTime(System.currentTimeMillis());
forumContent.setScore(new Random().nextInt(100));
forumContent.setTower(i);
forumContent.setContent("我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋");
add(forumContent);
}
}});
} }
} }

@ -1,17 +1,15 @@
package com.community.pocket.data.main.forum; package com.community.pocket.data.main.forum;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.ForumHot;
import com.community.pocket.data.model.Hot;
import com.community.pocket.data.model.UserHot;
import com.community.pocket.ui.main.ui.forum.hot.ForumHotResponse; import com.community.pocket.ui.main.ui.forum.hot.ForumHotResponse;
import com.community.pocket.util.HttpRequest;
import java.util.ArrayList; import com.community.pocket.util.HttpUtil;
import java.util.List; import com.community.pocket.util.SimpleHttpParse;
/** /**
* 热门动态接口请求 * 热门动态接口请求
* TODO 完善逻辑
*/ */
public class ForumHotRequest { public class ForumHotRequest {
private static volatile ForumHotRequest instance; private static volatile ForumHotRequest instance;
@ -27,27 +25,9 @@ public class ForumHotRequest {
} }
//加载热门信息 //加载热门信息
public ForumHotResponse loadHot() { @HttpRequest("/forum/hot")
List<UserHot> userHots = new ArrayList<>(); public void loadHot(MutableLiveData<ForumHotResponse> liveData) {
List<ForumHot> topicHots = new ArrayList<>(); HttpUtil.getRequest(HttpUtil.Method.GET,
List<ForumHot> activeHots = new ArrayList<>(); new SimpleHttpParse<ForumHotResponse>(liveData, R.string.load_hot_ok, R.string.load_hot_fail).getInterface(ForumHotResponse.class));
for (int i = 0; i < 3; i++) {
UserHot userHot = new UserHot();
userHot.setUserId(i);
userHot.setUserName("user" + i);
userHots.add(userHot);
ForumHot forumHot = new ForumHot();
forumHot.setForumId(i);
forumHot.setTitle("topIc" + i);
topicHots.add(forumHot);
ForumHot activeHot = new ForumHot();
activeHot.setForumId(i);
activeHot.setTitle("hot" + i);
activeHots.add(activeHot);
}
ForumHotResponse response = new ForumHotResponse();
response.setSuccess(R.string.load_hot_ok);
response.setBody(new Hot(userHots, topicHots, activeHots));
return response;
} }
} }

@ -1,17 +1,16 @@
package com.community.pocket.data.main.forum; package com.community.pocket.data.main.forum;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Forum;
import com.community.pocket.ui.main.ui.forum.my.ForumMyResponse; import com.community.pocket.ui.main.ui.forum.my.ForumMyResponse;
import com.community.pocket.util.HttpRequest;
import java.util.ArrayList; import com.community.pocket.util.HttpUtil;
import java.util.List; import com.community.pocket.util.SimpleHttpParse;
import java.util.Random;
/** /**
* 我的帖子请求接口 * 我的帖子请求接口
* TODO 完善逻辑
*/ */
public class ForumMyRequest { public class ForumMyRequest {
private static volatile ForumMyRequest instance; private static volatile ForumMyRequest instance;
@ -27,22 +26,11 @@ public class ForumMyRequest {
} }
/** /**
* @return 加载我的帖子 * 加载我的帖子
*/ */
public ForumMyResponse loadForumMy() { @HttpRequest("/forum/my")
List<Forum> forumList = new ArrayList<>(); public void loadForumMy(MutableLiveData<ForumMyResponse> liveData) {
for (int i = 0; i < 10; i++) { HttpUtil.getRequest(HttpUtil.Method.GET,
Forum forum = new Forum(); new SimpleHttpParse<ForumMyResponse>(liveData, R.string.load_forum_my_ok, R.string.load_forum_my_fail).getInterface(ForumMyResponse.class));
forum.setTitle("标题" + i);
forum.setContent("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容");
forum.setUsername("发帖人" + i);
forum.setTime(System.currentTimeMillis());
forum.setReply(new Random().nextInt(100));
forumList.add(forum);
}
ForumMyResponse response = new ForumMyResponse();
response.setSuccess(R.string.load_forum_my_ok);
response.setBody(forumList);
return response;
} }
} }

@ -1,16 +1,15 @@
package com.community.pocket.data.main.forum; package com.community.pocket.data.main.forum;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Forum;
import com.community.pocket.ui.main.ui.forum.news.ForumNewResponse; import com.community.pocket.ui.main.ui.forum.news.ForumNewResponse;
import com.community.pocket.util.HttpRequest;
import java.util.ArrayList; import com.community.pocket.util.HttpUtil;
import java.util.List; import com.community.pocket.util.SimpleHttpParse;
import java.util.Random;
/** /**
* 最新帖子列表数据接口 * 最新帖子列表数据接口
* TODO 完善逻辑
*/ */
public class ForumNewRequest { public class ForumNewRequest {
private static volatile ForumNewRequest instance; private static volatile ForumNewRequest instance;
@ -25,20 +24,9 @@ public class ForumNewRequest {
return instance; return instance;
} }
public ForumNewResponse loadForumNew() { @HttpRequest("/forum/new")
List<Forum> forumList = new ArrayList<>(); public void loadForumNew(MutableLiveData<ForumNewResponse> liveData) {
for (int i = 0; i < 10; i++) { HttpUtil.getRequest(HttpUtil.Method.GET,
Forum forum = new Forum(); new SimpleHttpParse<ForumNewResponse>(liveData, R.string.load_forum_new_ok, R.string.load_forum_new_fail).getInterface(ForumNewResponse.class));
forum.setTitle("标题" + i);
forum.setContent("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容");
forum.setUsername("发帖人" + i);
forum.setTime(System.currentTimeMillis());
forum.setReply(new Random().nextInt(100));
forumList.add(forum);
}
ForumNewResponse response = new ForumNewResponse();
response.setSuccess(R.string.load_forum_new_ok);
response.setBody(forumList);
return response;
} }
} }

@ -1,13 +1,16 @@
package com.community.pocket.data.main.forum; package com.community.pocket.data.main.forum;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.main.ui.forum.post.ForumPostResponse; import com.community.pocket.ui.main.ui.forum.post.ForumPostResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import com.community.pocket.util.Valid; import com.community.pocket.util.Valid;
import java.util.ArrayList; import okhttp3.FormBody;
import java.util.List;
import java.util.Random;
/** /**
* 发表帖子请求接口 * 发表帖子请求接口
@ -42,11 +45,10 @@ public class ForumPostRequest {
} }
//检索投诉人 //检索投诉人
public ForumPostResponse<List<String>> searchPeople(String name) { @HttpRequest("/query/user")
return new ForumPostResponse<List<String>>().setSuccess(R.string.search_complain_name).setBody(new ArrayList<String>() {{ public void searchPeople(MutableLiveData<ForumPostResponse> liveData, String name) {
add("a" + new Random().nextInt(100000)); HttpUtil.getRequest(HttpUtil.Method.GET,
add("a" + new Random().nextInt(100000)); new SimpleHttpParse<ForumPostResponse>(liveData, R.string.search_complain_name, R.string.search_complain_name).getInterface(ForumPostResponse.class),
add("a" + new Random().nextInt(100000)); new FormBody.Builder().add("name", name).build());
}});
} }
} }

@ -1,15 +1,15 @@
package com.community.pocket.data.main.forum; package com.community.pocket.data.main.forum;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Notice;
import com.community.pocket.ui.main.ui.forum.main.ForumNoticeResponse; import com.community.pocket.ui.main.ui.forum.main.ForumNoticeResponse;
import com.community.pocket.util.HttpRequest;
import java.util.ArrayList; import com.community.pocket.util.HttpUtil;
import java.util.List; import com.community.pocket.util.SimpleHttpParse;
/** /**
* 论坛接口管理 * 论坛接口管理
* TODO 完善逻辑
*/ */
public class ForumRequest { public class ForumRequest {
private static volatile ForumRequest instance; private static volatile ForumRequest instance;
@ -25,21 +25,10 @@ public class ForumRequest {
} }
//加载公告数据 //加载公告数据
public ForumNoticeResponse loadNotices() { @HttpRequest("/forum/notice")
List<Notice> notices = new ArrayList<Notice>() {{ public void loadNotices(MutableLiveData<ForumNoticeResponse> liveData) {
for (int i = 0; i < 10; i++) {
Notice notice = new Notice();
notice.setTime(System.currentTimeMillis());
notice.setAuthor("作者" + i);
notice.setTitle("标题" + i);
notice.setContent("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i);
add(notice);
}
}}; HttpUtil.getRequest(HttpUtil.Method.GET,
ForumNoticeResponse forumNoticeResponse = new ForumNoticeResponse(); new SimpleHttpParse<ForumNoticeResponse>(liveData, R.string.load_notice_ok, R.string.load_notice_fail).getInterface(ForumNoticeResponse.class));
forumNoticeResponse.setSuccess(R.string.load_notice_ok);
forumNoticeResponse.setBody(notices);
return forumNoticeResponse;
} }
} }

@ -1,16 +1,18 @@
package com.community.pocket.data.main.garbage; package com.community.pocket.data.main.garbage;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.GarbageSorting;
import com.community.pocket.ui.main.ui.garbage.sorting.GarbageSortingResponse; import com.community.pocket.ui.main.ui.garbage.sorting.GarbageSortingResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import java.util.ArrayList; import okhttp3.FormBody;
import java.util.List;
/** /**
* 垃圾分类请求接口 * 垃圾分类请求接口
* TODO 完善逻辑
*/ */
public class GarbageSortingRequest { public class GarbageSortingRequest {
private static volatile GarbageSortingRequest instance; private static volatile GarbageSortingRequest instance;
@ -26,17 +28,10 @@ public class GarbageSortingRequest {
} }
//检索垃圾 //检索垃圾
public GarbageSortingResponse search() { @HttpRequest("/garbage/sorting")
List<GarbageSorting> garbageSortings = new ArrayList<>(); public void search(MutableLiveData<GarbageSortingResponse> liveData, String name) {
for (int i = 0; i < 10; i++) { HttpUtil.getRequest(HttpUtil.Method.GET,
GarbageSorting garbageSorting = new GarbageSorting(); new SimpleHttpParse<GarbageSortingResponse>(liveData, R.string.garbage_search_ok, R.string.garbage_search_ok).getInterface(GarbageSortingResponse.class),
garbageSorting.setName("test" + i); new FormBody.Builder().add("name", name).build());
garbageSorting.setSorting("有害垃圾");
garbageSortings.add(garbageSorting);
}
GarbageSortingResponse garbageSortingResponse = new GarbageSortingResponse();
garbageSortingResponse.setSuccess(R.string.garbage_search_ok);
garbageSortingResponse.setBody(garbageSortings);
return garbageSortingResponse;
} }
} }

@ -1,18 +1,17 @@
package com.community.pocket.data.main.garbage; package com.community.pocket.data.main.garbage;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.GarbageWaste;
import com.community.pocket.data.model.GarbageWasteManage;
import com.community.pocket.data.model.GarbageWastePrice;
import com.community.pocket.ui.main.ui.garbage.waste.GarbageWasteResponse; import com.community.pocket.ui.main.ui.garbage.waste.GarbageWasteResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import java.util.ArrayList; import okhttp3.FormBody;
import java.util.List;
import java.util.Random;
/** /**
* 废品回收接口 * 废品回收接口
* TODO 完善逻辑
*/ */
public class GarbageWasteRequest { public class GarbageWasteRequest {
private static volatile GarbageWasteRequest instance; private static volatile GarbageWasteRequest instance;
@ -28,45 +27,19 @@ public class GarbageWasteRequest {
} }
//检索默认废品信息 //检索默认废品信息
public GarbageWasteResponse searchDefault() { @HttpRequest("/garbage/waste")
GarbageWasteManage manage = new GarbageWasteManage(); public void searchDefault(MutableLiveData<GarbageWasteResponse> liveData) {
manage.setMobie("10086"); HttpUtil.getRequest(HttpUtil.Method.GET,
manage.setName("Test"); new SimpleHttpParse<GarbageWasteResponse>(liveData, R.string.garbage_waste_search_ok, R.string.garbage_waste_search_ok).getInterface(GarbageWasteResponse.class));
List<GarbageWastePrice> priceList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
GarbageWastePrice price = new GarbageWastePrice();
price.setName("waste" + i);
price.setPrice(new Random().nextInt(10) * 1F);
priceList.add(price);
}
GarbageWaste waste = new GarbageWaste();
waste.setDefaultList(priceList);
waste.setGarbageWasteManage(manage);
GarbageWasteResponse response = new GarbageWasteResponse();
response.setSuccess(R.string.garbage_waste_search_ok);
response.setBody(waste);
return response;
} }
//检索废品 //检索废品
public GarbageWasteResponse search(String name) { @HttpRequest("/garbage/waste/query")
List<GarbageWastePrice> priceList = new ArrayList<>(); public void search(MutableLiveData<GarbageWasteResponse> liveData, String name) {
for (int i = 0; i < 5; i++) { HttpUtil.getRequest(HttpUtil.Method.GET,
GarbageWastePrice price = new GarbageWastePrice(); new SimpleHttpParse<GarbageWasteResponse>(liveData, R.string.garbage_waste_search_ok, R.string.garbage_waste_search_ok).getInterface(GarbageWasteResponse.class),
price.setName("waste" + i); new FormBody.Builder().add("name", name).build());
price.setPrice(new Random().nextInt(10) * 1F);
priceList.add(price);
}
GarbageWaste waste = new GarbageWaste();
waste.setSearchList(priceList);
GarbageWasteResponse response = new GarbageWasteResponse();
response.setSuccess(R.string.garbage_waste_search_ok);
response.setBody(waste);
return response;
} }
} }

@ -1,12 +1,13 @@
package com.community.pocket.data.main.info; package com.community.pocket.data.main.info;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.MyInfo;
import com.community.pocket.ui.main.ui.info.InfoResponse; import com.community.pocket.ui.main.ui.info.InfoResponse;
import com.community.pocket.util.HttpRequest;
import java.util.ArrayList; import com.community.pocket.util.HttpUtil;
import java.util.Random; import com.community.pocket.util.SimpleHttpParse;
/** /**
* 个人信息请求接口 * 个人信息请求接口
@ -26,25 +27,14 @@ public class InfoRequest {
} }
//修改密码 //修改密码
public InfoResponse<String> modifyPwd(String oldpwd, String newpwd) { public void modifyPwd(String oldpwd, String newpwd) {
return new InfoResponse<String>().setSuccess(R.string.modify_pwd_ok);
} }
//获取个人信息 //获取个人信息
public InfoResponse<MyInfo> loadInfo() { @HttpRequest("/my/info")
MyInfo myInfo = new MyInfo(); public void loadInfo(MutableLiveData<InfoResponse> liveData) {
myInfo.setUsername("fff"); HttpUtil.getRequest(HttpUtil.Method.GET,
myInfo.setCreditScore(new Random().nextInt(100)); new SimpleHttpParse<InfoResponse>(liveData, R.string.load_info_ok, R.string.load_info_fail).getInterface(InfoResponse.class));
myInfo.setRecentPosts(new Random().nextInt(100));
myInfo.setRecentVisitors(new Random().nextInt(100));
myInfo.setMobie("123456");
myInfo.setEmail("abc@qq.com");
myInfo.setScoreHistory(new ArrayList<Integer>() {{
for (int i = 0; i < 100; i++) {
add(new Random().nextInt(100));
}
}});
return new InfoResponse<MyInfo>().setSuccess(R.string.load_info_ok).setBody(myInfo);
} }
} }

@ -1,15 +1,15 @@
package com.community.pocket.data.main.visitor; package com.community.pocket.data.main.visitor;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Visitor;
import com.community.pocket.ui.main.ui.visitor.my.VisitorMyResponse; import com.community.pocket.ui.main.ui.visitor.my.VisitorMyResponse;
import com.community.pocket.util.HttpRequest;
import java.util.ArrayList; import com.community.pocket.util.HttpUtil;
import java.util.List; import com.community.pocket.util.SimpleHttpParse;
/** /**
* 我的访客请求接口 * 我的访客请求接口
* TODO 完善逻辑
*/ */
public class VisitorMyRequest { public class VisitorMyRequest {
private static volatile VisitorMyRequest instance; private static volatile VisitorMyRequest instance;
@ -27,15 +27,9 @@ public class VisitorMyRequest {
/** /**
* 加载我的访客 * 加载我的访客
*/ */
public VisitorMyResponse loadMy() { @HttpRequest("/visitor/my")
List<Visitor> visitors = new ArrayList<>(); public void loadMy(MutableLiveData<VisitorMyResponse> liveData) {
for (int i = 0; i < 30; i++) { HttpUtil.getRequest(HttpUtil.Method.GET,
Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); new SimpleHttpParse<VisitorMyResponse>(liveData, R.string.load_visitor_my_ok, R.string.load_visitor_my_fail).getInterface(VisitorMyResponse.class));
visitors.add(visitor);
}
VisitorMyResponse response = new VisitorMyResponse();
response.setSuccess(R.string.load_visitor_my_ok);
response.setBody(visitors);
return response;
} }
} }

@ -1,14 +1,15 @@
package com.community.pocket.data.main.visitor; package com.community.pocket.data.main.visitor;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.main.ui.visitor.appointment.VisitorResponse; import com.community.pocket.ui.main.ui.visitor.appointment.VisitorResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import com.community.pocket.util.Valid; import com.community.pocket.util.Valid;
import java.util.ArrayList; import okhttp3.FormBody;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
/** /**
* 访客接口 * 访客接口
@ -34,23 +35,11 @@ public class VisitorRequest {
} }
//获取预约人 //获取预约人
public VisitorResponse<Map<String, List<String>>> searchPeople(String name) { @HttpRequest("/visitor/people")
return new VisitorResponse<Map<String, List<String>>>().setSuccess(R.string.visitor_appointment_people_ok).setBody(new HashMap<String, List<String>>() {{ public void searchPeople(MutableLiveData<VisitorResponse> liveData, String name) {
put("ac123" + new Random().nextInt(10), new ArrayList<String>() {{ HttpUtil.getRequest(HttpUtil.Method.GET,
add("11:00"); new SimpleHttpParse<VisitorResponse>(liveData, R.string.visitor_appointment_people_ok, R.string.visitor_appointment_people_fail).getInterface(VisitorResponse.class),
add("12:00"); new FormBody.Builder().add("name", name).build());
}});
put("ab123" + new Random().nextInt(10), new ArrayList<String>() {{
add("11:00");
add("13:00");
}});
put("b123123", new ArrayList<String>() {{
add("11:00");
add("14:00");
}});
}});
} }

@ -1,15 +1,15 @@
package com.community.pocket.data.main.visitor; package com.community.pocket.data.main.visitor;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Visitor;
import com.community.pocket.ui.main.ui.visitor.reservation.VisitorReservationResponse; import com.community.pocket.ui.main.ui.visitor.reservation.VisitorReservationResponse;
import com.community.pocket.util.HttpRequest;
import java.util.ArrayList; import com.community.pocket.util.HttpUtil;
import java.util.List; import com.community.pocket.util.SimpleHttpParse;
/** /**
* 我的预约请求接口 * 我的预约请求接口
* TODO 完善逻辑
*/ */
public class VisitorReservationRequest { public class VisitorReservationRequest {
private static volatile VisitorReservationRequest instance; private static volatile VisitorReservationRequest instance;
@ -25,17 +25,12 @@ public class VisitorReservationRequest {
} }
/** /**
* @return 我的预约 * 我的预约
*/ */
public VisitorReservationResponse loadReservation() { @HttpRequest("/visitor/reservation")
List<Visitor> visitors = new ArrayList<>(); public void loadReservation(MutableLiveData<VisitorReservationResponse> liveData) {
for (int i = 0; i < 30; i++) { HttpUtil.getRequest(HttpUtil.Method.GET,
Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); new SimpleHttpParse<VisitorReservationResponse>(liveData, R.string.load_visitor_my_ok, R.string.load_visitor_my_fail).getInterface(VisitorReservationResponse.class));
visitors.add(visitor);
}
VisitorReservationResponse response = new VisitorReservationResponse();
response.setSuccess(R.string.load_visitor_my_ok);
response.setBody(visitors);
return response;
} }
} }

@ -8,9 +8,15 @@ public class Visitor {
private long time; private long time;
private String notes; private String notes;
public Visitor(String name, long time, String notes) { public void setName(String name) {
this.name = name; this.name = name;
}
public void setTime(long time) {
this.time = time; this.time = time;
}
public void setNotes(String notes) {
this.notes = notes; this.notes = notes;
} }

@ -0,0 +1,27 @@
package com.community.pocket.data.model;
import java.util.List;
/**
* 检索预约人
*/
public class VisitorPeople {
private String name;
private List<String> time;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getTime() {
return time;
}
public void setTime(List<String> time) {
this.time = time;
}
}

@ -1,7 +1,6 @@
package com.community.pocket.data.resetpwd; package com.community.pocket.data.resetpwd;
import com.community.pocket.util.Result; import com.community.pocket.ui.resetpwd.ResetPwdResponse;
import com.community.pocket.util.Valid;
/** /**
* 重置密码请求 * 重置密码请求
@ -22,30 +21,34 @@ public class ResetPwdRequest {
/** /**
* 检查用户邮箱 * 检查用户邮箱
* TODO R.string.resetpwd_step1_ok
*/ */
public Result<String> checkUser(String username, String email) { public ResetPwdResponse checkUser(String username, String email) {
return new Result<>(Valid.ok, null); return new ResetPwdResponse();
} }
/** /**
* 发送验证码 * 发送验证码
* TODO R.string.resetpwd_step2_ok
*/ */
public Result<String> sendCode(String username, String email) { public ResetPwdResponse sendCode(String username, String email) {
return new Result<>(Valid.ok, null); return new ResetPwdResponse();
} }
/** /**
* 检查验证码 * 检查验证码
* TODO R.string.resetpwd_step2_valid_ok
*/ */
public Result<String> checkCode(String username, String email, String code) { public ResetPwdResponse checkCode(String username, String email, String code) {
return new Result<>(Valid.ok, null); return new ResetPwdResponse();
} }
/** /**
* 重置密码 * 重置密码
* TODO R.string.resetpwd_step3_ok
*/ */
public Result<String> resetPwd(String username, String password) { public ResetPwdResponse resetPwd(String username, String password) {
return new Result<>(Valid.ok, null); return new ResetPwdResponse();
} }
} }

@ -114,9 +114,9 @@ public class ForumDataActivity extends BaseActivity {
}); });
//监听帖子详情数据 //监听帖子详情数据
viewModel.getForumContentResponse().observe(this, new Observer<ForumDataResponse<List<ForumContent>>>() { viewModel.getForumContentResponse().observe(this, new Observer<ForumDataResponse>() {
@Override @Override
public void onChanged(ForumDataResponse<List<ForumContent>> listForumDataResponse) { public void onChanged(ForumDataResponse listForumDataResponse) {
if (listForumDataResponse == null) { if (listForumDataResponse == null) {
return; return;
} }

@ -1,46 +1,14 @@
package com.community.pocket.ui.main.ui.forum.data; package com.community.pocket.ui.main.ui.forum.data;
import androidx.annotation.Nullable; import com.community.pocket.data.model.ForumContent;
import com.community.pocket.ui.main.ui.share.Response;
import java.util.List;
/** /**
* 帖子详情数据管理 * 帖子详情数据管理
* *
* @param <T> 响应实体
*/ */
public class ForumDataResponse<T> { public class ForumDataResponse extends Response<List<ForumContent>> {
@Nullable
private Integer success;
@Nullable
private Integer error;
private T body;
@Nullable
public Integer getSuccess() {
return success;
}
public ForumDataResponse<T> setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
@Nullable
public Integer getError() {
return error;
}
public ForumDataResponse<T> setError(@Nullable Integer error) {
this.error = error;
return this;
}
T getBody() {
return body;
}
public ForumDataResponse<T> setBody(T body) {
this.body = body;
return this;
}
} }

@ -5,12 +5,8 @@ import androidx.lifecycle.ViewModel;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.main.forum.ForumDataRequest; import com.community.pocket.data.main.forum.ForumDataRequest;
import com.community.pocket.data.model.ForumContent;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil; import com.community.pocket.util.ValidUtil;
import java.util.List;
/** /**
* 帖子详情数据管理 * 帖子详情数据管理
*/ */
@ -22,7 +18,7 @@ class ForumDataViewModel extends ViewModel {
private MutableLiveData<ForumDataResponse> replayResponse = new MutableLiveData<>(); private MutableLiveData<ForumDataResponse> replayResponse = new MutableLiveData<>();
//帖子详情数据状态 //帖子详情数据状态
private MutableLiveData<ForumDataResponse<List<ForumContent>>> forumContentResponse = new MutableLiveData<>(); private MutableLiveData<ForumDataResponse> forumContentResponse = new MutableLiveData<>();
private ForumDataRequest forumDataRequest; private ForumDataRequest forumDataRequest;
@ -38,7 +34,7 @@ class ForumDataViewModel extends ViewModel {
return replayResponse; return replayResponse;
} }
MutableLiveData<ForumDataResponse<List<ForumContent>>> getForumContentResponse() { MutableLiveData<ForumDataResponse> getForumContentResponse() {
return forumContentResponse; return forumContentResponse;
} }
@ -57,16 +53,16 @@ class ForumDataViewModel extends ViewModel {
/** /**
* 回帖状态 * 回帖状态
* *TODO
* @param content 内容 * @param content 内容
*/ */
void sendReply(String content) { void sendReply(String content) {
Valid valid = forumDataRequest.sendReply(content); // Valid valid = forumDataRequest.sendReply(content);
if (valid == Valid.ok) { // if (valid == Valid.ok) {
replayResponse.setValue(new ForumDataResponse().setSuccess(R.string.forum_reply_ok)); // replayResponse.setValue(new ForumDataResponse().setSuccess(R.string.forum_reply_ok));
} else { // } else {
replayResponse.setValue(new ForumDataResponse().setError(R.string.forum_reply_fail)); // replayResponse.setValue(new ForumDataResponse().setError(R.string.forum_reply_fail));
} // }
} }
/** /**
@ -75,8 +71,7 @@ class ForumDataViewModel extends ViewModel {
* @param forumId 帖子id * @param forumId 帖子id
*/ */
void loadData(int forumId) { void loadData(int forumId) {
ForumDataResponse<List<ForumContent>> forumDataResponse = forumDataRequest.loadData(forumId); forumDataRequest.loadData(forumContentResponse, forumId);
forumContentResponse.setValue(forumDataResponse);
} }

@ -17,8 +17,7 @@ public class ForumHotViewModel extends BaseViewModel<ForumHotRequest> {
//加载热门信息 //加载热门信息
void loadHot() { void loadHot() {
ForumHotResponse response = getRequest().loadHot(); getRequest().loadHot(forumHotResponse);
forumHotResponse.setValue(response);
} }
@Override @Override

@ -17,8 +17,7 @@ public class ForumViewModel extends BaseViewModel<ForumRequest> {
} }
void loadNotice() { void loadNotice() {
ForumNoticeResponse response = getRequest().loadNotices(); getRequest().loadNotices(noticeDataResponse);
noticeDataResponse.setValue(response);
} }
@Override @Override

@ -16,8 +16,7 @@ public class ForumMyViewModel extends BaseViewModel<ForumMyRequest> {
} }
void loadForumMy() { void loadForumMy() {
ForumMyResponse response = getRequest().loadForumMy(); getRequest().loadForumMy(forumMyResponse);
forumMyResponse.setValue(response);
} }
@Override @Override

@ -18,8 +18,7 @@ public class ForumNewViewModel extends BaseViewModel<ForumNewRequest> {
} }
void loadForumNew() { void loadForumNew() {
ForumNewResponse response = getRequest().loadForumNew(); getRequest().loadForumNew(forumNewResponse);
forumNewResponse.setValue(response);
} }
@Override @Override

@ -4,7 +4,6 @@ import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.main.forum.ForumPostRequest; import com.community.pocket.data.main.forum.ForumPostRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil; import com.community.pocket.util.ValidUtil;
class ForumPostActiveViewModel extends ForumPostViewModel { class ForumPostActiveViewModel extends ForumPostViewModel {
@ -39,12 +38,13 @@ class ForumPostActiveViewModel extends ForumPostViewModel {
} }
//发帖请求状态 //发帖请求状态
//TODO
void sendPost(String type, String title, String content, String activeStartTime, String activeEndTime, String activeScore) { void sendPost(String type, String title, String content, String activeStartTime, String activeEndTime, String activeScore) {
Valid valid = forumPostRequest.sendActive(type, title, content, activeStartTime, activeEndTime, activeScore); // Valid valid = forumPostRequest.sendActive(type, title, content, activeStartTime, activeEndTime, activeScore);
if (valid == Valid.ok) { // if (valid == Valid.ok) {
forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); // forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok));
} else { // } else {
forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); // forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail));
} // }
} }
} }

@ -79,9 +79,9 @@ public class ForumPostComplainFragment extends ForumPostContent {
//监听发帖状态 //监听发帖状态
sendPost(viewModel); sendPost(viewModel);
viewModel.getSearchPeople().observe(getViewLifecycleOwner(), new Observer<ForumPostResponse<List<String>>>() { viewModel.getSearchPeople().observe(getViewLifecycleOwner(), new Observer<ForumPostResponse>() {
@Override @Override
public void onChanged(ForumPostResponse<List<String>> listForumPostResponse) { public void onChanged(ForumPostResponse listForumPostResponse) {
if (listForumPostResponse == null) { if (listForumPostResponse == null) {
return; return;
} }
@ -101,6 +101,7 @@ public class ForumPostComplainFragment extends ForumPostContent {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if (nameList != null && nameList.containsKey(s.toString())) { if (nameList != null && nameList.containsKey(s.toString())) {
viewModel.complainDataChanged(postTitle.getText().toString(), postContent.getText().toString(), searchName.getText().toString()); viewModel.complainDataChanged(postTitle.getText().toString(), postContent.getText().toString(), searchName.getText().toString());
return;
} }
myAutoCompleteTextView.searchHandler(); myAutoCompleteTextView.searchHandler();

@ -5,11 +5,8 @@ import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.main.forum.ForumPostRequest; import com.community.pocket.data.main.forum.ForumPostRequest;
import com.community.pocket.ui.main.ui.share.SearchViewModel; import com.community.pocket.ui.main.ui.share.SearchViewModel;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil; import com.community.pocket.util.ValidUtil;
import java.util.List;
/** /**
* 投诉贴数据管理 * 投诉贴数据管理
*/ */
@ -19,7 +16,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie
private MutableLiveData<ForumPostFormState.Complain> forumPostFormState = new MutableLiveData<>(); private MutableLiveData<ForumPostFormState.Complain> forumPostFormState = new MutableLiveData<>();
//检索投诉人 //检索投诉人
private MutableLiveData<ForumPostResponse<List<String>>> searchPeople = new MutableLiveData<>(); private MutableLiveData<ForumPostResponse> searchPeople = new MutableLiveData<>();
ForumPostComplainViewModel(ForumPostRequest forumPostRequest) { ForumPostComplainViewModel(ForumPostRequest forumPostRequest) {
super(forumPostRequest); super(forumPostRequest);
@ -29,7 +26,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie
return forumPostFormState; return forumPostFormState;
} }
MutableLiveData<ForumPostResponse<List<String>>> getSearchPeople() { MutableLiveData<ForumPostResponse> getSearchPeople() {
return searchPeople; return searchPeople;
} }
@ -54,14 +51,15 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie
* @param title 标题 * @param title 标题
* @param content 正文 * @param content 正文
* @param complain 投诉人 * @param complain 投诉人
* TODO
*/ */
void sendComplain(String title, String content, String complain) { void sendComplain(String title, String content, String complain) {
Valid valid = forumPostRequest.sendComplain(title, content, complain); // Valid valid = forumPostRequest.sendComplain(title, content, complain);
if (valid == Valid.ok) { // if (valid == Valid.ok) {
forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); // forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok));
} else { // } else {
forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); // forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail));
} // }
} }
/** /**
@ -70,8 +68,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie
* @param name 投诉人 * @param name 投诉人
*/ */
private void searchPeople(String name) { private void searchPeople(String name) {
ForumPostResponse<List<String>> forumPostResponse = forumPostRequest.searchPeople(name); forumPostRequest.searchPeople(searchPeople, name);
searchPeople.setValue(forumPostResponse);
} }
@Override @Override

@ -1,41 +1,12 @@
package com.community.pocket.ui.main.ui.forum.post; package com.community.pocket.ui.main.ui.forum.post;
import androidx.annotation.Nullable; import com.community.pocket.ui.main.ui.share.Response;
public class ForumPostResponse<T> { import java.util.List;
@Nullable
private Integer success;
@Nullable
private Integer error;
private T body; /**
* 检索投诉人响应结果
*/
public class ForumPostResponse extends Response<List<String>> {
@Nullable
public Integer getSuccess() {
return success;
}
public ForumPostResponse<T> setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
@Nullable
public Integer getError() {
return error;
}
public ForumPostResponse<T> setError(@Nullable Integer error) {
this.error = error;
return this;
}
T getBody() {
return body;
}
public ForumPostResponse<T> setBody(T body) {
this.body = body;
return this;
}
} }

@ -4,7 +4,6 @@ import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.main.forum.ForumPostRequest; import com.community.pocket.data.main.forum.ForumPostRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil; import com.community.pocket.util.ValidUtil;
/** /**
@ -34,12 +33,13 @@ class ForumPostTopicViewModel extends ForumPostViewModel {
} }
//发送动态贴 //发送动态贴
//TODO
void sendTopic(String title, String content) { void sendTopic(String title, String content) {
Valid valid = forumPostRequest.sendTopic(title, content); // Valid valid = forumPostRequest.sendTopic(title, content);
if (valid == Valid.ok) { // if (valid == Valid.ok) {
forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); // forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok));
} else { // } else {
forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); // forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail));
} // }
} }
} }

@ -79,6 +79,7 @@ public class GarbageSortingFragment extends BaseFragment {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if (garbageSortingAdpter != null && garbageSortingAdpter.containsKey(s.toString())) { if (garbageSortingAdpter != null && garbageSortingAdpter.containsKey(s.toString())) {
initView(garbageSortingAdpter.get(s.toString())); initView(garbageSortingAdpter.get(s.toString()));
return;
} }
myAutoCompleteTextView.searchHandler(); myAutoCompleteTextView.searchHandler();

@ -25,7 +25,6 @@ public class GarbageSortingViewModel extends BaseViewModel<GarbageSortingRequest
@Override @Override
public void search(String content) { public void search(String content) {
GarbageSortingResponse response = getRequest().search(); getRequest().search(garbageSortingResponse, content);
garbageSortingResponse.setValue(response);
} }
} }

@ -103,6 +103,7 @@ public class GarbageWasteFragment extends BaseFragment {
layout.removeAllViews(); layout.removeAllViews();
addHead(); addHead();
addItem(garbageWasteAdpter.get(s.toString())); addItem(garbageWasteAdpter.get(s.toString()));
return;
} }
if (s.length() == 0) { if (s.length() == 0) {

@ -29,14 +29,12 @@ public class GarbageWasteViewModel extends BaseViewModel<GarbageWasteRequest> im
//检索默认废品请求状态 //检索默认废品请求状态
void searchDefault() { void searchDefault() {
GarbageWasteResponse response = getRequest().searchDefault(); getRequest().searchDefault(defaultList);
defaultList.setValue(response);
} }
//检索废品请求状态 //检索废品请求状态
@Override @Override
public void search(String content) { public void search(String content) {
GarbageWasteResponse response = getRequest().search(content); getRequest().search(searchList, content);
searchList.setValue(response);
} }
} }

@ -161,9 +161,9 @@ public class InfoFragment extends BaseFragment {
}); });
//监听个人信息请求状态 //监听个人信息请求状态
viewModel.getInfoResponse().observe(getViewLifecycleOwner(), new Observer<InfoResponse<MyInfo>>() { viewModel.getInfoResponse().observe(getViewLifecycleOwner(), new Observer<InfoResponse>() {
@Override @Override
public void onChanged(InfoResponse<MyInfo> myInfoInfoResponse) { public void onChanged(InfoResponse myInfoInfoResponse) {
if (myInfoInfoResponse == null) { if (myInfoInfoResponse == null) {
return; return;
} }
@ -280,5 +280,7 @@ public class InfoFragment extends BaseFragment {
lineData.addDataSet(lineDataSet); lineData.addDataSet(lineDataSet);
lineChart.getDescription().setEnabled(false); lineChart.getDescription().setEnabled(false);
lineChart.setData(lineData); lineChart.setData(lineData);
lineChart.callOnClick();
} }
} }

@ -1,47 +1,12 @@
package com.community.pocket.ui.main.ui.info; package com.community.pocket.ui.main.ui.info;
import androidx.annotation.Nullable; import com.community.pocket.data.model.MyInfo;
import com.community.pocket.ui.main.ui.share.Response;
/** /**
* 个人信息响应结果 * 个人信息响应结果
* *
* @param <T> 响应实体信息
*/ */
public class InfoResponse<T> { public class InfoResponse extends Response<MyInfo> {
@Nullable
private Integer success;
@Nullable
private Integer error;
private T body;
@Nullable
public Integer getSuccess() {
return success;
}
public InfoResponse<T> setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
@Nullable
public Integer getError() {
return error;
}
public InfoResponse<T> setError(@Nullable Integer error) {
this.error = error;
return this;
}
T getBody() {
return body;
}
public InfoResponse<T> setBody(T body) {
this.body = body;
return this;
}
} }

@ -5,7 +5,6 @@ import androidx.lifecycle.ViewModel;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.main.info.InfoRequest; import com.community.pocket.data.main.info.InfoRequest;
import com.community.pocket.data.model.MyInfo;
import com.community.pocket.util.ValidUtil; import com.community.pocket.util.ValidUtil;
//个人信息UI数据管理 //个人信息UI数据管理
@ -18,7 +17,7 @@ class InfoViewModel extends ViewModel {
private MutableLiveData<InfoResponse> modifyResponse = new MutableLiveData<>(); private MutableLiveData<InfoResponse> modifyResponse = new MutableLiveData<>();
//个人信息请求状态 //个人信息请求状态
private MutableLiveData<InfoResponse<MyInfo>> infoResponse = new MutableLiveData<>(); private MutableLiveData<InfoResponse> infoResponse = new MutableLiveData<>();
//请求接口管理 //请求接口管理
private InfoRequest infoRequest; private InfoRequest infoRequest;
@ -35,7 +34,7 @@ class InfoViewModel extends ViewModel {
return modifyResponse; return modifyResponse;
} }
MutableLiveData<InfoResponse<MyInfo>> getInfoResponse() { MutableLiveData<InfoResponse> getInfoResponse() {
return infoResponse; return infoResponse;
} }
@ -55,14 +54,14 @@ class InfoViewModel extends ViewModel {
} }
//修改密码 //修改密码
//TODO
void modifyPwd(String oldpwd, String newpwd) { void modifyPwd(String oldpwd, String newpwd) {
InfoResponse<String> infoResponse = infoRequest.modifyPwd(oldpwd, newpwd); // InfoResponse<String> infoResponse = infoRequest.modifyPwd(oldpwd, newpwd);
modifyResponse.setValue(infoResponse); // modifyResponse.setValue(infoResponse);
} }
//获取个人信息 //获取个人信息
void loadInfo() { void loadInfo() {
InfoResponse<MyInfo> myInfoInfoResponse = infoRequest.loadInfo(); infoRequest.loadInfo(infoResponse);
infoResponse.setValue(myInfoInfoResponse);
} }
} }

@ -2,8 +2,11 @@ package com.community.pocket.ui.main.ui.share;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.gson.Gson;
/** /**
* 响应体父类 * 响应体父类
* *
@ -21,6 +24,27 @@ public abstract class Response<T> {
//响应体 //响应体
private T body; private T body;
//响应信息
private String message;
private Result result;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
@Nullable @Nullable
public Integer getSuccess() { public Integer getSuccess() {
return success; return success;
@ -70,4 +94,16 @@ public abstract class Response<T> {
public void setArgs(Object[] args) { public void setArgs(Object[] args) {
this.args = args; this.args = args;
} }
public enum Result {
OK,
FAIL
}
@NonNull
@Override
public String toString() {
return new Gson().toJson(body);
}
} }

@ -19,6 +19,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.adapter.VisitorAdpter; import com.community.pocket.data.adapter.VisitorAdpter;
import com.community.pocket.data.model.VisitorPeople;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange; import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView; import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView;
@ -33,7 +34,6 @@ import org.xutils.view.annotation.ViewInject;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
@ -129,9 +129,9 @@ public class VisitorAppointmentFragment extends BaseFragment {
}); });
//检索预约人请求结果 //检索预约人请求结果
appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), new Observer<VisitorResponse<Map<String, List<String>>>>() { appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), new Observer<VisitorResponse>() {
@Override @Override
public void onChanged(VisitorResponse<Map<String, List<String>>> visitorResponse) { public void onChanged(VisitorResponse visitorResponse) {
if (visitorResponse == null) { if (visitorResponse == null) {
return; return;
} }
@ -160,6 +160,7 @@ public class VisitorAppointmentFragment extends BaseFragment {
if (visitorAdpter != null && visitorAdpter.containsKey(s.toString())) { if (visitorAdpter != null && visitorAdpter.containsKey(s.toString())) {
appointmentViewModel.appointmentDataChanged(appointment.getText(), notes.getText()); appointmentViewModel.appointmentDataChanged(appointment.getText(), notes.getText());
initTime(s); initTime(s);
return;
} }
appointment.setTag(R.string.visitor_tag, s.toString()); appointment.setTag(R.string.visitor_tag, s.toString());
@ -181,7 +182,7 @@ public class VisitorAppointmentFragment extends BaseFragment {
* 搜索框 * 搜索框
*/ */
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void initSearch(Map<String, List<String>> arrays) { private void initSearch(List<VisitorPeople> arrays) {
// 设置适配器 // 设置适配器
if (visitorAdpter == null) { if (visitorAdpter == null) {
visitorAdpter = new VisitorAdpter(arrays, getContext()); visitorAdpter = new VisitorAdpter(arrays, getContext());

@ -1,46 +1,12 @@
package com.community.pocket.ui.main.ui.visitor.appointment; package com.community.pocket.ui.main.ui.visitor.appointment;
import androidx.annotation.NonNull; import com.community.pocket.data.model.VisitorPeople;
import androidx.annotation.Nullable; import com.community.pocket.ui.main.ui.share.Response;
import java.util.List;
/** /**
* 访客接口请求结果 * 访客接口请求结果
*/ */
public class VisitorResponse<T> { public class VisitorResponse extends Response<List<VisitorPeople>> {
@Nullable
private Integer success;
@Nullable
private Integer error;
private T body;
@Nullable
public Integer getSuccess() {
return success;
}
public VisitorResponse<T> setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
@Nullable
public Integer getError() {
return error;
}
public VisitorResponse<T> setError(@Nullable Integer error) {
this.error = error;
return this;
}
@NonNull
T getBody() {
return body;
}
public VisitorResponse<T> setBody(@NonNull T body) {
this.body = body;
return this;
}
} }

@ -8,12 +8,8 @@ import androidx.lifecycle.ViewModel;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.main.visitor.VisitorRequest; import com.community.pocket.data.main.visitor.VisitorRequest;
import com.community.pocket.ui.main.ui.share.SearchViewModel; import com.community.pocket.ui.main.ui.share.SearchViewModel;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil; import com.community.pocket.util.ValidUtil;
import java.util.List;
import java.util.Map;
/** /**
* 管理访客UI数据 * 管理访客UI数据
*/ */
@ -26,7 +22,7 @@ class VisitorViewModel extends ViewModel implements SearchViewModel {
private MutableLiveData<VisitorResponse> visitorResponse = new MutableLiveData<>(); private MutableLiveData<VisitorResponse> visitorResponse = new MutableLiveData<>();
//检索预约人 //检索预约人
private MutableLiveData<VisitorResponse<Map<String, List<String>>>> searchPeopleReq = new MutableLiveData<>(); private MutableLiveData<VisitorResponse> searchPeopleReq = new MutableLiveData<>();
//访客请求 //访客请求
private VisitorRequest visitorRequest; private VisitorRequest visitorRequest;
@ -43,24 +39,24 @@ class VisitorViewModel extends ViewModel implements SearchViewModel {
return visitorResponse; return visitorResponse;
} }
MutableLiveData<VisitorResponse<Map<String, List<String>>>> getSearchPeopleReq() { MutableLiveData<VisitorResponse> getSearchPeopleReq() {
return searchPeopleReq; return searchPeopleReq;
} }
//访客预约 //访客预约
//TODO
void appointment(String appointment, String chooseTime, String notes) { void appointment(String appointment, String chooseTime, String notes) {
Valid valid = visitorRequest.appointment(appointment, chooseTime, notes); // Valid valid = visitorRequest.appointment(appointment, chooseTime, notes);
if (valid == Valid.ok) { // if (valid == Valid.ok) {
visitorResponse.setValue(new VisitorResponse().setSuccess(R.string.visitor_appointment_ok)); // visitorResponse.setValue(new VisitorResponse().setSuccess(R.string.visitor_appointment_ok));
} else { // } else {
visitorResponse.setValue(new VisitorResponse().setError(R.string.visitor_appointment_fail)); // visitorResponse.setValue(new VisitorResponse().setError(R.string.visitor_appointment_fail));
} // }
} }
//检索预约人 //检索预约人
private void searchPeople(String name) { private void searchPeople(String name) {
VisitorResponse<Map<String, List<String>>> result = visitorRequest.searchPeople(name); visitorRequest.searchPeople(searchPeopleReq, name);
searchPeopleReq.setValue(result);
} }
//校验访客预约表单 //校验访客预约表单

@ -21,8 +21,7 @@ public class VisitorMyViewModel extends BaseViewModel<VisitorMyRequest> {
* 加载我的访客 * 加载我的访客
*/ */
void loadMy() { void loadMy() {
VisitorMyResponse response = getRequest().loadMy(); getRequest().loadMy(visitorMyResponse);
visitorMyResponse.setValue(response);
} }
@Override @Override

@ -18,8 +18,7 @@ public class VisitorReservationViewModel extends BaseViewModel<VisitorReservatio
} }
void loadReservation() { void loadReservation() {
VisitorReservationResponse response = getRequest().loadReservation(); getRequest().loadReservation(visitorReservationResponse);
visitorReservationResponse.setValue(response);
} }

@ -5,7 +5,7 @@ import androidx.annotation.Nullable;
/** /**
* 重置密码结果 * 重置密码结果
*/ */
class ResetPwdResponse { public class ResetPwdResponse {
@Nullable @Nullable
private Integer success; private Integer success;
@Nullable @Nullable

@ -5,8 +5,6 @@ import androidx.lifecycle.ViewModel;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.resetpwd.ResetPwdRequest; import com.community.pocket.data.resetpwd.ResetPwdRequest;
import com.community.pocket.util.Result;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil; import com.community.pocket.util.ValidUtil;
/** /**
@ -60,43 +58,26 @@ class ResetPwdViewModel extends ViewModel {
//重置密码第一步 //重置密码第一步
void checkUser(String username, String email) { void checkUser(String username, String email) {
Result<String> result = resetPwdRequest.checkUser(username, email); ResetPwdResponse response = resetPwdRequest.checkUser(username, email);
if (result.getValid() == Valid.ok) { resetPwdResultStep1.setValue(response);
resetPwdResultStep1.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step1_ok));
} else {
resetPwdResultStep1.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step1_fail));
}
} }
//重置密码第二步 //重置密码第二步
void sendCode(String username, String email) { void sendCode(String username, String email) {
Result<String> result = resetPwdRequest.sendCode(username, email); ResetPwdResponse response = resetPwdRequest.sendCode(username, email);
if (result.getValid() == Valid.ok) { resetPwdResultStep2.setValue(response);
resetPwdResultStep2.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step2_ok));
resetpwdStep2Changed();
} else {
resetPwdResultStep2.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step2_fail));
}
} }
//重置密码第二步 //重置密码第二步
void checkCode(String username, String email, String code) { void checkCode(String username, String email, String code) {
Result<String> result = resetPwdRequest.checkCode(username, email, code); ResetPwdResponse response = resetPwdRequest.checkCode(username, email, code);
if (result.getValid() == Valid.ok) { resetPwdResultStep2.setValue(response);
resetPwdResultStep2.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step2_valid_ok));
} else {
resetPwdResultStep2.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step2_valid_fail));
}
} }
//重置密码第三步 //重置密码第三步
void resetPwd(String username, String password) { void resetPwd(String username, String password) {
Result<String> result = resetPwdRequest.resetPwd(username, password); ResetPwdResponse response = resetPwdRequest.resetPwd(username, password);
if (result.getValid() == Valid.ok) { resetPwdResultStep3.setValue(response);
resetPwdResultStep3.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step3_ok));
} else {
resetPwdResultStep3.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step3_fail));
}
} }
//监听重置密码第一步表单触发校验 //监听重置密码第一步表单触发校验

@ -0,0 +1,15 @@
package com.community.pocket.util;
import org.jetbrains.annotations.NotNull;
import okhttp3.Call;
import okhttp3.Response;
/**
* 解析接口返回数据
*
* @param <T> 转化实体类型
*/
public interface HttpParse<T extends com.community.pocket.ui.main.ui.share.Response> {
void onParseOk(@NotNull Call call, @NotNull Response response, T t);
}

@ -0,0 +1,14 @@
package com.community.pocket.util;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
@Target({METHOD})
public @interface HttpRequest {
//接口地址
String value();
}

@ -0,0 +1,76 @@
package com.community.pocket.util;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import okhttp3.ResponseBody;
/**
* 解析HTTP响应体
*
* @param <T> 响应实体类型
*/
public class HttpResponse<T extends com.community.pocket.ui.main.ui.share.Response> implements Callback {
private Class<T> tClass;
private HttpParse<T> httpParse;
private static final String header = "Content-Type";
HttpResponse(Class<T> tClass, HttpParse<T> httpParse) {
this.tClass = tClass;
this.httpParse = httpParse;
}
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
e.printStackTrace();
Log.e(HttpResponse.class.getName(), e.toString());
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) {
String contentType = response.header(header);
if (contentType != null && contentType.contains("application/json")) {
ResponseBody body = response.body();
if (body != null) {
Gson gson = new Gson();
try {
String message = body.string();
Log.i(HttpUtil.class.getName(), "响应数据:\n" + message);
T jsonObject = gson.fromJson(message, tClass);
if (jsonObject != null) {
httpParse.onParseOk(call, response, jsonObject);
} else {
onParseError(call, response, "无法把数据" + message + "解析为" + tClass + "类型");
}
} catch (JsonSyntaxException e) {
onParseError(call, response, "解析异常" + e);
} catch (IOException e) {
onParseError(call, response, "解析异常" + e);
}
} else {
onParseError(call, response, "响应体为null");
}
} else {
onParseError(call, response, "接口不是响应json数据,非法响应头" + header + "=" + contentType);
}
}
private void onParseError(@NotNull Call call, @NotNull Response response, String err) {
Log.e(HttpResponse.class.getName(), err);
throw new RuntimeException(err);
}
}

@ -0,0 +1,108 @@
package com.community.pocket.util;
import androidx.annotation.NonNull;
import com.community.pocket.BuildConfig;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
public class HttpUtil {
private static final Map<String, HttpRequest> map = new HashMap<>();
public static void getRequest(Method method, Callback callback) {
getRequest(method, callback, null);
}
public static void getRequest(Method method, Callback callback, FormBody formBody) {
//1.创建OkHttpClient对象
OkHttpClient okHttpClient = new OkHttpClient();
//2.创建Request对象,设置一个url地址(百度地址),设置请求方式。
Request.Builder builder = new Request.Builder();
if (method == Method.GET && formBody != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < formBody.size(); i++) {
sb.append("&").append(formBody.name(i)).append("=").append(formBody.value(i));
}
builder = builder.url(BuildConfig.API_HOST + getUrl() + "?" + sb.substring(1)).method(method.name(), null);
} else {
builder = builder.url(BuildConfig.API_HOST + getUrl()).method(method.name(), formBody);
}
//3.创建一个call对象,参数就是Request请求对象
Call call = okHttpClient.newCall(builder.build());
//4.请求加入调度,重写回调方法
call.enqueue(callback);
}
public enum Method {
GET,
POST
}
/**
* 获取调用
*/
@NonNull
private static String getUrl() {
HttpRequest httpRequest = null;
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
String className = null;
String methodName = null;
for (int index = 1; index < stack.length; index++) {
if (HttpUtil.class.getName().equals(stack[index - 1].getClassName()) && !HttpUtil.class.getName().equals(stack[index].getClassName())) {
className = stack[index].getClassName();
methodName = stack[index].getMethodName();
break;
}
}
RuntimeException runtimeException = new RuntimeException("未知异常!!!");
if (className != null) {
try {
if (!map.containsKey(className + methodName)) {
Class c = Class.forName(className);
java.lang.reflect.Method[] methods = c.getMethods();
List<java.lang.reflect.Method> matchMethod = new ArrayList<>();
for (java.lang.reflect.Method m : methods) {
if (methodName.equals(m.getName()) && m.getAnnotation(HttpRequest.class) != null) {
matchMethod.add(m);
}
}
if (matchMethod.size() == 1) {
httpRequest = matchMethod.get(0).getAnnotation(HttpRequest.class);
map.put(matchMethod.get(0).getName(), httpRequest);
} else if (matchMethod.size() > 1) {
runtimeException = new RuntimeException(c.getName() + "包含多个方法名为:" + methodName + "的方法!!!");
} else {
runtimeException = new RuntimeException("类:" + c.getName() + "方法:" + methodName + "缺少注解" + HttpRequest.class + ",无法调用" + HttpUtil.class);
}
} else {
httpRequest = map.get(className + methodName);
}
if (httpRequest != null) {
return httpRequest.value();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
}
}
throw runtimeException;
}
}

@ -0,0 +1,5 @@
package com.community.pocket.util;
public interface MyCallBack<T> {
void call(T forumNoticeResponse);
}

@ -1,20 +0,0 @@
package com.community.pocket.util;
public class Result<T> {
private Valid valid;
private T body;
public Result(Valid valid, T body) {
this.valid = valid;
this.body = body;
}
public Valid getValid() {
return valid;
}
public T getBody() {
return body;
}
}

@ -0,0 +1,39 @@
package com.community.pocket.util;
import androidx.annotation.StringRes;
import androidx.lifecycle.MutableLiveData;
import org.jetbrains.annotations.NotNull;
import okhttp3.Call;
import okhttp3.Response;
public class SimpleHttpParse<T extends com.community.pocket.ui.main.ui.share.Response> implements HttpParse<T> {
private MutableLiveData liveData;
private Integer success;
private Integer error;
public SimpleHttpParse(MutableLiveData liveData, @StringRes Integer success, @StringRes Integer error) {
this.liveData = liveData;
this.success = success;
this.error = error;
}
public HttpResponse<T> getInterface(Class<T> tClass) {
return new HttpResponse<>(tClass, this);
}
@Override
@SuppressWarnings("unchecked")
public void onParseOk(@NotNull Call call, @NotNull Response response, T t) {
if (t.getResult() == com.community.pocket.ui.main.ui.share.Response.Result.OK) {
t.setSuccess(success);
} else {
t.setError(error);
}
liveData.postValue(t);
}
}

@ -1,5 +1,6 @@
package com.community.pocket.util; package com.community.pocket.util;
//TODO 测试类
public enum Valid { public enum Valid {
empty_err, empty_err,
password_err, password_err,

@ -2,7 +2,7 @@ package com.community.pocket;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
/** /**
* Example local unit test, which will execute on the development machine (host). * Example local unit test, which will execute on the development machine (host).
@ -14,4 +14,11 @@ public class ExampleUnitTest {
public void addition_isCorrect() { public void addition_isCorrect() {
assertEquals(4, 2 + 2); assertEquals(4, 2 + 2);
} }
@Test
public void class_tuil() {
// ForumRequest.getInstance().loadNotices(null);
//
// TimeUnit.SECONDS.sleep(100);
}
} }
Loading…
Cancel
Save