| | |
| | | package com.weikou.beibeivideo.ui.recommend; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.graphics.Color; |
| | | import android.graphics.Typeface; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.support.v4.widget.SwipeRefreshLayout; |
| | | import android.support.v7.widget.LinearLayoutManager; |
| | | import android.support.v7.widget.RecyclerView; |
| | | |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import android.text.Editable; |
| | | import android.text.TextUtils; |
| | | import android.text.TextWatcher; |
| | |
| | | import android.view.View.OnTouchListener; |
| | | import android.view.ViewGroup; |
| | | import android.view.inputmethod.EditorInfo; |
| | | import android.widget.AdapterView; |
| | | import android.widget.AdapterView.OnItemClickListener; |
| | | import android.widget.ArrayAdapter; |
| | | import android.widget.AutoCompleteTextView; |
| | | import android.widget.BaseAdapter; |
| | | import android.widget.EditText; |
| | | import android.widget.Filter; |
| | | import android.widget.Filterable; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.LinearLayout.LayoutParams; |
| | | import android.widget.ProgressBar; |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.google.gson.FieldNamingPolicy; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.lcjian.library.util.ManifestDataUtil; |
| | | import com.lcjian.library.util.common.SoftKeyboardUtils; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.qq.e.ads.cfg.VideoOption; |
| | | import com.qq.e.ads.nativ.NativeADUnifiedListener; |
| | | import com.qq.e.ads.nativ.NativeUnifiedAD; |
| | | import com.qq.e.ads.nativ.NativeUnifiedADData; |
| | | import com.qq.e.comm.util.AdError; |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.entity.VideoInfo; |
| | | import com.weikou.beibeivideo.entity.VideoType; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.entity.video.VideoContent; |
| | | import com.weikou.beibeivideo.ui.BaseActivity; |
| | | import com.weikou.beibeivideo.ui.video.SearchResultAdapter; |
| | | import com.weikou.beibeivideo.ui.video.SuggestKeysAdapter; |
| | | import com.weikou.beibeivideo.ui.video.VideoCloumn1Adapter; |
| | | import com.weikou.beibeivideo.util.DimenUtils; |
| | | import com.weikou.beibeivideo.util.JsonUtil; |
| | | import com.weikou.beibeivideo.util.UmengEventUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.util.ad.manager.SearchResultAdManager; |
| | | import com.weikou.beibeivideo.util.ad.GDTConstant; |
| | | import com.weikou.beibeivideo.util.goldcorn.GoldCornUtil; |
| | | import com.weikou.beibeivideo.util.ui.DividerItemDecoration; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.util.ui.TopStatusSettings; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | |
| | | |
| | | private FrameLayout fl_suggest; |
| | | |
| | | //赚影视豆 |
| | | private Runnable makeGoldCornRunnable; |
| | | |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setContentView(R.layout.search_result_activity); |
| | | initStatusBar(); |
| | | TopStatusSettings.setStatusViewAndDeepColor(this); |
| | | |
| | | suggestFragment = new SearchSuggestFragment(); |
| | | |
| | |
| | | |
| | | rv_video_search.setLayoutManager(new MyLinearLayoutManager(getApplicationContext())); |
| | | DividerItemDecoration decoration = new DividerItemDecoration(); |
| | | decoration.setSize(DimenUtils.dip2px(rv_video_search.getContext(), 6)); |
| | | decoration.setSize(DimenUtils.dip2px(rv_video_search.getContext(), 15)); |
| | | rv_video_search.addItemDecoration(decoration); |
| | | |
| | | adapter = new SearchResultAdapter(this, mVideoInfos); |
| | | adapter = new SearchResultAdapter(this, mVideoInfos, new SearchResultAdapter.VideoAlbumNavClickListener() { |
| | | @Override |
| | | public void onNav(int p) { |
| | | navClick(p); |
| | | } |
| | | }); |
| | | loading = LayoutInflater.from(this).inflate(R.layout.item_loading, null); |
| | | loading.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); |
| | | loading.setVisibility(View.GONE); |
| | |
| | | } else { |
| | | mCurrentKey = et_search_key.getEditableText().toString(); |
| | | } |
| | | |
| | | SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); |
| | | mCurrentPage = 1; |
| | | rl_search_result.setRefreshing(true); |
| | |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | |
| | | private void initTopBar(List<VideoType> videoTypeList) { |
| | | |
| | | private void initTopBar() { |
| | | int p = 0; |
| | | ll_top_bar.removeAllViews(); |
| | | LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); |
| | | for (int i = 0; i < videoTypeList.size(); i++) { |
| | | for (int i = 0; i < typeList.size(); i++) { |
| | | final View view = inflater.inflate(R.layout.item_search_result_top_bar_content, null); |
| | | TextView tv_name = view.findViewById(R.id.tv_name); |
| | | tv_name.setText(videoTypeList.get(i).getName()); |
| | | tv_name.setText(typeList.get(i).getName()); |
| | | setTopBarSelect(tv_name, i == p); |
| | | ll_top_bar.addView(view); |
| | | ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | int p = Integer.parseInt(view.getTag() + ""); |
| | | selectTopBar(p); |
| | | VideoType vt = videoTypeList.get(p); |
| | | |
| | | if (StringUtils.isBlank(mCurrentType) || !mCurrentType.equalsIgnoreCase(vt.getId())) { |
| | | mCurrentPage = 1; |
| | | mCurrentType = vt.getId(); |
| | | rl_search_result.setRefreshing(true); |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | navClick(p); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private void navClick(int p) { |
| | | if (typeList == null || typeList.size() <= p) |
| | | return; |
| | | selectTopBar(p); |
| | | VideoType vt = typeList.get(p); |
| | | |
| | | if (StringUtils.isBlank(mCurrentType) || !mCurrentType.equalsIgnoreCase(vt.getId())) { |
| | | mCurrentPage = 1; |
| | | mCurrentType = vt.getId(); |
| | | rl_search_result.setRefreshing(true); |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | } |
| | | |
| | | private void setTopBarSelect(TextView tv_name, boolean selected) { |
| | | if (selected) { |
| | | tv_name.setBackgroundResource(R.drawable.vpi__tab_selected_focused_holo); |
| | | tv_name.setTextSize(17); |
| | | tv_name.setTextColor(getResources().getColor(R.color.nav_highloght_text_color)); |
| | | tv_name.setTextSize(19); |
| | | tv_name.setTextColor(getResources().getColor(R.color.search_nav_highlight_text_color)); |
| | | tv_name.setPadding(0, 0, 0, DimenUtils.dip2px(getApplicationContext(), 5)); |
| | | tv_name.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); |
| | | } else { |
| | | tv_name.setBackground(null); |
| | | tv_name.setTextSize(12); |
| | | tv_name.setTextSize(14); |
| | | tv_name.setTextColor(getResources().getColor(R.color.nav_text_color)); |
| | | tv_name.setPadding(0, 0, 0, 0); |
| | | tv_name.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); |
| | | } |
| | | } |
| | | |
| | |
| | | }); |
| | | } |
| | | |
| | | private void fillAD(List<ExpressAdContainer> adList) { |
| | | if (adList != null) { |
| | | SearchResultActivity.this.adList.addAll(adList); |
| | | } |
| | | private synchronized void fillAD(List<ExpressAdContainer> adList) { |
| | | |
| | | if (adList.size() > 0) { |
| | | boolean hasAd = false; |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0) |
| | | for (VideoContent vc : mVideoInfos) { |
| | | if (vc.getType() == VideoContent.TYPE_AD) { |
| | | hasAd = true; |
| | | break; |
| | | } |
| | | //判断当前页面是否需要广告 |
| | | int albumCount = 0; |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0) |
| | | for (int i = 0; i < mVideoInfos.size(); i++) { |
| | | VideoContent vc = mVideoInfos.get(i); |
| | | if (vc.getType() == VideoContent.TYPE_AD) { |
| | | //更新广告 |
| | | vc.setAd(adList.get(0)); |
| | | adapter.notifyItemChanged(i); |
| | | return; |
| | | } else if (vc.getVideo().getShowType() == 1) { |
| | | albumCount++; |
| | | } |
| | | //不存在广告 |
| | | if (!hasAd) { |
| | | mVideoInfos.add(0, VideoContent.createAdContent(SearchResultActivity.this.adList.get(0))); |
| | | SearchResultActivity.this.adList.remove(0); |
| | | adapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | if (albumCount >= 2) { |
| | | VideoContent videoContent = VideoContent.createAdContent(adList.get(0)); |
| | | mVideoInfos.add(2, videoContent); |
| | | adapter.notifyItemInserted(2); |
| | | } |
| | | |
| | | } |
| | | |
| | | //拉取2.0的自渲染广告 |
| | | private void loadAd() { |
| | | ExpressAdContainer ad = SearchResultAdManager.getInstance(getApplicationContext()).consumeAD(); |
| | | if (ad == null) { |
| | | SearchResultAdManager.getInstance(getApplicationContext()).loadAD(1, new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<ExpressAdContainer> adList) { |
| | | //vivo无广告 |
| | | // if ("vivo".equalsIgnoreCase(ManifestDataUtil.getAppMetaData(getApplicationContext(), "UMENG_CHANNEL"))) { |
| | | // return; |
| | | // } |
| | | |
| | | String pid = GDTConstant.PID_2_SEARCH_RESULT_ALBUM; |
| | | NativeUnifiedAD mAdManager = new NativeUnifiedAD(this, pid, new NativeADUnifiedListener() { |
| | | |
| | | @Override |
| | | public void onNoAD(AdError adError) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADLoaded(List<NativeUnifiedADData> list) { |
| | | if (list != null && list.size() > 0) { |
| | | List<ExpressAdContainer> adList = new ArrayList<>(); |
| | | adList.add(new ExpressAdContainer(list.get(0))); |
| | | fillAD(adList); |
| | | } |
| | | }); |
| | | } else { |
| | | List<ExpressAdContainer> adList = new ArrayList<>(); |
| | | adList.add(ad); |
| | | fillAD(adList); |
| | | } |
| | | //加载下一个需要的广告 |
| | | SearchResultAdManager.getInstance(getApplicationContext()).autoLoadAd(); |
| | | } |
| | | }); |
| | | mAdManager.loadData(1); |
| | | } |
| | | |
| | | private List<ExpressAdContainer> adList = new ArrayList<>(); |
| | | // private void loadAd() { |
| | | // ExpressAdContainer ad = SearchResultAdManager.getInstance(getApplicationContext()).consumeAD(); |
| | | // if (ad == null) { |
| | | // SearchResultAdManager.getInstance(getApplicationContext()).loadAD(1, new ExpressAdManager.IAdLoadListener() { |
| | | // @Override |
| | | // public void onSuccess(List<ExpressAdContainer> adList) { |
| | | // fillAD(adList); |
| | | // } |
| | | // }); |
| | | // } else { |
| | | // List<ExpressAdContainer> adList = new ArrayList<>(); |
| | | // adList.add(ad); |
| | | // fillAD(adList); |
| | | // } |
| | | // //加载下一个需要的广告 |
| | | // SearchResultAdManager.getInstance(getApplicationContext()).autoLoadAd(); |
| | | // } |
| | | |
| | | |
| | | private void search(String key, String videoType) { |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | UmengEventUtil.search(getApplicationContext(), videoType); |
| | | |
| | |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | hiddenSuggestFragment(); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | |
| | | //挣影视豆 |
| | | if (makeGoldCornRunnable == null) |
| | | makeGoldCornRunnable = GoldCornUtil.makeGoldCorn(getIntent(), et_search_key, null, null, 2, null); |
| | | |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | |
| | | JSONObject rootData = jsonObject.getJSONObject("Data"); |
| | | List<VideoInfo> videoInfos = gson.fromJson( |
| | | List<VideoInfo> videoInfos = JsonUtil.videoGson.fromJson( |
| | | |
| | | rootData.getJSONArray("data").toString(), |
| | | new TypeToken<List<VideoInfo>>() { |
| | |
| | | //设置导航栏 |
| | | if (rootData.opt("typeList") != null) { |
| | | if (typeList == null) { |
| | | typeList = gson.fromJson( |
| | | typeList = JsonUtil.videoGson.fromJson( |
| | | rootData |
| | | .getJSONArray("typeList").toString(), |
| | | new TypeToken<List<VideoType>>() { |
| | | }.getType()); |
| | | initTopBar(typeList); |
| | | initTopBar(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | if (adList.size() > 0) { |
| | | int adPosition = (int) (videoContentList.size() * Math.random()); |
| | | if (mCurrentPage == 1) |
| | | adPosition = 0; |
| | | videoContentList.add(adPosition, VideoContent.createAdContent(adList.get(0))); |
| | | adList.remove(0); |
| | | } |
| | | //记录当前的广告信息 |
| | | VideoContent adContent = null; |
| | | int adContentP = -1; |
| | | if (mCurrentPage <= 1) { |
| | | for (int i = 0; i < mVideoInfos.size(); i++) { |
| | | if (mVideoInfos.get(i).getType() == VideoContent.TYPE_AD) { |
| | | adContent = mVideoInfos.get(i); |
| | | adContentP = i; |
| | | } |
| | | } |
| | | mVideoInfos.clear(); |
| | | } |
| | | |
| | | mVideoInfos.addAll(videoContentList); |
| | | if (adContent != null && mVideoInfos.size() >= adContentP) { |
| | | mVideoInfos.add(adContentP, adContent); |
| | | } |
| | | adapter.notifyDataSetChanged(); |
| | | |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0) { |
| | |
| | | rl_search_result.setVisibility(View.GONE); |
| | | } |
| | | |
| | | //加载下一次要用的广告 |
| | | if (videoInfos.size() > 0) { |
| | | if (adList.size() < 1) |
| | | loadAd(); |
| | | if (mCurrentPage == 1) { |
| | | loadAd(); |
| | | } |
| | | } |
| | | } |
| | |
| | | public void onClick(View v) { |
| | | switch (v.getId()) { |
| | | case R.id.tv_search_cancel: { |
| | | finish(); |
| | | if (fl_suggest.getVisibility() == View.VISIBLE) { |
| | | hiddenSuggestFragment(); |
| | | } else { |
| | | finish(); |
| | | } |
| | | } |
| | | break; |
| | | case R.id.tv_top_bar_left: |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | GoldCornUtil.removeCallbacks(et_search_key, makeGoldCornRunnable); |
| | | } |
| | | } |