| | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.graphics.Color; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | |
| | | import android.widget.AdapterView.OnItemClickListener; |
| | | import android.widget.ArrayAdapter; |
| | | import android.widget.AutoCompleteTextView; |
| | | import android.widget.BaseAdapter; |
| | | import android.widget.Filter; |
| | | import android.widget.Filterable; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.LinearLayout.LayoutParams; |
| | | import android.widget.ProgressBar; |
| | | import android.widget.TextView; |
| | |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | 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.ad.ExpressAdManager; |
| | |
| | | |
| | | private View loading; |
| | | |
| | | private LinearLayout ll_top_bar; |
| | | |
| | | List<VideoType> typeList; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | |
| | | et_search_key = findViewById(R.id.et_search_key); |
| | | tv_search_cancel = findViewById(R.id.tv_search_cancel); |
| | | rv_video_search = findViewById(R.id.rv_video_search); |
| | | findViewById(R.id.tv_moive_all).setOnClickListener(this); |
| | | findViewById(R.id.tv_moive).setOnClickListener(this); |
| | | findViewById(R.id.tv_moive_special).setOnClickListener(this); |
| | | ll_top_bar = findViewById(R.id.ll_top_bar); |
| | | |
| | | tv_search_cancel.setOnClickListener(this); |
| | | et_search_key.addTextChangedListener(new TextWatcher() { |
| | | |
| | |
| | | mCurrentKey = parent.getItemAtPosition(position).toString(); |
| | | SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); |
| | | mCurrentPage = 1; |
| | | //清除顶部分类 |
| | | typeList = null; |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | }); |
| | |
| | | SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); |
| | | mCurrentPage = 1; |
| | | rl_search_result.setRefreshing(true); |
| | | //清除顶部分类 |
| | | typeList = null; |
| | | search(mCurrentKey, mCurrentType); |
| | | return true; |
| | | } |
| | |
| | | }); |
| | | |
| | | |
| | | rv_video_search.setLayoutManager(new LinearLayoutManager(getApplicationContext())); |
| | | rv_video_search.setLayoutManager(new MyLinearLayoutManager(getApplicationContext())); |
| | | DividerItemDecoration decoration = new DividerItemDecoration(); |
| | | decoration.setSize(DimenUtils.dip2px(rv_video_search.getContext(), 6)); |
| | | rv_video_search.addItemDecoration(decoration); |
| | |
| | | int total = manager.getItemCount(); |
| | | if (newState == RecyclerView.SCROLL_STATE_IDLE) { |
| | | if ((!isLoad) && last == total - 1 && mVideoInfos.size() < 1000) { |
| | | mCurrentPage++; |
| | | isLoad = true; |
| | | loading.setVisibility(View.VISIBLE); |
| | | search(mCurrentKey, mCurrentType); |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0 && !rl_search_result.isRefreshing()) {//列表中有数据才能加载更多 |
| | | mCurrentPage++; |
| | | isLoad = true; |
| | | loading.setVisibility(View.VISIBLE); |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | rl_search_result.setRefreshing(true); |
| | | search(mCurrentKey, mCurrentType); |
| | | // loadAd(); |
| | | } |
| | | |
| | | private void initTopBar(List<VideoType> videoTypeList) { |
| | | int p = 0; |
| | | ll_top_bar.removeAllViews(); |
| | | LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); |
| | | for (int i = 0; i < videoTypeList.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()); |
| | | setTopBarSelect(tv_name, i == p); |
| | | ll_top_bar.addView(view); |
| | | ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); |
| | | params.rightMargin = DimenUtils.dip2px(getApplicationContext(), 17); |
| | | params.leftMargin = DimenUtils.dip2px(getApplicationContext(), 10); |
| | | view.setTag(i); |
| | | view.setOnClickListener(new OnClickListener() { |
| | | @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); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | 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(Color.parseColor("#FFFFFF")); |
| | | tv_name.setPadding(0, 0, 0, DimenUtils.dip2px(getApplicationContext(), 5)); |
| | | } else { |
| | | tv_name.setBackground(null); |
| | | tv_name.setTextSize(12); |
| | | tv_name.setTextColor(Color.parseColor("#999999")); |
| | | tv_name.setPadding(0, 0, 0, 0); |
| | | } |
| | | } |
| | | |
| | | private void selectTopBar(int p) { |
| | | for (int i = 0; i < ll_top_bar.getChildCount(); i++) { |
| | | TextView tv = ll_top_bar.getChildAt(i).findViewById(R.id.tv_name); |
| | | setTopBarSelect(tv, i == p); |
| | | } |
| | | } |
| | | |
| | | private void suggestSearch(String key) { |
| | |
| | | .getJSONObject("Data").getJSONArray("data") |
| | | .toString(), new TypeToken<List<String>>() { |
| | | }.getType()); |
| | | ArrayAdapter<String> adapter = new ArrayAdapter<String>( |
| | | SearchResultActivity.this, |
| | | android.R.layout.simple_list_item_1, |
| | | results); |
| | | SuggestKeysAdapter adapter = new SuggestKeysAdapter(getApplicationContext(), results); |
| | | et_search_key.setAdapter(adapter); |
| | | adapter.notifyDataSetChanged(); |
| | | } |
| | |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | JSONObject rootData = jsonObject.getJSONObject("Data"); |
| | | List<VideoInfo> videoInfos = gson.fromJson( |
| | | jsonObject.getJSONObject("Data") |
| | | .getJSONArray("data").toString(), |
| | | |
| | | rootData.getJSONArray("data").toString(), |
| | | new TypeToken<List<VideoInfo>>() { |
| | | }.getType()); |
| | | |
| | | //设置导航栏 |
| | | if (rootData.opt("typeList") != null) { |
| | | if (typeList == null) { |
| | | typeList = gson.fromJson( |
| | | rootData |
| | | .getJSONArray("typeList").toString(), |
| | | new TypeToken<List<VideoType>>() { |
| | | }.getType()); |
| | | initTopBar(typeList); |
| | | } |
| | | } |
| | | |
| | | List<VideoContent> videoContentList = new ArrayList<>(); |
| | | for (VideoInfo video : videoInfos) { |
| | |
| | | videoContentList.add(adPosition, VideoContent.createAdContent(adList.get(0))); |
| | | adList.remove(0); |
| | | } |
| | | if (mCurrentPage <= 1) |
| | | if (mCurrentPage <= 1) { |
| | | mVideoInfos.clear(); |
| | | } |
| | | mVideoInfos.addAll(videoContentList); |
| | | adapter.notifyDataSetChanged(); |
| | | |
| | |
| | | case R.id.tv_top_bar_left: |
| | | finish(); |
| | | break; |
| | | case R.id.tv_moive_all: |
| | | rl_search_result.setRefreshing(true); |
| | | mVideoInfos.clear(); |
| | | mCurrentPage = 1; |
| | | mCurrentType = "0"; |
| | | findViewById(R.id.tv_moive_all).setBackgroundResource(R.drawable.ic_select2); |
| | | findViewById(R.id.tv_moive).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive_special).setBackgroundResource(R.drawable.ic_select1); |
| | | search(mCurrentKey, mCurrentType); |
| | | break; |
| | | case R.id.tv_moive: |
| | | mVideoInfos.clear(); |
| | | rl_search_result.setRefreshing(true); |
| | | mCurrentPage = 1; |
| | | mCurrentType = "1"; |
| | | findViewById(R.id.tv_moive_all).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive).setBackgroundResource(R.drawable.ic_select2); |
| | | findViewById(R.id.tv_moive_special).setBackgroundResource(R.drawable.ic_select1); |
| | | search(mCurrentKey, mCurrentType); |
| | | break; |
| | | case R.id.tv_moive_special: |
| | | mVideoInfos.clear(); |
| | | rl_search_result.setRefreshing(true); |
| | | mCurrentPage = 1; |
| | | mCurrentType = "2"; |
| | | findViewById(R.id.tv_moive_all).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive_special).setBackgroundResource(R.drawable.ic_select2); |
| | | search(mCurrentKey, mCurrentType); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | .putString("history", |
| | | builder.substring(0, builder.length() - 1)).commit(); |
| | | } |
| | | |
| | | |
| | | class MyLinearLayoutManager extends LinearLayoutManager { |
| | | |
| | | public MyLinearLayoutManager(Context context) { |
| | | super(context); |
| | | } |
| | | |
| | | @Override |
| | | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { |
| | | try { |
| | | super.onLayoutChildren(recycler, state); |
| | | } catch (IndexOutOfBoundsException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |