171 lines
6.1 KiB
Java
171 lines
6.1 KiB
Java
package com.ubt.jimu.community.view.fragment;
|
|
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import butterknife.ButterKnife;
|
|
import butterknife.Unbinder;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.cache.SharePreferenceHelper;
|
|
import com.ubt.jimu.base.entities.RecommendBean;
|
|
import com.ubt.jimu.base.http.ApiObserver;
|
|
import com.ubt.jimu.community.presenter.SearchPresenter;
|
|
import com.ubt.jimu.community.view.SearchActivity;
|
|
import com.ubt.jimu.community.view.adapter.search.SearchRecommendAdapter;
|
|
import com.ubt.jimu.push.JimuPushMessage;
|
|
import com.ubt.jimu.widgets.SpaceItemDecoration;
|
|
import com.ubt.jimu.widgets.screenAdaptive.XLinearLayout;
|
|
import com.ubt.jimu.widgets.screenAdaptive.XRelativeLayout;
|
|
import com.ubtech.view.fragment.BaseFragment;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class RecommendFragment extends BaseFragment {
|
|
private SearchPresenter a;
|
|
private SearchRecommendAdapter b;
|
|
private SharePreferenceHelper c;
|
|
private List<String> d;
|
|
private Unbinder e;
|
|
RecyclerView rvRecommend;
|
|
RecyclerView rvSearchHistory;
|
|
TextView tvClear;
|
|
TextView tvHistory;
|
|
TextView tvKeywords;
|
|
TextView tvSearch;
|
|
TextView tvSearchHistory;
|
|
XLinearLayout xlIntroduce;
|
|
XRelativeLayout xrHistory;
|
|
|
|
private void bindClick() {
|
|
this.tvClear.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.community.view.fragment.a
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
RecommendFragment.this.a(view);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void h(List<String> list) {
|
|
if (list == null || list.size() == 0) {
|
|
this.rvSearchHistory.setVisibility(8);
|
|
this.tvHistory.setVisibility(0);
|
|
} else {
|
|
this.rvSearchHistory.setVisibility(0);
|
|
this.tvHistory.setVisibility(8);
|
|
}
|
|
}
|
|
|
|
private void initData() {
|
|
this.c = new SharePreferenceHelper();
|
|
this.d = (List) this.c.readObject(SharePreferenceHelper.SP_KEY_SEARCH_HISTORY);
|
|
if (this.d == null) {
|
|
this.d = new ArrayList();
|
|
}
|
|
this.b = new SearchRecommendAdapter(this.mActivity, this, "history", this.d, this.a);
|
|
this.rvSearchHistory.setLayoutManager(new LinearLayoutManager(this.mActivity, 1, false));
|
|
this.rvSearchHistory.a(new SpaceItemDecoration(10, 0));
|
|
this.rvSearchHistory.setAdapter(this.b);
|
|
final SearchRecommendAdapter searchRecommendAdapter = new SearchRecommendAdapter(this.mActivity, this, JimuPushMessage.TYPE_MODEL_RECOMMEMD, new RecommendBean().getKeys(), this.a);
|
|
this.rvRecommend.setLayoutManager(new GridLayoutManager(this.mActivity, 4));
|
|
this.rvRecommend.setAdapter(searchRecommendAdapter);
|
|
this.a.a(this, searchRecommendAdapter, new ApiObserver<RecommendBean>(((SearchActivity) this.mActivity).viewLoading) { // from class: com.ubt.jimu.community.view.fragment.RecommendFragment.1
|
|
@Override // com.ubt.jimu.base.http.ApiObserver, io.reactivex.Observer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void onNext(RecommendBean recommendBean) {
|
|
if (recommendBean.getKeys() == null) {
|
|
RecommendFragment.this.j(null);
|
|
} else {
|
|
searchRecommendAdapter.notifyChanged(recommendBean.getKeys());
|
|
RecommendFragment.this.j(recommendBean.getKeys());
|
|
}
|
|
}
|
|
});
|
|
b();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void j(List<String> list) {
|
|
if (list == null || list.size() == 0) {
|
|
this.rvRecommend.setVisibility(8);
|
|
this.tvKeywords.setVisibility(0);
|
|
} else {
|
|
this.rvRecommend.setVisibility(0);
|
|
this.tvKeywords.setVisibility(8);
|
|
}
|
|
}
|
|
|
|
public static RecommendFragment o() {
|
|
return new RecommendFragment();
|
|
}
|
|
|
|
public void b() {
|
|
List<String> list = (List) this.c.readObject(SharePreferenceHelper.SP_KEY_SEARCH_HISTORY);
|
|
if (list == null) {
|
|
this.tvClear.setAlpha(0.3f);
|
|
return;
|
|
}
|
|
this.b.notifyChanged(list);
|
|
h(list);
|
|
if (list.size() > 0) {
|
|
this.tvClear.setAlpha(1.0f);
|
|
} else {
|
|
this.tvClear.setAlpha(0.3f);
|
|
}
|
|
}
|
|
|
|
public void c(String str) {
|
|
this.b.a(str);
|
|
}
|
|
|
|
public void d(int i) {
|
|
XLinearLayout xLinearLayout = this.xlIntroduce;
|
|
if (xLinearLayout == null || this.xrHistory == null) {
|
|
return;
|
|
}
|
|
if (i == 0) {
|
|
xLinearLayout.setVisibility(0);
|
|
this.xrHistory.setVisibility(0);
|
|
} else {
|
|
xLinearLayout.setVisibility(8);
|
|
this.xrHistory.setVisibility(8);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubtech.view.fragment.BaseFragment, androidx.fragment.app.Fragment
|
|
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
|
return layoutInflater.inflate(R.layout.fragment_search_rd, viewGroup, false);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroyView() {
|
|
this.e.unbind();
|
|
super.onDestroyView();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onViewCreated(View view, Bundle bundle) {
|
|
super.onViewCreated(view, bundle);
|
|
this.e = ButterKnife.a(this, view);
|
|
initData();
|
|
bindClick();
|
|
}
|
|
|
|
public /* synthetic */ void a(View view) {
|
|
this.d.clear();
|
|
this.c.saveObject(SharePreferenceHelper.SP_KEY_SEARCH_HISTORY, this.d);
|
|
this.b.notifyDataSetChanged();
|
|
h(this.d);
|
|
this.tvClear.setAlpha(0.3f);
|
|
}
|
|
|
|
public void a(SearchPresenter searchPresenter) {
|
|
this.a = searchPresenter;
|
|
}
|
|
}
|