Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
X
xxsq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王雪伟
xxsq
Commits
5a5aa459
Commit
5a5aa459
authored
Jun 17, 2022
by
王雪伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[提交人]:王雪伟
[提交简述] :1.1.1 [实现方案] :
parent
e872b1a6
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
1034 additions
and
3 deletions
+1034
-3
NetConfig.java
cms/src/main/java/com/zxhl/cms/common/NetConfig.java
+1
-1
SearchActivity.kt
.../main/java/com/zxbw/modulemain/activity/SearchActivity.kt
+224
-0
SearchGoodsTopAdapter.kt
...java/com/zxbw/modulemain/adapter/SearchGoodsTopAdapter.kt
+104
-0
SearchContract.kt
.../main/java/com/zxbw/modulemain/contract/SearchContract.kt
+18
-0
SearchPresenter.kt
...ain/java/com/zxbw/modulemain/presenter/SearchPresenter.kt
+31
-0
SPUtils.java
...Main/src/main/java/com/zxbw/modulemain/uitls/SPUtils.java
+137
-0
ZFlowLayout.java
...n/src/main/java/com/zxbw/modulemain/view/ZFlowLayout.java
+342
-0
box_result_detail_back_icon.png
...c/main/res/drawable-xhdpi/box_result_detail_back_icon.png
+0
-0
icon_qingchu_lishi.png
...leMain/src/main/res/drawable-xhdpi/icon_qingchu_lishi.png
+0
-0
icon_sousuo.png
moduleMain/src/main/res/drawable-xhdpi/icon_sousuo.png
+0
-0
icon_xialajiantou.png
moduleMain/src/main/res/drawable-xhdpi/icon_xialajiantou.png
+0
-0
img_search_bg.png
moduleMain/src/main/res/drawable-xhdpi/img_search_bg.png
+0
-0
cursor_color2.xml
moduleMain/src/main/res/drawable/cursor_color2.xml
+6
-0
shape_white_r10_half.xml
moduleMain/src/main/res/drawable/shape_white_r10_half.xml
+11
-0
shape_white_r20.xml
moduleMain/src/main/res/drawable/shape_white_r20.xml
+9
-0
activity_layout_search.xml
moduleMain/src/main/res/layout/activity_layout_search.xml
+131
-0
fragment_layout_home.xml
moduleMain/src/main/res/layout/fragment_layout_home.xml
+1
-2
item_view_search_history.xml
moduleMain/src/main/res/layout/item_view_search_history.xml
+14
-0
item_view_search_history_btn_img.xml
.../src/main/res/layout/item_view_search_history_btn_img.xml
+5
-0
No files found.
cms/src/main/java/com/zxhl/cms/common/NetConfig.java
View file @
5a5aa459
...
@@ -21,7 +21,7 @@ public class NetConfig {
...
@@ -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_WEB_URL
=
""
;
public
static
String
BASE_URL
=
""
;
public
static
String
BASE_URL
=
""
;
public
static
String
BASE_NEW_URL
=
""
;
public
static
String
BASE_NEW_URL
=
""
;
...
...
moduleMain/src/main/java/com/zxbw/modulemain/activity/SearchActivity.kt
0 → 100644
View file @
5a5aa459
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
moduleMain/src/main/java/com/zxbw/modulemain/adapter/SearchGoodsTopAdapter.kt
0 → 100644
View file @
5a5aa459
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
moduleMain/src/main/java/com/zxbw/modulemain/contract/SearchContract.kt
0 → 100644
View file @
5a5aa459
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
moduleMain/src/main/java/com/zxbw/modulemain/presenter/SearchPresenter.kt
0 → 100644
View file @
5a5aa459
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
moduleMain/src/main/java/com/zxbw/modulemain/uitls/SPUtils.java
0 → 100644
View file @
5a5aa459
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
();
}
}
moduleMain/src/main/java/com/zxbw/modulemain/view/ZFlowLayout.java
0 → 100644
View file @
5a5aa459
package
com
.
zxbw
.
modulemain
.
view
;
import
android.content.Context
;
import
android.util.AttributeSet
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.TextView
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 实现流式布局,自定义ViewGroup,实现标签等 - 单行垂直居中 或 水平平分
* <p>
* 可以设置展开和收起按钮
*/
public
class
ZFlowLayout
extends
ViewGroup
{
/**
* 存储每一行的剩余的空间
*/
private
List
<
Integer
>
lineSpaces
=
new
ArrayList
<>();
/**
* 存储每一行的高度
*/
private
List
<
Integer
>
lineHeights
=
new
ArrayList
<>();
/**
* 存储每一行的view
*/
private
List
<
List
<
View
>>
lineViews
=
new
ArrayList
<>();
/**
* 提供添加view
*/
private
List
<
View
>
children
=
new
ArrayList
<>();
/**
* 每一行是否平分空间
*/
private
boolean
isAverageInRow
=
false
;
/**
* 每一列是否垂直居中
*/
private
boolean
isAverageInColumn
=
true
;
private
int
mLineCount
=
0
;
//行数
private
int
mTwoLineViewCount
=
0
;
//前两行里面view的个数
//展开是最多显示几行
private
int
mExpandLineCount
=
5
;
//展开时显示view的个数
private
int
mExpandLineViewCount
=
0
;
public
ZFlowLayout
(
Context
context
)
{
super
(
context
);
}
public
ZFlowLayout
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
}
public
ZFlowLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
}
public
int
getLineCount
()
{
return
mLineCount
;
}
public
int
getTwoLineViewCount
()
{
return
mTwoLineViewCount
;
}
public
int
getExpandLineViewCount
()
{
return
mExpandLineViewCount
;
}
/**
* 设置是否每列垂直居中
*
* @param averageInColumn 是否垂直居中
*/
public
void
setAverageInColumn
(
boolean
averageInColumn
)
{
if
(
isAverageInColumn
!=
averageInColumn
)
{
isAverageInColumn
=
averageInColumn
;
requestLayout
();
}
}
/**
* 设置是否每一行居中
*
* @param averageInRow 是否水平平分
*/
public
void
setAverageInRow
(
boolean
averageInRow
)
{
if
(
isAverageInRow
!=
averageInRow
)
{
isAverageInRow
=
averageInRow
;
requestLayout
();
}
}
/**
* 动态添加view
*/
public
void
setChildren
(
List
<
View
>
children
)
{
if
(
children
==
null
)
return
;
this
.
children
=
children
;
mLineCount
=
0
;
mTwoLineViewCount
=
0
;
mExpandLineViewCount
=
0
;
this
.
removeAllViews
();
for
(
int
i
=
0
;
i
<
children
.
size
();
i
++)
{
this
.
addView
(
children
.
get
(
i
));
if
(
children
.
get
(
i
)
instanceof
TextView
)
{
int
finalI
=
i
;
children
.
get
(
i
).
setOnClickListener
(
v
->
{
if
(
mOnTagClickListener
!=
null
)
{
mOnTagClickListener
.
onTagClick
(
children
.
get
(
finalI
),
finalI
);
}
});
}
}
}
/**
* 重新方法用来获取子view的margin值
*/
@Override
public
LayoutParams
generateLayoutParams
(
AttributeSet
attrs
)
{
return
new
MarginLayoutParams
(
getContext
(),
attrs
);
}
@Override
protected
void
onMeasure
(
int
widthMeasureSpec
,
int
heightMeasureSpec
)
{
//清除记录数据
lineSpaces
.
clear
();
lineHeights
.
clear
();
lineViews
.
clear
();
//测量view的宽高
int
widthMode
=
MeasureSpec
.
getMode
(
widthMeasureSpec
);
int
viewWidth
=
MeasureSpec
.
getSize
(
widthMeasureSpec
);
int
heightMode
=
MeasureSpec
.
getMode
(
heightMeasureSpec
);
int
viewHeight
=
MeasureSpec
.
getSize
(
heightMeasureSpec
);
//计算children的数量
int
count
=
this
.
getChildCount
();
//统计子view总共高度
int
childrenTotalHeight
=
0
;
//一行中剩余的空间
int
lineLeftSpace
=
0
;
int
lineRealWidth
=
0
;
int
lineRealHeight
=
0
;
List
<
View
>
list
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
View
child
=
getChildAt
(
i
);
//不可见的View不作处理
if
(
child
.
getVisibility
()
==
GONE
)
continue
;
//对子view进行测量
measureChild
(
child
,
widthMeasureSpec
,
heightMeasureSpec
);
//获取子view的间距
MarginLayoutParams
params
=
(
MarginLayoutParams
)
child
.
getLayoutParams
();
//获取view占据的空间大小
int
childViewWidth
=
child
.
getMeasuredWidth
()
+
params
.
leftMargin
+
params
.
rightMargin
;
int
childViewHeight
=
child
.
getMeasuredHeight
()
+
params
.
topMargin
+
params
.
bottomMargin
;
// System.out.println("111111111 视图 " + " 子View宽度: " + childViewWidth + " lineRealWidth:" + lineRealWidth + " lineRealHeight :" + lineRealHeight);
if
(
childViewWidth
+
lineRealWidth
<=
viewWidth
)
{
// 一行
//已占用的空间
lineRealWidth
+=
childViewWidth
;
//剩余的空间
lineLeftSpace
=
viewWidth
-
lineRealWidth
;
//一行的最大高度
lineRealHeight
=
Math
.
max
(
lineRealHeight
,
childViewHeight
);
//将一行中的view加到同意个集合
list
.
add
(
child
);
}
else
{
// 下一行
if
(
list
.
size
()
!=
0
)
{
// 统计上一行的总高度
childrenTotalHeight
+=
lineRealHeight
;
//上一行的高度
lineHeights
.
add
(
lineRealHeight
);
//上一行剩余的空间
lineSpaces
.
add
(
lineLeftSpace
);
//将上一行的元素保存起来
lineViews
.
add
(
list
);
}
//重置一行中已占用的空间
lineRealWidth
=
childViewWidth
;
//重置一行中剩余的空间
lineLeftSpace
=
viewWidth
-
lineRealWidth
;
//重置一行中的高度
lineRealHeight
=
childViewHeight
;
//更换新的集合存储下一行的元素
list
=
new
ArrayList
<>();
list
.
add
(
child
);
}
if
(
i
==
count
-
1
)
{
// 最后一个元素
childrenTotalHeight
+=
lineRealHeight
;
// 将最后一行的信息保存下来
lineViews
.
add
(
list
);
lineHeights
.
add
(
lineRealHeight
);
lineSpaces
.
add
(
lineLeftSpace
);
}
}
// 宽度可以不用考虑 主要考虑高度
if
(
heightMode
==
MeasureSpec
.
EXACTLY
)
{
setMeasuredDimension
(
viewWidth
,
viewHeight
);
}
else
{
setMeasuredDimension
(
viewWidth
,
childrenTotalHeight
);
}
}
@Override
protected
void
onLayout
(
boolean
changed
,
int
l
,
int
t
,
int
r
,
int
b
)
{
// View最开始左边
int
viewLeft
=
0
;
// View最开始上边
int
viewTop
=
0
;
// 每一个view layout的位置
int
vl
;
int
vt
;
int
vr
;
int
vb
;
// 每一行中每一个view多平分的空间
float
averageInRow
;
// 每一列中每一个view距离顶部的高度
float
averageInColumn
;
// 列数
int
columns
=
lineViews
.
size
();
mLineCount
=
columns
;
for
(
int
i
=
0
;
i
<
columns
;
i
++)
{
// 该行剩余的空间
int
lineSpace
=
lineSpaces
.
get
(
i
);
// 该行的高度
int
lineHeight
=
lineHeights
.
get
(
i
);
// 该行的所有元素
List
<
View
>
list
=
lineViews
.
get
(
i
);
// 每一行的view的个数
int
rows
=
list
.
size
();
if
(
i
==
0
||
i
==
1
)
{
mTwoLineViewCount
=
mTwoLineViewCount
+
rows
;
}
if
(
i
<
mExpandLineCount
)
{
mExpandLineViewCount
=
mExpandLineViewCount
+
rows
;
}
// view layout的位置
// 每一行中每一个view多平分的空间<一行只有一个不管>
if
(
isAverageInRow
&&
rows
>
1
)
{
averageInRow
=
lineSpace
*
1.0f
/
(
rows
+
1
);
}
else
{
averageInRow
=
0
;
}
// 获取View的间距属性
MarginLayoutParams
params
;
for
(
int
j
=
0
;
j
<
rows
;
j
++)
{
// 对应位置的view元素
View
child
=
list
.
get
(
j
);
params
=
(
MarginLayoutParams
)
child
.
getLayoutParams
();
// 是否计算每一列中的元素垂直居中的时候多出的距离
if
(
isAverageInColumn
&&
rows
>
1
)
{
averageInColumn
=
(
lineHeight
-
child
.
getMeasuredHeight
()
-
params
.
topMargin
-
params
.
bottomMargin
)
/
2
;
}
else
{
averageInColumn
=
0
;
}
// 左边位置 =起始位置+view左间距+多平分的空间
vl
=
(
int
)
(
viewLeft
+
params
.
leftMargin
+
averageInRow
);
// 上面的位置 = 起始位置+view上间距+多平分的空间
vt
=
(
int
)
(
viewTop
+
params
.
topMargin
+
averageInColumn
);
vr
=
vl
+
child
.
getMeasuredWidth
();
vb
=
vt
+
child
.
getMeasuredHeight
();
child
.
layout
(
vl
,
vt
,
vr
,
vb
);
viewLeft
+=
child
.
getMeasuredWidth
()
+
params
.
leftMargin
+
params
.
rightMargin
+
averageInRow
;
}
viewLeft
=
0
;
viewTop
+=
lineHeight
;
}
}
private
OnTagClickListener
mOnTagClickListener
;
public
void
setOnTagClickListener
(
OnTagClickListener
onTagClickListener
)
{
mOnTagClickListener
=
onTagClickListener
;
}
public
interface
OnTagClickListener
{
void
onTagClick
(
View
view
,
int
position
);
}
}
moduleMain/src/main/res/drawable-xhdpi/box_result_detail_back_icon.png
0 → 100644
View file @
5a5aa459
401 Bytes
moduleMain/src/main/res/drawable-xhdpi/icon_qingchu_lishi.png
0 → 100644
View file @
5a5aa459
409 Bytes
moduleMain/src/main/res/drawable-xhdpi/icon_sousuo.png
0 → 100644
View file @
5a5aa459
3.39 KB
moduleMain/src/main/res/drawable-xhdpi/icon_xialajiantou.png
0 → 100644
View file @
5a5aa459
1.34 KB
moduleMain/src/main/res/drawable-xhdpi/img_search_bg.png
0 → 100644
View file @
5a5aa459
9.26 KB
moduleMain/src/main/res/drawable/cursor_color2.xml
0 → 100644
View file @
5a5aa459
<?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
moduleMain/src/main/res/drawable/shape_white_r10_half.xml
0 → 100644
View file @
5a5aa459
<?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
moduleMain/src/main/res/drawable/shape_white_r20.xml
0 → 100644
View file @
5a5aa459
<?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
moduleMain/src/main/res/layout/activity_layout_search.xml
0 → 100644
View file @
5a5aa459
<?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
moduleMain/src/main/res/layout/fragment_layout_home.xml
View file @
5a5aa459
...
@@ -71,8 +71,7 @@
...
@@ -71,8 +71,7 @@
android:layout_below=
"@+id/id_title_sys_bar_view"
android:layout_below=
"@+id/id_title_sys_bar_view"
android:layout_marginLeft=
"15dp"
android:layout_marginLeft=
"15dp"
android:layout_marginRight=
"15dp"
android:layout_marginRight=
"15dp"
android:background=
"@drawable/shape_ffffff_r20"
android:background=
"@drawable/shape_ffffff_r20"
>
android:visibility=
"gone"
>
<TextView
<TextView
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
...
...
moduleMain/src/main/res/layout/item_view_search_history.xml
0 → 100644
View file @
5a5aa459
<?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"
/>
moduleMain/src/main/res/layout/item_view_search_history_btn_img.xml
0 → 100644
View file @
5a5aa459
<?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"
/>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment