From 2eec3de87b6b616a69a46c1f97c2397159031d2f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 21 十一月 2023 18:01:43 +0800 Subject: [PATCH] 广告升级/bug修复 --- BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java | 351 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 298 insertions(+), 53 deletions(-) diff --git a/BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java b/BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java index dc0cfe2..1eab838 100644 --- a/BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java +++ b/BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java @@ -4,36 +4,46 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.graphics.Color; import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; 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.FrameLayout; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; +import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; +import com.androidquery.AQuery; 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.StringUtils; +import com.lcjian.library.widget.FlowLayout; +import com.lcjian.library.widget.MyGridView; import com.qq.e.ads.cfg.VideoOption; import com.qq.e.ads.nativ.ADSize; import com.qq.e.ads.nativ.NativeExpressAD; @@ -45,17 +55,26 @@ import com.weikou.beibeivideo.entity.ad.AdPositionEnum; import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; import com.weikou.beibeivideo.ui.BaseActivity; +import com.weikou.beibeivideo.ui.common.CommonFragmentActivity; +import com.weikou.beibeivideo.ui.common.GridVideoAdapter1; +import com.weikou.beibeivideo.ui.main.MainActivity; import com.weikou.beibeivideo.ui.video.SuggestKeysAdapter; import com.weikou.beibeivideo.util.BeibeiConstant; import com.weikou.beibeivideo.R; import com.weikou.beibeivideo.util.DimenUtils; import com.weikou.beibeivideo.util.ad.AdUtil; import com.weikou.beibeivideo.util.ad.ExpressAdManager; +import com.weikou.beibeivideo.util.goldcorn.GoldCornUtil; +import com.weikou.beibeivideo.util.ui.TopStatusSettings; import org.apache.http.Header; +import org.json.JSONArray; import org.json.JSONObject; +import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; public class SearchActivity extends BaseActivity implements OnClickListener { @@ -68,15 +87,18 @@ private GridView gv_hot_search; - private GridView gv_history_search; + private FlowLayout fl_history_search; - private LinearLayout ll_search_history; + private LinearLayout ll_search_history, ll_search_rank; private SearchSuggestFragment suggestFragment; + private FrameLayout fl_suggest; + private String value = ""; - private boolean touchSearchInput = false; + private AQuery mAQuery; + private void initView() { fl_advertisement = findViewById(R.id.fl_advertisement); @@ -84,16 +106,20 @@ fl_advertisement.setOnClickListener(this); tv_search_cancel = findViewById(R.id.tv_search_cancel); gv_hot_search = findViewById(R.id.gv_hot_search); - gv_history_search = findViewById(R.id.gv_history_search); + fl_history_search = findViewById(R.id.fl_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); + ll_search_rank = findViewById(R.id.ll_search_rank); + mAQuery = new AQuery(this); } @Override protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); setContentView(R.layout.search_actvity); - initStatusBar(); + TopStatusSettings.setStatusViewAndDeepColor(this); initView(); suggestFragment = new SearchSuggestFragment(); @@ -101,16 +127,21 @@ @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { - Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); + if (StringUtils.isEmpty(et_search_key.getEditableText() - .toString())) { + + "") && StringUtils.isEmpty(et_search_key.getHint() + "")) { Toast.makeText(SearchActivity.this, "璇疯緭鍏ユ悳绱㈠唴瀹�!", Toast.LENGTH_LONG).show(); return false; } else { - intent.putExtra("key", et_search_key.getEditableText() - .toString()); + if (!StringUtils.isEmpty(et_search_key.getEditableText() + + "")) { + jumpToSearch(et_search_key.getEditableText() + + ""); + } else { + jumpToSearch(et_search_key.getHint() + ""); + } } - startActivity(intent); + return true; } @@ -143,30 +174,23 @@ @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); } }); if (!TextUtils.isEmpty(value)) { 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); } et_search_key.setOnTouchListener(new OnTouchListener() { @@ -176,13 +200,6 @@ // getCompoundDrawables() 鍙互鑾峰彇涓�涓暱搴︿负4鐨勬暟缁勶紝 // 瀛樻斁drawableLeft锛孯ight锛孴op锛孊ottom鍥涗釜鍥剧墖璧勬簮瀵硅薄 // 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) @@ -207,31 +224,23 @@ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - Intent intent = new Intent(SearchActivity.this, - SearchResultActivity.class); - intent.putExtra("key", - (String) parent.getItemAtPosition(position)); - startActivity(intent); - } - }); - gv_history_search.setOnItemClickListener(new OnItemClickListener() { - - @Override - public void onItemClick(AdapterView<?> parent, View view, - int position, long id) { - Intent intent = new Intent(SearchActivity.this, - SearchResultActivity.class); - intent.putExtra("key", - (String) parent.getItemAtPosition(position)); - startActivity(intent); + jumpToSearch((String) parent.getItemAtPosition(position)); } }); et_search_key.setHint(getIntent().getStringExtra("key")); + mAQuery.id(R.id.iv_short_video).clicked(new OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(SearchActivity.this, MainActivity.class).putExtra("position", 0+"").putExtra("cposition", 1+"")); + finish(); + } + }); getHotSearch(); getHistorySearch(); initAdvertisement();// 骞跨偣閫氬箍鍛� + getSearchRank(); } @Override @@ -249,7 +258,10 @@ public void onClick(final 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_search_clear_his: clearHistorySearch(); @@ -262,7 +274,38 @@ } } + + 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) { + jumpToSearch(st); + 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 +316,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(); + } + } }); } @@ -297,13 +350,35 @@ if (!StringUtils.isBlank(historyStr)) { String[] historyArray = historyStr.split(","); ll_search_history.setVisibility(View.VISIBLE); - List<String> history = new ArrayList<String>(); + List<String> history = new ArrayList<>(); for (int i = 0; i < 10 && i < historyArray.length; i++) { if (!TextUtils.isEmpty(historyArray[historyArray.length - 1 - i])) { - history.add(historyArray[historyArray.length - 1 - i]); + String st = historyArray[historyArray.length - 1 - i]; + if (st != null && !history.contains(st.trim())) + history.add(st.trim()); } } - gv_history_search.setAdapter(new GridSuggestionAdapter(history, false)); + + fl_history_search.removeAllViews(); + for (String st : history) { + TextView textView = new TextView(getApplicationContext()); + textView.setEllipsize(TextUtils.TruncateAt.END); + textView.setTextSize(13); + textView.setPadding(DimenUtils.dip2px(getApplicationContext(), 20), DimenUtils.dip2px(getApplicationContext(), 5), DimenUtils.dip2px(getApplicationContext(), 20), DimenUtils.dip2px(getApplicationContext(), 5)); + textView.setText(st); + textView.setTextColor(getResources().getColor(R.color.search_item_text_color)); + textView.setBackgroundResource(R.drawable.shape_search_history_item_bg); + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); + params.setMargins(0, DimenUtils.dip2px(getApplicationContext(), 15), DimenUtils.dip2px(getApplicationContext(), 13), 0); + textView.setLayoutParams(params); + textView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + jumpToSearch(st); + } + }); + fl_history_search.addView(textView); + } } else { ll_search_history.setVisibility(View.GONE); } @@ -336,8 +411,32 @@ .getJSONObject("Data").getJSONArray("data") .toString(), new TypeToken<List<String>>() { }.getType()); - gv_hot_search.setAdapter(new GridSuggestionAdapter( + if (hotSearchs == null || hotSearchs.size() == 0) { + gv_hot_search.setVisibility(View.GONE); + } else { + gv_hot_search.setVisibility(View.VISIBLE); + } + + gv_hot_search.setAdapter(new HotSearchAdapter( hotSearchs, true)); + } else { + gv_hot_search.setVisibility(View.GONE); + } + } + }); + } + + private void getSearchRank() { + BeibeiVideoAPI.getSearchRank(this, + new BasicTextHttpResponseHandler() { + @Override + public void onSuccessPerfect(int statusCode, + Header[] headers, JSONObject jsonObject) + throws Exception { + if (jsonObject.getBoolean("IsPost")) { + JSONObject data = jsonObject + .getJSONObject("Data").getJSONObject("data"); + initSearchRank(data); } } }); @@ -350,7 +449,17 @@ // 1.鍔犺浇骞垮憡锛屽厛璁剧疆鍔犺浇涓婁笅鏂囩幆澧冨拰鏉′欢 private void initAdvertisement() { - AdUtil.AD_TYPE adType = AdUtil.getAdType(getApplicationContext(), AdPositionEnum.videoSearch); + //vivo鏃犲箍鍛� +// if ("vivo".equalsIgnoreCase(ManifestDataUtil.getAppMetaData(getApplicationContext(), "UMENG_CHANNEL"))) { +// return; +// } + + AdUtil.AD_TYPE adType1 = AdUtil.getAdType(getApplicationContext(), AdPositionEnum.videoSearch); + if (adType1 == AdUtil.AD_TYPE.gdt) { + adType1 = AdUtil.AD_TYPE.gdt2; + } + final AdUtil.AD_TYPE adType = adType1; + fl_advertisement.post(new Runnable() { @Override public void run() { @@ -367,10 +476,10 @@ }); } else if (adType != null) { AdUtil.AD_TYPE newAdType = null; - if (adType == AdUtil.AD_TYPE.gdt) { + if (adType == AdUtil.AD_TYPE.gdt2) { newAdType = AdUtil.AD_TYPE.csj; } else - newAdType = AdUtil.AD_TYPE.gdt; + newAdType = AdUtil.AD_TYPE.gdt2; new ExpressAdManager(newAdType, getApplicationContext()).loadSearchAd(DimenUtils.px2dip(getApplicationContext(), width), new ExpressAdManager.IAdLoadListener() { @Override @@ -383,13 +492,149 @@ } }); } + } }); } + } }); } }); } + private void initSearchRank(JSONObject data) { + ll_search_rank.removeAllViews(); + Type type = new TypeToken<List<String>>() { + }.getType(); + Gson gson = new Gson(); + int count = 0; + for (Iterator<String> its = data.keys(); its.hasNext(); ) { + String key = its.next(); + JSONArray array = data.optJSONArray(key); + List<String> list = gson.fromJson(array.toString(), type); + String[] sts = new String[list.size()]; + int row = list.size() / 2; + for (int i = 0; i < list.size(); i++) { + if (i < row) { + sts[i * 2] = list.get(i); + } else { + sts[(i % row) * 2 + 1] = list.get(i); + } + + } + count++; + addSearchRankView(key, Arrays.asList(sts), ll_search_rank, count == data.length()); + } + } + + private void addSearchRankView(String title, List<String> contentList, LinearLayout container, boolean last) { + View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_search_rank, null); + MyGridView gv = view.findViewById(R.id.gv_content); + TextView tv_title = view.findViewById(R.id.tv_title); + tv_title.setText(title); + gv.setAdapter(new SearchRankAdapter(contentList, getApplicationContext())); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DimenUtils.dip2px(getApplicationContext(), 284), LinearLayout.LayoutParams.WRAP_CONTENT); + params.rightMargin = DimenUtils.dip2px(getApplicationContext(), !last ? 11 : 0); + container.addView(view, params); + } + + private void jumpToSearch(String key) { + Intent intent = new Intent(SearchActivity.this, + SearchResultActivity.class); + intent.putExtra("key", key); + if (getIntent() != null) { + intent.putExtra("goldcorn", getIntent().getStringExtra("goldcorn")); + getIntent().removeExtra("goldcorn"); + } + startActivity(intent); + } + + + class SearchRankAdapter extends BaseAdapter { + + private List<String> mList; + private LayoutInflater layoutInflater; + + public SearchRankAdapter(List<String> list, Context context) { + this.mList = list; + layoutInflater = LayoutInflater.from(context); + } + + //鏈�澶�8涓� + @Override + public int getCount() { + return mList == null ? 0 : (mList.size()>8?8:mList.size()); + } + + @Override + public Object getItem(int position) { + return mList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + viewHolder = new ViewHolder(); + convertView = LayoutInflater.from(parent.getContext()).inflate( + R.layout.item_search_rank_content, parent, false); + viewHolder.tv_rank = convertView + .findViewById(R.id.tv_rank); + viewHolder.tv_content = convertView + .findViewById(R.id.tv_content); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + if (position % 2 == 0) { + viewHolder.tv_rank.setText((position / 2 + 1) + ""); + } else { + viewHolder.tv_rank.setText((getCount() / 2 + (position + 1) / 2) + ""); + } + viewHolder.tv_content.setText(mList.get(position)); + + String color = "#C2C2C2"; + switch (viewHolder.tv_rank.getText() + "") { + case "1": + color = "#FE3E3C"; + break; + case "2": + color = "#FE853C"; + break; + case "3": + color = "#FEC03C"; + break; + default: + color = "#C2C2C2"; + } + GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, + new int[]{Color.parseColor(color), Color.parseColor(color)}); + gd.setCornerRadius(DimenUtils.dip2px(convertView.getContext(), 4)); + viewHolder.tv_rank.setBackground(gd); + convertView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + jumpToSearch(mList.get(position)); + } + }); + return convertView; + } + + class ViewHolder { + TextView tv_rank; + TextView tv_content; + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + } } -- Gitblit v1.8.0