From 174661a3758560682704d132b159a3e56f660b59 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Tue, 21 Apr 2020 11:51:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=A0=E8=BD=BD=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E5=B8=96=E5=AD=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/main/forum/ForumMyRequest.java | 2 +- .../data/main/forum/ForumNewRequest.java | 2 +- .../com/community/pocket/ui/BaseFragment.java | 13 +- .../pocket/ui/main/ui/forum/FormLoad.java | 5 + .../pocket/ui/main/ui/forum/ForumPost.java | 49 +++- .../ui/main/ui/forum/main/ForumFragment.java | 39 ++- .../ui/main/ui/forum/my/ForumMyFragment.java | 43 ++- .../ui/main/ui/forum/my/ForumMyResponse.java | 2 + .../ui/main/ui/forum/my/ForumMyViewModel.java | 11 +- .../main/ui/forum/news/ForumNewFragment.java | 51 +++- .../main/ui/forum/news/ForumNewResponse.java | 2 + .../main/ui/forum/news/ForumNewViewModel.java | 6 +- .../main/ui/forum/post/ForumPostContent.java | 27 +- .../VisitorAppointmentFragment.java | 76 +++-- .../layout/main/layout/forum/layout/forum.xml | 1 - .../forum/layout/forum_hot_fragment.xml | 124 ++++----- .../layout/forum/layout/forum_my_fragment.xml | 32 +-- .../forum/layout/forum_new_fragment.xml | 32 +-- .../forum/layout/forum_post_fragment.xml | 80 +++--- .../layout/visitor_appointment_fragment.xml | 263 ++++++++---------- app/src/main/res/values-en-rUS/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 23 files changed, 463 insertions(+), 400 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/FormLoad.java 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 49a3400..4df9e3a 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 @@ -31,7 +31,7 @@ public class ForumMyRequest { * 加载我的帖子 */ @HttpRequest("/forum/my") - public void loadForumMy(MutableLiveData liveData, int page, String title) { + public void loadForumMy(MutableLiveData liveData, Long page, String title) { HttpUtil.getRequest(HttpUtil.Method.GET, new SimpleHttpParse(liveData).getInterface(ForumMyResponse.class), new FormBody.Builder() 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 369973c..05620a7 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 @@ -28,7 +28,7 @@ public class ForumNewRequest { } @HttpRequest("/forum/new") - public void loadForumNew(MutableLiveData liveData, int page, String title) { + public void loadForumNew(MutableLiveData liveData, Long page, String title) { HttpUtil.getRequest(HttpUtil.Method.GET, new SimpleHttpParse(liveData).getInterface(ForumNewResponse.class), new FormBody.Builder() diff --git a/app/src/main/java/com/community/pocket/ui/BaseFragment.java b/app/src/main/java/com/community/pocket/ui/BaseFragment.java index 0383884..0cf79fa 100644 --- a/app/src/main/java/com/community/pocket/ui/BaseFragment.java +++ b/app/src/main/java/com/community/pocket/ui/BaseFragment.java @@ -27,8 +27,8 @@ public abstract class BaseFragment extends Fragment { } //获取父级Fragment - protected T getParentFragment(int level) { - return getParentFragment(level, null); + protected T getParentFragment(Class tClass) { + return getParentFragment(tClass, null); } //校验token失败跳转到登陆页 @@ -38,17 +38,18 @@ public abstract class BaseFragment extends Fragment { //获取父级Fragment @SuppressWarnings("unchecked") - private T getParentFragment(int level, Fragment fragment) { - if (level-- > 0) { + private T getParentFragment(Class tClass, Fragment fragment) { if (fragment == null) { fragment = getParentFragment(); } else { fragment = fragment.getParentFragment(); } - return getParentFragment(level, fragment); + if (fragment != null) { + return fragment.getClass().isAssignableFrom(tClass) ? (T) fragment : getParentFragment(tClass, fragment); } else { - return (T) fragment; + throw new RuntimeException("not fround parent Fragment for " + tClass); } + } //格式化日期 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/FormLoad.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/FormLoad.java new file mode 100644 index 0000000..6ed7bab --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/FormLoad.java @@ -0,0 +1,5 @@ +package com.community.pocket.ui.main.ui.forum; + +public interface FormLoad { + void loadForumNew(Long page, String title); +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java index 0c7015b..3c6c4f6 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java @@ -1,18 +1,23 @@ package com.community.pocket.ui.main.ui.forum; import android.content.Intent; +import android.os.Build; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.Toast; + +import androidx.annotation.RequiresApi; +import androidx.appcompat.widget.SearchView; +import androidx.core.widget.NestedScrollView; import com.community.pocket.R; import com.community.pocket.data.model.Forum; import com.community.pocket.data.model.Page; import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.main.ui.forum.data.ForumDataActivity; +import com.community.pocket.ui.main.ui.forum.main.ForumFragment; import com.community.pocket.util.Param; import org.xutils.view.annotation.ViewInject; @@ -33,10 +38,9 @@ public abstract class ForumPost extends BaseFragment { */ protected void loadPost(Page forumList) { - if (forumList.isEmpty()) { - Toast.makeText(getContext(), R.string.no_more_forum, Toast.LENGTH_LONG).show(); - } else { - layout.removeViews(1, layout.getChildCount() - 1); + if (forumList.getCurrentPage() == 1) { + layout.removeAllViews(); + } for (int i = 0; i < forumList.getList().size(); i++) { final Forum forum = forumList.getList().get(i); @@ -74,19 +78,36 @@ public abstract class ForumPost extends BaseFragment { //打开帖子 Button button = childView.findViewById(R.id.showAll); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(getContext(), ForumDataActivity.class); - intent.putExtra(Param.forumId.name(), forum.getId()); - startActivityForResult(intent, 1); -// startActivity(intent); - } + button.setOnClickListener(v -> { + Intent intent = new Intent(getContext(), ForumDataActivity.class); + intent.putExtra(Param.forumId.name(), forum.getId()); + startActivityForResult(intent, 1); }); layout.addView(childView); + } - } } + protected abstract FormLoad getViewModel(); + + protected abstract Long getCurrentPage(); + + protected abstract SearchView searchView(); + + protected void load(Long page) { + getViewModel().loadForumNew(page, searchView().getQuery().toString()); + } + + //滚动加载更多帖子 + @RequiresApi(api = Build.VERSION_CODES.M) + protected void loadMore() { + //滚动加载更多帖子 + ForumFragment forumFragment = getParentFragment(ForumFragment.class); + forumFragment.getScrollView().setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> { + if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) { + load(getCurrentPage() + 1); + } + }); + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java index 58589ca..50925c8 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java @@ -3,6 +3,7 @@ package com.community.pocket.ui.main.ui.forum.main; import android.annotation.SuppressLint; import android.os.Build; import android.os.Bundle; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.widget.Button; @@ -12,6 +13,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.core.widget.NestedScrollView; +import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; @@ -26,6 +28,7 @@ import org.xutils.view.annotation.Event; import org.xutils.view.annotation.ViewInject; import java.util.List; +import java.util.concurrent.TimeUnit; /** * 论坛框架 @@ -37,7 +40,7 @@ public class ForumFragment extends MainFragment { private MyBanner banner; @ViewInject(R.id.scroll_body) - private NestedScrollView nestedScrollView; + private NestedScrollView scrollView; @ViewInject(R.id.forum_new) private Button newButton; @@ -47,6 +50,9 @@ public class ForumFragment extends MainFragment { @ViewInject(R.id.notice_next) private ImageView noticeNext; + //触发自动滚动 + private MutableLiveData autoScroll = new MutableLiveData<>(); + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -69,6 +75,8 @@ public class ForumFragment extends MainFragment { initNotice(forumNoticeResponse.getNoticeList()); } }); + + resumeAutoScroll(); } //初始化公告箭头事件 @@ -79,6 +87,10 @@ public class ForumFragment extends MainFragment { initClickListener(noticeNext); } + public NestedScrollView getScrollView() { + return scrollView; + } + //箭头随焦点改变透明度 @SuppressLint("ClickableViewAccessibility") private void initFocusListener(ImageView imageView) { @@ -103,6 +115,24 @@ public class ForumFragment extends MainFragment { } else { banner.setCurrentItem(banner.getCurrentItem() < banner.getItemCount() - 1 ? banner.getCurrentItem() + 1 : 0); } + new Thread(() -> { + try { + TimeUnit.SECONDS.sleep(3); + autoScroll.postValue(true); + } catch (InterruptedException e) { + e.printStackTrace(); + Log.e(ForumFragment.class.getName(), e.toString()); + } + }).start(); + }); + } + + //恢复自动滚动 + private void resumeAutoScroll() { + this.autoScroll.observe(getViewLifecycleOwner(), aBoolean -> { + if (aBoolean) { + banner.start(); + } }); } @@ -127,10 +157,11 @@ public class ForumFragment extends MainFragment { } private void scrollTop() { - nestedScrollView.fling(0); - nestedScrollView.smoothScrollTo(0, 0); + scrollView.fling(0); + scrollView.smoothScrollTo(0, 0); } - + + //跳转热榜界面 @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Event(value = R.id.forum_hot) diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java index 1915a6b..69748b1 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java @@ -7,10 +7,10 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SearchView; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; +import com.community.pocket.ui.main.ui.forum.FormLoad; import com.community.pocket.ui.main.ui.forum.ForumPost; import com.community.pocket.ui.main.ui.share.Response; @@ -28,19 +28,21 @@ public class ForumMyFragment extends ForumPost { @ViewInject(R.id.search) private SearchView searchView; + private Long currentPage = 1L; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class); - viewModel.loadForumMy(1, ""); + load(1L); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (!query.isEmpty()) { - viewModel.loadForumMy(1, searchView.getQuery().toString()); + load(1L); return true; } else { return false; @@ -55,18 +57,16 @@ public class ForumMyFragment extends ForumPost { }); //监听我的帖子加载状态 - viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(ForumMyResponse forumMyResponse) { - if (forumMyResponse == null) { - return; - } + viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), forumMyResponse -> { + if (forumMyResponse == null) { + return; + } - forumMyResponse.toast(getContext()); + forumMyResponse.toast(getContext()); - if (forumMyResponse.getResult() == Response.Result.OK) { - loadPost(forumMyResponse.getForumList()); - } + if (forumMyResponse.getResult() == Response.Result.OK) { + this.currentPage = forumMyResponse.getForumList().getCurrentPage(); + loadPost(forumMyResponse.getForumList()); } }); } @@ -81,10 +81,25 @@ public class ForumMyFragment extends ForumPost { return View.VISIBLE; } + @Override + protected FormLoad getViewModel() { + return viewModel; + } + + @Override + protected Long getCurrentPage() { + return currentPage; + } + + @Override + protected SearchView searchView() { + return searchView; + } + @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - viewModel.loadForumMy(1, ""); + load(1L); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java index ba2e9ea..493dbc4 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java @@ -23,6 +23,8 @@ public class ForumMyResponse extends Response { enum Msg implements CustomMessage { ok(R.string.load_forum_my_ok), + ok_empty(R.string.no_more_forum), + ok_more(R.string.load_more_forum_ok), fail(R.string.load_forum_my_fail), token(R.string.invalid_token); 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 a16fe2d..777e378 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 @@ -3,10 +3,11 @@ package com.community.pocket.ui.main.ui.forum.my; import androidx.lifecycle.MutableLiveData; import com.community.pocket.data.main.forum.ForumMyRequest; +import com.community.pocket.ui.main.ui.forum.FormLoad; import com.community.pocket.ui.main.ui.share.BaseViewModel; //我的帖子UI数据管理 -public class ForumMyViewModel extends BaseViewModel { +public class ForumMyViewModel extends BaseViewModel implements FormLoad { //我的帖子请求状态 private MutableLiveData forumMyResponse = new MutableLiveData<>(); @@ -15,12 +16,14 @@ public class ForumMyViewModel extends BaseViewModel { return forumMyResponse; } - void loadForumMy(int page, String title) { - getRequest().loadForumMy(forumMyResponse, page, title); - } @Override protected ForumMyRequest getRequest() { return ForumMyRequest.getInstance(); } + + @Override + public void loadForumNew(Long page, String title) { + getRequest().loadForumMy(forumMyResponse, page, title); + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java index 67767f5..3fa2fac 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java @@ -1,16 +1,17 @@ package com.community.pocket.ui.main.ui.forum.news; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SearchView; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; +import com.community.pocket.ui.main.ui.forum.FormLoad; import com.community.pocket.ui.main.ui.forum.ForumPost; import com.community.pocket.ui.main.ui.share.Response; @@ -28,19 +29,21 @@ public class ForumNewFragment extends ForumPost { @ViewInject(R.id.search) private SearchView searchView; + private Long currentPage = 1L; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumNewViewModel.class); - viewModel.loadForumNew(1, searchView.getQuery().toString()); + load(1L); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (!query.isEmpty()) { - viewModel.loadForumNew(1, searchView.getQuery().toString()); + load(1L); return true; } else { return false; @@ -54,21 +57,25 @@ public class ForumNewFragment extends ForumPost { } }); + //监听最新帖子请求状态 - viewModel.getForumNewResponse().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(ForumNewResponse forumNewResponse) { - if (forumNewResponse == null) { - return; - } + viewModel.getForumNewResponse().observe(getViewLifecycleOwner(), forumNewResponse -> { + if (forumNewResponse == null) { + return; + } - forumNewResponse.toast(getContext()); + forumNewResponse.toast(getContext()); - if (forumNewResponse.getResult() == Response.Result.OK) { - loadPost(forumNewResponse.getForumList()); - } + if (forumNewResponse.getResult() == Response.Result.OK) { + this.currentPage = forumNewResponse.getForumList().getCurrentPage(); + loadPost(forumNewResponse.getForumList()); } }); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + loadMore(); + } + } @Override @@ -81,10 +88,24 @@ public class ForumNewFragment extends ForumPost { return View.GONE; } + @Override + protected FormLoad getViewModel() { + return viewModel; + } + + @Override + protected Long getCurrentPage() { + return currentPage; + } + + @Override + protected SearchView searchView() { + return searchView; + } + @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - - viewModel.loadForumNew(1, searchView.getQuery().toString()); + load(1L); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java index c7f0893..a5e699e 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java @@ -18,6 +18,8 @@ public class ForumNewResponse extends Response { enum Msg implements CustomMessage { ok(R.string.load_forum_new_ok), + ok_empty(R.string.no_more_forum), + ok_more(R.string.load_more_forum_ok), fail(R.string.load_forum_new_fail); 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 cc869c1..085ed74 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 @@ -3,12 +3,13 @@ package com.community.pocket.ui.main.ui.forum.news; import androidx.lifecycle.MutableLiveData; import com.community.pocket.data.main.forum.ForumNewRequest; +import com.community.pocket.ui.main.ui.forum.FormLoad; import com.community.pocket.ui.main.ui.share.BaseViewModel; /** * 最新帖子 */ -public class ForumNewViewModel extends BaseViewModel { +public class ForumNewViewModel extends BaseViewModel implements FormLoad { //最新帖子请求状态 private MutableLiveData forumNewResponse = new MutableLiveData<>(); @@ -17,7 +18,8 @@ public class ForumNewViewModel extends BaseViewModel { return forumNewResponse; } - void loadForumNew(int page, String title) { + @Override + public void loadForumNew(Long page, String title) { getRequest().loadForumNew(forumNewResponse, page, title); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java index 5cb34fd..fac8bbb 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java @@ -10,7 +10,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.lifecycle.Observer; import com.community.pocket.R; import com.community.pocket.ui.BaseFragment; @@ -58,7 +57,7 @@ abstract class ForumPostContent extends BaseFragment { //初始化父级布局组件 @RequiresApi(api = Build.VERSION_CODES.KITKAT) private void initParentView() { - ForumPostFragment forumPostFragment = getParentFragment(2); + ForumPostFragment forumPostFragment = getParentFragment(ForumPostFragment.class); View parentView = Objects.requireNonNull(Objects.requireNonNull(forumPostFragment).getView()); postTitle = parentView.findViewById(R.id.post_title); postButton = parentView.findViewById(R.id.post_button); @@ -67,20 +66,16 @@ abstract class ForumPostContent extends BaseFragment { //监听发帖状态 void sendPost(ForumPostViewModel viewModel) { - viewModel.getForumPostResponse().observe(getViewLifecycleOwner(), new Observer() { - @RequiresApi(api = Build.VERSION_CODES.KITKAT) - @Override - public void onChanged(ForumPostResponse forumPostResponse) { - if (forumPostResponse == null) { - return; - } - - forumPostResponse.toast(getContext()); - if (forumPostResponse.getResult() == Response.Result.OK) { - ForumFragment forumFragment = getParentFragment(4); - Button button = Objects.requireNonNull(forumFragment.getView()).findViewById(R.id.forum_new); - forumFragment._new(button); - } + viewModel.getForumPostResponse().observe(getViewLifecycleOwner(), forumPostResponse -> { + if (forumPostResponse == null) { + return; + } + + forumPostResponse.toast(getContext()); + if (forumPostResponse.getResult() == Response.Result.OK) { + ForumFragment forumFragment = getParentFragment(ForumFragment.class); + Button button = Objects.requireNonNull(forumFragment.getView()).findViewById(R.id.forum_new); + forumFragment._new(button); } }); } 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 14281ef..241cfed 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,7 +19,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; @@ -99,63 +98,54 @@ public class VisitorAppointmentFragment extends BaseFragment { myAutoCompleteTextView = new MyAutoCompleteTextView(appointment, appointmentViewModel); //监听访客预约表单校验状态 - appointmentViewModel.getVisitorFormState().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(VisitorFormState visitorFormState) { - if (visitorFormState == null) { - return; - } - submit.setEnabled(visitorFormState.isDataValid()); - if (visitorFormState.getAppointmentError() != null) { - appointment.setError(getString(visitorFormState.getAppointmentError(), PropertiesUtil.getIntValue("username.length"))); - } + appointmentViewModel.getVisitorFormState().observe(getViewLifecycleOwner(), visitorFormState -> { + if (visitorFormState == null) { + return; + } + submit.setEnabled(visitorFormState.isDataValid()); + if (visitorFormState.getAppointmentError() != null) { + appointment.setError(getString(visitorFormState.getAppointmentError(), PropertiesUtil.getIntValue("username.length"))); + } - if (visitorFormState.getDateError() != null) { - if (visitorFormState.getDateError() == R.string.visitor_invalid_date) { - chooseDate.setError(getString(visitorFormState.getDateError(), today)); - } else { - chooseDate.setError(getString(visitorFormState.getDateError())); - } + if (visitorFormState.getDateError() != null) { + if (visitorFormState.getDateError() == R.string.visitor_invalid_date) { + chooseDate.setError(getString(visitorFormState.getDateError(), today)); + } else { + chooseDate.setError(getString(visitorFormState.getDateError())); } + } - if (visitorFormState.getNotesError() != null) { - notes.setError(getString(visitorFormState.getNotesError())); - } + if (visitorFormState.getNotesError() != null) { + notes.setError(getString(visitorFormState.getNotesError())); } }); //监听预约请求结果 - appointmentViewModel.getVisitorResponse().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(VisitorResponse visitorResponse) { - if (visitorResponse == null) { - return; - } + appointmentViewModel.getVisitorResponse().observe(getViewLifecycleOwner(), visitorResponse -> { + if (visitorResponse == null) { + return; + } - visitorResponse.toast(getContext()); + visitorResponse.toast(getContext()); - if (visitorResponse.getResult() == Response.Result.OK) { - VisitorFragment visitorFragment = getParentFragment(2); - Button button = Objects.requireNonNull(visitorFragment.getView()).findViewById(R.id.visitor_reservation); - visitorFragment.reservation(button); - } + if (visitorResponse.getResult() == Response.Result.OK) { + VisitorFragment visitorFragment = getParentFragment(VisitorFragment.class); + Button button = Objects.requireNonNull(visitorFragment.getView()).findViewById(R.id.visitor_reservation); + visitorFragment.reservation(button); } }); //检索预约人请求结果 - appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(VisitorPeopleResponse visitorResponse) { - if (visitorResponse == null) { - return; - } + appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), visitorResponse -> { + if (visitorResponse == null) { + return; + } - visitorResponse.toast(getContext()); + visitorResponse.toast(getContext()); - if (visitorResponse.getResult() == Response.Result.OK) { - if (!visitorResponse.getVisitorPeopleList().isEmpty()) { - initSearch(visitorResponse.getVisitorPeopleList()); - } + if (visitorResponse.getResult() == Response.Result.OK) { + if (!visitorResponse.getVisitorPeopleList().isEmpty()) { + initSearch(visitorResponse.getVisitorPeopleList()); } } }); diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum.xml b/app/src/main/res/layout/main/layout/forum/layout/forum.xml index 2d75da7..c255a1e 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum.xml @@ -67,7 +67,6 @@ android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/size_100" android:background="@color/colorAccent" app:defaultNavHost="true" app:navGraph="@navigation/forum_navigation" /> diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml index a0972c8..5b4dd69 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml @@ -1,5 +1,5 @@ - - - + android:layout_height="@dimen/size_200" + android:layout_marginTop="@dimen/size_50" + android:background="@drawable/border"> - + - + - + - + - + - + - + - + + - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml index c2d90b0..d6b0401 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml @@ -1,25 +1,23 @@ - - + android:layout_height="wrap_content" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - - - - - - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml index 4d4ea76..3101a59 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml @@ -1,25 +1,23 @@ - - + android:layout_height="wrap_content" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - - - - - - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_post_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_post_fragment.xml index 682e939..7e12d05 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_post_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_post_fragment.xml @@ -1,57 +1,53 @@ - - + android:layout_height="wrap_content" + android:orientation="vertical" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - - - - - + android:ems="10" + android:hint="@string/prompt_title" + android:importantForAutofill="no" + android:inputType="none|text" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + - + -