BuWanVideo/res/drawable/shape_search_keyword_bg.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/res/layout/item_search_result_top_bar_content.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/res/layout/search_actvity.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/res/layout/search_result_activity.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/res/layout/search_result_top_bar.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/res/layout/suggestion_grid_item.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchResultActivity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchSuggestFragment.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
BuWanVideo/res/drawable/shape_search_keyword_bg.xml
@@ -2,5 +2,5 @@ <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="40dp" /> <solid android:color="#3D3D3D" /> <solid android:color="@color/search_item_bg_color" /> </shape> BuWanVideo/res/layout/item_search_result_top_bar_content.xml
@@ -8,11 +8,11 @@ android:id="@+id/tv_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/vpi__tab_selected_focused_holo" android:background="@null" android:text="电视剧" android:paddingBottom="15dp" android:gravity="center" android:textColor="@color/white" android:textColor="@color/nav_text_color" android:textSize="17sp"></TextView> BuWanVideo/res/layout/search_actvity.xml
@@ -77,8 +77,7 @@ <ScrollView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" BuWanVideo/res/layout/search_result_activity.xml
@@ -2,7 +2,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/theme" android:background="@color/page_content_bg_color" android:orientation="vertical"> <include layout="@layout/view_status_bar" /> @@ -33,22 +33,22 @@ android:scaleType="fitCenter" android:src="@drawable/ic_activity_main_search"></ImageView> <AutoCompleteTextView <EditText android:id="@+id/et_search_key" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_weight="1" android:background="@null" android:completionThreshold="1" android:hint="请输入搜索内容" android:imeOptions="actionSearch" android:inputType="text" android:padding="5dp" android:textAppearance="?android:attr/textAppearance" android:textColor="@color/white" android:textColor="@color/search_input_text_color" android:textColorHint="@color/search_input_hint_text_color" android:textCursorDrawable="@null" android:textSize="15sp" /> android:textSize="14sp" /> </LinearLayout> @@ -60,62 +60,80 @@ android:paddingLeft="17dp" android:paddingRight="18dp" android:text="取消" android:textColor="#ffffffff" android:textSize="12sp"></TextView> </LinearLayout> <include layout="@layout/search_result_top_bar" /> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/rl_search_result" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_video_search" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp"></android.support.v7.widget.RecyclerView> </android.support.v4.widget.SwipeRefreshLayout> <LinearLayout android:id="@+id/ll_empty" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" android:visibility="gone"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_empty"></ImageView> <TextView android:layout_marginTop="12dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="抱歉,暂未搜索到相关内容..." android:textColor="@color/white"></TextView> android:textColor="@color/item_title_text_color" android:textSize="14sp"></TextView> </LinearLayout> <FrameLayout android:id="@+id/fl_advertisement" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone"> android:layout_height="0dp" android:layout_weight="1"> <ImageView android:id="@+id/iv_search_result_ad" <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" /> </FrameLayout> android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/search_result_top_bar" /> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/rl_search_result" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_video_search" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp"></android.support.v7.widget.RecyclerView> </android.support.v4.widget.SwipeRefreshLayout> <LinearLayout android:id="@+id/ll_empty" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" android:visibility="gone"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_empty"></ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="抱歉,暂未搜索到相关内容..." android:textColor="@color/white"></TextView> </LinearLayout> <FrameLayout android:id="@+id/fl_advertisement" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone"> <ImageView android:id="@+id/iv_search_result_ad" android:layout_width="match_parent" android:layout_height="wrap_content" /> </FrameLayout> </LinearLayout> <FrameLayout android:id="@+id/fl_suggest" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/page_content_bg_color" android:visibility="gone"></FrameLayout> </FrameLayout> </LinearLayout> BuWanVideo/res/layout/search_result_top_bar.xml
@@ -2,7 +2,7 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/theme" android:background="@color/page_content_bg_color" android:orientation="horizontal" android:paddingLeft="8dp" android:paddingRight="8dp" BuWanVideo/res/layout/suggestion_grid_item.xml
@@ -19,7 +19,7 @@ android:singleLine="true" android:text="123123" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#DDDDDD" android:textColor="@color/search_item_text_color" android:textSize="12sp" /> </LinearLayout> BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java
@@ -74,6 +74,8 @@ private SearchSuggestFragment suggestFragment; private FrameLayout fl_suggest; private String value = ""; private boolean touchSearchInput = false; @@ -87,6 +89,7 @@ gv_history_search = findViewById(R.id.gv_history_search); tv_clear = findViewById(R.id.tv_search_clear_his); ll_search_history = findViewById(R.id.ll_search_history); fl_suggest = findViewById(R.id.fl_suggest); } @Override @@ -143,19 +146,14 @@ @Override public void afterTextChanged(Editable s) { if (!TextUtils.isEmpty(s.toString()) || !TextUtils.isEmpty(et_search_key.getHint())) { suggestSearch(s.toString()); if (s != null && !TextUtils.isEmpty(s.toString())) { et_search_key.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_clear, 0); // tv_search_cancel.setText(R.string.search); } else { et_search_key.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); // tv_search_cancel.setText(R.string.cancel); } suggestSearch(s != null ? s.toString() : null); } }); @@ -176,13 +174,6 @@ // getCompoundDrawables() 可以获取一个长度为4的数组, // 存放drawableLeft,Right,Top,Bottom四个图片资源对象 // index=2 表示的是 drawableRight 图片资源对象 if (et_search_key.isFocused()) { findViewById(R.id.fl_suggest).setVisibility(View.VISIBLE); getSupportFragmentManager().beginTransaction().replace(R.id.fl_suggest, suggestFragment).commitAllowingStateLoss(); } else { findViewById(R.id.fl_suggest).setVisibility(View.GONE); getSupportFragmentManager().beginTransaction().remove(suggestFragment).commitAllowingStateLoss(); } Drawable drawable = et_search_key.getCompoundDrawables()[2]; if (drawable == null) @@ -262,7 +253,41 @@ } } private void hiddenSuggestFragment() { fl_suggest.setVisibility(View.GONE); getSupportFragmentManager().beginTransaction().remove(suggestFragment).commitAllowingStateLoss(); } private void showSuggestFragment(String key, List<String> list) { Bundle bundle = new Bundle(); bundle.putString("key", key); bundle.putString("list", new Gson().toJson(list)); fl_suggest.setVisibility(View.VISIBLE); // if (suggestFragment.isAdded()) { // return; // } suggestFragment.setItemClickListener(new SearchSuggestFragment.OnItemClickListener() { @Override public void onClick(String st) { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra("key", st); startActivity(intent); hiddenSuggestFragment(); } }); suggestFragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.fl_suggest, suggestFragment).commitAllowingStateLoss(); } private void suggestSearch(String key) { if (StringUtils.isEmpty(key)) { hiddenSuggestFragment(); } SharedPreferences preferences = getSharedPreferences("user", Context.MODE_PRIVATE); String uid = preferences.getString("uid", ""); @@ -273,19 +298,29 @@ public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { List<String> results = null; if (jsonObject.getBoolean("IsPost")) { Gson gson = new GsonBuilder().setFieldNamingPolicy( FieldNamingPolicy.UPPER_CAMEL_CASE) .create(); List<String> results = gson.fromJson(jsonObject results = gson.fromJson(jsonObject .getJSONObject("Data").getJSONArray("data") .toString(), new TypeToken<List<String>>() { }.getType()); suggestFragment.setData(key, results); // SuggestKeysAdapter adapter = new SuggestKeysAdapter(getApplicationContext(), results); // et_search_key.setAdapter(adapter); // adapter.notifyDataSetChanged(); } if (results != null && results.size() > 0) { showSuggestFragment(key, results); suggestFragment.setData(key, results); } else { hiddenSuggestFragment(); } } }); } BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchResultActivity.java
@@ -26,8 +26,10 @@ 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; @@ -68,7 +70,7 @@ public class SearchResultActivity extends BaseActivity implements OnClickListener { private AutoCompleteTextView et_search_key; private EditText et_search_key; private TextView tv_search_cancel; @@ -101,11 +103,17 @@ private LinearLayout ll_empty; private SearchSuggestFragment suggestFragment; private FrameLayout fl_suggest; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_result_activity); initStatusBar(); suggestFragment = new SearchSuggestFragment(); rl_search_result = findViewById(R.id.rl_search_result); et_search_key = findViewById(R.id.et_search_key); @@ -113,6 +121,7 @@ rv_video_search = findViewById(R.id.rv_video_search); ll_top_bar = findViewById(R.id.ll_top_bar); ll_empty = findViewById(R.id.ll_empty); fl_suggest = findViewById(R.id.fl_suggest); tv_search_cancel.setOnClickListener(this); et_search_key.addTextChangedListener(new TextWatcher() { @@ -131,33 +140,18 @@ @Override public void afterTextChanged(Editable s) { if (!TextUtils.isEmpty(s.toString()) || !TextUtils.isEmpty(et_search_key.getText())) { if (mFirst) { mFirst = false; } else { suggestSearch(s.toString()); } if (!TextUtils.isEmpty(s.toString())) { et_search_key.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_clear, 0); } else { et_search_key.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } } }); et_search_key.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mFirst = true; mCurrentKey = parent.getItemAtPosition(position).toString(); SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); mCurrentPage = 1; //清除顶部分类 typeList = null; search(mCurrentKey, mCurrentType); if (mFirst) { mFirst = false; } else { suggestSearch(s != null ? s.toString() : null); } } }); @@ -190,18 +184,7 @@ @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { if (StringUtils.isEmpty(et_search_key.getEditableText() .toString())) { mCurrentKey = et_search_key.getText().toString(); } else { mCurrentKey = et_search_key.getEditableText().toString(); } SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); mCurrentPage = 1; rl_search_result.setRefreshing(true); //清除顶部分类 typeList = null; search(mCurrentKey, mCurrentType); startSearch(); return true; } return false; @@ -268,6 +251,21 @@ // loadAd(); } private void startSearch() { if (StringUtils.isEmpty(et_search_key.getEditableText() .toString())) { mCurrentKey = et_search_key.getText().toString(); } else { mCurrentKey = et_search_key.getEditableText().toString(); } SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); mCurrentPage = 1; rl_search_result.setRefreshing(true); //清除顶部分类 typeList = null; search(mCurrentKey, mCurrentType); } private void initTopBar(List<VideoType> videoTypeList) { int p = 0; ll_top_bar.removeAllViews(); @@ -304,12 +302,12 @@ if (selected) { tv_name.setBackgroundResource(R.drawable.vpi__tab_selected_focused_holo); tv_name.setTextSize(17); tv_name.setTextColor(Color.parseColor("#FFFFFF")); tv_name.setTextColor(getResources().getColor(R.color.nav_highloght_text_color)); 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.setTextColor(getResources().getColor(R.color.nav_text_color)); tv_name.setPadding(0, 0, 0, 0); } } @@ -321,7 +319,37 @@ } } private void hiddenSuggestFragment() { fl_suggest.setVisibility(View.GONE); getSupportFragmentManager().beginTransaction().remove(suggestFragment).commitAllowingStateLoss(); } private void showSuggestFragment(String key, List<String> list) { Bundle bundle = new Bundle(); bundle.putString("key", key); bundle.putString("list", new Gson().toJson(list)); fl_suggest.setVisibility(View.VISIBLE); suggestFragment.setItemClickListener(new SearchSuggestFragment.OnItemClickListener() { @Override public void onClick(String st) { mFirst = true; hiddenSuggestFragment(); et_search_key.setText(st); startSearch(); } }); suggestFragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.fl_suggest, suggestFragment).commitAllowingStateLoss(); } private void suggestSearch(String key) { if (StringUtils.isEmpty(key)) { hiddenSuggestFragment(); } SharedPreferences preferences = getSharedPreferences("user", Context.MODE_PRIVATE); String uid = preferences.getString("uid", ""); @@ -332,18 +360,29 @@ public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { List<String> results = null; if (jsonObject.getBoolean("IsPost")) { Gson gson = new GsonBuilder().setFieldNamingPolicy( FieldNamingPolicy.UPPER_CAMEL_CASE) .create(); List<String> results = gson.fromJson(jsonObject results = gson.fromJson(jsonObject .getJSONObject("Data").getJSONArray("data") .toString(), new TypeToken<List<String>>() { }.getType()); SuggestKeysAdapter adapter = new SuggestKeysAdapter(getApplicationContext(), results); et_search_key.setAdapter(adapter); adapter.notifyDataSetChanged(); // SuggestKeysAdapter adapter = new SuggestKeysAdapter(getApplicationContext(), results); // et_search_key.setAdapter(adapter); // adapter.notifyDataSetChanged(); } if (results != null && results.size() > 0) { showSuggestFragment(key, results); suggestFragment.setData(key, results); } else { hiddenSuggestFragment(); } } }); } BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchSuggestFragment.java
@@ -15,11 +15,14 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.lcjian.library.RetainViewFragment; import com.weikou.beibeivideo.R; import com.weikou.beibeivideo.util.DimenUtils; import com.weikou.beibeivideo.util.ui.DividerItemDecoration; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; @@ -31,7 +34,7 @@ private RecyclerView rv_suggest; private List<String> mList = null; private List<String> mList = new ArrayList<>(); private String key; private SearchSuggestAdapter adapter; @@ -46,20 +49,31 @@ } private void initData() { mList = new ArrayList<>(); adapter = new SearchSuggestAdapter(getContext(), mList); rv_suggest.setAdapter(adapter); Bundle bundle = getArguments(); if (bundle != null) { key = bundle.getString("key"); String list = bundle.getString("list"); Type type = new TypeToken<List<String>>() { }.getType(); List<String> mList1 = new Gson().fromJson(list, type); setData(key, mList1); } } public void setData(String key, List<String> list) { this.key = key; if (mList == null) { initData(); } mList.clear(); mList.addAll(list); adapter.notifyDataSetChanged(); } private OnItemClickListener clickListener; public void setItemClickListener(OnItemClickListener clickListener) { this.clickListener = clickListener; } @Override @@ -112,10 +126,9 @@ viewHolder.view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, SearchResultActivity.class); intent.putExtra("key", st); startActivity(intent); if (clickListener != null) { clickListener.onClick(st); } } }); @@ -142,4 +155,10 @@ } } interface OnItemClickListener { public void onClick(String st); } }