| | |
| | | import android.graphics.drawable.GradientDrawable; |
| | | import android.os.Bundle; |
| | | import android.provider.Settings; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.BaseAdapter; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.RelativeLayout; |
| | | import android.widget.ScrollView; |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.tejia.lijin.app.R; |
| | | import com.tejia.lijin.app.contract.SearchFgContract; |
| | | import com.tejia.lijin.app.entity.HotSearch; |
| | | import com.tejia.lijin.app.presenter.SearchFgPresenter; |
| | | import com.tejia.lijin.app.ui.dialog.OrderAppealHistoryDeleteHintDialog; |
| | | import com.tejia.lijin.app.ui.invite.ShareBrowserActivity; |
| | | import com.tejia.lijin.app.util.Constant; |
| | | import com.tejia.lijin.app.util.FlowLayout; |
| | | import com.tejia.lijin.app.util.GlideRoundTransform; |
| | | import com.tejia.lijin.app.util.RecordImageTextVideo; |
| | | import com.tejia.lijin.app.util.umengCustomEvent.SearchCustomEvent; |
| | | import com.tejia.lijin.app.view.BaseFragment; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.wpc.library.content.ConnectivityChangeHelper; |
| | | import com.wpc.library.util.NetUtils; |
| | | import com.wpc.library.util.cache.DiskLruCache; |
| | | import com.wpc.library.util.common.StorageUtils; |
| | | import com.wpc.library.util.common.StringUtils; |
| | | import com.wpc.library.widget.MyListView; |
| | | import com.tejia.lijin.app.contract.SearchFgContract; |
| | | import com.tejia.lijin.app.presenter.SearchFgPresenter; |
| | | import com.tejia.lijin.app.R; |
| | | import com.tejia.lijin.app.util.Constant; |
| | | import com.tejia.lijin.app.view.BaseFragment; |
| | | import com.tejia.lijin.app.entity.HotSearch; |
| | | import com.tejia.lijin.app.ui.dialog.OrderAppealHistoryDeleteHintDialog; |
| | | import com.tejia.lijin.app.ui.invite.ShareBrowserActivity; |
| | | import com.tejia.lijin.app.util.FlowLayout; |
| | | import com.tejia.lijin.app.util.GlideRoundTransform; |
| | | import com.tejia.lijin.app.util.RecordImageTextVideo; |
| | | import com.tejia.lijin.app.util.umengCustomEvent.SearchCustomEvent; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | |
| | | */ |
| | | |
| | | public class FragmentSearch extends BaseFragment<SearchFgContract.SearchView, SearchFgPresenter> implements SearchFgContract.SearchView, View.OnClickListener { |
| | | private FlowLayout fl_hot_search; |
| | | private HistoryAdapter adapter; |
| | | private MyListView lv_history; |
| | | // private AutoCompleteTextView et_search; |
| | | private TextView tv_clear_history; |
| | | private FlowLayout fl_hot_search, fl_search_history; |
| | | private ConnectivityChangeHelper mChangeHelper; |
| | | private LinearLayout ll_no_net, ll_no_data, ll_request_failture, |
| | | ll_search_history_hint; |
| | | private ScrollView sv_search; |
| | | // public String Searchtxt;//搜索关键词 |
| | | private DiskLruCache cache; |
| | | private RelativeLayout ll_guidevideo;//优惠券视频教程 |
| | | private RelativeLayout ll_guidevideo2;//优惠券视频教程 更多 |
| | |
| | | ll_guidevideo2 = contentView.findViewById(R.id.ll_guidevideo2); |
| | | ll_guidevideoimg = contentView.findViewById(R.id.ll_guidevideoimg); |
| | | fl_hot_search = contentView.findViewById(R.id.fl_hot_search); |
| | | fl_search_history = contentView.findViewById(R.id.fl_search_history); |
| | | ll_no_net = contentView.findViewById(R.id.ll_no_net); |
| | | ll_no_data = contentView.findViewById(R.id.ll_no_data); |
| | | ll_request_failture = contentView.findViewById(R.id.ll_request_failture); |
| | | contentView.findViewById(R.id.tv_net_setting).setOnClickListener(this); |
| | | contentView.findViewById(R.id.tv_refresh).setOnClickListener(this); |
| | | sv_search = contentView.findViewById(R.id.sv_search); |
| | | lv_history = contentView.findViewById(R.id.lv_search_history); |
| | | ll_search_history_hint = contentView.findViewById(R.id.ll_search_history_hint); |
| | | tv_clear_history = contentView.findViewById(R.id.tv_clear_history); |
| | | tv_clear_history.setOnClickListener(this); |
| | | contentView.findViewById(R.id.iv_delete_history).setOnClickListener(this); |
| | | ll_guidevideo2.setOnClickListener(this); |
| | | ll_guidevideoimg.setOnClickListener(this); |
| | | |
| | | mPresenter.initCacheData(cache, fl_hot_search, mBundle.getInt("id"), hList);//热门搜索缓存 |
| | | adapter = new HistoryAdapter(mList); |
| | | lv_history.setAdapter(adapter); |
| | | setSearchHistoryData(); |
| | | |
| | | mChangeHelper = new ConnectivityChangeHelper(getContext(), |
| | | new ConnectivityChangeHelper.OnConnectivityChangeListener() { |
| | | |
| | | @Override |
| | | public void onNetworkUnAvailable() { |
| | | if (mList.size()==0) |
| | | if (mList.size() == 0) |
| | | requestState(3); |
| | | } |
| | | |
| | |
| | | }); |
| | | |
| | | //编辑完之后点击软键盘上的回车键 |
| | | // setHotData(); |
| | | // setHotData(); |
| | | |
| | | //改变 shape 背景色 |
| | | GradientDrawable p = (GradientDrawable) ll_guidevideoimg.getBackground(); |
| | |
| | | .transform(new GlideRoundTransform(getContext(), 8)) |
| | | .into(ll_guidevideoimg); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void setSearchHistoryData() { |
| | | //设置历史搜索数据 |
| | | mPresenter.fillFlowData(mList, fl_search_history, new SearchFgPresenter.ISearchItemClick() { |
| | | @Override |
| | | public void onClick(String text, int position) { |
| | | mPresenter.addSearchHistory(text, mBundle.getInt("id")); |
| | | SearchCustomEvent.searchHistory(getContext()); |
| | | mPresenter.addSearchResultActivity(text, mBundle.getInt("id")); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | |
| | | super.setUserVisibleHint(isVisibleToUser); |
| | | if (isVisibleToUser && (getActivity()) != null) { |
| | | //TODO now it's visible to user对用户可见 |
| | | mPresenter.setHistoricalRecords(mBundle.getInt("id"), mList, adapter, ll_search_history_hint, null, ll_guidevideo, videoPicture); |
| | | mPresenter.setHistoricalRecords(mBundle.getInt("id"), mList, ll_search_history_hint, null, ll_guidevideo, videoPicture); |
| | | setSearchHistoryData(); |
| | | Random random = new Random(); |
| | | String key = getActivity().getIntent().getStringExtra("key"); |
| | | // if (mBundle.getInt("id") != 1) { |
| | |
| | | public void onResume() { |
| | | super.onResume(); |
| | | mChangeHelper.registerReceiver(); |
| | | MobclickAgent.onPageStart("搜索页"); |
| | | mPresenter.setHistoricalRecords(mBundle.getInt("id"), mList, adapter, ll_search_history_hint, null, ll_guidevideo, videoPicture);//显示历史记录 |
| | | mPresenter.setHistoricalRecords(mBundle.getInt("id"), mList, ll_search_history_hint, null, ll_guidevideo, videoPicture);//显示历史记录 |
| | | setSearchHistoryData(); |
| | | } |
| | | |
| | | @Override |
| | | public void onPause() { |
| | | super.onPause(); |
| | | mChangeHelper.unregisterReceiver(); |
| | | MobclickAgent.onPageEnd("搜索页"); |
| | | } |
| | | |
| | | |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | switch (v.getId()) { |
| | | case R.id.tv_clear_history: |
| | | case R.id.iv_delete_history: |
| | | // clearHistory(); |
| | | OrderAppealHistoryDeleteHintDialog.Builder builder = new OrderAppealHistoryDeleteHintDialog.Builder(getContext()); |
| | | builder.setMessage("是否要清空搜索记录?").setNegativeButton("不了", new DialogInterface.OnClickListener() { |
| | |
| | | SharedPreferences sp; |
| | | if (mBundle.getInt("id") == Constant.GOODS_TYPE_TB) { |
| | | sp = getContext().getSharedPreferences("searchHistory", Context.MODE_PRIVATE); |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_JD) { |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_JD) { |
| | | sp = getContext().getSharedPreferences("searchHistory_jd", Context.MODE_PRIVATE); |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_PDD) { |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_PDD) { |
| | | sp = getContext().getSharedPreferences("searchHistory_pdd", Context.MODE_PRIVATE); |
| | | }else if (mBundle.getInt("id") == Constant.GOODS_TYPE_VIP) { |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_VIP) { |
| | | sp = getContext().getSharedPreferences("searchHistory_vip", Context.MODE_PRIVATE); |
| | | }else if (mBundle.getInt("id") == Constant.GOODS_TYPE_SUNING) { |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_SUNING) { |
| | | sp = getContext().getSharedPreferences("searchHistory_suning", Context.MODE_PRIVATE); |
| | | } else { |
| | | sp = getContext().getSharedPreferences("searchHistory", Context.MODE_PRIVATE); |
| | |
| | | editor.clear(); |
| | | editor.apply(); |
| | | mList.clear(); |
| | | adapter.notifyDataSetChanged(); |
| | | setSearchHistoryData(); |
| | | ll_search_history_hint.setVisibility(View.GONE); |
| | | if (videoPicture == null || videoPicture.length() == 0 || videoPicture.equals(" ")) {//视频图片为空 隐藏视频 |
| | | ll_guidevideo.setVisibility(View.GONE); |
| | |
| | | } catch (PackageManager.NameNotFoundException e) { |
| | | e.printStackTrace(); |
| | | return 1; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 历史记录 |
| | | */ |
| | | public class HistoryAdapter extends BaseAdapter { |
| | | List<String> mList; |
| | | |
| | | public HistoryAdapter(List<String> list) { |
| | | mList = list; |
| | | } |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return mList == null ? 0 : mList.size(); |
| | | } |
| | | |
| | | @Override |
| | | public Object getItem(int position) { |
| | | return mList.get(position); |
| | | } |
| | | |
| | | @Override |
| | | public long getItemId(int position) { |
| | | return position; |
| | | } |
| | | |
| | | @Override |
| | | public View getView(final int position, View view, ViewGroup parent) { |
| | | view = LayoutInflater.from(getContext()).inflate(R.layout.item_search_history, null); |
| | | final TextView tv_search_content = view.findViewById(R.id.tv_search_content); |
| | | final ImageView iv_search_content_close = view.findViewById(R.id.iv_search_content_close); |
| | | tv_search_content.setText(mList.get(position)); |
| | | tv_search_content.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | mPresenter.addSearchHistory(tv_search_content.getText().toString(), mBundle.getInt("id")); |
| | | SearchCustomEvent.searchHistory(getContext()); |
| | | mPresenter.addSearchResultActivity(tv_search_content.getText().toString(), mBundle.getInt("id")); |
| | | } |
| | | }); |
| | | iv_search_content_close.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | mList.remove(position); |
| | | notifyDataSetChanged(); |
| | | if (mList.size() == 0) { |
| | | ll_search_history_hint.setVisibility(View.GONE); |
| | | if (videoPicture == null || videoPicture.length() == 0 || videoPicture.equals(" ")) {//视频图片为空 隐藏视频 |
| | | ll_guidevideo.setVisibility(View.GONE); |
| | | } else { |
| | | ll_guidevideo.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | SharedPreferences sp; |
| | | if (mBundle.getInt("id") == Constant.GOODS_TYPE_TB) { |
| | | sp = getContext().getSharedPreferences("searchHistory", Context.MODE_PRIVATE); |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_JD) { |
| | | sp = getContext().getSharedPreferences("searchHistory_jd", Context.MODE_PRIVATE); |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_PDD) { |
| | | sp = getContext().getSharedPreferences("searchHistory_pdd", Context.MODE_PRIVATE); |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_VIP) { |
| | | sp = getContext().getSharedPreferences("searchHistory_vip", Context.MODE_PRIVATE); |
| | | } else if (mBundle.getInt("id") == Constant.GOODS_TYPE_SUNING) { |
| | | sp = getContext().getSharedPreferences("searchHistory_suning", Context.MODE_PRIVATE); |
| | | } else { |
| | | sp = getContext().getSharedPreferences("searchHistory", Context.MODE_PRIVATE); |
| | | } |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.clear(); |
| | | editor.putInt("searchNums", mList.size()); |
| | | for (int i = 0; i < mList.size(); i++) { |
| | | editor.putString("searchItem_" + (mList.size() - 1 - i), mList.get(mList.size() - 1 - i)); |
| | | } |
| | | editor.apply(); |
| | | } |
| | | }); |
| | | return view; |
| | | } |
| | | } |
| | | } |