From 3efd35f8971d017d2240fe4bc464e3797bc79003 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Wed, 10 Aug 2022 14:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98,shouye=20ytuijian?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/common/dialog/LoadingDialog.java | 41 ---------- .../yunbao/live/views/LiveEndViewHolder.java | 15 ---- .../yunbao/main/activity/MainActivity.java | 6 -- .../yunbao/main/activity/SearchActivity.java | 6 -- .../main/adapter/SearchResultsAdapter.java | 5 -- .../adapter/SearchResultsItemAdapter.java | 16 +--- .../fragment/SearchRecommendFragment.java | 6 -- .../fragment/SearchResultsItemFragment.java | 73 +++++++++++++++--- .../res/layout/view_search_results_item.xml | 74 +++++++++++++++++++ 9 files changed, 137 insertions(+), 105 deletions(-) delete mode 100644 common/src/main/java/com/yunbao/common/dialog/LoadingDialog.java diff --git a/common/src/main/java/com/yunbao/common/dialog/LoadingDialog.java b/common/src/main/java/com/yunbao/common/dialog/LoadingDialog.java deleted file mode 100644 index 8c1c3e126..000000000 --- a/common/src/main/java/com/yunbao/common/dialog/LoadingDialog.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.yunbao.common.dialog; - -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.view.Gravity; -import android.view.Window; -import android.view.WindowManager; - -import com.yunbao.common.R; - -/** - * 耗时操作通用Loading弹窗 - */ -public class LoadingDialog extends AbsDialogFragment { - @Override - protected int getLayoutId() { - return R.layout.view_loading; - } - - @Override - protected int getDialogStyle() { - return R.style.dialog4; - } - - @Override - protected boolean canCancel() { - return false; - } - - - @Override - protected void setWindowAttributes(Window window) { - window.setWindowAnimations(R.style.bottomToTopAnim); - WindowManager.LayoutParams params = window.getAttributes(); - params.width = WindowManager.LayoutParams.WRAP_CONTENT; - params.height = WindowManager.LayoutParams.WRAP_CONTENT; - params.gravity = Gravity.CENTER; - window.setAttributes(params); - window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - } -} diff --git a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java index e1275aec9..619b6d456 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java @@ -20,7 +20,6 @@ import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LiveInfoModel; import com.yunbao.common.bean.SetAttentsModel; -import com.yunbao.common.dialog.LoadingDialog; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; @@ -102,9 +101,6 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList * 加载用户猜你喜欢数据 */ private void initDataOfUser() { - //展示网络请求弹窗 - LoadingDialog fragment = new LoadingDialog(); - fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "LoadingDialog"); MainNetManager.get((Activity) mContext) .anchorRecommend("3", new HttpCallback() { @Override @@ -119,7 +115,6 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList } else { changeBatchUser.setVisibility(View.GONE); } - fragment.dismiss(); //组装搜索历史数据 adapter.showData(data.getList()); @@ -127,7 +122,6 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList @Override public void onError(String error) { - fragment.dismiss(); } }); } @@ -228,20 +222,16 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList followUser.setVisibility(TextUtils.equals(liveBean.getIsattention(), "1") ? View.GONE : View.VISIBLE); followUser.setOnClickListener(v -> { - LoadingDialog fragment = new LoadingDialog(); - fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "LoadingDialog"); LiveNetManager.get(mContext) .setAttents(String.valueOf(liveBean.getUid()), new HttpCallback() { @Override public void onSuccess(SetAttentsModel data) { followUser.setVisibility(View.GONE); - fragment.dismiss(); } @Override public void onError(String error) { ToastUtil.show(error); - fragment.dismiss(); } }); }); @@ -308,14 +298,10 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList */ @Subscribe(threadMode = ThreadMode.MAIN) public void onJumpUserHome(JumpUserHomeEvent event) { - //展示网络请求弹窗 - LoadingDialog fragment = new LoadingDialog(); - fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "LoadingDialog"); LiveNetManager.get(mContext) .getLiveInfo(String.valueOf(event.getModel().getId()), new HttpCallback() { @Override public void onSuccess(LiveInfoModel data) { - fragment.dismiss(); LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(mContext, (liveBean, liveType, liveTypeVal, liveSdk) -> { if (liveBean == null) { return; @@ -339,7 +325,6 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList @Override public void onError(String error) { - fragment.dismiss(); RouteUtil.forwardUserHome(mContext, String.valueOf(event.getModel().getId()), 0); diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index aa17ccdec..2eb169b31 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -53,7 +53,6 @@ import com.yunbao.common.bean.LiveSvgGiftBean; import com.yunbao.common.bean.UpdataListBean; import com.yunbao.common.custom.TabButtonGroup; import com.yunbao.common.dialog.InstructorOperationDialog; -import com.yunbao.common.dialog.LoadingDialog; import com.yunbao.common.event.InstructorOperationEvent; import com.yunbao.common.event.MessageIMEvent; import com.yunbao.common.event.NoviceInstructorEvent; @@ -418,9 +417,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene * 首页推荐位 */ private void initAnchorRecommendBanner() { - //展示网络请求弹窗 - LoadingDialog fragment = new LoadingDialog(); - fragment.show(getSupportFragmentManager(), "LoadingDialog"); MainNetManager.get(mContext) .anchorRecommend("10", new com.yunbao.common.http.base.HttpCallback() { @Override @@ -433,14 +429,12 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene floatBanner.setVisibility(View.GONE); findViewById(R.id.banner_click).setVisibility(View.GONE); } - fragment.dismiss(); } @Override public void onError(String error) { - fragment.dismiss(); } }); } diff --git a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java index 6160f8eb7..370376009 100644 --- a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java @@ -19,7 +19,6 @@ import androidx.fragment.app.FragmentTransaction; import com.blankj.utilcode.util.GsonUtils; import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.bean.LiveInfoModel; -import com.yunbao.common.dialog.LoadingDialog; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.SearchHistoryRecordManager; @@ -170,14 +169,10 @@ public class SearchActivity extends AbsActivity { */ @Subscribe(threadMode = ThreadMode.MAIN) public void onJumpUserHome(JumpUserHomeEvent event) { - //展示网络请求弹窗 - LoadingDialog fragment = new LoadingDialog(); - fragment.show(getSupportFragmentManager(), "LoadingDialog"); LiveNetManager.get(mContext) .getLiveInfo(String.valueOf(event.getModel().getId()), new HttpCallback() { @Override public void onSuccess(LiveInfoModel data) { - fragment.dismiss(); LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(mContext, (liveBean, liveType, liveTypeVal, liveSdk) -> { if (liveBean == null) { return; @@ -193,7 +188,6 @@ public class SearchActivity extends AbsActivity { @Override public void onError(String error) { - fragment.dismiss(); //跳转到个人资料 if (imm != null && mEditText != null) { imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java index 11bd9614c..ecf6f1f48 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java @@ -11,7 +11,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.bean.SearchModel; import com.yunbao.common.bean.SetAttentsModel; -import com.yunbao.common.dialog.LoadingDialog; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.utils.ToastUtil; @@ -47,8 +46,6 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { resultsViewHolder.setCallback(new SearchResultsViewHolder.SearchResultsCallback() { @Override public void focusOn(SearchModel model) { - LoadingDialog fragment = new LoadingDialog(); - fragment.show(((FragmentActivity) context).getSupportFragmentManager(), "LoadingDialog"); LiveNetManager.get(context) .setAttents(String.valueOf(model.getId()), new HttpCallback() { @Override @@ -59,13 +56,11 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { } } notifyDataSetChanged(); - fragment.dismiss(); } @Override public void onError(String error) { ToastUtil.show(error); - fragment.dismiss(); } }); } diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java index a62f55728..b8dbd9492 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java @@ -24,7 +24,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { private final int ANCHOR = 2, USER = 3, EMPTY = 4; private int type = -1; //确定是不是全部展示列表 - private boolean isAll = true, empty = false; + private boolean isAll = true; private String searchKey = ""; @NonNull @@ -67,9 +67,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { @Override public int getItemViewType(int position) { - if (empty) { - return EMPTY; - } + if (type == 1 && lists.size() > 1) { if (position == 0) { return ANCHOR; @@ -100,18 +98,8 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { if (mLists.get(1).size() == 0) { this.type = USER; } - if (mLists.get(0).size() == 0 && mLists.get(1).size() == 0) { - empty = true; - } else { - empty = false; - } } else { isAll = false; - if (mLists.get(0).size() == 0) { - empty = true; - } else { - empty = false; - } } lists.clear(); for (List searchModels : mLists) { diff --git a/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java b/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java index aea0a208b..6926e4f5b 100644 --- a/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java @@ -10,7 +10,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.SearchRecommendModel; -import com.yunbao.common.dialog.LoadingDialog; import com.yunbao.common.event.SearchRecommendEvent; import com.yunbao.common.fragment.BaseFragment; import com.yunbao.common.http.base.HttpCallback; @@ -57,14 +56,10 @@ public class SearchRecommendFragment extends BaseFragment { @Override protected void loadData() { - //展示网络请求弹窗 - LoadingDialog fragment = new LoadingDialog(); - fragment.show(getChildFragmentManager(), "LoadingDialog"); MainNetManager.get(getActivity()) .anchorRecommend("10", new HttpCallback() { @Override public void onSuccess(AnchorRecommendModel data) { - fragment.dismiss(); //组装搜索历史数据 List searchRecommendModels = new ArrayList<>(); Map historyRecordMap = SearchHistoryRecordManager.get(getActivity()).getHistoryRecordMap(); @@ -79,7 +74,6 @@ public class SearchRecommendFragment extends BaseFragment { @Override public void onError(String error) { - fragment.dismiss(); } }); } diff --git a/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java b/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java index 23297c3e7..6a759cd45 100644 --- a/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java @@ -4,17 +4,23 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.SearchModel; -import com.yunbao.common.dialog.LoadingDialog; +import com.yunbao.common.event.SearchRecommendEvent; import com.yunbao.common.fragment.BaseFragment; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.main.MainNetManager; +import com.yunbao.common.utils.Bus; import com.yunbao.common.views.weight.OnRecyclerViewScrollListener; import com.yunbao.main.R; +import com.yunbao.main.adapter.SearchRecommendBodyAdapter; import com.yunbao.main.adapter.SearchResultsItemAdapter; import com.yunbao.main.utils.WordsTypeUtil; @@ -30,6 +36,10 @@ public class SearchResultsItemFragment extends BaseFragment { private int type = 1; private RecyclerView searchList; private SearchResultsItemAdapter itemAdapter; + private LinearLayout emptyLayout; + private RecyclerView liveList; + private SearchRecommendBodyAdapter adapter; + private ImageView changeBatch; @Override public View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) { @@ -44,7 +54,9 @@ public class SearchResultsItemFragment extends BaseFragment { @Override protected void initViews(Bundle savedInstanceState, View contentView) { searchList = contentView.findViewById(R.id.search_list); + emptyLayout = contentView.findViewById(R.id.empty_layout); itemAdapter = new SearchResultsItemAdapter(); + searchList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); searchList.setAdapter(itemAdapter); searchList.addOnScrollListener(new OnRecyclerViewScrollListener() { @@ -54,6 +66,32 @@ public class SearchResultsItemFragment extends BaseFragment { setSearchKey(searchKey, type); } }); + emptyLayout.setVisibility(View.GONE); + liveList = contentView.findViewById(R.id.live_list); + changeBatch = contentView.findViewById(R.id.change_batch); + liveList.setLayoutManager(new GridLayoutManager(contentView.getContext(), 2, GridLayoutManager.VERTICAL, false)); + adapter = new SearchRecommendBodyAdapter(getActivity()); + liveList.setAdapter(adapter); + //启用嵌套滚动 + liveList.setNestedScrollingEnabled(false); + changeBatch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Bus.get().post(new SearchRecommendEvent()); + } + }); + MainNetManager.get(getActivity()) + .anchorRecommend("10", new HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel data) { + adapter.showData(data.getList()); + + } + + @Override + public void onError(String error) { + } + }); } @Override @@ -68,9 +106,6 @@ public class SearchResultsItemFragment extends BaseFragment { * @param type 類型 */ public void setSearchKey(String searchKey, int type) { - //展示网络请求弹窗 - LoadingDialog fragment = new LoadingDialog(); - fragment.show(getChildFragmentManager(), "LoadingDialog"); this.searchKey = searchKey; this.type = type; if (type == 1) { @@ -80,18 +115,24 @@ public class SearchResultsItemFragment extends BaseFragment { type, page, new HttpCallback>>() { @Override public void onSuccess(List> data) { - fragment.dismiss(); if (page > 1) { itemAdapter.onLoadMoreData(data, searchKey); } else { - itemAdapter.showData(data, type, searchKey); + + if (data.get(0).size() == 0 && data.get(1).size() == 0) { + emptyLayout.setVisibility(View.VISIBLE); + searchList.setVisibility(View.GONE); + } else { + itemAdapter.showData(data, type, searchKey); + searchList.setVisibility(View.VISIBLE); + } } } @Override public void onError(String error) { - - fragment.dismiss(); + emptyLayout.setVisibility(View.VISIBLE); + searchList.setVisibility(View.GONE); } }); } else { @@ -101,14 +142,21 @@ public class SearchResultsItemFragment extends BaseFragment { type, page, new HttpCallback>() { @Override public void onSuccess(List data) { - fragment.dismiss(); List> listList = new ArrayList<>(); listList.add(data); if (page > 1) { itemAdapter.onLoadMoreData(listList, searchKey); } else { - itemAdapter.showData(listList, type, searchKey); + if (data.size() == 0) { + emptyLayout.setVisibility(View.VISIBLE); + searchList.setVisibility(View.GONE); + + } else { + itemAdapter.showData(listList, type, searchKey); + searchList.setVisibility(View.VISIBLE); + } + } @@ -116,8 +164,8 @@ public class SearchResultsItemFragment extends BaseFragment { @Override public void onError(String error) { - - fragment.dismiss(); + emptyLayout.setVisibility(View.VISIBLE); + searchList.setVisibility(View.GONE); } }); } @@ -164,4 +212,5 @@ public class SearchResultsItemFragment extends BaseFragment { searchRecommendFragment.setArguments(bundle); return searchRecommendFragment; } + } diff --git a/main/src/main/res/layout/view_search_results_item.xml b/main/src/main/res/layout/view_search_results_item.xml index 6dd0a1126..6b2a9f674 100644 --- a/main/src/main/res/layout/view_search_results_item.xml +++ b/main/src/main/res/layout/view_search_results_item.xml @@ -42,4 +42,78 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fadingEdge="none" /> + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file