diff --git a/app/build.gradle b/app/build.gradle index 45de868..d17a529 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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: 'multi-languages' android { @@ -15,9 +19,15 @@ android { } buildTypes { + debug{ + buildConfigField('String','API_HOST',"\""+RAP2_API_HOST+"\"") + } + release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + + buildConfigField('String','API_HOST',"\""+API_HOST+"\"") } } sourceSets { @@ -58,4 +68,7 @@ dependencies { implementation 'com.github.PhilJay:MPAndroidChart:v3.1.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' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index aeaf47e..b58dbcb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,8 @@ - + + { - private Map> map; - private List list; - + private List dataList; + private List list = new ArrayList<>(); + private Map map = new HashMap<>(); - public VisitorAdpter(Map> map, Context context) { + public VisitorAdpter(List dataList, Context context) { super(context, android.R.layout.simple_list_item_1); - addAll(map); + addAll(dataList); } - public void addAll(Map> map) { - this.map = map; - this.list = new ArrayList<>(this.map.keySet()); + public void addAll(List dataList) { 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); } @@ -33,10 +43,19 @@ public class VisitorAdpter extends ArrayAdapter { } public List getTime(String name) { - return map.get(name); + VisitorPeople people = map.get(name); + if (people != null) { + return people.getTime(); + } else { + return new ArrayList<>(); + } } public List getList() { return list; } + + public List getDataList() { + return dataList; + } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java index d071674..4d92451 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java @@ -1,13 +1,15 @@ package com.community.pocket.data.main.forum; +import androidx.lifecycle.MutableLiveData; + 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.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; import com.community.pocket.util.Valid; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import okhttp3.FormBody; /** * 帖子详情数据接口 @@ -32,17 +34,10 @@ public class ForumDataRequest { } //获取帖子详情数据 - public ForumDataResponse> loadData(int forumId) { - return new ForumDataResponse>().setSuccess(R.string.forum_data_ok).setBody(new ArrayList() {{ - for (int i = 1; i < 10; i++) { - ForumContent forumContent = new ForumContent(); - forumContent.setUsername("fffname" + i); - forumContent.setTime(System.currentTimeMillis()); - forumContent.setScore(new Random().nextInt(100)); - forumContent.setTower(i); - forumContent.setContent("我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋我是笨蛋"); - add(forumContent); - } - }}); + @HttpRequest("/forum/content") + public void loadData(MutableLiveData liveData, int forumId) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.forum_data_ok, R.string.forum_data_fail).getInterface(ForumDataResponse.class), + new FormBody.Builder().add("forumId", String.valueOf(forumId)).build()); } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java index 0051165..51eaff2 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumHotRequest.java @@ -1,17 +1,15 @@ package com.community.pocket.data.main.forum; +import androidx.lifecycle.MutableLiveData; + 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 java.util.ArrayList; -import java.util.List; +import com.community.pocket.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; /** * 热门动态接口请求 - * TODO 完善逻辑 */ public class ForumHotRequest { private static volatile ForumHotRequest instance; @@ -27,27 +25,9 @@ public class ForumHotRequest { } //加载热门信息 - public ForumHotResponse loadHot() { - List userHots = new ArrayList<>(); - List topicHots = new ArrayList<>(); - List activeHots = new ArrayList<>(); - 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; + @HttpRequest("/forum/hot") + public void loadHot(MutableLiveData liveData) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.load_hot_ok, R.string.load_hot_fail).getInterface(ForumHotResponse.class)); } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java index 28c567d..7ed8f1e 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java @@ -1,17 +1,16 @@ package com.community.pocket.data.main.forum; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; -import com.community.pocket.data.model.Forum; import com.community.pocket.ui.main.ui.forum.my.ForumMyResponse; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import com.community.pocket.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; /** * 我的帖子请求接口 - * TODO 完善逻辑 */ public class ForumMyRequest { private static volatile ForumMyRequest instance; @@ -27,22 +26,11 @@ public class ForumMyRequest { } /** - * @return 加载我的帖子 + * 加载我的帖子 */ - public ForumMyResponse loadForumMy() { - List forumList = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - Forum forum = new Forum(); - 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; + @HttpRequest("/forum/my") + public void loadForumMy(MutableLiveData liveData) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.load_forum_my_ok, R.string.load_forum_my_fail).getInterface(ForumMyResponse.class)); } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java index 788d438..1a4523f 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java @@ -1,16 +1,15 @@ package com.community.pocket.data.main.forum; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; -import com.community.pocket.data.model.Forum; import com.community.pocket.ui.main.ui.forum.news.ForumNewResponse; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import com.community.pocket.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; /** * 最新帖子列表数据接口 - * TODO 完善逻辑 */ public class ForumNewRequest { private static volatile ForumNewRequest instance; @@ -25,20 +24,9 @@ public class ForumNewRequest { return instance; } - public ForumNewResponse loadForumNew() { - List forumList = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - Forum forum = new Forum(); - 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; + @HttpRequest("/forum/new") + public void loadForumNew(MutableLiveData liveData) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.load_forum_new_ok, R.string.load_forum_new_fail).getInterface(ForumNewResponse.class)); } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java index ab5efd7..507e101 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java @@ -1,13 +1,16 @@ package com.community.pocket.data.main.forum; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; 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 java.util.ArrayList; -import java.util.List; -import java.util.Random; +import okhttp3.FormBody; /** * 发表帖子请求接口 @@ -42,11 +45,10 @@ public class ForumPostRequest { } //检索投诉人 - public ForumPostResponse> searchPeople(String name) { - return new ForumPostResponse>().setSuccess(R.string.search_complain_name).setBody(new ArrayList() {{ - add("a" + new Random().nextInt(100000)); - add("a" + new Random().nextInt(100000)); - add("a" + new Random().nextInt(100000)); - }}); + @HttpRequest("/query/user") + public void searchPeople(MutableLiveData liveData, String name) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.search_complain_name, R.string.search_complain_name).getInterface(ForumPostResponse.class), + new FormBody.Builder().add("name", name).build()); } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumRequest.java index a930502..d7868d7 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumRequest.java @@ -1,15 +1,15 @@ package com.community.pocket.data.main.forum; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; -import com.community.pocket.data.model.Notice; import com.community.pocket.ui.main.ui.forum.main.ForumNoticeResponse; - -import java.util.ArrayList; -import java.util.List; +import com.community.pocket.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; /** * 论坛接口管理 - * TODO 完善逻辑 */ public class ForumRequest { private static volatile ForumRequest instance; @@ -25,21 +25,10 @@ public class ForumRequest { } //加载公告数据 - public ForumNoticeResponse loadNotices() { - List notices = new ArrayList() {{ - 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); - } + @HttpRequest("/forum/notice") + public void loadNotices(MutableLiveData liveData) { - }}; - ForumNoticeResponse forumNoticeResponse = new ForumNoticeResponse(); - forumNoticeResponse.setSuccess(R.string.load_notice_ok); - forumNoticeResponse.setBody(notices); - return forumNoticeResponse; + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.load_notice_ok, R.string.load_notice_fail).getInterface(ForumNoticeResponse.class)); } } diff --git a/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java index 5bcd444..348a558 100644 --- a/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java @@ -1,16 +1,18 @@ package com.community.pocket.data.main.garbage; +import androidx.lifecycle.MutableLiveData; + 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.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; -import java.util.ArrayList; -import java.util.List; +import okhttp3.FormBody; /** * 垃圾分类请求接口 - * TODO 完善逻辑 */ public class GarbageSortingRequest { private static volatile GarbageSortingRequest instance; @@ -26,17 +28,10 @@ public class GarbageSortingRequest { } //检索垃圾 - public GarbageSortingResponse search() { - List garbageSortings = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - GarbageSorting garbageSorting = new GarbageSorting(); - garbageSorting.setName("test" + i); - garbageSorting.setSorting("有害垃圾"); - garbageSortings.add(garbageSorting); - } - GarbageSortingResponse garbageSortingResponse = new GarbageSortingResponse(); - garbageSortingResponse.setSuccess(R.string.garbage_search_ok); - garbageSortingResponse.setBody(garbageSortings); - return garbageSortingResponse; + @HttpRequest("/garbage/sorting") + public void search(MutableLiveData liveData, String name) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.garbage_search_ok, R.string.garbage_search_ok).getInterface(GarbageSortingResponse.class), + new FormBody.Builder().add("name", name).build()); } } diff --git a/app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java index 86a19e2..abe9de4 100644 --- a/app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/garbage/GarbageWasteRequest.java @@ -1,18 +1,17 @@ package com.community.pocket.data.main.garbage; +import androidx.lifecycle.MutableLiveData; + 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.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import okhttp3.FormBody; /** * 废品回收接口 - * TODO 完善逻辑 */ public class GarbageWasteRequest { private static volatile GarbageWasteRequest instance; @@ -28,45 +27,19 @@ public class GarbageWasteRequest { } //检索默认废品信息 - public GarbageWasteResponse searchDefault() { - GarbageWasteManage manage = new GarbageWasteManage(); - manage.setMobie("10086"); - manage.setName("Test"); - - List 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; + @HttpRequest("/garbage/waste") + public void searchDefault(MutableLiveData liveData) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.garbage_waste_search_ok, R.string.garbage_waste_search_ok).getInterface(GarbageWasteResponse.class)); } //检索废品 - public GarbageWasteResponse search(String name) { - List priceList = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - GarbageWastePrice price = new GarbageWastePrice(); - price.setName("waste" + i); - price.setPrice(new Random().nextInt(10) * 1F); - priceList.add(price); - } + @HttpRequest("/garbage/waste/query") + public void search(MutableLiveData liveData, String name) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.garbage_waste_search_ok, R.string.garbage_waste_search_ok).getInterface(GarbageWasteResponse.class), + new FormBody.Builder().add("name", name).build()); - GarbageWaste waste = new GarbageWaste(); - waste.setSearchList(priceList); - GarbageWasteResponse response = new GarbageWasteResponse(); - response.setSuccess(R.string.garbage_waste_search_ok); - response.setBody(waste); - return response; } } diff --git a/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java b/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java index ece9480..1b32a81 100644 --- a/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java @@ -1,12 +1,13 @@ package com.community.pocket.data.main.info; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; -import com.community.pocket.data.model.MyInfo; import com.community.pocket.ui.main.ui.info.InfoResponse; - -import java.util.ArrayList; -import java.util.Random; +import com.community.pocket.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; /** * 个人信息请求接口 @@ -26,25 +27,14 @@ public class InfoRequest { } //修改密码 - public InfoResponse modifyPwd(String oldpwd, String newpwd) { - return new InfoResponse().setSuccess(R.string.modify_pwd_ok); + public void modifyPwd(String oldpwd, String newpwd) { + } //获取个人信息 - public InfoResponse loadInfo() { - MyInfo myInfo = new MyInfo(); - myInfo.setUsername("fff"); - myInfo.setCreditScore(new Random().nextInt(100)); - myInfo.setRecentPosts(new Random().nextInt(100)); - myInfo.setRecentVisitors(new Random().nextInt(100)); - myInfo.setMobie("123456"); - myInfo.setEmail("abc@qq.com"); - myInfo.setScoreHistory(new ArrayList() {{ - for (int i = 0; i < 100; i++) { - add(new Random().nextInt(100)); - } - }}); - - return new InfoResponse().setSuccess(R.string.load_info_ok).setBody(myInfo); + @HttpRequest("/my/info") + public void loadInfo(MutableLiveData liveData) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.load_info_ok, R.string.load_info_fail).getInterface(InfoResponse.class)); } } diff --git a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java index bab15de..3f54890 100644 --- a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java @@ -1,15 +1,15 @@ package com.community.pocket.data.main.visitor; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; -import com.community.pocket.data.model.Visitor; import com.community.pocket.ui.main.ui.visitor.my.VisitorMyResponse; - -import java.util.ArrayList; -import java.util.List; +import com.community.pocket.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; /** * 我的访客请求接口 - * TODO 完善逻辑 */ public class VisitorMyRequest { private static volatile VisitorMyRequest instance; @@ -27,15 +27,9 @@ public class VisitorMyRequest { /** * 加载我的访客 */ - public VisitorMyResponse loadMy() { - List visitors = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); - visitors.add(visitor); - } - VisitorMyResponse response = new VisitorMyResponse(); - response.setSuccess(R.string.load_visitor_my_ok); - response.setBody(visitors); - return response; + @HttpRequest("/visitor/my") + public void loadMy(MutableLiveData liveData) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.load_visitor_my_ok, R.string.load_visitor_my_fail).getInterface(VisitorMyResponse.class)); } } diff --git a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java index cad890b..40279d6 100644 --- a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java @@ -1,14 +1,15 @@ package com.community.pocket.data.main.visitor; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; 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 java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; +import okhttp3.FormBody; /** * 访客接口 @@ -34,23 +35,11 @@ public class VisitorRequest { } //获取预约人 - public VisitorResponse>> searchPeople(String name) { - return new VisitorResponse>>().setSuccess(R.string.visitor_appointment_people_ok).setBody(new HashMap>() {{ - put("ac123" + new Random().nextInt(10), new ArrayList() {{ - add("11:00"); - add("12:00"); - }}); - - put("ab123" + new Random().nextInt(10), new ArrayList() {{ - add("11:00"); - add("13:00"); - }}); - - put("b123123", new ArrayList() {{ - add("11:00"); - add("14:00"); - }}); - }}); + @HttpRequest("/visitor/people") + public void searchPeople(MutableLiveData liveData, String name) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.visitor_appointment_people_ok, R.string.visitor_appointment_people_fail).getInterface(VisitorResponse.class), + new FormBody.Builder().add("name", name).build()); } diff --git a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java index 72bd23d..1dd3ba1 100644 --- a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java @@ -1,15 +1,15 @@ package com.community.pocket.data.main.visitor; +import androidx.lifecycle.MutableLiveData; + import com.community.pocket.R; -import com.community.pocket.data.model.Visitor; import com.community.pocket.ui.main.ui.visitor.reservation.VisitorReservationResponse; - -import java.util.ArrayList; -import java.util.List; +import com.community.pocket.util.HttpRequest; +import com.community.pocket.util.HttpUtil; +import com.community.pocket.util.SimpleHttpParse; /** * 我的预约请求接口 - * TODO 完善逻辑 */ public class VisitorReservationRequest { private static volatile VisitorReservationRequest instance; @@ -25,17 +25,12 @@ public class VisitorReservationRequest { } /** - * @return 我的预约 + * 我的预约 */ - public VisitorReservationResponse loadReservation() { - List visitors = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); - visitors.add(visitor); - } - VisitorReservationResponse response = new VisitorReservationResponse(); - response.setSuccess(R.string.load_visitor_my_ok); - response.setBody(visitors); - return response; + @HttpRequest("/visitor/reservation") + public void loadReservation(MutableLiveData liveData) { + HttpUtil.getRequest(HttpUtil.Method.GET, + new SimpleHttpParse(liveData, R.string.load_visitor_my_ok, R.string.load_visitor_my_fail).getInterface(VisitorReservationResponse.class)); + } } diff --git a/app/src/main/java/com/community/pocket/data/model/Visitor.java b/app/src/main/java/com/community/pocket/data/model/Visitor.java index b44ddd1..a4ba181 100644 --- a/app/src/main/java/com/community/pocket/data/model/Visitor.java +++ b/app/src/main/java/com/community/pocket/data/model/Visitor.java @@ -8,9 +8,15 @@ public class Visitor { private long time; private String notes; - public Visitor(String name, long time, String notes) { + public void setName(String name) { this.name = name; + } + + public void setTime(long time) { this.time = time; + } + + public void setNotes(String notes) { this.notes = notes; } diff --git a/app/src/main/java/com/community/pocket/data/model/VisitorPeople.java b/app/src/main/java/com/community/pocket/data/model/VisitorPeople.java new file mode 100644 index 0000000..b0a82ea --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/VisitorPeople.java @@ -0,0 +1,27 @@ +package com.community.pocket.data.model; + +import java.util.List; + +/** + * 检索预约人 + */ +public class VisitorPeople { + private String name; + private List time; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getTime() { + return time; + } + + public void setTime(List time) { + this.time = time; + } +} diff --git a/app/src/main/java/com/community/pocket/data/resetpwd/ResetPwdRequest.java b/app/src/main/java/com/community/pocket/data/resetpwd/ResetPwdRequest.java index eb13d18..5548612 100644 --- a/app/src/main/java/com/community/pocket/data/resetpwd/ResetPwdRequest.java +++ b/app/src/main/java/com/community/pocket/data/resetpwd/ResetPwdRequest.java @@ -1,7 +1,6 @@ package com.community.pocket.data.resetpwd; -import com.community.pocket.util.Result; -import com.community.pocket.util.Valid; +import com.community.pocket.ui.resetpwd.ResetPwdResponse; /** * 重置密码请求 @@ -22,30 +21,34 @@ public class ResetPwdRequest { /** * 检查用户邮箱 + * TODO R.string.resetpwd_step1_ok */ - public Result checkUser(String username, String email) { - return new Result<>(Valid.ok, null); + public ResetPwdResponse checkUser(String username, String email) { + return new ResetPwdResponse(); } /** * 发送验证码 + * TODO R.string.resetpwd_step2_ok */ - public Result sendCode(String username, String email) { - return new Result<>(Valid.ok, null); + public ResetPwdResponse sendCode(String username, String email) { + return new ResetPwdResponse(); } /** * 检查验证码 + * TODO R.string.resetpwd_step2_valid_ok */ - public Result checkCode(String username, String email, String code) { - return new Result<>(Valid.ok, null); + public ResetPwdResponse checkCode(String username, String email, String code) { + return new ResetPwdResponse(); } /** * 重置密码 + * TODO R.string.resetpwd_step3_ok */ - public Result resetPwd(String username, String password) { - return new Result<>(Valid.ok, null); + public ResetPwdResponse resetPwd(String username, String password) { + return new ResetPwdResponse(); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java index e6d070f..5ac3e56 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java @@ -114,9 +114,9 @@ public class ForumDataActivity extends BaseActivity { }); //监听帖子详情数据 - viewModel.getForumContentResponse().observe(this, new Observer>>() { + viewModel.getForumContentResponse().observe(this, new Observer() { @Override - public void onChanged(ForumDataResponse> listForumDataResponse) { + public void onChanged(ForumDataResponse listForumDataResponse) { if (listForumDataResponse == null) { return; } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java index 7042a73..c270887 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java @@ -1,46 +1,14 @@ 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 响应实体 */ -public class ForumDataResponse { - @Nullable - private Integer success; - @Nullable - private Integer error; - - private T body; - - @Nullable - public Integer getSuccess() { - return success; - } - - public ForumDataResponse setSuccess(@Nullable Integer success) { - this.success = success; - return this; - } - - @Nullable - public Integer getError() { - return error; - } - - public ForumDataResponse setError(@Nullable Integer error) { - this.error = error; - return this; - } - - T getBody() { - return body; - } +public class ForumDataResponse extends Response> { - public ForumDataResponse setBody(T body) { - this.body = body; - return this; - } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java index 8bc386f..1ab74af 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java @@ -5,12 +5,8 @@ import androidx.lifecycle.ViewModel; import com.community.pocket.R; 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 java.util.List; - /** * 帖子详情数据管理 */ @@ -22,7 +18,7 @@ class ForumDataViewModel extends ViewModel { private MutableLiveData replayResponse = new MutableLiveData<>(); //帖子详情数据状态 - private MutableLiveData>> forumContentResponse = new MutableLiveData<>(); + private MutableLiveData forumContentResponse = new MutableLiveData<>(); private ForumDataRequest forumDataRequest; @@ -38,7 +34,7 @@ class ForumDataViewModel extends ViewModel { return replayResponse; } - MutableLiveData>> getForumContentResponse() { + MutableLiveData getForumContentResponse() { return forumContentResponse; } @@ -57,16 +53,16 @@ class ForumDataViewModel extends ViewModel { /** * 回帖状态 - * + *TODO * @param content 内容 */ void sendReply(String content) { - Valid valid = forumDataRequest.sendReply(content); - if (valid == Valid.ok) { - replayResponse.setValue(new ForumDataResponse().setSuccess(R.string.forum_reply_ok)); - } else { - replayResponse.setValue(new ForumDataResponse().setError(R.string.forum_reply_fail)); - } +// Valid valid = forumDataRequest.sendReply(content); +// if (valid == Valid.ok) { +// replayResponse.setValue(new ForumDataResponse().setSuccess(R.string.forum_reply_ok)); +// } else { +// replayResponse.setValue(new ForumDataResponse().setError(R.string.forum_reply_fail)); +// } } /** @@ -75,8 +71,7 @@ class ForumDataViewModel extends ViewModel { * @param forumId 帖子id */ void loadData(int forumId) { - ForumDataResponse> forumDataResponse = forumDataRequest.loadData(forumId); - forumContentResponse.setValue(forumDataResponse); + forumDataRequest.loadData(forumContentResponse, forumId); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotViewModel.java index 6895ca1..5e54b69 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotViewModel.java @@ -17,8 +17,7 @@ public class ForumHotViewModel extends BaseViewModel { //加载热门信息 void loadHot() { - ForumHotResponse response = getRequest().loadHot(); - forumHotResponse.setValue(response); + getRequest().loadHot(forumHotResponse); } @Override diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumViewModel.java index fe7e545..3429ff3 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumViewModel.java @@ -17,8 +17,7 @@ public class ForumViewModel extends BaseViewModel { } void loadNotice() { - ForumNoticeResponse response = getRequest().loadNotices(); - noticeDataResponse.setValue(response); + getRequest().loadNotices(noticeDataResponse); } @Override diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java index b9945e0..818f7cb 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java @@ -16,8 +16,7 @@ public class ForumMyViewModel extends BaseViewModel { } void loadForumMy() { - ForumMyResponse response = getRequest().loadForumMy(); - forumMyResponse.setValue(response); + getRequest().loadForumMy(forumMyResponse); } @Override diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java index fefa08f..b01fe0c 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java @@ -18,8 +18,7 @@ public class ForumNewViewModel extends BaseViewModel { } void loadForumNew() { - ForumNewResponse response = getRequest().loadForumNew(); - forumNewResponse.setValue(response); + getRequest().loadForumNew(forumNewResponse); } @Override diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java index b8e08a8..51b9756 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java @@ -4,7 +4,6 @@ import androidx.lifecycle.MutableLiveData; import com.community.pocket.R; import com.community.pocket.data.main.forum.ForumPostRequest; -import com.community.pocket.util.Valid; import com.community.pocket.util.ValidUtil; 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) { - Valid valid = forumPostRequest.sendActive(type, title, content, activeStartTime, activeEndTime, activeScore); - if (valid == Valid.ok) { - forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); - } else { - forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); - } +// Valid valid = forumPostRequest.sendActive(type, title, content, activeStartTime, activeEndTime, activeScore); +// if (valid == Valid.ok) { +// forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); +// } else { +// forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); +// } } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java index a00a9dc..3cecef4 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java @@ -79,9 +79,9 @@ public class ForumPostComplainFragment extends ForumPostContent { //监听发帖状态 sendPost(viewModel); - viewModel.getSearchPeople().observe(getViewLifecycleOwner(), new Observer>>() { + viewModel.getSearchPeople().observe(getViewLifecycleOwner(), new Observer() { @Override - public void onChanged(ForumPostResponse> listForumPostResponse) { + public void onChanged(ForumPostResponse listForumPostResponse) { if (listForumPostResponse == null) { return; } @@ -101,6 +101,7 @@ public class ForumPostComplainFragment extends ForumPostContent { public void afterTextChanged(Editable s) { if (nameList != null && nameList.containsKey(s.toString())) { viewModel.complainDataChanged(postTitle.getText().toString(), postContent.getText().toString(), searchName.getText().toString()); + return; } myAutoCompleteTextView.searchHandler(); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java index 23b9c9a..551af63 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java @@ -5,11 +5,8 @@ import androidx.lifecycle.MutableLiveData; import com.community.pocket.R; import com.community.pocket.data.main.forum.ForumPostRequest; import com.community.pocket.ui.main.ui.share.SearchViewModel; -import com.community.pocket.util.Valid; import com.community.pocket.util.ValidUtil; -import java.util.List; - /** * 投诉贴数据管理 */ @@ -19,7 +16,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie private MutableLiveData forumPostFormState = new MutableLiveData<>(); //检索投诉人 - private MutableLiveData>> searchPeople = new MutableLiveData<>(); + private MutableLiveData searchPeople = new MutableLiveData<>(); ForumPostComplainViewModel(ForumPostRequest forumPostRequest) { super(forumPostRequest); @@ -29,7 +26,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie return forumPostFormState; } - MutableLiveData>> getSearchPeople() { + MutableLiveData getSearchPeople() { return searchPeople; } @@ -54,14 +51,15 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie * @param title 标题 * @param content 正文 * @param complain 投诉人 + * TODO */ void sendComplain(String title, String content, String complain) { - Valid valid = forumPostRequest.sendComplain(title, content, complain); - if (valid == Valid.ok) { - forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); - } else { - forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); - } +// Valid valid = forumPostRequest.sendComplain(title, content, complain); +// if (valid == Valid.ok) { +// forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); +// } else { +// forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); +// } } /** @@ -70,8 +68,7 @@ class ForumPostComplainViewModel extends ForumPostViewModel implements SearchVie * @param name 投诉人 */ private void searchPeople(String name) { - ForumPostResponse> forumPostResponse = forumPostRequest.searchPeople(name); - searchPeople.setValue(forumPostResponse); + forumPostRequest.searchPeople(searchPeople, name); } @Override diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostResponse.java index 31581bc..e391fcd 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostResponse.java @@ -1,41 +1,12 @@ 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 { - @Nullable - private Integer success; - @Nullable - private Integer error; +import java.util.List; - private T body; +/** + * 检索投诉人响应结果 + */ +public class ForumPostResponse extends Response> { - @Nullable - public Integer getSuccess() { - return success; - } - - public ForumPostResponse setSuccess(@Nullable Integer success) { - this.success = success; - return this; - } - - @Nullable - public Integer getError() { - return error; - } - - public ForumPostResponse setError(@Nullable Integer error) { - this.error = error; - return this; - } - - T getBody() { - return body; - } - - public ForumPostResponse setBody(T body) { - this.body = body; - return this; - } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java index 7be9aae..8d01da3 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java @@ -4,7 +4,6 @@ import androidx.lifecycle.MutableLiveData; import com.community.pocket.R; import com.community.pocket.data.main.forum.ForumPostRequest; -import com.community.pocket.util.Valid; import com.community.pocket.util.ValidUtil; /** @@ -34,12 +33,13 @@ class ForumPostTopicViewModel extends ForumPostViewModel { } //发送动态贴 + //TODO void sendTopic(String title, String content) { - Valid valid = forumPostRequest.sendTopic(title, content); - if (valid == Valid.ok) { - forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); - } else { - forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); - } +// Valid valid = forumPostRequest.sendTopic(title, content); +// if (valid == Valid.ok) { +// forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok)); +// } else { +// forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail)); +// } } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java index 1416f60..2bc1d67 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java @@ -79,6 +79,7 @@ public class GarbageSortingFragment extends BaseFragment { public void afterTextChanged(Editable s) { if (garbageSortingAdpter != null && garbageSortingAdpter.containsKey(s.toString())) { initView(garbageSortingAdpter.get(s.toString())); + return; } myAutoCompleteTextView.searchHandler(); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java index 2869b41..cb5a053 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java @@ -25,7 +25,6 @@ public class GarbageSortingViewModel extends BaseViewModel im //检索默认废品请求状态 void searchDefault() { - GarbageWasteResponse response = getRequest().searchDefault(); - defaultList.setValue(response); + getRequest().searchDefault(defaultList); } //检索废品请求状态 @Override public void search(String content) { - GarbageWasteResponse response = getRequest().search(content); - searchList.setValue(response); + getRequest().search(searchList, content); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java index 62d5b9e..1ed0500 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java @@ -161,9 +161,9 @@ public class InfoFragment extends BaseFragment { }); //监听个人信息请求状态 - viewModel.getInfoResponse().observe(getViewLifecycleOwner(), new Observer>() { + viewModel.getInfoResponse().observe(getViewLifecycleOwner(), new Observer() { @Override - public void onChanged(InfoResponse myInfoInfoResponse) { + public void onChanged(InfoResponse myInfoInfoResponse) { if (myInfoInfoResponse == null) { return; } @@ -280,5 +280,7 @@ public class InfoFragment extends BaseFragment { lineData.addDataSet(lineDataSet); lineChart.getDescription().setEnabled(false); lineChart.setData(lineData); + lineChart.callOnClick(); + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java index 5243104..5606b06 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java @@ -1,47 +1,12 @@ 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 响应实体信息 */ -public class InfoResponse { - @Nullable - private Integer success; - @Nullable - private Integer error; - - private T body; - - @Nullable - public Integer getSuccess() { - return success; - } - - public InfoResponse setSuccess(@Nullable Integer success) { - this.success = success; - return this; - } - - @Nullable - public Integer getError() { - return error; - } - - public InfoResponse setError(@Nullable Integer error) { - this.error = error; - return this; - } - - T getBody() { - return body; - } - - public InfoResponse setBody(T body) { - this.body = body; - return this; - } +public class InfoResponse extends Response { } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoViewModel.java index 579be6f..c36583f 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoViewModel.java @@ -5,7 +5,6 @@ import androidx.lifecycle.ViewModel; import com.community.pocket.R; import com.community.pocket.data.main.info.InfoRequest; -import com.community.pocket.data.model.MyInfo; import com.community.pocket.util.ValidUtil; //个人信息UI数据管理 @@ -18,7 +17,7 @@ class InfoViewModel extends ViewModel { private MutableLiveData modifyResponse = new MutableLiveData<>(); //个人信息请求状态 - private MutableLiveData> infoResponse = new MutableLiveData<>(); + private MutableLiveData infoResponse = new MutableLiveData<>(); //请求接口管理 private InfoRequest infoRequest; @@ -35,7 +34,7 @@ class InfoViewModel extends ViewModel { return modifyResponse; } - MutableLiveData> getInfoResponse() { + MutableLiveData getInfoResponse() { return infoResponse; } @@ -55,14 +54,14 @@ class InfoViewModel extends ViewModel { } //修改密码 + //TODO void modifyPwd(String oldpwd, String newpwd) { - InfoResponse infoResponse = infoRequest.modifyPwd(oldpwd, newpwd); - modifyResponse.setValue(infoResponse); +// InfoResponse infoResponse = infoRequest.modifyPwd(oldpwd, newpwd); +// modifyResponse.setValue(infoResponse); } //获取个人信息 void loadInfo() { - InfoResponse myInfoInfoResponse = infoRequest.loadInfo(); - infoResponse.setValue(myInfoInfoResponse); + infoRequest.loadInfo(infoResponse); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java b/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java index f993b8d..a4e8866 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java @@ -2,8 +2,11 @@ package com.community.pocket.ui.main.ui.share; import android.content.Context; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.gson.Gson; + /** * 响应体父类 * @@ -21,6 +24,27 @@ public abstract class Response { //响应体 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 public Integer getSuccess() { return success; @@ -70,4 +94,16 @@ public abstract class Response { public void setArgs(Object[] args) { this.args = args; } + + + public enum Result { + OK, + FAIL + } + + @NonNull + @Override + public String toString() { + return new Gson().toJson(body); + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java index 37c964f..e7d523e 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java @@ -19,6 +19,7 @@ import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; 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.listener.MyTextChange; 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.Method; import java.util.List; -import java.util.Map; import java.util.Objects; /** @@ -129,9 +129,9 @@ public class VisitorAppointmentFragment extends BaseFragment { }); //检索预约人请求结果 - appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), new Observer>>>() { + appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), new Observer() { @Override - public void onChanged(VisitorResponse>> visitorResponse) { + public void onChanged(VisitorResponse visitorResponse) { if (visitorResponse == null) { return; } @@ -160,6 +160,7 @@ public class VisitorAppointmentFragment extends BaseFragment { if (visitorAdpter != null && visitorAdpter.containsKey(s.toString())) { appointmentViewModel.appointmentDataChanged(appointment.getText(), notes.getText()); initTime(s); + return; } appointment.setTag(R.string.visitor_tag, s.toString()); @@ -181,7 +182,7 @@ public class VisitorAppointmentFragment extends BaseFragment { * 搜索框 */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) - private void initSearch(Map> arrays) { + private void initSearch(List arrays) { // 设置适配器 if (visitorAdpter == null) { visitorAdpter = new VisitorAdpter(arrays, getContext()); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorResponse.java index 6c7e791..0bfc67b 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorResponse.java @@ -1,46 +1,12 @@ package com.community.pocket.ui.main.ui.visitor.appointment; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; +import com.community.pocket.data.model.VisitorPeople; +import com.community.pocket.ui.main.ui.share.Response; + +import java.util.List; /** * 访客接口请求结果 */ -public class VisitorResponse { - @Nullable - private Integer success; - @Nullable - private Integer error; - - private T body; - - @Nullable - public Integer getSuccess() { - return success; - } - - public VisitorResponse setSuccess(@Nullable Integer success) { - this.success = success; - return this; - } - - @Nullable - public Integer getError() { - return error; - } - - public VisitorResponse setError(@Nullable Integer error) { - this.error = error; - return this; - } - - @NonNull - T getBody() { - return body; - } - - public VisitorResponse setBody(@NonNull T body) { - this.body = body; - return this; - } +public class VisitorResponse extends Response> { } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java index 6fdf447..4e0f23d 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java @@ -8,12 +8,8 @@ import androidx.lifecycle.ViewModel; import com.community.pocket.R; import com.community.pocket.data.main.visitor.VisitorRequest; import com.community.pocket.ui.main.ui.share.SearchViewModel; -import com.community.pocket.util.Valid; import com.community.pocket.util.ValidUtil; -import java.util.List; -import java.util.Map; - /** * 管理访客UI数据 */ @@ -26,7 +22,7 @@ class VisitorViewModel extends ViewModel implements SearchViewModel { private MutableLiveData visitorResponse = new MutableLiveData<>(); //检索预约人 - private MutableLiveData>>> searchPeopleReq = new MutableLiveData<>(); + private MutableLiveData searchPeopleReq = new MutableLiveData<>(); //访客请求 private VisitorRequest visitorRequest; @@ -43,24 +39,24 @@ class VisitorViewModel extends ViewModel implements SearchViewModel { return visitorResponse; } - MutableLiveData>>> getSearchPeopleReq() { + MutableLiveData getSearchPeopleReq() { return searchPeopleReq; } //访客预约 + //TODO void appointment(String appointment, String chooseTime, String notes) { - Valid valid = visitorRequest.appointment(appointment, chooseTime, notes); - if (valid == Valid.ok) { - visitorResponse.setValue(new VisitorResponse().setSuccess(R.string.visitor_appointment_ok)); - } else { - visitorResponse.setValue(new VisitorResponse().setError(R.string.visitor_appointment_fail)); - } +// Valid valid = visitorRequest.appointment(appointment, chooseTime, notes); +// if (valid == Valid.ok) { +// visitorResponse.setValue(new VisitorResponse().setSuccess(R.string.visitor_appointment_ok)); +// } else { +// visitorResponse.setValue(new VisitorResponse().setError(R.string.visitor_appointment_fail)); +// } } //检索预约人 private void searchPeople(String name) { - VisitorResponse>> result = visitorRequest.searchPeople(name); - searchPeopleReq.setValue(result); + visitorRequest.searchPeople(searchPeopleReq, name); } //校验访客预约表单 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java index 03d38fa..6fdfc2d 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java @@ -21,8 +21,7 @@ public class VisitorMyViewModel extends BaseViewModel { * 加载我的访客 */ void loadMy() { - VisitorMyResponse response = getRequest().loadMy(); - visitorMyResponse.setValue(response); + getRequest().loadMy(visitorMyResponse); } @Override diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java index a629185..a440f85 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java @@ -18,8 +18,7 @@ public class VisitorReservationViewModel extends BaseViewModel result = resetPwdRequest.checkUser(username, email); - if (result.getValid() == Valid.ok) { - resetPwdResultStep1.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step1_ok)); - } else { - resetPwdResultStep1.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step1_fail)); - } + ResetPwdResponse response = resetPwdRequest.checkUser(username, email); + resetPwdResultStep1.setValue(response); } //重置密码第二步 void sendCode(String username, String email) { - Result result = resetPwdRequest.sendCode(username, email); - if (result.getValid() == Valid.ok) { - resetPwdResultStep2.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step2_ok)); - resetpwdStep2Changed(); - } else { - resetPwdResultStep2.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step2_fail)); - } + ResetPwdResponse response = resetPwdRequest.sendCode(username, email); + resetPwdResultStep2.setValue(response); } //重置密码第二步 void checkCode(String username, String email, String code) { - Result result = resetPwdRequest.checkCode(username, email, code); - if (result.getValid() == Valid.ok) { - resetPwdResultStep2.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step2_valid_ok)); - } else { - resetPwdResultStep2.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step2_valid_fail)); - } + ResetPwdResponse response = resetPwdRequest.checkCode(username, email, code); + resetPwdResultStep2.setValue(response); } //重置密码第三步 void resetPwd(String username, String password) { - Result result = resetPwdRequest.resetPwd(username, password); - if (result.getValid() == Valid.ok) { - resetPwdResultStep3.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step3_ok)); - } else { - resetPwdResultStep3.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step3_fail)); - } + ResetPwdResponse response = resetPwdRequest.resetPwd(username, password); + resetPwdResultStep3.setValue(response); } //监听重置密码第一步表单触发校验 diff --git a/app/src/main/java/com/community/pocket/util/HttpParse.java b/app/src/main/java/com/community/pocket/util/HttpParse.java new file mode 100644 index 0000000..7a1d652 --- /dev/null +++ b/app/src/main/java/com/community/pocket/util/HttpParse.java @@ -0,0 +1,15 @@ +package com.community.pocket.util; + +import org.jetbrains.annotations.NotNull; + +import okhttp3.Call; +import okhttp3.Response; + +/** + * 解析接口返回数据 + * + * @param 转化实体类型 + */ +public interface HttpParse { + void onParseOk(@NotNull Call call, @NotNull Response response, T t); +} diff --git a/app/src/main/java/com/community/pocket/util/HttpRequest.java b/app/src/main/java/com/community/pocket/util/HttpRequest.java new file mode 100644 index 0000000..7fcc124 --- /dev/null +++ b/app/src/main/java/com/community/pocket/util/HttpRequest.java @@ -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(); +} diff --git a/app/src/main/java/com/community/pocket/util/HttpResponse.java b/app/src/main/java/com/community/pocket/util/HttpResponse.java new file mode 100644 index 0000000..e4d2bd0 --- /dev/null +++ b/app/src/main/java/com/community/pocket/util/HttpResponse.java @@ -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 响应实体类型 + */ +public class HttpResponse implements Callback { + + private Class tClass; + + private HttpParse httpParse; + + private static final String header = "Content-Type"; + + HttpResponse(Class tClass, HttpParse 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); + } + +} diff --git a/app/src/main/java/com/community/pocket/util/HttpUtil.java b/app/src/main/java/com/community/pocket/util/HttpUtil.java new file mode 100644 index 0000000..dbf93f7 --- /dev/null +++ b/app/src/main/java/com/community/pocket/util/HttpUtil.java @@ -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 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 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; + } + +} diff --git a/app/src/main/java/com/community/pocket/util/MyCallBack.java b/app/src/main/java/com/community/pocket/util/MyCallBack.java new file mode 100644 index 0000000..240bfe9 --- /dev/null +++ b/app/src/main/java/com/community/pocket/util/MyCallBack.java @@ -0,0 +1,5 @@ +package com.community.pocket.util; + +public interface MyCallBack { + void call(T forumNoticeResponse); +} diff --git a/app/src/main/java/com/community/pocket/util/Result.java b/app/src/main/java/com/community/pocket/util/Result.java deleted file mode 100644 index 6b45da7..0000000 --- a/app/src/main/java/com/community/pocket/util/Result.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.community.pocket.util; - -public class Result { - 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; - } -} diff --git a/app/src/main/java/com/community/pocket/util/SimpleHttpParse.java b/app/src/main/java/com/community/pocket/util/SimpleHttpParse.java new file mode 100644 index 0000000..1158e35 --- /dev/null +++ b/app/src/main/java/com/community/pocket/util/SimpleHttpParse.java @@ -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 implements HttpParse { + + 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 getInterface(Class 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); + } +} diff --git a/app/src/main/java/com/community/pocket/util/Valid.java b/app/src/main/java/com/community/pocket/util/Valid.java index 1e09235..915ac41 100644 --- a/app/src/main/java/com/community/pocket/util/Valid.java +++ b/app/src/main/java/com/community/pocket/util/Valid.java @@ -1,5 +1,6 @@ package com.community.pocket.util; +//TODO 测试类 public enum Valid { empty_err, password_err, diff --git a/app/src/test/java/com/community/pocket/ExampleUnitTest.java b/app/src/test/java/com/community/pocket/ExampleUnitTest.java index 522801e..98e604e 100644 --- a/app/src/test/java/com/community/pocket/ExampleUnitTest.java +++ b/app/src/test/java/com/community/pocket/ExampleUnitTest.java @@ -2,7 +2,7 @@ package com.community.pocket; 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). @@ -14,4 +14,11 @@ public class ExampleUnitTest { public void addition_isCorrect() { assertEquals(4, 2 + 2); } + + @Test + public void class_tuil() { +// ForumRequest.getInstance().loadNotices(null); +// +// TimeUnit.SECONDS.sleep(100); + } } \ No newline at end of file