Commit 5a5aa459 authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :1.1.1
[实现方案] :
parent e872b1a6
......@@ -21,7 +21,7 @@ public class NetConfig {
}
// 根据调试选项更新环境
public static Environment sEnvironment = PRODUCT;// 当前环境
public static Environment sEnvironment = DEV;// 当前环境
public static String BASE_WEB_URL = "";
public static String BASE_URL = "";
public static String BASE_NEW_URL = "";
......
package com.zxbw.modulemain.activity
import android.content.Intent
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import com.zxbw.modulemain.R
import com.zxbw.modulemain.adapter.SearchGoodsTopAdapter
import com.zxbw.modulemain.contract.SearchContract
import com.zxbw.modulemain.presenter.SearchPresenter
import com.zxbw.modulemain.uitls.SPUtils
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.shop.ShopListEntity
import com.zxhl.cms.utils.EventUtils
import com.zxhl.cms.utils.OnRecycleItemClickListener
import kotlinx.android.synthetic.main.activity_layout_search.*
/**
* @author (wangXuewei)
* @datetime 2022-06-06 14:20 GMT+8
* @detail :搜索
*/
class SearchActivity : BaseActivity(), SearchContract.View,
OnRecycleItemClickListener<ShopListEntity> {
private var mPresenter: SearchPresenter? = null
var mGoodsAdapter: SearchGoodsTopAdapter? = null
override fun before() {
super.before()
setStatusBarBackground(resources.getColor(com.zxhl.cms.R.color.transparent))
}
override fun onClick(v: View?) {
when (v) {
id_img_back_search -> {
finish()
}
id_img_clean_history -> {
id_search_history_view.removeAllViews()
SPUtils.getInstance(this).cleanHistory()
}
id_search_btn -> {
val searchValue = id_edt_input_value.text.toString().trim()
if (searchValue.isNullOrEmpty()) {
showToast("请输入要搜索的商品")
} else {
SPUtils.getInstance(this).saveHistory(searchValue)
// showToast(searchValue)
// JumpUtils.SearchReslutJumo(searchValue, "0", "")
finish()
}
}
}
}
override fun layoutID(): Int {
return R.layout.activity_layout_search
}
override fun init() {
id_img_back_search.setOnClickListener(this)
id_search_btn.setOnClickListener(this)
id_img_clean_history.setOnClickListener(this)
mGoodsAdapter = SearchGoodsTopAdapter(this, this)
id_rck_goods_list.layoutManager = GridLayoutManager(this, 3)
id_rck_goods_list.adapter = mGoodsAdapter
mPresenter = SearchPresenter(this)
mPresenter?.getSearchHistory()
mPresenter?.getBestGoodsList()
id_edt_input_value.setOnKeyListener { v, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_ENTER && event?.action == KeyEvent.ACTION_UP) {
hideKeyBoard()
id_search_btn.callOnClick()
}
false
}
EventUtils.onEvent("SearchPageShow")
}
override fun setSearchHistory() {
val historyList = SPUtils.getInstance(this).historyList
if (historyList.size == 1 && historyList[0].isNullOrEmpty()) {
} else {
initHistoryView(historyList.toList())
}
}
override fun setBestGoodsList(result: List<ShopListEntity>?) {
if (result.isNullOrEmpty()) {
id_tv_title2.visibility = View.GONE
id_rck_goods_list.visibility = View.GONE
} else {
id_tv_title2.visibility = View.VISIBLE
id_rck_goods_list.visibility = View.VISIBLE
mGoodsAdapter?.clear()
mGoodsAdapter?.appendToList(result)
}
}
private var mViewList: MutableList<View> = ArrayList()
fun initHistoryView(mData: List<String>) {
mViewList.clear()
for (i in mData.indices) {
var mTv = LayoutInflater.from(this)
.inflate(
R.layout.item_view_search_history,
id_search_history_view,
false
) as TextView
mTv.text = mData[i]
mViewList.add(mTv);
}
id_search_history_view.setChildren(mViewList)
id_search_history_view.viewTreeObserver.addOnGlobalLayoutListener(object :
OnGlobalLayoutListener {
override fun onGlobalLayout() {
id_search_history_view.viewTreeObserver.removeOnGlobalLayoutListener(this)
val lineCount = id_search_history_view.lineCount
val twoLineViewCount = id_search_history_view.twoLineViewCount
val expandLineViewCount = id_search_history_view.expandLineViewCount
if (lineCount > 2) {
initHistoryClose(twoLineViewCount, expandLineViewCount, mData)
}
}
})
id_search_history_view.setOnTagClickListener { view, position ->
// JumpUtils.SearchReslutJumo(mData[position], "0", "")
finish()
}
}
fun initHistoryClose(twoLineViewCount: Int, expandLineViewCount: Int, mData: List<String>) {
mViewList.clear();
for (i in 0 until twoLineViewCount) {
var mTv = LayoutInflater.from(this)
.inflate(
R.layout.item_view_search_history,
id_search_history_view,
false
) as TextView
mTv.text = mData[i]
mViewList.add(mTv);
}
//展开按钮
var mCloseBtn = LayoutInflater.from(this)
.inflate(
R.layout.item_view_search_history_btn_img,
id_search_history_view,
false
) as ImageView
mCloseBtn.setImageResource(R.drawable.icon_xialajiantou);
mCloseBtn.setOnClickListener {
initHistoryOpen(twoLineViewCount, expandLineViewCount, mData);
}
mViewList.add(mCloseBtn)
id_search_history_view.setChildren(mViewList)
id_search_history_view.viewTreeObserver.addOnGlobalLayoutListener(object :
OnGlobalLayoutListener {
override fun onGlobalLayout() {
id_search_history_view.viewTreeObserver.removeOnGlobalLayoutListener(this)
val lineCount = id_search_history_view.lineCount
val twoLineViewCount = id_search_history_view.twoLineViewCount
if (lineCount > 2) {
initHistoryClose(
twoLineViewCount - 1,
id_search_history_view.expandLineViewCount,
mData
)
}
}
})
}
fun initHistoryOpen(twoLineViewCount: Int, expandLineViewCount: Int, mData: List<String>) {
mViewList.clear();
for (i in mData.indices) {
var mTv = LayoutInflater.from(this)
.inflate(
R.layout.item_view_search_history,
id_search_history_view,
false
) as TextView
mTv.text = mData[i]
mViewList.add(mTv);
}
// //收起按钮
// var mCloseBtn = LayoutInflater.from(this)
// .inflate(
// R.layout.item_view_search_history_btn_img,
// id_search_history_view,
// false
// ) as ImageView
// mCloseBtn.setImageResource(R.drawable.icon_xialajiantou);
// mCloseBtn.setOnClickListener {
// initHistoryClose(twoLineViewCount, expandLineViewCount, mData);
// }
// mViewList.add(mCloseBtn);
id_search_history_view.setChildren(mViewList)
}
override fun onItemClick(view: View?, position: Int, data: ShopListEntity?) {
EventUtils.onEvent("ShopGoodsClick", data?.id ?: "-1")
// var intent = Intent();
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// intent.putExtra("goods", data)
// intent.setClass(this, ShopGoodsDetailActivity().javaClass)
// startActivity(intent)
}
}
\ No newline at end of file
package com.zxbw.modulemain.adapter
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.graphics.Paint
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zxbw.modulemain.R
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.box.DepotEntity
import com.zxhl.cms.net.model.box.ShopOrderEntity
import com.zxhl.cms.net.model.shop.ShopListEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.utils.Utils
import com.zxhl.cms.widget.RecycleImageView
//搜索商品排行榜
class SearchGoodsTopAdapter :
BaseRecyclerAdapter<ShopListEntity, SearchGoodsTopAdapter.ViewHolder> {
private var mContext: Context? = null
private val listener: OnRecycleItemClickListener<ShopListEntity>
// private var mTopIconList = listOf(
//// R.drawable.icon_goods_top1,
//// R.drawable.icon_goods_top2,
//// R.drawable.icon_goods_top3,
//// R.drawable.icon_goods_top4,
//// R.drawable.icon_goods_top5,
//// R.drawable.icon_goods_top6,
//// R.drawable.icon_goods_top7,
//// R.drawable.icon_goods_top8,
//// R.drawable.icon_goods_top9
// )
constructor(
content: Context?,
listener: OnRecycleItemClickListener<ShopListEntity>
) : super() {
mContext = content
this.listener = listener
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
var bean = mList[position]
// holder.id_rl_goods_item?.setOnClickListener {
// listener?.onItemClick(it, position, bean)
// }
// holder.id_tv_goods_name?.text = bean.productName
//// holder.id_tv_goods_price?.text = bean.salePriceStr
// holder.id_tv_goods_price?.text = bean.originalPriceDb
// holder.id_img_goods_img?.setLoadImageUrl(bean.mainImage, false)
// holder.id_tv_goods_sale_num?.text = "${bean.salesVolume ?: "0"}人付款"
//// holder.id_tv_goods_old_price?.text = "¥${bean.originalPriceDb}"
// holder.id_tv_goods_old_price?.text = "¥${bean.salePriceStr}"
// holder.id_tv_goods_old_price?.paint?.flags = Paint.STRIKE_THRU_TEXT_FLAG
if (position < 9) {
// holder.id_img_goods_number?.setImageResource(mTopIconList[position])
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
// return ViewHolder(
// LayoutInflater.from(AppContext.get())
// .inflate(R.layout.item_search_goods_view, parent, false)
// )
return ViewHolder(
LayoutInflater.from(AppContext.get())
.inflate(R.layout.item_layout_skill_time, parent, false)
)
}
class ViewHolder : RecyclerView.ViewHolder {
// var id_rl_goods_item: RelativeLayout?
// var id_img_goods_img: RecycleImageView?
// var id_tv_goods_name: TextView?
// var id_tv_goods_price: TextView?
// var id_tv_goods_old_price: TextView?
// var id_tv_goods_sale_num: TextView?
// var id_img_goods_number: ImageView?
constructor(
itemView: View
) : super(itemView) {
// id_rl_goods_item = itemView.findViewById<RelativeLayout>(R.id.id_rl_goods_item)
// id_img_goods_img = itemView.findViewById<RecycleImageView>(R.id.id_img_goods_img)
// id_tv_goods_name = itemView.findViewById<TextView>(R.id.id_tv_goods_name)
// id_tv_goods_price = itemView.findViewById<TextView>(R.id.id_tv_goods_price)
// id_tv_goods_old_price = itemView.findViewById<TextView>(R.id.id_tv_goods_old_price)
// id_tv_goods_sale_num = itemView.findViewById<TextView>(R.id.id_tv_goods_sale_num)
// id_img_goods_number = itemView.findViewById<ImageView>(R.id.id_img_goods_number)
}
}
}
\ No newline at end of file
package com.zxbw.modulemain.contract
import com.zxhl.cms.net.model.shop.ShopListEntity
class SearchContract {
interface View {
fun setSearchHistory()
fun setBestGoodsList(result: List<ShopListEntity>?)
}
interface Presenter {
fun getSearchHistory()
fun getBestGoodsList()
}
}
\ No newline at end of file
package com.zxbw.modulemain.presenter
import com.zxbw.modulemain.contract.SearchContract
class SearchPresenter : SearchContract.Presenter {
private val mView: SearchContract.View
constructor(mView: SearchContract.View) {
this.mView = mView
}
override fun getSearchHistory() {
mView.setSearchHistory()
}
override fun getBestGoodsList() {
// ApiClient.shopApi.getShopHotProducts()
// .compose(RxSchedulers.observableIO2Main())
// .subscribe(object : BaseObserver<List<ShopListEntity>>() {
// override fun onSuccess(result: List<ShopListEntity>?) {
// mView.setBestGoodsList(result)
// }
//
// override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// mView.setBestGoodsList(null)
// }
// })
}
}
\ No newline at end of file
package com.zxbw.modulemain.uitls;
import android.content.Context;
import android.content.SharedPreferences;
/**
* @author (wangXuewei)
* @datetime 2022-06-08 13:54 GMT+8
* @detail :
*/
public class SPUtils {
private static SharedPreferences sp;
private static SPUtils instance = new SPUtils();
public static Context mContext;
/**
* 保存在手机里面的文件名
*/
public static final String FILE_NAME = "UserShop";
public static final String FILE_SEARCH = "search_history";
private SPUtils() {
}
/**
* xxx改为你想保存的sp文件名称
*/
public static SPUtils getInstance(Context context) {
mContext = context;
if (sp == null) {
sp = context.getApplicationContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
}
return instance;
}
/**
* 保存数据
*/
public void put(String key, Object value) {
if (value instanceof Integer) {
sp.edit().putInt(key, (Integer) value).apply();
} else if (value instanceof String) {
sp.edit().putString(key, (String) value).apply();
} else if (value instanceof Boolean) {
sp.edit().putBoolean(key, (Boolean) value).apply();
} else if (value instanceof Float) {
sp.edit().putFloat(key, (Float) value).apply();
} else if (value instanceof Long) {
sp.edit().putLong(key, (Long) value).apply();
}
}
/**
* 2. 读取数据
*/
public int getInt(String key, int defValue) {
return sp.getInt(key, defValue);
}
public String getString(String key, String defValue) {
return sp.getString(key, defValue);
}
public boolean getBoolean(String key, boolean defValue) {
return sp.getBoolean(key, defValue);
}
/**
* 读取数据
*
* @param key
* @param defValue
* @return
*/
public <T> T get(String key, T defValue) {
T t = null;
if (defValue instanceof String || defValue == null) {
String value = sp.getString(key, (String) defValue);
t = (T) value;
} else if (defValue instanceof Integer) {
Integer value = sp.getInt(key, (Integer) defValue);
t = (T) value;
} else if (defValue instanceof Boolean) {
Boolean value = sp.getBoolean(key, (Boolean) defValue);
t = (T) value;
} else if (defValue instanceof Float) {
Float value = sp.getFloat(key, (Float) defValue);
t = (T) value;
}
return t;
}
/**
* 保存搜索记录
*
* @param keyword
*/
public void saveHistory(String keyword) {
// 获取搜索框信息
SharedPreferences mysp = mContext.getSharedPreferences(FILE_SEARCH, 0);
String old_text = mysp.getString("history", "");
// 利用StringBuilder.append新增内容,逗号便于读取内容时用逗号拆分开
StringBuilder builder = new StringBuilder(old_text);
builder.append(keyword + ",");
// 判断搜索内容是否已经存在于历史文件,已存在则不重复添加
if (!old_text.contains(keyword + ",")) {
SharedPreferences.Editor myeditor = mysp.edit();
myeditor.putString("history", builder.toString());
myeditor.commit();
}
}
public String[] getHistoryList() {
// 获取搜索记录文件内容
SharedPreferences sp = mContext.getSharedPreferences(FILE_SEARCH, 0);
String history = sp.getString("history", "");
// 用逗号分割内容返回数组
String[] history_arr = history.split(",");
// 保留前50条数据
if (history_arr.length > 50) {
String[] newArrays = new String[50];
System.arraycopy(history_arr, 0, newArrays, 0, 50);
}
return history_arr;
}
/**
* 清除搜索记录
*/
public void cleanHistory() {
SharedPreferences sp = mContext.getSharedPreferences(FILE_SEARCH, 0);
SharedPreferences.Editor editor = sp.edit();
editor.clear();
editor.commit();
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="1dp" />
<solid android:color="#7477F5" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<solid android:color="@color/white" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="@color/white" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/id_sys_bar_view"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="5dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/img_search_bg" />
<LinearLayout
android:id="@+id/id_ll_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/id_sys_bar_view"
android:layout_marginLeft="6dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/id_img_back_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="@drawable/box_result_detail_back_icon" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="@drawable/shape_white_r20"
android:gravity="center_vertical|right"
android:orientation="horizontal"
android:paddingLeft="12dp"
android:paddingRight="2dp">
<EditText
android:id="@+id/id_edt_input_value"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:hint="请输入要搜索的商品"
android:imeOptions="actionSearch"
android:maxLength="50"
android:singleLine="true"
android:textCursorDrawable="@drawable/cursor_color2" />
<ImageView
android:id="@+id/id_search_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_sousuo" />
</LinearLayout>
</LinearLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/id_ll_search"
android:background="@drawable/shape_white_r10_half">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/id_tv_title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="历史搜索"
android:textColor="@color/color_333333"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/id_img_clean_history"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:padding="10dp"
android:src="@drawable/icon_qingchu_lishi" />
<com.zxbw.modulemain.view.ZFlowLayout
android:id="@+id/id_search_history_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/id_tv_title1"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp" />
<TextView
android:id="@+id/id_tv_title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/id_search_history_view"
android:layout_margin="16dp"
android:text="热门商品"
android:textColor="@color/color_333333"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/id_rck_goods_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/id_tv_title2"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:visibility="gone" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
\ No newline at end of file
......@@ -71,8 +71,7 @@
android:layout_below="@+id/id_title_sys_bar_view"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/shape_ffffff_r20"
android:visibility="gone">
android:background="@drawable/shape_ffffff_r20">
<TextView
android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_tv_search_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/shape_f5f6f7_r21"
android:paddingLeft="9dp"
android:paddingTop="3dp"
android:paddingRight="9dp"
android:paddingBottom="3dp"
android:text="背心夏宽松复古"
android:textColor="@color/color_999999"
android:textSize="14sp" />
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_tv_search_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment