完成分享对话框动态添加的功能,待接入服务端
This commit is contained in:
@@ -6,4 +6,4 @@ import com.mogo.module.share.R
|
||||
* 可配置按钮封装
|
||||
* @author tongchenfei
|
||||
*/
|
||||
data class FixableButton(val id:Int = 0,val iconUrl:String = "", val iconRes:Int = R.drawable.share_block_up, val content:String="拥堵")
|
||||
data class FixableButton(val id:Int = 0,val poiType:String = "10007",val iconUrl:String = "", val iconRes:Int = R.drawable.share_block_up, val content:String="拥堵")
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.module.share.dialog
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.GridLayout
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -65,7 +66,9 @@ class GridFixableShareDialog(context:Context):BaseFloatDialog(context) {
|
||||
Logger.d(TAG, "share btn click: $it")
|
||||
randomGenerateBtn()
|
||||
}
|
||||
randomGenerateBtn()
|
||||
findViewById<FrameLayout>(R.id.flShareDialogContainer).setOnClickListener { dismiss() }
|
||||
|
||||
gridBtnManager.showDefaultBtns()
|
||||
}
|
||||
|
||||
private fun randomGenerateBtn(){
|
||||
|
||||
@@ -9,23 +9,29 @@ import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.mogo.module.share.R
|
||||
import com.mogo.module.share.bean.FixableButton
|
||||
import com.mogo.service.tanlu.IMogoTanluProvider
|
||||
import com.mogo.utils.glide.GlideApp
|
||||
|
||||
/**
|
||||
* 用来管理生成对应的分享按钮
|
||||
*/
|
||||
class GridBtnManager(val context:Context,val container:GridLayout) {
|
||||
class GridBtnManager(val context: Context, val container: GridLayout) {
|
||||
private val inflater = LayoutInflater.from(context)
|
||||
|
||||
fun resetContainer(){
|
||||
fun resetContainer() {
|
||||
container.removeAllViews()
|
||||
}
|
||||
|
||||
fun generateShareButton(button: FixableButton): View {
|
||||
val view = inflater.inflate(R.layout.item_share_btn, container,false )
|
||||
val view = inflater.inflate(R.layout.item_share_btn, container, false)
|
||||
val img = view.findViewById<ImageView>(R.id.ivShareIcon)
|
||||
val content = view.findViewById<TextView>(R.id.tvShareContent)
|
||||
GlideApp.with(context).load(button.iconRes).into(img)
|
||||
// 优先加载url图片,然后加载资源图片
|
||||
if (button.iconUrl.isNotEmpty()) {
|
||||
GlideApp.with(context).load(button.iconUrl).centerInside().into(img)
|
||||
} else {
|
||||
GlideApp.with(context).load(button.iconRes).centerInside().into(img)
|
||||
}
|
||||
content.text = button.content
|
||||
view.setOnClickListener {
|
||||
btnClickListener?.invoke(button)
|
||||
@@ -34,7 +40,21 @@ class GridBtnManager(val context:Context,val container:GridLayout) {
|
||||
return view
|
||||
}
|
||||
|
||||
private var btnClickListener:((fixableButton:FixableButton)->Unit)? =null
|
||||
fun showDefaultBtns() {
|
||||
resetContainer()
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_BLOCK, iconRes = R.drawable.share_block_up, content = "拥堵"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_TRAFFIC_CHECK, iconRes = R.drawable.share_traffic_check, content = "交通检查"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_CLOSURE, iconRes = R.drawable.share_road_closure, content = "封路"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_ACCIDENT, iconRes = R.drawable.share_accident, content = "事故"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_ROAD_CONSTRUCTION, iconRes = R.drawable.share_road_construction, content = "道路施工"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_REAL_TIME_TRAFFIC, iconRes = R.drawable.share_real_time_traffic, content = "实时路况"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_SEEK_HELP, iconRes = R.drawable.share_seek_help, content = "故障求助"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_STAGNANT_WATER, iconRes = R.drawable.share_stagnant_water, content = "道路积水"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_ROAD_ICY, iconRes = R.drawable.share_road_icy, content = "道路结冰"))
|
||||
generateShareButton(FixableButton(poiType = IMogoTanluProvider.TYPE_DENSE_FOG, iconRes = R.drawable.share_dense_fog, content = "浓雾"))
|
||||
}
|
||||
|
||||
private var btnClickListener: ((fixableButton: FixableButton) -> Unit)? = null
|
||||
fun setShareClickListener(listener: ((fixableButton: FixableButton) -> Unit)) {
|
||||
btnClickListener = listener
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user